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
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCurrentParamsToStatement
(PreparedStatement statement) void
protected void
addParamsToStatement
(PreparedStatement statement, Map<String, Object> params) protected void
void
clearSql()
Clears the current SQL query being built.void
clearSql
(boolean keepCurrentBoundParams) Clears the current SQL query being built.protected void
close
(PreparedStatement statement) Closes statement quietlyprotected void
Closes resultSet quietlyprotected void
copyParamsAndStaticTokensTo
(Statement newStm) protected Connection
protected String
protected String
protected StringBuilder
getSql
(boolean friendly) Returns the current SQL query.protected BasicFormatterImpl
protected String
parse()
void
setBoolean
(String paramName, Boolean value) void
void
void
void
setInInteger
(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 sectionvoid
Explodes a collection of Long and replaces the specified param with them, so it can be used inside a <codeIN(:ids)</code sectionvoid
setInstant
(String paramName, Instant value) This replaces setTimestamp()!void
setInString
(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.void
setInStringFromEnumNames
(String paramName, Enum<?>... enumItems) Uses a list of enum names so it can be used inside aIN(:ids)
section.void
setInStringFromEnumNames
(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.void
setInteger
(String paramName, Integer value) void
void
setLongList
(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.id
protected void
protected void
setStaticTokens
(Map<String, String> tokens) void
void
Appends some SQL to the query to launch.toString()
-
Constructor Details
-
StatementBase
-
-
Method Details
-
getQueryBuilder
-
getSqlFormmatter
-
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 callStatement.clearSql()
first! -
clearSql
public void clearSql()Description copied from interface:Statement
Clears the current SQL query being built. Also removes any bound parameters. -
clearSql
public void clearSql(boolean keepCurrentBoundParams) Description copied from interface:Statement
Clears the current SQL query being built. -
getSql
Description copied from interface:Statement
Returns 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:Statement
This replaces setTimestamp()!- Specified by:
setInstant
in interfaceStatement
-
setDate
-
setString
-
setBoolean
- Specified by:
setBoolean
in interfaceStatement
-
setInteger
- Specified by:
setInteger
in interfaceStatement
-
setLong
-
setFloat
-
setDouble
-
setInLong
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 -
setInInteger
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 interfaceStatement
-
setInString
Description copied from interface:Statement
Explodes a collection of String and replaces the specified param with them, so it can be used inside aIN(:ids)
section.- Specified by:
setInString
in interfaceStatement
-
setInStringFromEnumNames
Description copied from interface:Statement
Explodes a collection of enum names and replaces the specified param with them, so it can be used inside aIN(:ids)
section.- Specified by:
setInStringFromEnumNames
in interfaceStatement
-
setInStringFromEnumNames
Description copied from interface:Statement
Uses a list of enum names so it can be used inside aIN(:ids)
section.- Specified by:
setInStringFromEnumNames
in interfaceStatement
-
setLongList
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 interfaceStatement
-
toString
-