Class AbstractNamedParameterStatement<StatementType extends Statement>
- java.lang.Object
-
- com.identityworksllc.iiq.common.query.AbstractNamedParameterStatement<StatementType>
-
- Type Parameters:
StatementType
- The type of statement,PreparedStatement
orCallableStatement
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
NamedParameterStatement
public abstract class AbstractNamedParameterStatement<StatementType extends Statement> extends Object implements AutoCloseable
The abstract superclass for the named parameter statement types.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
allowMissingAttributes
If true, invoking one of the setXXX methods on a non-existent parameter will be silently ignored.protected Connection
connection
The connectionprotected Map<String,int[]>
indexMap
Maps parameter names to arrays of ints which are the parameter indices.protected StatementType
statement
The statement this object is wrapping.
-
Constructor Summary
Constructors Constructor Description AbstractNamedParameterStatement()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
addBatch()
Adds an item to the current batch.void
close()
Closes the statement.int[]
executeBatch()
Executes all of the batched statements.protected int[]
getIndexes(String name)
Returns the indexes for a parameter.Set<String>
getParameterNames()
Returns the set of parameter names.StatementType
getStatement()
Returns the underlying statement.boolean
isClosed()
Returns true if the wrapped statement is closedstatic String
parse(String query, Map<String,int[]> indexMap)
Parses a query with named parameters.void
setAllowMissingAttributes(boolean allowMissingAttributes)
Sets the flag to allow an attempt to set missing attributes without throwing an exception.void
setFetchDirection(int i)
void
setFetchSize(int i)
void
setMaxRows(int i)
Set the max rows in the result setabstract void
setObject(String name, Object value)
Abstract method for use by subclasses to register their own specific value typesvoid
setParameters(Map<String,Object> parameters)
Sets all parameters to this named parameter statement in bulk from the given Mapvoid
setQueryTimeout(int seconds)
Sets the query timeout
-
-
-
Field Detail
-
allowMissingAttributes
protected boolean allowMissingAttributes
If true, invoking one of the setXXX methods on a non-existent parameter will be silently ignored.The default is to throw an exception.
-
connection
protected Connection connection
The connection
-
indexMap
protected Map<String,int[]> indexMap
Maps parameter names to arrays of ints which are the parameter indices.
-
statement
protected StatementType extends Statement statement
The statement this object is wrapping.
-
-
Constructor Detail
-
AbstractNamedParameterStatement
public AbstractNamedParameterStatement()
-
-
Method Detail
-
parse
public static String parse(String query, Map<String,int[]> indexMap)
Parses a query with named parameters.The parameter-index mappings are put into the map, and the parsed query is returned.
- Parameters:
query
- query to parseindexMap
- map to hold parameter-index mappings- Returns:
- the parsed query
-
addBatch
public abstract void addBatch() throws SQLException
Adds an item to the current batch.Oddly this is not implemented in
Statement
, but it is implemented by both sub-types of statement.- Throws:
SQLException
- See Also:
PreparedStatement.addBatch()
,PreparedStatement.addBatch()
-
close
public void close() throws SQLException
Closes the statement.- Specified by:
close
in interfaceAutoCloseable
- Throws:
SQLException
- if an error occurred- See Also:
Statement.close()
-
executeBatch
public int[] executeBatch() throws SQLException
Executes all of the batched statements.See
Statement.executeBatch()
andaddBatch()
for details.- Returns:
- update counts for each statement
- Throws:
SQLException
- if something went wrong
-
getIndexes
protected int[] getIndexes(String name)
Returns the indexes for a parameter.- Parameters:
name
- parameter name- Returns:
- parameter indexes
- Throws:
IllegalArgumentException
- if the parameter does not exist
-
getParameterNames
public Set<String> getParameterNames()
Returns the set of parameter names.- Returns:
- An unmodifiable set of parameter names
-
getStatement
public StatementType getStatement()
Returns the underlying statement.- Returns:
- the statement
-
isClosed
public boolean isClosed() throws SQLException
Returns true if the wrapped statement is closed- Returns:
- True if the wrapped statement is closed
- Throws:
SQLException
- See Also:
Statement.isClosed()
-
setAllowMissingAttributes
public void setAllowMissingAttributes(boolean allowMissingAttributes)
Sets the flag to allow an attempt to set missing attributes without throwing an exception.With this flag set to false, any attempt to invoke setString, or any other setXYZ method, will result in an exception.
- Parameters:
allowMissingAttributes
-true
if we should not throw an exception when a parameter is unused
-
setFetchDirection
public void setFetchDirection(int i) throws SQLException
- Throws:
SQLException
- See Also:
Statement.setFetchDirection(int)
-
setFetchSize
public void setFetchSize(int i) throws SQLException
- Throws:
SQLException
- See Also:
Statement.setFetchSize(int)
-
setMaxRows
public void setMaxRows(int i) throws SQLException
Set the max rows in the result set- Parameters:
i
- The result row size- Throws:
SQLException
- on errors
-
setObject
public abstract void setObject(String name, Object value) throws SQLException
Abstract method for use by subclasses to register their own specific value types- Parameters:
name
- The name of the argument to setvalue
- The value to set- Throws:
SQLException
-
setParameters
public final void setParameters(Map<String,Object> parameters) throws SQLException
Sets all parameters to this named parameter statement in bulk from the given Map- Parameters:
parameters
- The parameters in question- Throws:
SQLException
- if any failures occur
-
setQueryTimeout
public void setQueryTimeout(int seconds) throws SQLException
Sets the query timeout- Parameters:
seconds
- The timeout for this query in seconds- Throws:
SQLException
- if any errors occur- See Also:
Statement.setQueryTimeout(int)
-
-