Package overit.geocall.sql
Class StandardDBStatement
java.lang.Object
overit.geocall.sql.StandardDBStatement
- All Implemented Interfaces:
AutoCloseable,DataAttributesHolder,DBFieldMapper,DBObjectMapper,DBStatement,CancelListener
@Component
@Scope("prototype")
public class StandardDBStatement
extends Object
implements DBStatement, DBFieldMapper, DBObjectMapper, CancelListener
The class is the standard implementation of the
DBStatement interface-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classprotected classprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionSet of explicitly setted parameters.protected List<StandardDBStatement.SqlPair> protected booleanprotected ArrayList<int[]> protected HashMapMap of pairs<variable,value>used for the definition of anyDBObjectMapassociated with some parameter of the statement.protected static Stringprotected DBFieldMapprotected intStores the maximum number of rows requested to a statement.protected DBObjectMapMap of pairs<variable,value>used to compile the statement.protected booleanprotected StandardDBStatement.Parsingprotected PooledConnectionThe connection of the statementprotected intprotected intStores the number of initial rows to be skippedprotected FragmentTemporary variable that define the SQL statement, as setted into the setSql methodprotected static StringDelimiter used for variables, ie the portions of SQL that come after a question mark.protected intDefine the permission when the result set is managed.Fields inherited from interface overit.geocall.sql.DBStatement
LOG, NULL_STRINGS_FOR_LIKE -
Constructor Summary
ConstructorsConstructorDescriptionCreates a statement starting from the connection -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBatch()Adds a set of parameters to the statement object's batch of commands.voidaddBatch(int batchSize) Adds a set of parameters to the statement object's batch of commands.voidcancel()Cancels this statement object.voidclose()Closes the SQL statementcreateCall(String call) Explicitly creates a PreparedStatement.voiddefine(String field, DBObjectMap dbom) Specifies aDBObjectMapthat must be used to load a column resulting from a SELECTvoiddefineParam(String field, DBObjectMap dbom) Explicitly specifies aDBObjectMapthat must be used to prepare the statement for a specific variable in the SQL string.int[]Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts.Translates the statement, compiles and execute itexecuteQuery(boolean roData) Deprecated.protected DBViewintTranslates the statement, compiles and execute itRetrieves theDBFieldMapobjectImplements theDBObjectMapperinterface.Returns theDBTypeassociated to thePooledConnectioncurrently in use.Executes the SQL query in this statement object and returns theResultSetobject generated by the queryreads the result set raw at the current position and construct a key-value map af all the fields according to the statement specificationReturns theStatementon which theDBStatementactsbooleanChecks the presence of aDBFieldMapobjectbooleanImplements theDBObjectMapperinterface.booleanReturnstruein case aSQL INSERTquery is in progress;falseotherwise.booleanReturnstruein case aSQL UPDATEquery is in progress;falseotherwise.protected voidout(StringBuilder sb, String s) protected voidprotected voidvoidextracts aDBCursorfrom the statement and submits it to an explicit scanning prcedurevoidSets the value of a variable ?voidSets the values of all the variables ?voidsetDataAttributes(List<DataAttribute> dataAttributes) Sets the provideddataAttributes.voidsetDBFieldMap(DBFieldMap fieldmap) Sets theDBFieldMapobjectvoidsetDBObjectMap(DBObjectMap objectmap) Implements theDBObjectMapperinterface.voidsetEdmRegistry(EDMRegistry edmRegistry) voidsetExtendedAttributeDatabaseAdapter(overit.geocall.edm.service.ExtendedAttributeDatabaseAdapter extendedAttributeDatabaseAdapter) voidsetExtendedAttributesAdapter(overit.geocall.edm.service.ExtendedAttributeAdapter extendedAttributeAdapter) voidsetMaxRows(int n) Sets the maximum number of rows to searchvoidsetQueryTimeout(int secs) Sets a time (in seconds) after which the query times outvoidsetResultSetToDBViewConverter(overit.geocall.sql.ResultSetToDBViewConverter resultSetToDBViewConverter) voidsetSkipRows(int n) Sets the number of initial rows to be skipped.voidSets the SQL string of the statement.voidSets the SQL Fragment of the statement.voidSets conditionally the SQL string of the statement.voidsetSqlIn(String sqlpart, String sqlkey, Collection values) Sets conditionally the SQL string of the statement.voidSets conditionally the SQL string of the statement.voidSets conditionally the SQL string of the statement.voidsetSqlOut(String sqlpart, String sqlkey, Collection values) Sets conditionally the SQL string of the statement.voidsetUpdatable(boolean updatable) Sets if theResultSetis updatableprotected static StringParses the string passed as parameter and and makes it suitable to be inserted in alikestatementMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface overit.geocall.edm.model.DataAttributesHolder
getEntities
-
Field Details
-
_delimiter
-
_variableDelimiter
Delimiter used for variables, ie the portions of SQL that come after a question mark. For these portions of code, the dot character is not considered a delimiter; in this way we can support variables composed by TABLE.FIELD -
_pc
The connection of the statement -
_alSqlParis
-
_pairs
Map of pairs<variable,value>used to compile the statement. This map must be appropriately filled with theset()method -
_definitions
Map of pairs<variable,value>used for the definition of anyDBObjectMapassociated with some parameter of the statement. This map must be appropriately filled with thedefine()method -
_alreadySetted
Set of explicitly setted parameters. It's useful for don't re-set unnecessarily the same arguments during the compilation of the statement -
_sql
Temporary variable that define the SQL statement, as setted into the setSql method -
_parsing
-
_maxRows
protected int _maxRowsStores the maximum number of rows requested to a statement. The default value is 0, that means that there isn't a limitation -
concurResultSet
protected int concurResultSetDefine the permission when the result set is managed. The default value is 1007, that means that the result set is only in read mode -
_skipRows
protected int _skipRowsStores the number of initial rows to be skipped -
_batched
protected boolean _batched -
_queryTimeout
protected int _queryTimeout -
_parameterWithReferences
protected boolean _parameterWithReferences -
_batchResults
-
_fieldmap
-
_objectmap
-
-
Constructor Details
-
StandardDBStatement
Creates a statement starting from the connection- Parameters:
pc- The connection that create the instance
-
-
Method Details
-
out
-
setResultSetToDBViewConverter
@Autowired public void setResultSetToDBViewConverter(overit.geocall.sql.ResultSetToDBViewConverter resultSetToDBViewConverter) -
setExtendedAttributesAdapter
@Autowired public void setExtendedAttributesAdapter(overit.geocall.edm.service.ExtendedAttributeAdapter extendedAttributeAdapter) -
setExtendedAttributeDatabaseAdapter
public void setExtendedAttributeDatabaseAdapter(overit.geocall.edm.service.ExtendedAttributeDatabaseAdapter extendedAttributeDatabaseAdapter) -
setEdmRegistry
-
setSql
Sets the SQL string of the statement.
The string contains variables like @field that can be properly converted in a DB field name or like ?value. Those must be different and must be expressly set by one of the methodset(map)orset(key,value)- Specified by:
setSqlin interfaceDBStatement- Parameters:
sqlpart- The SQL string
-
setSqlOn
Sets conditionally the SQL string of the statement.
The SQL string is inserted into the statement only if it will be setted to the statement (with one of the methodsset(map)orset(key,value)) a key that corresponds to the key passed as second parameter- Specified by:
setSqlOnin interfaceDBStatement- Parameters:
sqlpart- The SQL stringsqlkey- The key that must be setted to the statement
-
setSqlIn
Sets conditionally the SQL string of the statement.
The SQL string is inserted into the statement only if it will be setted to the statement with one of the methodsset(map)orset(key,value)) a key that corresponds to the key passed as second parameter and the object associated to the key is equal to one of the objects passed as third parameter- Specified by:
setSqlInin interfaceDBStatement- Parameters:
sqlpart- The SQL stringsqlkey- The key that must be setted to the statementvalues- The array of Objects used for comparison
-
setSqlIn
Sets conditionally the SQL string of the statement.
The SQL string is inserted into the statement only if it will be setted to the statement with one of the methodsset(map)orset(key,value)) a key that corresponds to the key passed as second parameter and the object associated to the key is different to all of the objects passed as third parameter- Specified by:
setSqlInin interfaceDBStatement- Parameters:
sqlpart- The SQL stringsqlkey- The key that must be setted to the statementvalues- The array of Objects used for comparison
-
setSqlOut
Description copied from interface:DBStatementSets conditionally the SQL string of the statement.
The SQL string is inserted into the statement only if it will be set to the statement with one of the methodsset(map)orset(key,value)) a key that corresponds to the key passed as second parameter and the object associated to the key is different to all of the objects passed as third parameter- Specified by:
setSqlOutin interfaceDBStatement- Parameters:
sqlpart- The SQL stringsqlkey- The key that must be set to the statementvalues- The array of Objects used for comparison
-
setSqlOut
Description copied from interface:DBStatementSets conditionally the SQL string of the statement.
The SQL string is inserted into the statement only if it will be set to the statement with one of the methodsset(map)orset(key,value)) a key that corresponds to the key passed as second parameter and the object associated to the key is different to all of the objects passed as third parameter- Specified by:
setSqlOutin interfaceDBStatement- Parameters:
sqlpart- The SQL stringsqlkey- The key that must be set to the statementvalues- The collection of Objects used for comparison
-
setSql
Description copied from interface:DBStatementSets the SQL Fragment of the statement.
The string contains variables like @field that can be properly converted in a DB field name or like ?value. Those must be different and must be expressly set by one of the methodset(map)orset(key,value)- Specified by:
setSqlin interfaceDBStatement- Parameters:
sql- The SQL Fragment
-
set
Sets the value of a variable ?value. With this method one value of an SQL statement is compiled. These value can be appropriately converted by a converter (like theDBObjectMap) before being passed to the DB- Specified by:
setin interfaceDBStatement- Parameters:
k- The name of the variable ?value in the SQL stringo- The value of the variable ?value in the SQL string
-
set
Sets the values of all the variables ?value. With this method all the values of an SQL statement are compiled. These values can be appropriately converted by a converter (like theDBObjectMap) before being passed to the DB- Specified by:
setin interfaceDBStatement- Parameters:
map- The map in which each entry defines the value of a variable ?value
-
define
Specifies aDBObjectMapthat must be used to load a column resulting from a SELECT- Specified by:
definein interfaceDBStatement- Parameters:
field- The name of the column of the ResultSet obtained from a querydbom- The object that can map every object in the column
-
defineParam
Explicitly specifies aDBObjectMapthat must be used to prepare the statement for a specific variable in the SQL string.- Specified by:
defineParamin interfaceDBStatement- Parameters:
field- The name of the variable in the SQL stringdbom- The object that can map every object specified for the variable
-
toInStatementString
Parses the string passed as parameter and and makes it suitable to be inserted in alikestatement- Parameters:
s- The string that must be inserted in alikestatement- Returns:
- The string correctly adapted to be inserted in a
likestatement
-
close
Closes the SQL statement- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceDBStatement- Throws:
SQLException- If the communication with the database throws an exception, that it is raised to the caller
-
registerKeys
- Throws:
SQLException
-
removeKeys
- Throws:
SQLException
-
executeUpdate
Translates the statement, compiles and execute it- Specified by:
executeUpdatein interfaceDBStatement- Returns:
- The number of the rows updated or inserted into the database
- Throws:
SQLException- If the communication with the database throws an exception, that it is raised to the caller
-
addBatch
Description copied from interface:DBStatementAdds a set of parameters to the statement object's batch of commands. SeeStatement.addBatch(String)- Specified by:
addBatchin interfaceDBStatement- Throws:
SQLException- If the communication with the database throws an exception, that it is raised to the caller
-
addBatch
Description copied from interface:DBStatementAdds a set of parameters to the statement object's batch of commands. SeeStatement.addBatch(String).- Specified by:
addBatchin interfaceDBStatement- Parameters:
batchSize- size of the batch (useful for executing the batch whenever the batch size reaches this value).- Throws:
SQLException- If the communication with the database throws an exception, that it is raised to the caller.
-
executeBatch
Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. SeeStatement.executeBatch()- Specified by:
executeBatchin interfaceDBStatement- Returns:
- An array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch
- Throws:
SQLException- If the communication with the database throws an exception, that it is raised to the caller
-
getResultSet
Executes the SQL query in this statement object and returns theResultSetobject generated by the query- Specified by:
getResultSetin interfaceDBStatement- Returns:
- The
ResultSetobject that contains the data produced by the query - Throws:
SQLException- If the communication with the database throws an exception, that it is raised to the caller
-
executeQuery
Translates the statement, compiles and execute it- Specified by:
executeQueryin interfaceDBStatement- Returns:
- The view resulting for the SQL query, totally kept in RAM
- Throws:
SQLException- If the communication with the database throws an exception, that it is raised to the caller
-
executeQuery
Deprecated.usedbStatement.executeQuery()ordbStatement.executeQuery().setRoData()insteadTranslates the statement, compiles and execute it.- Specified by:
executeQueryin interfaceDBStatement- Parameters:
roData- true if the result must be not modifiable, false otherwise. A value of true is the same as callingdbStatement.executeQuery().setRoData();- Returns:
- The DBView resulting for the SQL query, totally kept in RAM
- Throws:
SQLException- If the communication with the database throws an exception, that it is raised to the caller
-
executeQueryLoad
- Throws:
SQLException
-
getRowMapFromResultSet
Description copied from interface:DBStatementreads the result set raw at the current position and construct a key-value map af all the fields according to the statement specification- Specified by:
getRowMapFromResultSetin interfaceDBStatement- Parameters:
rs- the result set- Returns:
- the key-value map
- Throws:
SQLException- if some sql error happens in the record loading
-
scan
Description copied from interface:DBStatementextracts aDBCursorfrom the statement and submits it to an explicit scanning prcedure- Specified by:
scanin interfaceDBStatement- Parameters:
dbs- the scanning procedure- Throws:
SQLException- if some sql error happens in the scanning procedure
-
setMaxRows
public void setMaxRows(int n) Sets the maximum number of rows to search- Specified by:
setMaxRowsin interfaceDBStatement- Parameters:
n- Maximum number of rows
-
setUpdatable
public void setUpdatable(boolean updatable) Description copied from interface:DBStatementSets if theResultSetis updatable- Specified by:
setUpdatablein interfaceDBStatement- Parameters:
updatable- iftruetheResultSetis updatable, otherwisefalse
-
setSkipRows
public void setSkipRows(int n) Sets the number of initial rows to be skipped. Even these lines, although skipped, are counted in the maxrows parameter.- Specified by:
setSkipRowsin interfaceDBStatement- Parameters:
n- Number of rows to be skipped
-
setQueryTimeout
public void setQueryTimeout(int secs) Sets a time (in seconds) after which the query times out- Parameters:
secs- Number of seconds before the timeout
-
getDBFieldMap
Retrieves theDBFieldMapobject- Specified by:
getDBFieldMapin interfaceDBFieldMapper- Returns:
- The DBFieldMap object of the statement
-
setDBFieldMap
Sets theDBFieldMapobject- Specified by:
setDBFieldMapin interfaceDBFieldMapper- Parameters:
fieldmap- The DBFieldMap to set
-
haveDBFieldMap
public boolean haveDBFieldMap()Checks the presence of aDBFieldMapobject- Specified by:
haveDBFieldMapin interfaceDBFieldMapper- Returns:
- true if there is a correct DBFieldMap object (not null), false otherwise
-
getDBObjectMap
Implements theDBObjectMapperinterface. It returns theDBObjectMapof the instance- Specified by:
getDBObjectMapin interfaceDBObjectMapper- Returns:
- The
DBObjectMapof the instance
-
setDBObjectMap
Implements theDBObjectMapperinterface. Sets theDBObjectMapof the instance- Specified by:
setDBObjectMapin interfaceDBObjectMapper- Parameters:
objectmap- TheDBObjectMapof the instance
-
haveDBObjectMap
public boolean haveDBObjectMap()Implements theDBObjectMapperinterface. Checks the presence of a validDBObjectMapin the instance- Specified by:
haveDBObjectMapin interfaceDBObjectMapper- Returns:
- true if there is a correct DBObjectMap object (not null), false otherwise
-
getStatement
Returns theStatementon which theDBStatementacts- Specified by:
getStatementin interfaceDBStatement- Returns:
- SQL statement used to access the database
- Throws:
SQLException- If the communication with the database throws an exception, that it is raised to the caller
-
createStatement
Explicitly creates a PreparedStatement. It is useful when you want to use a PreparedStatement and also have the same release mechanisms of the DBStatement- Specified by:
createStatementin interfaceDBStatement- Returns:
- The PreparedStatement created and used to access the database
- Throws:
SQLException- If the communication with the database throws an exception, that it is raised to the caller
-
createCall
- Specified by:
createCallin interfaceDBStatement- Throws:
SQLException
-
cancel
public void cancel()Cancels this statement object. SeeStatement.cancel()- Specified by:
cancelin interfaceCancelListener
-
getDataAttributes
Description copied from interface:DataAttributesHolder- Specified by:
getDataAttributesin interfaceDataAttributesHolder- Returns:
- a
List<DataAttribute> about theEDMdata attributes.
-
setDataAttributes
Description copied from interface:DataAttributesHolderSets the provideddataAttributes.- Specified by:
setDataAttributesin interfaceDataAttributesHolder- Parameters:
dataAttributes-List<DataAttribute> about theEDMdata attributes to be set.
-
isUpdateInProgress
public boolean isUpdateInProgress()Description copied from interface:DBStatementReturnstruein case aSQL UPDATEquery is in progress;falseotherwise.- Specified by:
isUpdateInProgressin interfaceDBStatement- Returns:
truein case aSQL UPDATEquery is in progress;falseotherwise.
-
isInsertInProgress
public boolean isInsertInProgress()Description copied from interface:DBStatementReturnstruein case aSQL INSERTquery is in progress;falseotherwise.- Specified by:
isInsertInProgressin interfaceDBStatement- Returns:
truein case aSQL INSERTquery is in progress;falseotherwise.
-
getDbType
Description copied from interface:DBStatementReturns theDBTypeassociated to thePooledConnectioncurrently in use.- Specified by:
getDbTypein interfaceDBStatement- Returns:
- the
DBTypeassociated to thePooledConnectioncurrently in use.
-
dbStatement.executeQuery()ordbStatement.executeQuery().setRoData()instead