| java.lang.Object simpleorm.core.SDriver
All known Subclasses: simpleorm.core.SDriverInformix, simpleorm.core.SDriverSybase, simpleorm.core.SDriverInterbase, simpleorm.core.SDriverMySQL, simpleorm.core.SDriverHSQL, simpleorm.core.SDriverDaffodil, simpleorm.core.SDriverDB2, simpleorm.core.SDriverDerby, simpleorm.core.SDriverMSSQL, simpleorm.core.SDriverSapDB, simpleorm.core.SDriverPostgres, simpleorm.core.SDriverOracle,
SDriver | public class SDriver implements SConstants(Code) | | This is the generic database driver that contains minimal
database dependent code. Specific SimpleORM drivers extend this
class and specialize its methods as required. The driver type is
infered from the jdbc connection's meta data.
## Profiling suggests that memoising these generaters could produce a
5-10% improvement in bulk updates.
There is now one driver instance per connection so one can say
SConnection.getDriver().setMyFavouriteParam(...)
SQL 92 standard data types, I think:-
boolean, Character(n), character varying(n), date, float(p), real, double precission, smallint, int | integer,
decimal(p,s), numeric(p,s), time, interval, timestamp with timezone,
|
Method Summary | |
protected void | aReferenceSQL(SFieldReference topRef, SFieldReference fldRef, StringBuffer sbFkey, StringBuffer sbRefed) | protected void | addNull(StringBuffer sql, SFieldMeta fld) | public String | alterTableAddColumnSQL(SFieldMeta field) These alow you to create a new SFieldMeta object at runtime
and then update the table to include it. | public String | alterTableDropColumnSQL(SFieldMeta field) | protected boolean | canResultSetAbsolute() true if resultset.absolure(nn) works properly to implement limit/offset. | protected String | clauseSeparator(String indent) | protected String | columnTypeSQL(SFieldMeta field) | protected String | createSequenceDDL(String name) | public String | createTableSQL(SRecordMeta meta) Returns a CREATE TABLE for this table. | protected String | deleteSQL(SRecordMeta from, SArrayList where, SRecordInstance instance, Object[] keyMetaValues) Returns the SQL statement for an DELETE in a structured way.
Used by flush(). | protected String | driverName() | protected String | dropSequenceDDL(String name) | public void | dropTableNoError(String table) Utility routine for dropping tables called by SConnection. | protected String | forUpdateSQL(boolean forUpdate) Returns update clause, may not be valid in certain lock modes etc. | protected String | foreignKeysSQL(SRecordMeta meta) Returns FOREIGN KEY (FKCOL, FKCOL) REFERENCES FTABLE (KCOL,
KCOL) appended to end. | protected String | fromSQL(SRecordMeta from, SRecordMeta[] joinTables) Returns the FROM Table, Table... | protected long | generateKeySelectMax(SRecordMeta rec, SFieldMeta keyFld) Generates a new key using SELECT MAX+1. | protected long | generateKeySequence(SRecordMeta rec, SFieldMeta keyFld) | protected String | indexKeySQL(SRecordMeta meta) | protected void | initResultSet(SResultSet srs) Called just after executeQuery to Skip over records until offset
has been reached. | protected String | insertSQL(SArrayList updates, SRecordMeta from) Returns the SQL statement for an INSERT in a structured way.
Used by flush(). | protected void | makeForeignKeyIndexSQL(SRecordMeta meta, int fx, SFieldReference fldRef, StringBuffer sbFkey, StringBuffer sbRefed, StringBuffer fkey) | protected String | mapForeignKeys(SRecordMeta meta, boolean foreignKey) | public int | maxIdentNameLength() The maximum size for table names and foreign key constraint names. | static SDriver | newSDriver(java.sql.Connection con, String driverName) Chooses default driver based on the connection's meta data.
Note that if you have trouble with the driver defaulting mechanism, then
specify the driver explicitly as the third parameter to SConnection.attach.
Note also that a new driver instance is created each time. | protected String | postColumnSQL(SFieldMeta field) After NOT NULL but before the ",", ie column specific annotations. | protected String | postFromSQL(boolean forUpdate, boolean unrepeatableRead) For MSSQL. | protected String | postTablePostParenSQL(SRecordMeta meta) Any other text to be added after the final ")". | protected String | postTablePreParenSQL(SRecordMeta meta) | protected String | primaryKeySQL(SRecordMeta meta) Return PRIMARY KEY(KCOL, KCOL) appended to end. | public String | quoteColumn(String ident) | public String | quoteConstraint(String ident) | public String | quoteIdentifier(String ident) Wraps identifiers in "s to avoid reserved word issues. | public String | quoteTable(String ident) | public void | registerDriver() Add driver to the list of possible drivers that can be found by
SConnection.attach. | protected String | selectSQL(SFieldMeta[] select, SRecordMeta from, SFieldMeta[] where, String orderBy, boolean forUpdate, boolean unrepeatableRead, SPreparedStatement sps) Returns the SQL statement for a SELECT in a structured way.
Used by findOrInsert. | protected String | selectSQL(SFieldMeta[] select, SRecordMeta from, String where, String orderBy, boolean forUpdate, boolean unrepeatableRead, SPreparedStatement sps) | public boolean | supportsKeySequences() | public boolean | supportsLocking() True if exclusive locks are properly supported. | protected String | updateSQL(SArrayList updates, SRecordMeta from, SArrayList where, SRecordInstance instance, Object[] keyMetaValues) Returns the SQL statement for an UPDATE in a structured way.
Used by flush(). | protected void | whereSQL(StringBuffer ret, SArrayList where, SRecordInstance instance, Object[] keyMetaValues) Produces the WHERE clause of UPDATE and DELETE statements. | protected String | wholeColumnSQL(SFieldMeta fld) Returns MY_COL VARCHAR(13) NOT NULL . |
drivers | static SArrayList drivers(Code) | | Note that these are only prototypes.
New SDriver instances are created for each connection.
See static below.
|
alterTableAddColumnSQL | public String alterTableAddColumnSQL(SFieldMeta field)(Code) | | These alow you to create a new SFieldMeta object at runtime
and then update the table to include it. Eg. for end user
customizations.
## Ideally this could be further automated so that the SRecordMeta
and JDBC meta data for a table could be compared and the table
automatically altered.
|
canResultSetAbsolute | protected boolean canResultSetAbsolute()(Code) | | true if resultset.absolure(nn) works properly to implement limit/offset.
|
clauseSeparator | protected String clauseSeparator(String indent)(Code) | | Normally newline and indent to separate clauses of large SQL
statement
|
createTableSQL | public String createTableSQL(SRecordMeta meta)(Code) | | Returns a CREATE TABLE for this table. Delegated
from SRecord. This is split up into many sub-methods so that
they can be selectively specialized by other drivers.
|
deleteSQL | protected String deleteSQL(SRecordMeta from, SArrayList where, SRecordInstance instance, Object[] keyMetaValues)(Code) | | Returns the SQL statement for an DELETE in a structured way.
Used by flush(). where are SArrayLists of
SFieldMetas. Returns SQL statement as a string.
|
driverName | protected String driverName()(Code) | | The driver name to be compared to getMetaData().getDriverName()
|
dropTableNoError | public void dropTableNoError(String table)(Code) | | Utility routine for dropping tables called by SConnection.
Driver specific versions should only hide table non existant
errors (and not warn about them).
|
forUpdateSQL | protected String forUpdateSQL(boolean forUpdate)(Code) | | Returns update clause, may not be valid in certain lock modes etc.
Right at the end of the query.
Oracle, Postgresql, and new in MS SQL 2005 support data versioning
or snapshots. This means that repeatable read is achieved by
caching the previous value read instead of using read locks. This
approach makes it critical to add FOR UPDATE where appropriate or
there is effectively no locking.
Indeed, in Oracle, you are guaranteed that several SELECTS will
return the same value, but a subsequent SELECT FOR UPDATE in the
same transaction may return a different value.
|
foreignKeysSQL | protected String foreignKeysSQL(SRecordMeta meta)(Code) | | Returns FOREIGN KEY (FKCOL, FKCOL) REFERENCES FTABLE (KCOL,
KCOL) appended to end.
|
generateKeySelectMax | protected long generateKeySelectMax(SRecordMeta rec, SFieldMeta keyFld)(Code) | | Generates a new key using SELECT MAX+1. This will (hopefully)
be specialized for each database driver to be correct. Note that
there is a global counter kept so it will actually work OK if
all the updates are from one JVM. Amazing that there is still
no standard way to do this in SQL.
## (There is scope to optimize this at some point so that one JDBC
call can both generate the sequence number and insert a new
record. But that means that the new record's key is not
available until insert time which causes problems for foreign
keys. Alternatively one can get batches of 10 (say) sequences
at a time and then use an internal counter, but this will leave
big holes in the sequence. Defer this to version 1.)
|
initResultSet | protected void initResultSet(SResultSet srs)(Code) | | Called just after executeQuery to Skip over records until offset
has been reached. Drivers may optimize this in various ways,
eg. LIMIT keywords where supported by the database, or by using
the JDBC
|
insertSQL | protected String insertSQL(SArrayList updates, SRecordMeta from)(Code) | | Returns the SQL statement for an INSERT in a structured way.
Used by flush(). updates and
where are SArrayLists of SFieldMetas. Returns SQL
statement as a string.
|
maxIdentNameLength | public int maxIdentNameLength()(Code) | | The maximum size for table names and foreign key constraint names.
|
newSDriver | static SDriver newSDriver(java.sql.Connection con, String driverName)(Code) | | Chooses default driver based on the connection's meta data.
Note that if you have trouble with the driver defaulting mechanism, then
specify the driver explicitly as the third parameter to SConnection.attach.
Note also that a new driver instance is created each time.
|
postColumnSQL | protected String postColumnSQL(SFieldMeta field)(Code) | | After NOT NULL but before the ",", ie column specific annotations.
|
postFromSQL | protected String postFromSQL(boolean forUpdate, boolean unrepeatableRead)(Code) | | For MSSQL. Just after all the tables in the From clause.
|
postTablePostParenSQL | protected String postTablePostParenSQL(SRecordMeta meta)(Code) | | Any other text to be added after the final ")". No ";".
|
postTablePreParenSQL | protected String postTablePreParenSQL(SRecordMeta meta)(Code) | | Any other text to be added before the final ")"
|
primaryKeySQL | protected String primaryKeySQL(SRecordMeta meta)(Code) | | Return PRIMARY KEY(KCOL, KCOL) appended to end.
|
quoteIdentifier | public String quoteIdentifier(String ident)(Code) | | Wraps identifiers in "s to avoid reserved word issues.
(Override this for dbs that use different chars, eg [xxx] for MS-SQL.
We do quote these days to avoid the endless problems with reserved words.
|
registerDriver | public void registerDriver()(Code) | | Add driver to the list of possible drivers that can be found by
SConnection.attach. The key is returned by driverName.
|
selectSQL | protected String selectSQL(SFieldMeta[] select, SRecordMeta from, SFieldMeta[] where, String orderBy, boolean forUpdate, boolean unrepeatableRead, SPreparedStatement sps)(Code) | | Returns the SQL statement for a SELECT in a structured way.
Used by findOrInsert. select and
where are arrays of SFieldMeta s. Returns
SQL statement as a string.
This now quotes table and column names so that they become
case independent.
sps is links to the SPreparedStatement object. It can have arbitrary properties set to
provide fine control over the query. Examples include limits.
|
supportsKeySequences | public boolean supportsKeySequences()(Code) | | |
supportsLocking | public boolean supportsLocking()(Code) | | True if exclusive locks are properly supported. Otherwise
optimistic locks are always used.
|
whereSQL | protected void whereSQL(StringBuffer ret, SArrayList where, SRecordInstance instance, Object[] keyMetaValues)(Code) | | Produces the WHERE clause of UPDATE and DELETE statements.
Needs to know the instance values so that it can use the IS NULL
test (for optimisitic locking).
|
|
|