Class StatementBase
java.lang.Object
org.spincast.plugins.jdbc.statements.StatementBase
- All Implemented Interfaces:
Statement
- Direct Known Subclasses:
BatchInsertStatementDefault,DeleteStatementDefault,InsertStatementDefault,SelectStatementDefault,UpdateStatementDefault
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCurrentParamsToStatement(PreparedStatement statement) voidprotected voidaddParamsToStatement(PreparedStatement statement, Map<String, Object> params) protected voidvoidclearSql()Clears the current SQL query being built.voidclearSql(boolean keepCurrentBoundParams) Clears the current SQL query being built.protected voidclose(PreparedStatement statement) Closes statement quietlyprotected voidCloses resultSet quietlyprotected voidcopyParamsAndStaticTokensTo(Statement newStm) protected Connectionprotected Stringprotected Stringprotected StringBuildergetSql(boolean friendly) Returns the current SQL query.protected BasicFormatterImplprotected Stringparse()voidsetBoolean(String paramName, Boolean value) voidvoidvoidvoidsetInInteger(String paramName, Set<Integer> items) Explodes a collection of Integer and replaces the specified param with them, so it can be used inside a <codeIN(:ids)</code sectionvoidExplodes a collection of Long and replaces the specified param with them, so it can be used inside a <codeIN(:ids)</code sectionvoidsetInstant(String paramName, Instant value) This replaces setTimestamp()!voidsetInString(String paramName, Set<String> items) Explodes a collection of String and replaces the specified param with them, so it can be used inside aIN(:ids)section.voidsetInStringFromEnumNames(String paramName, Enum<?>... enumItems) Uses a list of enum names so it can be used inside aIN(:ids)section.voidsetInStringFromEnumNames(String paramName, Set<? extends Enum<?>> enumItems) Explodes a collection of enum names and replaces the specified param with them, so it can be used inside aIN(:ids)section.voidsetInteger(String paramName, Integer value) voidvoidsetLongList(String paramName, List<Long> items) 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.idprotected voidprotected voidsetStaticTokens(Map<String, String> tokens) voidvoidAppends some SQL to the query to launch.toString()
-
Constructor Details
-
StatementBase
-
-
Method Details
-
getQueryBuilder
-
getSqlFormmatter
-
sql
Description copied from interface:StatementAppends some SQL to the query to launch. If you want to restart the query from scratch, you need to callStatement.clearSql()first! -
clearSql
public void clearSql()Description copied from interface:StatementClears the current SQL query being built. Also removes any bound parameters. -
clearSql
public void clearSql(boolean keepCurrentBoundParams) Description copied from interface:StatementClears the current SQL query being built. -
getSql
Description copied from interface:StatementReturns the current SQL query. -
getOriginalQuery
-
getParsedQuery
-
getParams
-
setParams
-
getStaticTokens
-
setStaticTokens
-
copyParamsAndStaticTokensTo
-
parse
-
clearParams
protected void clearParams() -
getIndexMap
-
getConnection
-
addCurrentParamsToStatement
-
addParamsToStatement
-
close
Closes statement quietly -
close
Closes resultSet quietly -
addParam
-
setInstant
Description copied from interface:StatementThis replaces setTimestamp()!- Specified by:
setInstantin interfaceStatement
-
setDate
-
setString
-
setBoolean
- Specified by:
setBooleanin interfaceStatement
-
setInteger
- Specified by:
setIntegerin interfaceStatement
-
setLong
-
setFloat
-
setDouble
-
setInLong
Description copied from interface:StatementExplodes a collection of Long and replaces the specified param with them, so it can be used inside a <codeIN(:ids)</code section -
setInInteger
Description copied from interface:StatementExplodes a collection of Integer and replaces the specified param with them, so it can be used inside a <codeIN(:ids)</code section- Specified by:
setInIntegerin interfaceStatement
-
setInString
Description copied from interface:StatementExplodes a collection of String and replaces the specified param with them, so it can be used inside aIN(:ids)section.- Specified by:
setInStringin interfaceStatement
-
setInStringFromEnumNames
Description copied from interface:StatementExplodes a collection of enum names and replaces the specified param with them, so it can be used inside aIN(:ids)section.- Specified by:
setInStringFromEnumNamesin interfaceStatement
-
setInStringFromEnumNames
Description copied from interface:StatementUses a list of enum names so it can be used inside aIN(:ids)section.- Specified by:
setInStringFromEnumNamesin interfaceStatement
-
setLongList
Description copied from interface:StatementExplodes 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.idThis allows to retrieve a list of rows, using ids, *in the order the ids are specified*.
- Specified by:
setLongListin interfaceStatement
-
toString
-