Java Doc for SDriver.java in  » Database-ORM » SimpleORM » simpleorm » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » SimpleORM » simpleorm.core 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


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,



Field Summary
static  SArrayListdrivers
     Note that these are only prototypes.


Method Summary
protected  voidaReferenceSQL(SFieldReference topRef, SFieldReference fldRef, StringBuffer sbFkey, StringBuffer sbRefed)
    
protected  voidaddNull(StringBuffer sql, SFieldMeta fld)
    
public  StringalterTableAddColumnSQL(SFieldMeta field)
     These alow you to create a new SFieldMeta object at runtime and then update the table to include it.
public  StringalterTableDropColumnSQL(SFieldMeta field)
    
protected  booleancanResultSetAbsolute()
     true if resultset.absolure(nn) works properly to implement limit/offset.
protected  StringclauseSeparator(String indent)
    
protected  StringcolumnTypeSQL(SFieldMeta field)
    
protected  StringcreateSequenceDDL(String name)
    
public  StringcreateTableSQL(SRecordMeta meta)
     Returns a CREATE TABLE for this table.
protected  StringdeleteSQL(SRecordMeta from, SArrayList where, SRecordInstance instance, Object[] keyMetaValues)
     Returns the SQL statement for an DELETE in a structured way. Used by flush().
protected  StringdriverName()
    
protected  StringdropSequenceDDL(String name)
    
public  voiddropTableNoError(String table)
     Utility routine for dropping tables called by SConnection.
protected  StringforUpdateSQL(boolean forUpdate)
     Returns update clause, may not be valid in certain lock modes etc.
protected  StringforeignKeysSQL(SRecordMeta meta)
     Returns FOREIGN KEY (FKCOL, FKCOL) REFERENCES FTABLE (KCOL, KCOL) appended to end.
protected  StringfromSQL(SRecordMeta from, SRecordMeta[] joinTables)
     Returns the FROM Table, Table...
protected  longgenerateKeySelectMax(SRecordMeta rec, SFieldMeta keyFld)
     Generates a new key using SELECT MAX+1.
protected  longgenerateKeySequence(SRecordMeta rec, SFieldMeta keyFld)
    
protected  StringindexKeySQL(SRecordMeta meta)
    
protected  voidinitResultSet(SResultSet srs)
     Called just after executeQuery to Skip over records until offset has been reached.
protected  StringinsertSQL(SArrayList updates, SRecordMeta from)
     Returns the SQL statement for an INSERT in a structured way. Used by flush().
protected  voidmakeForeignKeyIndexSQL(SRecordMeta meta, int fx, SFieldReference fldRef, StringBuffer sbFkey, StringBuffer sbRefed, StringBuffer fkey)
    
protected  StringmapForeignKeys(SRecordMeta meta, boolean foreignKey)
    
public  intmaxIdentNameLength()
     The maximum size for table names and foreign key constraint names.
static  SDrivernewSDriver(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  StringpostColumnSQL(SFieldMeta field)
     After NOT NULL but before the ",", ie column specific annotations.
protected  StringpostFromSQL(boolean forUpdate, boolean unrepeatableRead)
     For MSSQL.
protected  StringpostTablePostParenSQL(SRecordMeta meta)
     Any other text to be added after the final ")".
protected  StringpostTablePreParenSQL(SRecordMeta meta)
    
protected  StringprimaryKeySQL(SRecordMeta meta)
     Return PRIMARY KEY(KCOL, KCOL) appended to end.
public  StringquoteColumn(String ident)
    
public  StringquoteConstraint(String ident)
    
public  StringquoteIdentifier(String ident)
     Wraps identifiers in "s to avoid reserved word issues.
public  StringquoteTable(String ident)
    
public  voidregisterDriver()
     Add driver to the list of possible drivers that can be found by SConnection.attach.
protected  StringselectSQL(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  StringselectSQL(SFieldMeta[] select, SRecordMeta from, String where, String orderBy, boolean forUpdate, boolean unrepeatableRead, SPreparedStatement sps)
    
public  booleansupportsKeySequences()
    
public  booleansupportsLocking()
     True if exclusive locks are properly supported.
protected  StringupdateSQL(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  voidwhereSQL(StringBuffer ret, SArrayList where, SRecordInstance instance, Object[] keyMetaValues)
     Produces the WHERE clause of UPDATE and DELETE statements.
protected  StringwholeColumnSQL(SFieldMeta fld)
     Returns MY_COL VARCHAR(13) NOT NULL.

Field Detail
drivers
static SArrayList drivers(Code)
Note that these are only prototypes. New SDriver instances are created for each connection. See static below.





Method Detail
aReferenceSQL
protected void aReferenceSQL(SFieldReference topRef, SFieldReference fldRef, StringBuffer sbFkey, StringBuffer sbRefed)(Code)



addNull
protected void addNull(StringBuffer sql, SFieldMeta fld)(Code)



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.



alterTableDropColumnSQL
public String alterTableDropColumnSQL(SFieldMeta field)(Code)



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



columnTypeSQL
protected String columnTypeSQL(SFieldMeta field)(Code)



createSequenceDDL
protected String createSequenceDDL(String name)(Code)



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()



dropSequenceDDL
protected String dropSequenceDDL(String name)(Code)



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.



fromSQL
protected String fromSQL(SRecordMeta from, SRecordMeta[] joinTables)(Code)
Returns the FROM Table, Table... clause



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.)




generateKeySequence
protected long generateKeySequence(SRecordMeta rec, SFieldMeta keyFld)(Code)



indexKeySQL
protected String indexKeySQL(SRecordMeta meta)(Code)
Needed for MySQL to create indexes on foreign keys



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.



makeForeignKeyIndexSQL
protected void makeForeignKeyIndexSQL(SRecordMeta meta, int fx, SFieldReference fldRef, StringBuffer sbFkey, StringBuffer sbRefed, StringBuffer fkey)(Code)



mapForeignKeys
protected String mapForeignKeys(SRecordMeta meta, boolean foreignKey)(Code)



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.



quoteColumn
public String quoteColumn(String ident)(Code)



quoteConstraint
public String quoteConstraint(String ident)(Code)



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.



quoteTable
public String quoteTable(String ident)(Code)



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 SFieldMetas. 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.




selectSQL
protected String selectSQL(SFieldMeta[] select, SRecordMeta from, String where, String orderBy, boolean forUpdate, boolean unrepeatableRead, SPreparedStatement sps)(Code)



supportsKeySequences
public boolean supportsKeySequences()(Code)



supportsLocking
public boolean supportsLocking()(Code)
True if exclusive locks are properly supported. Otherwise optimistic locks are always used.




updateSQL
protected String updateSQL(SArrayList updates, SRecordMeta from, SArrayList where, SRecordInstance instance, Object[] keyMetaValues)(Code)
Returns the SQL statement for an UPDATE in a structured way. Used by flush(). updates and where are SArrayLists of SFieldMetas. Returns SQL statement as a string.



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).



wholeColumnSQL
protected String wholeColumnSQL(SFieldMeta fld)(Code)
Returns MY_COL VARCHAR(13) NOT NULL.
See Also:   SDriver.SMANDATORY



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.