|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--org.mmbase.storage.database.Support2Storage
|
+--org.mmbase.storage.database.AbstractDatabaseStorage
|
+--org.mmbase.storage.database.SQL92DatabaseStorage
SQL92DatabaseStorage extends AbstractDatabaseStorage to implement the basic functionality for creating and
updating databse tables, using SQL.
Most statements created here are ANSI SQL 92, with the exception of statements for creating
extended tables (see create(org.mmbase.module.core.MMObjectBuilder, org.mmbase.storage.Transaction)).
It does not take into account db-specific effects of inheritance - as various databases have their own
methods, it may be necessary to override the create(org.mmbase.module.core.MMObjectBuilder, org.mmbase.storage.Transaction), insertIntoTable(org.mmbase.module.core.MMObjectBuilder, org.mmbase.module.core.MMObjectNode, org.mmbase.storage.database.DatabaseTransaction),
commitToTable(org.mmbase.module.core.MMObjectBuilder, org.mmbase.module.core.MMObjectNode, org.mmbase.storage.database.DatabaseTransaction), and deleteFromTable(org.mmbase.module.core.MMObjectBuilder, org.mmbase.module.core.MMObjectNode, org.mmbase.storage.database.DatabaseTransaction) methods.
The basic implementation of these methods assumes an OO-database that does not require the use of
specific database routines (i.e. alternate SQL syntax).
Furthermore, most sql statements are now contained in their own wrapper methods:
createSQL(java.lang.String, java.lang.String, java.lang.String, java.lang.String), insertSQL(java.lang.String, java.lang.String, java.lang.String), updateSQL(java.lang.String, java.lang.String, int), deleteSQL(java.lang.String, int) and various
methods for returning SQL SELECT statements.
You can override these method to change the sql statements used by the database layer.
| Fields inherited from class org.mmbase.storage.database.AbstractDatabaseStorage |
mmb |
| Fields inherited from interface org.mmbase.storage.database.DatabaseStorage |
KEY_FOREIGN, KEY_NONE, KEY_NOTNULL, KEY_PRIMARY, KEY_SECONDARY |
| Constructor Summary | |
protected |
SQL92DatabaseStorage()
Constructs the AbstractDatabaseSupport database layer support class |
| Method Summary | |
boolean |
addField(MMObjectBuilder builder,
java.lang.String fieldname)
Adds a field to the table of this builder. |
protected java.lang.String |
applyCreateScheme(java.lang.String tableName,
java.lang.String fieldDefinitions,
java.lang.String parentTableName)
Applies the create scheme (if available), and returns the result (a field type defintiton string) |
boolean |
changeField(MMObjectBuilder builder,
java.lang.String fieldname)
Changes a field to the table of this builder. |
boolean |
commit(MMObjectNode node,
Transaction trans)
Commit this node to the specified builder table within a transaction. |
protected boolean |
commitToTable(MMObjectBuilder builder,
MMObjectNode node,
DatabaseTransaction trans)
Commit the changes to this node to the specified builder table. |
boolean |
create(MMObjectBuilder builder,
Transaction trans)
Create a database table for the specified builder. |
boolean |
created(MMObjectBuilder builder)
Tells if a table for the builder already exists |
boolean |
created(java.lang.String tableName)
Tells if a table already exists |
boolean |
createObjectStorage(Transaction trans)
Create the object table (the basic table for all objects) within a transaction |
protected java.lang.String |
createSQL(java.lang.String tableName,
java.lang.String fields,
java.lang.String parentTableName,
java.lang.String parentFields)
Returns the SQL command to use for creating a specified table, optionally extending another supplied table. |
boolean |
delete(MMObjectNode node,
Transaction trans)
Delete a node within a transaction |
boolean |
deleteFromTable(MMObjectBuilder builder,
MMObjectNode node,
DatabaseTransaction trans)
Remove a node from the specified builder table. |
protected java.lang.String |
deleteSQL(java.lang.String tableName,
int number)
Returns the SQL command to use for deleting an object in a table. |
boolean |
drop(MMObjectBuilder builder)
Drops the table of this builder. |
protected java.lang.String |
dropSQL(java.lang.String tableName)
Returns the SQL command to use for dropping a specified table Overide this method to add a database-specific syntax or optimalization |
byte[] |
getBytes(MMObjectNode node,
java.lang.String fieldname)
Get bytes from blob |
protected abstract byte[] |
getBytes(java.lang.String tableName,
java.lang.String fieldname,
int number)
Get bytes from blob |
protected java.util.List |
getFieldsOrderCreate(MMObjectBuilder builder)
Returns the fields of a builder in the order in which they should be created. |
MMObjectNode |
getNode(MMObjectBuilder builder,
int number,
Transaction trans)
Select a node from a specified builder |
int |
getNodeType(int number,
Transaction trans)
Returns the nodetype for a specified nodereference |
protected MMObjectBuilder |
getParentBuilder(MMObjectBuilder builder)
Returns the parent builder of the specifed builder. |
protected java.lang.String |
getParentTableName(MMObjectBuilder builder)
Returns the name of the parent table of the specifed builder. |
java.lang.String |
getText(MMObjectNode node,
java.lang.String fieldname)
Get text from blob |
protected abstract java.lang.String |
getText(java.lang.String tableName,
java.lang.String fieldname,
int number)
Get text from blob |
void |
init(MMBase mmb,
XMLDatabaseReader document)
Initializes the database layer. |
int |
insert(MMObjectNode node,
Transaction trans)
This method inserts a new object within a transaction, and registers the change. |
protected int |
insertIntoTable(MMObjectBuilder builder,
MMObjectNode node,
DatabaseTransaction trans)
This method inserts a new object in a specified builder table. |
protected java.lang.String |
insertSQL(java.lang.String tableName,
java.lang.String fieldNames,
java.lang.String fieldValues)
Returns the SQL command to use for inserting an object in a table. |
boolean |
isAllowedParentBuilder(MMObjectBuilder builder)
Returns whether this database support layer allows for builder to be a parent builder (that is, other builders can 'extend' this builder and its database tables). |
protected boolean |
isParentField(MMObjectBuilder builder,
java.lang.String fieldName)
Tests whether the specified field is a member of the parent table of the specifed builder. |
protected void |
loadExistingTables()
Load the names of the existing tables for this MMBase instance in memory. |
void |
loadFieldFromTable(MMObjectNode node,
java.lang.String fieldname,
java.sql.ResultSet rs,
int i)
Stores a field in a table ResultSet in a MMObjectNode. |
protected void |
loadSupportInformation()
Load information on database support (i.e support of rollback). |
protected void |
prepare()
Prepares the database layer. |
protected byte[] |
readBytesFromFile(java.lang.String filename)
Reads a byte array from a file. |
boolean |
removeField(MMObjectBuilder builder,
java.lang.String fieldname)
Deletes a field from the table of this builder. |
protected java.lang.String |
selectSQL(java.lang.String tableName,
java.lang.String fieldNames,
java.lang.String where,
java.lang.String orderby,
int offset,
int max)
Returns the SQL command to use for selecting data from a table. |
boolean |
setValuePreparedStatement(java.sql.PreparedStatement stmt,
MMObjectNode node,
java.lang.String fieldname,
int i)
Set a prepared statement field i with value of key from the given node. |
int |
size(MMObjectBuilder builder)
Return number of objects in a builder |
int |
size(java.lang.String tableName)
Return number of entries consisting in given table. |
boolean |
supportsExtendedTables()
Returns whether this storage layer supports extended tables. |
boolean |
supportsRollback()
Returns whether rollback on storage level is supported. |
protected java.lang.String |
updateSQL(java.lang.String tableName,
java.lang.String setFields,
int number)
Returns the SQL command to use for updating an object in a table. |
boolean |
updateStorage(MMObjectBuilder builder)
Changes the storage of a builder to match its new configuration. |
protected boolean |
writeBytesToFile(java.lang.String filename,
byte[] value)
Writes a byte array to a file. |
| Methods inherited from class org.mmbase.storage.database.Support2Storage |
commit, createObjectTable, decodeDBnodeField, decodeDBnodeField, getAllowedField, getConnection, getDBByte, getDBKey, getDBText, getDisallowedField, getMMNodeSearch2SQL, getOTypeString, getOwnerString, getShortedByte, getShortedText, insert, removeNode, updateTable |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.mmbase.storage.Storage |
commit, create, createKey, createKey, createObjectStorage, createTransaction, delete, getNode, getNodeType, insert, registerParentBuilder |
| Constructor Detail |
protected SQL92DatabaseStorage()
| Method Detail |
public void init(MMBase mmb,
XMLDatabaseReader document)
init in interface DatabaseStorageinit in class AbstractDatabaseStoragemmb - the MBase instance that uses this database layerdocument - the database configuration documentprotected void loadExistingTables()
protected void loadSupportInformation()
protected void prepare()
public boolean supportsExtendedTables()
supportsExtendedTables in interface DatabaseStoragesupportsExtendedTables in class AbstractDatabaseStoragepublic boolean supportsRollback()
supportsRollback in interface StoragesupportsRollback in class AbstractDatabaseStorage
protected java.lang.String applyCreateScheme(java.lang.String tableName,
java.lang.String fieldDefinitions,
java.lang.String parentTableName)
applyCreateScheme in class AbstractDatabaseStoragetableName - the table to createfieldDefinitions - comma separated list of field definitionsparentTableName - the parent table (only used in OO databases)
protected java.lang.String createSQL(java.lang.String tableName,
java.lang.String fields,
java.lang.String parentTableName,
java.lang.String parentFields)
createSQL in class AbstractDatabaseStoragetableName - the name of the table to createfields - the definitions of the fieldsparentTableName - the name of the parent table. this value is null if
the table to be created has no parent table. The table is assumed to exist.parentFields - the definitions of the fields of the parent table (for use by relational databases)protected java.lang.String dropSQL(java.lang.String tableName)
tableName - the name of the table to drop
protected java.lang.String insertSQL(java.lang.String tableName,
java.lang.String fieldNames,
java.lang.String fieldValues)
insertSQL in class AbstractDatabaseStoragetableName - the name of the table where to insertfieldNames - the names of the fields to insertfieldValues - the values (generally '?' tokens that will be replaced) of the fields to insert
protected java.lang.String updateSQL(java.lang.String tableName,
java.lang.String setFields,
int number)
updateSQL in class AbstractDatabaseStoragetableName - the name of the table where to updatesetfields - the set-commands for the table fields, generally of the format 'field1=?, field2=? ...'number - the number of the object to update
protected java.lang.String deleteSQL(java.lang.String tableName,
int number)
deleteSQL in class AbstractDatabaseStoragetableName - the name of the table where to deletenumber - the number of the object to delete
protected java.lang.String selectSQL(java.lang.String tableName,
java.lang.String fieldNames,
java.lang.String where,
java.lang.String orderby,
int offset,
int max)
selectSQL in class AbstractDatabaseStoragetableName - the name of the table where to updatefieldNames - commaseparated list of fieldnames to retrieve, can be null (retrieve all fields)where - constraints, can be null (no constraints)orderby - optional fields to order by, can be null (no order)offset - offset from where to select records. Note: if you specify an offset larger than 0, you have to specify maxmax - maximum number of records, can be -1 (no max)public boolean isAllowedParentBuilder(MMObjectBuilder builder)
isAllowedParentBuilder in interface StorageisAllowedParentBuilder in class AbstractDatabaseStoragebuilder - the builder to test
public boolean setValuePreparedStatement(java.sql.PreparedStatement stmt,
MMObjectNode node,
java.lang.String fieldname,
int i)
throws java.sql.SQLException
setValuePreparedStatement in interface DatabaseStoragesetValuePreparedStatement in class AbstractDatabaseStoragejava.sql.SQLException - if an error occurred while filling in the fields
public void loadFieldFromTable(MMObjectNode node,
java.lang.String fieldname,
java.sql.ResultSet rs,
int i)
loadFieldFromTable in interface DatabaseStorageloadFieldFromTable in class AbstractDatabaseStoragenode - the node to store the field infieldname - the name of the field as it is known to MMBasers - the ResultSet containing the table rowi - the index of the field in the ResultSet
protected abstract java.lang.String getText(java.lang.String tableName,
java.lang.String fieldname,
int number)
getText in class Support2Storage
public java.lang.String getText(MMObjectNode node,
java.lang.String fieldname)
getText in interface StoragegetText in class AbstractDatabaseStorageorg.mmbase.storage.Storagenode - the node to retrieve the text fromfieldname - the name of the field to retrieve
protected abstract byte[] getBytes(java.lang.String tableName,
java.lang.String fieldname,
int number)
getBytes in class Support2Storage
public byte[] getBytes(MMObjectNode node,
java.lang.String fieldname)
getBytes in interface StoragegetBytes in class AbstractDatabaseStorageorg.mmbase.storage.Storagenode - the node to retrieve the byte array fromfieldname - the name of the field to retrieve
public int insert(MMObjectNode node,
Transaction trans)
throws StorageException
insert in interface Storageinsert in class AbstractDatabaseStoragenode - The node to inserttrans - the transaction to perform the insert inStorageException - if an error occurred during insert
protected int insertIntoTable(MMObjectBuilder builder,
MMObjectNode node,
DatabaseTransaction trans)
throws StorageException
insertSQL(java.lang.String, java.lang.String, java.lang.String),
using the name and fields of the specified builder.
Override this method to add required code, such as recursive updates for relational databases.
Only fields with states of DBSTATE_PERSISTENT or DBSTATE_SYSTEM are stored in the database tables.builder - the builder to store the node in. This can be a parentbuilder of the node's actual buildernode - The node to inserttrans - the transaction to perform the insert inStorageException - if an error occurred during insert
public boolean commit(MMObjectNode node,
Transaction trans)
throws StorageException
commit in interface Storagecommit in class AbstractDatabaseStoragebuilder - the builder to commit the node to. This can be a parentbuilder of the node's actual buildernode - The node to committrans - the transaction to perform the insert inStorageException - if an error occurred during commit
protected boolean commitToTable(MMObjectBuilder builder,
MMObjectNode node,
DatabaseTransaction trans)
throws StorageException
builder - the builder to commit the node to. This can be a parentbuilder of the node's actual buildernode - The node to committrans - the transaction to perform the insert inStorageException - if an error occurred during commit
public boolean delete(MMObjectNode node,
Transaction trans)
throws StorageException
delete in interface Storagedelete in class AbstractDatabaseStoragenode - The node to deletetrans - the transaction to perform the insert inStorageException - if an error occurred during delete
public boolean deleteFromTable(MMObjectBuilder builder,
MMObjectNode node,
DatabaseTransaction trans)
throws StorageException
builder - the builder to remove the node from. This can be a parentbuilder of the node's actual buildernode - The node to deletetrans - the transaction to perform the insert inStorageException - if an error occurred during delete
public MMObjectNode getNode(MMObjectBuilder builder,
int number,
Transaction trans)
throws StorageException
getNode in interface StoragegetNode in class AbstractDatabaseStoragebuilder - The builder to select fromnumber - the number of the nodetrans - the transaction to perform the insert inStorageException - if an error occurred during selection
public int getNodeType(int number,
Transaction trans)
throws StorageException
getNodeType in interface StoragegetNodeType in class AbstractDatabaseStoragenumber - the number of the nodetrans - the transaction to perform the insert inStorageException - if an error occurred during selectionprotected java.util.List getFieldsOrderCreate(MMObjectBuilder builder)
builder - the buidler whose fields to retrieve and sortprotected MMObjectBuilder getParentBuilder(MMObjectBuilder builder)
builder - the buidler to find the parent ofprotected java.lang.String getParentTableName(MMObjectBuilder builder)
builder - the builder to find the parent of
protected boolean isParentField(MMObjectBuilder builder,
java.lang.String fieldName)
builder - the builder to find the parent offieldname - the name to test
public boolean create(MMObjectBuilder builder,
Transaction trans)
throws StorageException
create in interface Storagecreate in class AbstractDatabaseStoragebuilder - the builder to create the table for\trans - the transaction to perform the insert inStorageException - if an error occurred during create
public boolean createObjectStorage(Transaction trans)
throws StorageException
createObjectStorage in interface StoragecreateObjectStorage in class AbstractDatabaseStoragetrans - the transaction to perform the insert inStorageException - if an error occurred during createpublic boolean created(MMObjectBuilder builder)
created in interface Storagecreated in class AbstractDatabaseStoragebuilder - the builder to checkpublic boolean created(java.lang.String tableName)
tableName - name of the table to checkpublic int size(MMObjectBuilder builder)
size in interface Storagesize in class AbstractDatabaseStoragebuilder - the builder whose objects to countpublic int size(java.lang.String tableName)
tableName - the table whose records to counted
protected boolean writeBytesToFile(java.lang.String filename,
byte[] value)
file - name the path of the filevalue - the value to writeprotected byte[] readBytesFromFile(java.lang.String filename)
readBytesFromFile in class Support2Storagefile - name the path of the filepublic boolean drop(MMObjectBuilder builder)
drop in interface Storagedrop in class AbstractDatabaseStoragebuilder - the builder whose table to drop
public boolean addField(MMObjectBuilder builder,
java.lang.String fieldname)
addField in interface StorageaddField in class AbstractDatabaseStoragebuilder - the builder whose table to changefieldname - the name fo the field to add
public boolean removeField(MMObjectBuilder builder,
java.lang.String fieldname)
removeField in interface StorageremoveField in class AbstractDatabaseStoragebuilder - the builder whose table to changefieldname - the name fo the field to delete
public boolean changeField(MMObjectBuilder builder,
java.lang.String fieldname)
changeField in interface StoragechangeField in class AbstractDatabaseStoragebuilder - the builder whose table to changefieldname - the name fo the field to changepublic boolean updateStorage(MMObjectBuilder builder)
updateStorage in interface StorageupdateStorage in class AbstractDatabaseStoragebuilder - the builder whose table to change
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||