org.mmbase.storage.database
Class RelationalDatabaseStorage

java.lang.Object
  |
  +--org.mmbase.storage.database.Support2Storage
        |
        +--org.mmbase.storage.database.AbstractDatabaseStorage
              |
              +--org.mmbase.storage.database.SQL92DatabaseStorage
                    |
                    +--org.mmbase.storage.database.RelationalDatabaseStorage
All Implemented Interfaces:
DatabaseStorage, MMJdbc2NodeInterface, Storage

public class RelationalDatabaseStorage
extends SQL92DatabaseStorage
implements DatabaseStorage, MMJdbc2NodeInterface

RelationalDatabaseStorage implements the DatabaseStorage interface and the MMJdbc2NodeInterface for Ansi SQL 92 relational databases. This class extends AbstractDatabaseStorage to include methods for retrieving data from a relational database systems. It overrides the various update methods to allow for recursive updates on parent tables, the methods for storing and retrieving huge texts and bytefields, and teh methods for determining database key (for the object 'number' field).

Since:
MMBase-1.6
Version:
$Id: RelationalDatabaseStorage.java,v 1.4 2002/11/12 16:57:53 pierre Exp $
Author:
Pierre van Rooden

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
RelationalDatabaseStorage()
          Constructs the Ansi SQL database layer support class
 
Method Summary
protected  boolean commitObjectTable(MMObjectNode node, DatabaseTransaction trans)
          Commit this node to the object table.
 boolean commitToTable(MMObjectBuilder builder, MMObjectNode node, DatabaseTransaction trans)
          Commit this node to the specified builder table.
 int createKey(Transaction trans)
          Gives an unique number for a node to be inserted.
 boolean deleteFromTable(MMObjectBuilder builder, MMObjectNode node, DatabaseTransaction trans)
          Remove a node from the specified builder table.
protected  boolean deleteObjectTable(MMObjectNode node, DatabaseTransaction trans)
          Remove a node from the object table.
 byte[] getBytes(java.lang.String tableName, java.lang.String fieldname, int number)
          Get byte of a database blob
 byte[] getDBByte(java.sql.ResultSet rs, int idx)
          Get byte of a database blob
 java.lang.String getDBText(java.sql.ResultSet rs, int idx)
          Get text of a database blob
 java.lang.String getText(java.lang.String tableName, java.lang.String fieldname, int number)
          Get text from blob
 int insertIntoTable(MMObjectBuilder builder, MMObjectNode node, DatabaseTransaction trans)
          This method inserts a new object in a specified builder table.
protected  int insertObjectTable(MMObjectNode node, DatabaseTransaction trans)
          This method inserts a new object in the object table.
protected  void prepare()
          Prepares the database layer.
 void setDBByte(int i, java.sql.PreparedStatement stmt, byte[] bytes)
          Set byte array in database
 void setDBText(int i, java.sql.PreparedStatement stmt, java.lang.String body)
          Set text array in database
 boolean supportsExtendedTables()
          Returns whether this storage layer supports extended tables.
 
Methods inherited from class org.mmbase.storage.database.SQL92DatabaseStorage
addField, applyCreateScheme, changeField, commit, create, created, created, createObjectStorage, createSQL, delete, deleteSQL, drop, dropSQL, getBytes, getFieldsOrderCreate, getNode, getNodeType, getParentBuilder, getParentTableName, getText, init, insert, insertSQL, isAllowedParentBuilder, isParentField, loadExistingTables, loadFieldFromTable, loadSupportInformation, readBytesFromFile, removeField, selectSQL, setValuePreparedStatement, size, size, supportsRollback, updateSQL, updateStorage, writeBytesToFile
 
