|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.mmbase.module.database.support.BaseJdbc2Node
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.
| Field Summary |
| 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 |
| Fields inherited from interface org.mmbase.storage.search.SearchQueryHandler |
FEATURE_MAX_NUMBER, FEATURE_OFFSET, SUPPORT_NONE, SUPPORT_NORMAL, SUPPORT_OPTIMAL, SUPPORT_WEAK |
| Constructor Summary | |
protected |
SQL92DatabaseStorage()
Deprecated. Constructs the AbstractDatabaseSupport database layer support class |
| Method Summary | |
boolean |
addField(MMObjectBuilder builder,
java.lang.String fieldname)
Deprecated. 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)
Deprecated. Applies the create scheme (if available), and returns the result (a field type defintiton string) |
boolean |
changeField(MMObjectBuilder builder,
java.lang.String fieldname)
Deprecated. Changes a field to the table of this builder. |
boolean |
commit(MMObjectNode node,
Transaction trans)
Deprecated. Commit this node to the specified builder table within a transaction. |
protected boolean |
commitToTable(MMObjectBuilder builder,
MMObjectNode node,
DatabaseTransaction trans)
Deprecated. Commit the changes to this node to the specified builder table. |
boolean |
create(MMObjectBuilder builder,
Transaction trans)
Deprecated. Create a database table for the specified builder. |
boolean |
created(MMObjectBuilder builder)
Deprecated. Tells if a table for the builder already exists |
boolean |
created(java.lang.String tableName)
Deprecated. Tells if a table already exists |
boolean |
createObjectStorage(Transaction trans)
Deprecated. 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)
Deprecated. Returns the SQL command to use for creating a specified table, optionally extending another supplied table. |
boolean |
delete(MMObjectNode node,
Transaction trans)
Deprecated. Delete a node within a transaction |
boolean |
deleteFromTable(MMObjectBuilder builder,
MMObjectNode node,
DatabaseTransaction trans)
Deprecated. Remove a node from the specified builder table. |
protected java.lang.String |
deleteSQL(java.lang.String tableName,
int number)
Deprecated. Returns the SQL command to use for deleting an object in a table. |
boolean |
drop(MMObjectBuilder builder)
Deprecated. Drops the table of this builder. |
protected java.lang.String |
dropSQL(java.lang.String tableName)
Deprecated. Returns the SQL command to use for dropping a specified table Overide this method to add a database-specific syntax or optimalization |
protected java.io.File |
getBinaryFile(java.lang.String tableName,
java.lang.String fieldName,
int number)
Deprecated. Defines how binary (blob) files must look like. |
byte[] |
getBytes(MMObjectNode node,
java.lang.String fieldName)
Deprecated. retrieves bytes from file or database depending on if getStoreBinayAsFIle is true |
protected java.util.List |
getFieldsOrderCreate(MMObjectBuilder builder)
Deprecated. Returns the fields of a builder in the order in which they should be created. |
MMObjectNode |
getNode(MMObjectBuilder builder,
int number,
Transaction trans)
Deprecated. Select a node from a specified builder |
int |
getNodeType(int number,
Transaction trans)
Deprecated. Returns the nodetype for a specified nodereference |
protected MMObjectBuilder |
getParentBuilder(MMObjectBuilder builder)
Deprecated. Returns the parent builder of the specifed builder. |
protected java.lang.String |
getParentTableName(MMObjectBuilder builder)
Deprecated. Returns the name of the parent table of the specifed builder. |
java.lang.String |
getText(MMObjectNode node,
java.lang.String fieldname)
Deprecated. Get text from blob |
protected abstract java.lang.String |
getText(java.lang.String tableName,
java.lang.String fieldname,
int number)
Deprecated. Get text from blob |
void |
init(MMBase mmb,
XMLDatabaseReader document)
Deprecated. Initializes the database layer. |
int |
insert(MMObjectNode node,
Transaction trans)
Deprecated. This method inserts a new object within a transaction, and registers the change. |
protected int |
insertIntoTable(MMObjectBuilder builder,
MMObjectNode node,
DatabaseTransaction trans)
Deprecated. 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)
Deprecated. Returns the SQL command to use for inserting an object in a table. |
boolean |
isAllowedParentBuilder(MMObjectBuilder builder)
Deprecated. 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)
Deprecated. Tests whether the specified field is a member of the parent table of the specifed builder. |
protected void |
loadExistingTables()
Deprecated. 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)
Deprecated. Stores a field in a table ResultSet in a MMObjectNode. |
protected void |
loadSupportInformation()
Deprecated. Load information on database support (i.e support of rollback). |
protected void |
prepare()
Deprecated. Prepares the database layer. |
protected byte[] |
readBytesFromFile(java.lang.String tableName,
java.lang.String fieldName,
int number)
Deprecated. Reads a byte array from a file. |
boolean |
removeField(MMObjectBuilder builder,
java.lang.String fieldname)
Deprecated. 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)
Deprecated. 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)
Deprecated. Set prepared statement field i with value of key from node |
int |
size(MMObjectBuilder builder)
Deprecated. Return number of objects in a builder |
int |
size(java.lang.String tableName)
Deprecated. Return number of entries consisting in given table. |
boolean |
supportsRollback()
Deprecated. Returns whether rollback on storage level is supported. |
protected java.lang.String |
updateSQL(java.lang.String tableName,
java.lang.String setFields,
int number)
Deprecated. Returns the SQL command to use for updating an object in a table. |
boolean |
updateStorage(MMObjectBuilder builder)
Deprecated. Changes the storage of a builder to match its new configuration. |
protected boolean |
writeBytesToFile(java.lang.String tableName,
java.lang.String fieldName,
int number,
byte[] value)
Deprecated. Writes a byte array to a file. |
| Methods inherited from class org.mmbase.storage.database.Support2Storage |
commit, createObjectTable, decodeDBnodeField, decodeDBnodeField, getAllowedField, getConnection, getDBKey, getDisallowedField, getMMNodeSearch2SQL, getOTypeString, getOwnerString, getShortedByte, getShortedText, insert, removeNode, updateTable |
| Methods inherited from class org.mmbase.module.database.support.BaseJdbc2Node |
getNodes, getSupportLevel, getSupportLevel, init |
| 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 |
| Methods inherited from interface org.mmbase.storage.search.SearchQueryHandler |
getNodes, getSupportLevel, getSupportLevel |
| 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 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 updatenumber - 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
DatabaseStorage
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)
DatabaseStorage
loadFieldFromTable in interface DatabaseStorageloadFieldFromTable in class AbstractDatabaseStorage
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 AbstractDatabaseStorage
public final byte[] getBytes(MMObjectNode node,
java.lang.String fieldName)
getBytes in interface StoragegetBytes in class AbstractDatabaseStorage
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 in
StorageException - 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 in
StorageException - if an error occurred during insert
public boolean commit(MMObjectNode node,
Transaction trans)
throws StorageException
commit in interface Storagecommit in class AbstractDatabaseStoragenode - The node to committrans - the transaction to perform the insert in
StorageException - 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 in
StorageException - 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 in
StorageException - 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 in
StorageException - 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 in
StorageException - 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 in
StorageException - if an error occurred during selectionprotected java.util.List getFieldsOrderCreate(MMObjectBuilder builder)
builder - the buidler whose fields to retrieve and sort
protected MMObjectBuilder getParentBuilder(MMObjectBuilder builder)
builder - the buidler to find the parent of
protected 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 of
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 in
StorageException - 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 in
StorageException - if an error occurred during createpublic boolean created(MMObjectBuilder builder)
created in interface Storagecreated in class AbstractDatabaseStoragebuilder - the builder to check
public boolean created(java.lang.String tableName)
created in interface MMJdbc2NodeInterfacetableName - name of the table to check
public int size(MMObjectBuilder builder)
size in interface Storagesize in class AbstractDatabaseStoragebuilder - the builder whose objects to count
public int size(java.lang.String tableName)
tableName - the table whose records to counted
protected java.io.File getBinaryFile(java.lang.String tableName,
java.lang.String fieldName,
int number)
tableName - fieldName - number -
protected boolean writeBytesToFile(java.lang.String tableName,
java.lang.String fieldName,
int number,
byte[] value)
value - the value to write
protected byte[] readBytesFromFile(java.lang.String tableName,
java.lang.String fieldName,
int number)
readBytesFromFile in class Support2Storagepublic 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 change
public 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: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||