|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.datanucleus.store.rdbms.SQLController
public class SQLController
Controller for execution of SQL statements to the underlying RDBMS datastore. Currently provides access to PreparedStatements and Connections.
Separates statements into 2 categories.
An "update" statement can be batched. When getting the PreparedStatement the calling method passes in an argument to signify if it can be batched (whether it will use the statement before any other statement can execute), and if so will be cached against the Connection in use. When the statement is to be processed by the calling method it would pass in the "processNow" argument as false. This will leave the statement in the cache as "ready-to-be-processed" in case anything else comes in in the meantime. If the next statement to be requested has the same text and can also be batched then it will be returned the current statement so that it can populate it with its values. When the statement is ready for processing since it is in the cache the new values are added to the batch. Again the statement could be executed at that point or could continue batching.
Typical (unbatched) invocation would be as follows :-
SQLController sql = rdbmsMgr.getSQLController(); PreparedStatement ps = sql.getStatementForUpdate(conn, myStmt, false); // No batching sql.executeStatementUpdate(myStmt, ps, true); // Execute now, dont wait sql.closeStatement(ps);
Typical (batched) invocation would be as follows :-
SQLController sql = rdbmsMgr.getSQLController(); PreparedStatement ps = sql.getStatementForUpdate(conn, myStmt, true); // Batching sql.executeStatementUpdate(myStmt, ps, false); // Execute later sql.closeStatement(ps); ... PreparedStatement ps = sql.getStatementForUpdate(conn, myStmt, true); // Batching (same statement as first) sql.executeStatementUpdate(myStmt, ps, false); // Execute later sql.closeStatement(ps);
Things to note :-
| Field Summary | |
|---|---|
protected static org.datanucleus.util.Localiser |
LOCALISER
Localiser for messages. |
protected int |
maxBatchSize
Maximum batch size (-1 implies no limit). |
protected boolean |
paramValuesInBrackets
|
protected int |
queryTimeout
Timeout to apply to queries (where required) in milliseconds. |
protected boolean |
supportsBatching
Whether batching is supported for this controller (datastore). |
| Constructor Summary | |
|---|---|
SQLController(boolean supportsBatching,
int maxBatchSize,
int queryTimeout,
boolean paramValuesInBrackets)
Constructor. |
|
| Method Summary | |
|---|---|
void |
abortStatementForConnection(org.datanucleus.store.connection.ManagedConnection conn,
PreparedStatement ps)
Method to call to remove the current batched statement for this connection and close it due to an error preventing continuation. |
void |
closeStatement(org.datanucleus.store.connection.ManagedConnection conn,
PreparedStatement ps)
Convenience method to close a PreparedStatement. |
ResultSet |
executeStatementQuery(org.datanucleus.store.ExecutionContext ec,
org.datanucleus.store.connection.ManagedConnection conn,
String stmt,
PreparedStatement ps)
Method to execute a PreparedStatement query, and return the ResultSet. |
int[] |
executeStatementUpdate(org.datanucleus.store.ExecutionContext ec,
org.datanucleus.store.connection.ManagedConnection conn,
String stmt,
PreparedStatement ps,
boolean processNow)
Method to execute a PreparedStatement update. |
protected org.datanucleus.store.rdbms.SQLController.ConnectionStatementState |
getConnectionStatementState(org.datanucleus.store.connection.ManagedConnection conn)
Convenience method to get the state for this connection. |
PreparedStatement |
getStatementForQuery(org.datanucleus.store.connection.ManagedConnection conn,
String stmtText)
Convenience method to create a new PreparedStatement for a query. |
PreparedStatement |
getStatementForQuery(org.datanucleus.store.connection.ManagedConnection conn,
String stmtText,
String resultSetType,
String resultSetConcurrency)
Convenience method to create a new PreparedStatement for a query. |
PreparedStatement |
getStatementForUpdate(org.datanucleus.store.connection.ManagedConnection conn,
String stmtText,
boolean batchable)
Convenience method to create a new PreparedStatement for an update. |
protected int[] |
processConnectionStatement(org.datanucleus.store.connection.ManagedConnection conn)
Convenience method to process the currently waiting statement for the passed Connection. |
void |
processStatementsForConnection(org.datanucleus.store.connection.ManagedConnection conn)
Convenience method to process any batched statement for the specified connection. |
protected void |
removeConnectionStatementState(org.datanucleus.store.connection.ManagedConnection conn)
Convenience method to remove the state for this connection. |
protected void |
setConnectionStatementState(org.datanucleus.store.connection.ManagedConnection conn,
org.datanucleus.store.rdbms.SQLController.ConnectionStatementState state)
Convenience method to set the state for this connection. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final org.datanucleus.util.Localiser LOCALISER
protected boolean supportsBatching
protected int maxBatchSize
protected int queryTimeout
protected boolean paramValuesInBrackets
| Constructor Detail |
|---|
public SQLController(boolean supportsBatching,
int maxBatchSize,
int queryTimeout,
boolean paramValuesInBrackets)
supportsBatching - Whether batching is to be supported.maxBatchSize - The maximum batch sizequeryTimeout - Timeout for queries (ms)paramValuesInBrackets - Whether param values are put in the log in brackets or not| Method Detail |
|---|
public PreparedStatement getStatementForUpdate(org.datanucleus.store.connection.ManagedConnection conn,
String stmtText,
boolean batchable)
throws SQLException
conn - The Connection to use for the statementstmtText - Statement textbatchable - Whether this statement is batchable. Whether we will process the statement before any other statement
SQLException - thrown if an error occurs creating the statement
public PreparedStatement getStatementForQuery(org.datanucleus.store.connection.ManagedConnection conn,
String stmtText)
throws SQLException
conn - The Connection to use for the statementstmtText - Statement text
SQLException - thrown if an error occurs creating the statement
public PreparedStatement getStatementForQuery(org.datanucleus.store.connection.ManagedConnection conn,
String stmtText,
String resultSetType,
String resultSetConcurrency)
throws SQLException
conn - The Connection to use for the statementstmtText - Statement textresultSetType - Type of result setresultSetConcurrency - Concurrency for the result set
SQLException - thrown if an error occurs creating the statement
public int[] executeStatementUpdate(org.datanucleus.store.ExecutionContext ec,
org.datanucleus.store.connection.ManagedConnection conn,
String stmt,
PreparedStatement ps,
boolean processNow)
throws SQLException
conn - The connection (required since the one on PreparedStatement is not always the same so we cant use it)stmt - The statement textps - The Prepared StatementprocessNow - Whether to process this statement now (only applies if is batched)
SQLException - Thrown if an error occurs
public ResultSet executeStatementQuery(org.datanucleus.store.ExecutionContext ec,
org.datanucleus.store.connection.ManagedConnection conn,
String stmt,
PreparedStatement ps)
throws SQLException
conn - The connection (required since the one on PreparedStatement is not always the same so we can't use it)stmt - The statement textps - The Prepared Statement
SQLException - Thrown if an error occurs
public void abortStatementForConnection(org.datanucleus.store.connection.ManagedConnection conn,
PreparedStatement ps)
conn - The connectionps - The statement
public void closeStatement(org.datanucleus.store.connection.ManagedConnection conn,
PreparedStatement ps)
throws SQLException
conn - The Connectionps - The PreparedStatement
SQLException - if an error occurs closing the statement
public void processStatementsForConnection(org.datanucleus.store.connection.ManagedConnection conn)
throws SQLException
conn - The connection
SQLException - Thrown if an error occurs on processing of the batch
protected int[] processConnectionStatement(org.datanucleus.store.connection.ManagedConnection conn)
throws SQLException
conn - The connection
SQLException - if an error occurs processing the batchprotected void removeConnectionStatementState(org.datanucleus.store.connection.ManagedConnection conn)
conn - The Connectionprotected org.datanucleus.store.rdbms.SQLController.ConnectionStatementState getConnectionStatementState(org.datanucleus.store.connection.ManagedConnection conn)
conn - The Connection
protected void setConnectionStatementState(org.datanucleus.store.connection.ManagedConnection conn,
org.datanucleus.store.rdbms.SQLController.ConnectionStatementState state)
conn - The Connectionstate - The state
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||