Methods inherited from class org.mmbase.storage.database.AbstractDatabaseStorage
applyForeignKeyScheme, applyKeyScheme, applyNotNullScheme, applyPrimaryKeyScheme, applyScheme, commit, constructFieldDefinition, constructFieldDefinition, create, createDatabaseTransaction, createDatabaseTransaction, createKey, createObjectStorage, createSQL, createTransaction, delete, deployDatabaseDocument, getBinaryFilePath, getCreateExtendedScheme, getCreateScheme, getFieldNameMap, getForeignKeyScheme, getFullTableName, getJDBC, getKeyScheme, getMaxDropSize, getNode, getNodeType, getNotNullScheme, getNumberString, getPrimaryKeyScheme, getStoreBinaryAsFile, getTypeMap, insert, mapToMMBaseFieldName, mapToTableFieldName, matchType, registerChanged, registerParentBuilder, selectSQL, selectSQL, selectSQL, setBinaryFilePath, setCreateExtendedScheme, setCreateScheme, setFieldNameMap, setForeignKeyScheme, setKeyScheme, setMaxDropSize, setNotNullScheme, setPrimaryKeyScheme, setStoreBinaryAsFile, setTypeMap
 
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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.mmbase.storage.database.DatabaseStorage
deployDatabaseDocument, getBinaryFilePath, getCreateExtendedScheme, getCreateScheme, getFieldNameMap, getForeignKeyScheme, getJDBC, getKeyScheme, getMaxDropSize, getNotNullScheme, getPrimaryKeyScheme, getStoreBinaryAsFile, getTypeMap, init, loadFieldFromTable, mapToMMBaseFieldName, mapToTableFieldName, registerChanged, setBinaryFilePath, setCreateExtendedScheme, setCreateScheme, setFieldNameMap, setForeignKeyScheme, setKeyScheme, setMaxDropSize, setNotNullScheme, setPrimaryKeyScheme, setStoreBinaryAsFile, setTypeMap, setValuePreparedStatement
 
Methods inherited from interface org.mmbase.storage.Storage
addField, changeField, commit, commit, create, create, created, createKey, createObjectStorage, createObjectStorage, createTransaction, delete, delete, drop, getBytes, getNode, getNode, getNodeType, getNodeType, getText, insert, insert, isAllowedParentBuilder, registerParentBuilder, removeField, size, supportsRollback, updateStorage
 
Methods inherited from interface org.mmbase.module.database.support.MMJdbc2NodeInterface
addField, changeField, commit, create, created, createObjectTable, decodeDBnodeField, decodeDBnodeField, drop, getAllowedField, getConnection, getDBKey, getDisallowedField, getMMNodeSearch2SQL, getNumberString, getOTypeString, getOwnerString, getShortedByte, getShortedText, init, insert, isAllowedParentBuilder, registerParentBuilder, removeField, removeNode, updateTable
 

Constructor Detail

RelationalDatabaseStorage

public RelationalDatabaseStorage()
Constructs the Ansi SQL database layer support class
Method Detail

prepare

protected void prepare()
Prepares the database layer. This code creates a 'numbertable' for MMBase to track number generation by the createKey(org.mmbase.storage.Transaction) method. Override this method if you use a different way of generating keys, or if you need to make other preparations for your database.
Overrides:
prepare in class SQL92DatabaseStorage

supportsExtendedTables

public boolean supportsExtendedTables()
Returns whether this storage layer supports extended tables.
Specified by:
supportsExtendedTables in interface DatabaseStorage
Overrides:
supportsExtendedTables in class SQL92DatabaseStorage
Returns:
boolean true if extended tables are supported

getText

public java.lang.String getText(java.lang.String tableName,
                                java.lang.String fieldname,
                                int number)
Get text from blob
Overrides:
getText in class SQL92DatabaseStorage

getBytes

public byte[] getBytes(java.lang.String tableName,
                       java.lang.String fieldname,
                       int number)
Get byte of a database blob
Overrides:
getBytes in class SQL92DatabaseStorage

getDBByte

public byte[] getDBByte(java.sql.ResultSet rs,
                        int idx)
Get byte of a database blob
Specified by:
getDBByte in interface MMJdbc2NodeInterface
Overrides:
getDBByte in class Support2Storage

