|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.sakaiproject.component.framework.sql.BasicSqlService
BasicSqlService implements the SqlService to support (mostly Legacy) Sakai code.
Nested Class Summary | |
class |
BasicSqlService.StreamWithConnection
StreamWithConnection is a cover over a stream that comes from a statmenet result in a connection, holding all these until closed. |
Field Summary | |
protected DataSource |
defaultDataSource
The "shared", "common" database connection pool |
protected DataSource |
longDataSource
The "slow" connection pool for file uploads/downloads |
protected boolean |
m_autoDdl
Configuration: to run the ddl on init or not. |
protected GregorianCalendar |
m_cal
Used to work with dates in GMT in the db. |
protected boolean |
m_commitAfterRead
Should we do a commit after a single statement read? |
protected boolean |
m_showSql
if true, debug each sql command with timing. |
protected String |
m_vendor
Database vendor used; possible values are oracle, mysql, hsqldb (default). |
Fields inherited from interface org.sakaiproject.service.framework.sql.SqlService |
DEFAULT |
Constructor Summary | |
BasicSqlService()
|
Method Summary | |
Connection |
borrowConnection()
Access an available or newly created Connection from the default pool. Will wait a while until one is available. |
void |
dbCancel(Connection conn)
Cancel the update that was locked on this connection. |
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. |
List |
dbRead(String sql)
Read a single field from the db, from multiple records, returned as string[], one per record. |
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. |
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. |
InputStream |
dbReadBinary(String sql,
Object[] fields,
boolean big)
Read a single field / record from the db, returning a stream on the result record / field. |
void |
dbReadBinary(String sql,
Object[] fields,
byte[] value)
Read a single field from the db, from multiple record - concatenating the binary values into value. |
void |
dbReadBlobAndUpdate(String sql,
byte[] content)
Read a single field BLOB from the db from one record, and update it's bytes with content. |
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. |
void |
dbUpdateCommit(String sql,
Object[] fields,
String var,
Connection conn)
Commit the update that was locked on this connection. |
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. |
boolean |
dbWrite(String sql)
Execute the "write" sql - no response. |
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. |
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. |
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. |
boolean |
dbWrite(String sql,
String var)
Execute the "write" sql - no response. a long field is set to "?" |
boolean |
dbWriteBinary(String sql,
Object[] fields,
byte[] var,
int offset,
int len)
Execute the "write" sql - no response. a long binary field is set to "?" |
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. |
void |
ddl(ClassLoader loader,
String resource)
Load and run the named file using the given class loader, as a ddl check / create. The first non-comment ('--') line will be run, and if successfull, all other non-comment lines will be run. SQL statements must be on a single line, and may have ';' terminators. |
protected void |
debug(String str,
String sql,
Object[] fields)
Append a message about this SQL statement to the DEBUG string in progress, if any |
protected String |
debugFields(Object[] fields)
|
void |
destroy()
Final cleanup. |
GregorianCalendar |
getCal()
Access the calendar used in processing Time objects for Sql. |
String |
getVendor()
|
void |
init()
Final initialization, once all dependencies are set. |
protected int |
prepareStatement(PreparedStatement pstmt,
Object[] fields)
Prepare a prepared statement with fields. |
void |
returnConnection(Connection conn)
Release a database connection. |
void |
setAutoDdl(String value)
Configuration: to run the ddl on init or not. |
void |
setCommitAfterRead(String value)
Configuration: should we do a commit after each single SQL read? |
void |
setDefaultDataSource(DataSource defaultDataSource)
|
void |
setLongDataSource(DataSource slowDataSource)
|
void |
setShowSql(String value)
Configuration: to show each sql command in the logs or not. |
void |
setVendor(String value)
Configuration: Database vendor used; possible values are oracle, mysql, hsqldb. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected DataSource defaultDataSource
protected DataSource longDataSource
protected boolean m_commitAfterRead
protected String m_vendor
protected boolean m_showSql
protected boolean m_autoDdl
protected final GregorianCalendar m_cal
Constructor Detail |
public BasicSqlService()
Method Detail |
public void setCommitAfterRead(String value)
value
- the setting (true of false) string.public void setVendor(String value)
value
- the Database vendor used.public void setShowSql(String value)
value
- the showSql setting.public void setAutoDdl(String value)
value
- the auto ddl value.public String getVendor()
getVendor
in interface SqlService
public void init()
public void destroy()
public Connection borrowConnection() throws SQLException
borrowConnection
in interface SqlService
SQLException
- if a connection cannot be delivered.public void returnConnection(Connection conn)
returnConnection
in interface SqlService
conn
- The connetion to release. If null or not one of ours, ignored.public GregorianCalendar getCal()
getCal
in interface SqlService
public List dbRead(String sql)
dbRead
in interface SqlService
sql
- The sql statement.
public List dbRead(String sql, Object[] fields, SqlReader reader)
dbRead
in interface SqlService
sql
- The sql statement.fields
- The array of fields for parameters.reader
- The reader object to read each record.
public List dbRead(Connection callerConn, String sql, Object[] fields, SqlReader reader)
dbRead
in interface SqlService
callerConn
- The db connection object to use (if not null).sql
- The sql statement.fields
- The array of fields for parameters.reader
- The reader object to read each record.
public void dbReadBinary(String sql, Object[] fields, byte[] value)
dbReadBinary
in interface SqlService
sql
- The sql statement.fields
- The array of fields for parameters.value
- The array of bytes to fill with the value read from the db.public void dbReadBinary(Connection callerConn, String sql, Object[] fields, byte[] value)
dbReadBinary
in interface SqlService
callerConn
- The optional db connection object to use.sql
- The sql statement.fields
- The array of fields for parameters.value
- The array of bytes to fill with the value read from the db.public InputStream dbReadBinary(String sql, Object[] fields, boolean big) throws ServerOverloadException
dbReadBinary
in interface SqlService
sql
- The sql statement.fields
- The array of fields for parameters.big
- If true, the read is expected to be potentially large.
ServerOverloadException
- if the read cannot complete due to lack of a free connection (if wait is false)public boolean dbWrite(String sql)
dbWrite
in interface SqlService
sql
- The sql statement.
public boolean dbWrite(String sql, String var)
dbWrite
in interface SqlService
sql
- The sql statement.var
- The value to bind to the first parameter in the sql statement.
public boolean dbWriteBinary(String sql, Object[] fields, byte[] var, int offset, int len)
dbWriteBinary
in interface SqlService
sql
- The sql statement.fields
- The array of fields for parameters.var
- The value to bind to the last parameter in the sql statement.offset
- The start within the var to writelen
- The number of bytes of var, starting with index, to write
public boolean dbWrite(String sql, Object[] fields)
dbWrite
in interface SqlService
sql
- The sql statement.fields
- The array of fields for parameters.
public boolean dbWrite(Connection connection, String sql, Object[] fields)
dbWrite
in interface SqlService
connection
- The connection to use.sql
- The sql statement.fields
- The array of fields for parameters.
public boolean dbWriteFailQuiet(Connection connection, String sql, Object[] fields)
dbWriteFailQuiet
in interface SqlService
connection
- The connection to use.sql
- The sql statement.fields
- The array of fields for parameters.
public boolean dbWrite(String sql, Object[] fields, String lastField)
dbWrite
in interface SqlService
sql
- The sql statement.fields
- The array of fields for 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)
sql
- The sql statement.fields
- The array of fields for parameters.lastField
- The value to bind to the last parameter in the sql statement.callerConnection
- The connection to use.failQuiet
- If true, don't log errors from statement failure
public void dbReadBlobAndUpdate(String sql, byte[] content)
dbReadBlobAndUpdate
in interface SqlService
sql
- The sql statement to select the BLOB.content
- The new bytes for the BLOB.public Connection dbReadLock(String sql, StringBuffer field)
dbReadLock
in interface SqlService
sql
- The sql statement.field
- A StringBuffer that will be filled with the field.
public void dbUpdateCommit(String sql, Object[] fields, String var, Connection conn)
dbUpdateCommit
in interface SqlService
sql
- The sql statement.fields
- The array of fields for parameters.var
- The value to bind to the last parameter in the sql statement.conn
- The database connection on which the lock was gained.public void dbCancel(Connection conn)
dbCancel
in interface SqlService
conn
- The database connection on which the lock was gained.public void ddl(ClassLoader loader, String resource)
ddl
in interface SqlService
loader
- The ClassLoader used to load the resource.resource
- The path name to the resource - vender string and .sql will be addedprotected int prepareStatement(PreparedStatement pstmt, Object[] fields) throws SQLException, UnsupportedEncodingException
pstmt
- The prepared statement to fill in.fields
- The Object array of values to fill in.
UnsupportedEncodingException
SQLException
protected void debug(String str, String sql, Object[] fields)
str
- The SQL statement.fields
- The bind fields.protected String debugFields(Object[] fields)
public void setDefaultDataSource(DataSource defaultDataSource)
defaultDataSource
- The defaultDataSource to set.public void setLongDataSource(DataSource slowDataSource)
slowDataSource
- The slowDataSource to set.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |