Class StatementBase

java.lang.Object
org.spincast.plugins.jdbc.statements.StatementBase
All Implemented Interfaces:
Statement
Direct Known Subclasses:
BatchInsertStatementDefault, DeleteStatementDefault, InsertStatementDefault, SelectStatementDefault, UpdateStatementDefault

public abstract class StatementBase extends Object implements Statement
If the connection's Connection.getAutoCommit() is true/code>, the connection will be automatically closed. If you want to prevent this, you can use the disableCloseConnection parameter... You can then reuse the connection, but it's up to you to close it when you're done.

Some code based on :

Author:
adam_crume http://www.javaworld.com/article/2077706/core-java/named-parameters-for-preparedstatement.html
  • Constructor Details

    • StatementBase

      public StatementBase(Connection connection)
  • Method Details

    • getQueryBuilder

      protected StringBuilder getQueryBuilder()
    • getSqlFormmatter

      protected BasicFormatterImpl getSqlFormmatter()
    • sql

      public void sql(String sql)
      Description copied from interface: Statement
      Appends some SQL to the query to launch. If you want to restart the query from scratch, you need to call Statement.clearSql() first!
      Specified by:
      sql in interface Statement
    • clearSql

      public void clearSql()
      Description copied from interface: Statement
      Clears the current SQL query being built. Also removes any bound parameters.
      Specified by:
      clearSql in interface Statement
    • clearSql

      public void clearSql(boolean keepCurrentBoundParams)
      Description copied from interface: Statement
      Clears the current SQL query being built.
      Specified by:
      clearSql in interface Statement
      Parameters:
      keepCurrentBoundParams - if true, the currently bound parameters won't be cleared, only the query.
    • getSql

      public String getSql(boolean friendly)
      Description copied from interface: Statement
      Returns the current SQL query.
      Specified by:
      getSql in interface Statement
    • getOriginalQuery

      protected String getOriginalQuery()
    • getParsedQuery

      protected String getParsedQuery()
    • getParams

      protected Map<String,Object> getParams()
    • setParams

      protected void setParams(Map<String,Object> params)
    • getStaticTokens

      protected Map<String,String> getStaticTokens()
    • setStaticTokens

      protected void setStaticTokens(Map<String,String> tokens)
    • copyParamsAndStaticTokensTo

      protected void copyParamsAndStaticTokensTo(Statement newStm)
    • parse

      protected String parse()
    • clearParams

      protected void clearParams()
    • getIndexMap

      protected Map<String,Set<Integer>> getIndexMap()
    • getConnection

      protected Connection getConnection()
    • addCurrentParamsToStatement

      protected void addCurrentParamsToStatement(PreparedStatement statement)
    • addParamsToStatement

      protected void addParamsToStatement(PreparedStatement statement, Map<String,Object> params)
    • close

      protected void close(PreparedStatement statement)
      Closes statement quietly
    • close

      protected void close(ResultSet resultSet)
      Closes resultSet quietly
    • addParam

      public void addParam(String paramName, Object value)
    • setInstant

      public void setInstant(String paramName, Instant value)
      Description copied from interface: Statement
      This replaces setTimestamp()!
      Specified by:
      setInstant in interface Statement
    • setDate

      public void setDate(String paramName, LocalDate value)
      Specified by:
      setDate in interface Statement
    • setString

      public void setString(String paramName, String value)
      Specified by:
      setString in interface Statement
    • setBoolean

      public void setBoolean(String paramName, Boolean value)
      Specified by:
      setBoolean in interface Statement
    • setInteger

      public void setInteger(String paramName, Integer value)
      Specified by:
      setInteger in interface Statement
    • setLong

      public void setLong(String paramName, Long value)
      Specified by:
      setLong in interface Statement
    • setFloat

      public void setFloat(String paramName, Float value)
      Specified by:
      setFloat in interface Statement
    • setDouble

      public void setDouble(String paramName, Double value)
      Specified by:
      setDouble in interface Statement
    • setInLong

      public void setInLong(String paramName, Set<Long> items)
      Description copied from interface: Statement
      Explodes a collection of Long and replaces the specified param with them, so it can be used inside a <codeIN(:ids)</code section
      Specified by:
      setInLong in interface Statement
    • setInInteger

      public void setInInteger(String paramName, Set<Integer> items)
      Description copied from interface: Statement
      Explodes a collection of Integer and replaces the specified param with them, so it can be used inside a <codeIN(:ids)</code section
      Specified by:
      setInInteger in interface Statement
    • setInString

      public void setInString(String paramName, Set<String> items)
      Description copied from interface: Statement
      Explodes a collection of String and replaces the specified param with them, so it can be used inside a IN(:ids) section.
      Specified by:
      setInString in interface Statement
    • setInStringFromEnumNames

      public void setInStringFromEnumNames(String paramName, Set<? extends Enum<?>> enumItems)
      Description copied from interface: Statement
      Explodes a collection of enum names and replaces the specified param with them, so it can be used inside a IN(:ids) section.
      Specified by:
      setInStringFromEnumNames in interface Statement
    • setInStringFromEnumNames

      public void setInStringFromEnumNames(String paramName, Enum<?>... enumItems)
      Description copied from interface: Statement
      Uses a list of enum names so it can be used inside a IN(:ids) section.
      Specified by:
      setInStringFromEnumNames in interface Statement
    • setLongList

      public void setLongList(String paramName, List<Long> items)
      Description copied from interface: Statement
      Explodes a list of Long and replaces the specified param with them, so it can be used to replace a "ids list" inside a (PostgreSQL example): INNER JOIN UNNEST('{:idsList}'::int[]) WITH ORDINALITY o(id, ord) ON o.id = myMainTable.id

      This allows to retrieve a list of rows, using ids, *in the order the ids are specified*.

      Specified by:
      setLongList in interface Statement
    • toString

      public String toString()
      Overrides:
      toString in class Object