getDBText

public java.lang.String getDBText(java.sql.ResultSet rs,
                                  int idx)
Get text of a database blob
Specified by:
getDBText in interface MMJdbc2NodeInterface
Overrides:
getDBText in class Support2Storage

setDBText

public void setDBText(int i,
                      java.sql.PreparedStatement stmt,
                      java.lang.String body)
Set text array in database
Overrides:
setDBText in class AbstractDatabaseStorage

setDBByte

public void setDBByte(int i,
                      java.sql.PreparedStatement stmt,
                      byte[] bytes)
Set byte array in database
Specified by:
setDBByte in interface MMJdbc2NodeInterface
Overrides:
setDBByte in class AbstractDatabaseStorage

createKey

public int createKey(Transaction trans)
              throws StorageException
Gives an unique number for a node to be inserted. This method will work with multiple mmbases
Specified by:
createKey in interface Storage
Overrides:
createKey in class AbstractDatabaseStorage
Parameters:
trans - the transaction to use for obtaining the key
Returns:
unique number
Throws:
StorageException - if an error occurred while obtaining the key

insertIntoTable

public int insertIntoTable(MMObjectBuilder builder,
                           MMObjectNode node,
                           DatabaseTransaction trans)
                    throws StorageException
This method inserts a new object in a specified builder table. Only fields with states of DBSTATE_PERSISTENT or DBSTATE_SYSTEM are stored in the database tables.
Overrides:
insertIntoTable in class SQL92DatabaseStorage
Parameters:
builder - the builder to store teh node in. This can be a parentbuilder of the node's actual builder
node - The node to insert
trans - the transaction to perform the insert in
Returns:
The (new) number for this node, or -1 if an error occurs.
Throws:
StorageException - if an error occurred during insert

insertObjectTable

protected int insertObjectTable(MMObjectNode node,
                                DatabaseTransaction trans)
                         throws StorageException
This method inserts a new object in the object table. Called by SQL92DatabaseStorage.insert(org.mmbase.module.core.MMObjectNode, org.mmbase.storage.Transaction) to maintain consistency.
Parameters:
node - The node to insert
trans - the transaction to perform the insert in
Returns:
The (new) number for this node, or -1 if an error occurs.
Throws:
StorageException - if an error occurred during insert

commitToTable

public boolean commitToTable(MMObjectBuilder builder,
                             MMObjectNode node,
                             DatabaseTransaction trans)
                      throws StorageException
Commit this node to the specified builder table.
Overrides:
commitToTable in class SQL92DatabaseStorage
Parameters:
builder - the builder to commit the node to. This can be a parentbuilder of the node's actual builder
node - The node to insert
trans - the transaction to perform the insert in
Returns:
true of succesful, false otherwise
Throws:
StorageException - if an error occurred during commit

commitObjectTable

protected boolean commitObjectTable(MMObjectNode node,
                                    DatabaseTransaction trans)
                             throws StorageException
Commit this node to the object table.
Parameters:
node - The node to insert
trans - the transaction to perform the insert in
Returns:
true of succesful, false otherwise
Throws:
StorageException - if an error occurred during commit

deleteFromTable

public boolean deleteFromTable(MMObjectBuilder builder,
                               MMObjectNode node,
                               DatabaseTransaction trans)
                        throws StorageException
Remove a node from the specified builder table.
Overrides:
deleteFromTable in class SQL92DatabaseStorage
Parameters:
builder - the builder to remove the node from. This can be a parentbuilder of the node's actual builder
node - The node to delete
trans - the transaction to perform the insert in
Throws:
StorageException - if an error occurred during delete

deleteObjectTable

protected boolean deleteObjectTable(MMObjectNode node,
                                    DatabaseTransaction trans)
                             throws StorageException
Remove a node from the object table.
Parameters:
node - The node to delete
trans - the transaction to perform the insert in
Throws:
StorageException - if an error occurred during delete


MMBase build 1.6.5.20030923