| java.lang.Object org.sakaiproject.db.impl.BasicSqlService
All known Subclasses: org.sakaiproject.db.impl.SqlServiceTest,
BasicSqlService | abstract public class BasicSqlService implements SqlService(Code) | |
BasicSqlService implements the SqlService.
|
Inner Class :public class StreamWithConnection extends InputStream | |
Method Summary | |
public Connection | borrowConnection() | public void | dbCancel(Connection conn) Cancel the update that was locked on this connection. | public Long | dbInsert(Connection callerConnection, String sql, Object[] fields, String autoColumn) Execute the "insert" sql, returning a possible auto-update field Long value
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: callerConnection - The connection to use. Parameters: autoColumn - The name of the db column that will have auto-update - we will return the value used (leave null to disable this feature). | public Long | dbInsert(Connection callerConnection, String sql, Object[] fields, String autoColumn, InputStream last, int lastLength) Execute the "insert" sql, returning a possible auto-update field Long value
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: callerConnection - The connection to use. Parameters: autoColumn - The name of the db column that will have auto-update - we will return the value used (leave null to disable this feature). Parameters: last - A stream to set as the last field. | public List | dbRead(String sql) Read a single field from the db, from multiple records, returned as string[], one per record.
Parameters: sql - The sql statement. | public List | dbRead(String sql, Object[] fields, SqlReader reader) Process a query, filling in with fields, and return the results as a List, one per record read. | public List | dbRead(Connection callerConn, String sql, Object[] fields, SqlReader reader) Process a query, filling in with fields, and return the results as a List, one per record read. | public void | dbReadBinary(String sql, Object[] fields, byte[] value) Read a single field from the db, from multiple record - concatenating the binary values into value. | public void | dbReadBinary(Connection callerConn, String sql, Object[] fields, byte[] value) Read a single field from the db, from multiple record - concatenating the binary values into value. | public InputStream | dbReadBinary(String sql, Object[] fields, boolean big) Read a single field / record from the db, returning a stream on the result record / field. | public void | dbReadBlobAndUpdate(String sql, byte[] content) Read a single field BLOB from the db from one record, and update it's bytes with content. | public Connection | dbReadLock(String sql, StringBuffer field) Read a single field from the db, from a single record, return the value found, and lock for update.
Parameters: sql - The sql statement. Parameters: field - A StringBuffer that will be filled with the field. | public void | dbUpdateCommit(String sql, Object[] fields, String var, Connection conn) Commit the update that was locked on this connection. | public boolean | dbWrite(String sql) Execute the "write" sql - no response.
Parameters: sql - The sql statement. | public boolean | dbWrite(String sql, String var) Execute the "write" sql - no response. | public boolean | dbWrite(String sql, Object[] fields) Execute the "write" sql - no response, using a set of fields from an array plus one more as params.
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. | public boolean | dbWrite(Connection connection, String sql, Object[] fields) Execute the "write" sql - no response, using a set of fields from an array and a given connection.
Parameters: connection - The connection to use. Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. | public boolean | dbWrite(String sql, Object[] fields, String lastField) Execute the "write" sql - no response, using a set of fields from an array plus one more as params.
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: lastField - The value to bind to the last parameter in the sql statement. | protected boolean | dbWrite(String sql, Object[] fields, String lastField, Connection callerConnection, boolean failQuiet) Execute the "write" sql - no response, using a set of fields from an array plus one more as params and connection.
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: lastField - The value to bind to the last parameter in the sql statement. Parameters: callerConnection - The connection to use. Parameters: failQuiet - If true, don't log errors from statement failure true if successful, false if not due to unique constraint violation or duplicate key (i.e. | public boolean | dbWriteBinary(String sql, Object[] fields, byte[] var, int offset, int len) Execute the "write" sql - no response. | public boolean | dbWriteFailQuiet(Connection connection, String sql, Object[] fields) Execute the "write" sql - no response, using a set of fields from an array and a given connection logging no errors on failure.
Parameters: connection - The connection to use. Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. | public void | ddl(ClassLoader loader, String resource) | protected void | debug(String str, String sql, Object[] fields) | protected String | debugFields(Object[] fields) | public void | destroy() Final cleanup. | public String | getBooleanConstant(boolean value) | public GregorianCalendar | getCal() | public Long | getNextSequence(String tableName, Connection conn) | public String | getVendor() | public void | init() Final initialization, once all dependencies are set. | protected int | prepareStatement(PreparedStatement pstmt, Object[] fields) Prepare a prepared statement with fields.
Parameters: pstmt - The prepared statement to fill in. Parameters: fields - The Object array of values to fill in. | public void | returnConnection(Connection conn) | public void | setAutoDdl(String value) Configuration: to run the ddl on init or not. | public void | setCommitAfterRead(String value) | public void | setDeadlockRetries(String value) Configuration: number of on-deadlock retries for save. | public void | setDefaultDataSource(DataSource defaultDataSource) | public void | setLongDataSource(DataSource slowDataSource) | public void | setShowSql(String value) Configuration: to show each sql command in the logs or not. | public void | setVendor(String value) Configuration: Database vendor used; possible values are oracle, mysql, hsqldb. | abstract protected ThreadLocalManager | threadLocalManager() | public boolean | transact(Runnable callback, String tag) | abstract protected UsageSessionService | usageSessionService() |
TRANSACTION_CONNECTION | final protected static String TRANSACTION_CONNECTION(Code) | | Key name in thread local to find the current transaction connection.
|
defaultDataSource | protected DataSource defaultDataSource(Code) | | The "shared", "common" database connection pool
|
longDataSource | protected DataSource longDataSource(Code) | | The "slow" connection pool for file uploads/downloads
|
m_autoDdl | protected boolean m_autoDdl(Code) | | Configuration: to run the ddl on init or not.
|
m_commitAfterRead | protected boolean m_commitAfterRead(Code) | | Should we do a commit after a single statement read?
|
m_deadlockRetries | protected int m_deadlockRetries(Code) | | Configuration: number of on-deadlock retries for save.
|
m_showSql | protected boolean m_showSql(Code) | | if true, debug each sql command with timing.
|
m_vendor | protected String m_vendor(Code) | | Database vendor used; possible values are oracle, mysql, hsqldb (default).
|
dbCancel | public void dbCancel(Connection conn)(Code) | | Cancel the update that was locked on this connection.
Parameters: conn - The database connection on which the lock was gained. |
dbInsert | public Long dbInsert(Connection callerConnection, String sql, Object[] fields, String autoColumn)(Code) | | Execute the "insert" sql, returning a possible auto-update field Long value
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: callerConnection - The connection to use. Parameters: autoColumn - The name of the db column that will have auto-update - we will return the value used (leave null to disable this feature). The auto-update value, or null |
dbInsert | public Long dbInsert(Connection callerConnection, String sql, Object[] fields, String autoColumn, InputStream last, int lastLength)(Code) | | Execute the "insert" sql, returning a possible auto-update field Long value
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: callerConnection - The connection to use. Parameters: autoColumn - The name of the db column that will have auto-update - we will return the value used (leave null to disable this feature). Parameters: last - A stream to set as the last field. The auto-update value, or null |
dbRead | public List dbRead(String sql)(Code) | | Read a single field from the db, from multiple records, returned as string[], one per record.
Parameters: sql - The sql statement. The List of Strings of single fields of the record found, or empty if none found. |
dbRead | public List dbRead(String sql, Object[] fields, SqlReader reader)(Code) | | Process a query, filling in with fields, and return the results as a List, one per record read. If a reader is provided, it will be called for each record to prepare the Object placed into the List. Otherwise, the first field of each record, as a
String, will be placed in the list.
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: reader - The reader object to read each record. The List of things read, one per record. |
dbRead | public List dbRead(Connection callerConn, String sql, Object[] fields, SqlReader reader)(Code) | | Process a query, filling in with fields, and return the results as a List, one per record read. If a reader is provided, it will be called for each record to prepare the Object placed into the List. Otherwise, the first field of each record, as a
String, will be placed in the list.
Parameters: callerConn - The db connection object to use (if not null). Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: reader - The reader object to read each record. The List of things read, one per record. |
dbReadBinary | public void dbReadBinary(String sql, Object[] fields, byte[] value)(Code) | | Read a single field from the db, from multiple record - concatenating the binary values into value.
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: value - The array of bytes to fill with the value read from the db. |
dbReadBinary | public void dbReadBinary(Connection callerConn, String sql, Object[] fields, byte[] value)(Code) | | Read a single field from the db, from multiple record - concatenating the binary values into value.
Parameters: callerConn - The optional db connection object to use. Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: value - The array of bytes to fill with the value read from the db. |
dbReadBinary | public InputStream dbReadBinary(String sql, Object[] fields, boolean big) throws ServerOverloadException(Code) | | Read a single field / record from the db, returning a stream on the result record / field. The stream holds the conection open - so it must be closed or finalized quickly!
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: big - If true, the read is expected to be potentially large. throws: ServerOverloadException - if the read cannot complete due to lack of a free connection (if wait is false) |
dbReadBlobAndUpdate | public void dbReadBlobAndUpdate(String sql, byte[] content)(Code) | | Read a single field BLOB from the db from one record, and update it's bytes with content.
Parameters: sql - The sql statement to select the BLOB. Parameters: content - The new bytes for the BLOB. |
dbReadLock | public Connection dbReadLock(String sql, StringBuffer field)(Code) | | Read a single field from the db, from a single record, return the value found, and lock for update.
Parameters: sql - The sql statement. Parameters: field - A StringBuffer that will be filled with the field. The Connection holding the lock. |
dbUpdateCommit | public void dbUpdateCommit(String sql, Object[] fields, String var, Connection conn)(Code) | | Commit the update that was locked on this connection.
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: var - The value to bind to the last parameter in the sql statement. Parameters: conn - The database connection on which the lock was gained. |
dbWrite | public boolean dbWrite(String sql)(Code) | | Execute the "write" sql - no response.
Parameters: sql - The sql statement. true if successful, false if not. |
dbWrite | public boolean dbWrite(String sql, String var)(Code) | | Execute the "write" sql - no response. a long field is set to "?" - fill it in with var
Parameters: sql - The sql statement. Parameters: var - The value to bind to the first parameter in the sql statement. true if successful, false if not. |
dbWrite | public boolean dbWrite(String sql, Object[] fields)(Code) | | Execute the "write" sql - no response, using a set of fields from an array plus one more as params.
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. true if successful, false if not. |
dbWrite | public boolean dbWrite(Connection connection, String sql, Object[] fields)(Code) | | Execute the "write" sql - no response, using a set of fields from an array and a given connection.
Parameters: connection - The connection to use. Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. true if successful, false if not. |
dbWrite | public boolean dbWrite(String sql, Object[] fields, String lastField)(Code) | | Execute the "write" sql - no response, using a set of fields from an array plus one more as params.
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: lastField - The value to bind to the last parameter in the sql statement. true if successful, false if not. |
dbWrite | protected boolean dbWrite(String sql, Object[] fields, String lastField, Connection callerConnection, boolean failQuiet)(Code) | | Execute the "write" sql - no response, using a set of fields from an array plus one more as params and connection.
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: lastField - The value to bind to the last parameter in the sql statement. Parameters: callerConnection - The connection to use. Parameters: failQuiet - If true, don't log errors from statement failure true if successful, false if not due to unique constraint violation or duplicate key (i.e. the record already exists) OR we are instructed to fail quiet. |
dbWriteBinary | public boolean dbWriteBinary(String sql, Object[] fields, byte[] var, int offset, int len)(Code) | | Execute the "write" sql - no response. a long binary field is set to "?" - fill it in with var
Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. Parameters: var - The value to bind to the last parameter in the sql statement. Parameters: offset - The start within the var to write Parameters: len - The number of bytes of var, starting with index, to write true if successful, false if not. |
dbWriteFailQuiet | public boolean dbWriteFailQuiet(Connection connection, String sql, Object[] fields)(Code) | | Execute the "write" sql - no response, using a set of fields from an array and a given connection logging no errors on failure.
Parameters: connection - The connection to use. Parameters: sql - The sql statement. Parameters: fields - The array of fields for parameters. true if successful, false if not. |
debug | protected void debug(String str, String sql, Object[] fields)(Code) | | Append a message about this SQL statement to the DEBUG string in progress, if any
Parameters: str - The SQL statement. Parameters: fields - The bind fields. |
destroy | public void destroy()(Code) | | Final cleanup.
|
getBooleanConstant | public String getBooleanConstant(boolean value)(Code) | | |
init | public void init()(Code) | | Final initialization, once all dependencies are set.
|
setAutoDdl | public void setAutoDdl(String value)(Code) | | Configuration: to run the ddl on init or not.
Parameters: value - the auto ddl value. |
setCommitAfterRead | public void setCommitAfterRead(String value)(Code) | | Configuration: should we do a commit after each single SQL read?
Parameters: value - the setting (true of false) string. |
setDeadlockRetries | public void setDeadlockRetries(String value)(Code) | | Configuration: number of on-deadlock retries for save.
Parameters: value - the number of on-deadlock retries for save. |
setDefaultDataSource | public void setDefaultDataSource(DataSource defaultDataSource)(Code) | | Parameters: defaultDataSource - The defaultDataSource to set. |
setLongDataSource | public void setLongDataSource(DataSource slowDataSource)(Code) | | Parameters: slowDataSource - The slowDataSource to set. |
setShowSql | public void setShowSql(String value)(Code) | | Configuration: to show each sql command in the logs or not.
Parameters: value - the showSql setting. |
setVendor | public void setVendor(String value)(Code) | | Configuration: Database vendor used; possible values are oracle, mysql, hsqldb.
Parameters: value - the Database vendor used. |
|
|