org.mmbase.storage.database
Class AbstractDatabaseStorage

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

public abstract class AbstractDatabaseStorage
extends Support2Storage
implements DatabaseStorage

AbstractDatabaseStorage implements part of the DatabaseStorage interface, and supplies utility routines for other support classes. In particulatr, this layer implements the 'stateless' builder update methods, methods for creating Transactions, and methods for setting and retrieving configuration data. Further, a number of utility methods are defined for constructing SQL-statements (or parts thereof) using schemes. Finally, a number of abstract methods relating to teh constrcution of SQL statements are defined, which a extending class should implement.

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

Field Summary
protected  MMBase mmb
          The MMBase instance that uses this database
 
Fields inherited from interface org.mmbase.storage.database.DatabaseStorage
KEY_FOREIGN, KEY_NONE, KEY_NOTNULL, KEY_PRIMARY, KEY_SECONDARY
 
Constructor Summary
protected AbstractDatabaseStorage()
          Constructs the AbstractDatabaseSupport database layer support class
 
Method Summary
abstract  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)
protected  java.lang.String applyForeignKeyScheme(java.lang.String fieldName, java.lang.String fieldType, java.lang.String reference)
          Applies the foreign key scheme (if available), and returns the result (a field type defintiton string)
protected  java.lang.String applyKeyScheme(java.lang.String fieldName, java.lang.String fieldType, java.lang.String indexName)
          Applies the key scheme (if available), and returns the result (a field type defintiton string)
protected  java.lang.String applyNotNullScheme(java.lang.String fieldName, java.lang.String fieldType)
          Applies the not null scheme (if available), and returns the result (a field type defintiton string)
protected  java.lang.String applyPrimaryKeyScheme(java.lang.String fieldName, java.lang.String fieldType)
          Applies the primary key scheme (if available), and returns the result (a field type defintiton string)
protected  java.lang.String applyScheme(java.lang.String scheme, java.lang.String a1, java.lang.String a2, java.lang.String a3)
          Applies a given scheme.
abstract  boolean changeField(MMObjectBuilder builder, java.lang.String fieldname)
          Changes a field to the table of this builder.
 boolean commit(MMObjectNode node)
          Commit this node to the specified builder table.
abstract  boolean commit(MMObjectNode node, Transaction trans)
          Commit this node to the specified builder table within a transaction.
protected  java.lang.String constructFieldDefinition(MMObjectBuilder builder, FieldDefs field)
          Constructs a creation definition segment for one field, to use in a CREATE TABLE sql comand
protected  java.lang.String constructFieldDefinition(java.lang.String tablename, java.lang.String fieldname, int type, int size, int keyType)
          Constructs a creation definition segment for one field, to use in a CREATE TABLE sql comand
 boolean create(MMObjectBuilder builder)
          Create a database table for the specified builder.
abstract  boolean create(MMObjectBuilder builder, Transaction trans)
          Create a database table for the specified builder.
abstract  boolean created(MMObjectBuilder builder)
          Tells if a table for the builder already exists
 DatabaseTransaction createDatabaseTransaction()
          Returns a newly created database transaction object.
 DatabaseTransaction createDatabaseTransaction(boolean useRollback)
          Returns a newly created database transaction object.
 int createKey()
          Gives an unique number for a node to be inserted.
abstract  int createKey(Transaction trans)
          Gives an unique number for a node to be inserted.
 boolean createObjectStorage()
          Create the object table (the basic table for all objects).
abstract  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)
          Returns the SQL command to use for creating a specified table
protected abstract  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.
 Transaction createTransaction()
          Returns a newly created transaction object.
 boolean delete(MMObjectNode node)
          Delete a node
abstract  boolean delete(MMObjectNode node, Transaction trans)
          Delete a node within a transaction
protected abstract  java.lang.String deleteSQL(java.lang.String tableName, int number)
          Returns the SQL command to use for deleting an object in a table.
 void deployDatabaseDocument(XMLDatabaseReader document)
          This reads database specific content from the database configuration document.
abstract  boolean drop(MMObjectBuilder builder)
          Drops the table of this builder.
 java.lang.String getBinaryFilePath()
          Returns the filepath where binary objects are stored.
abstract  byte[] getBytes(MMObjectNode node, java.lang.String fieldname)
          Get bytes from blob
 java.lang.String getCreateExtendedScheme()
          Returns the scheme (SQL command) to use for creating a table that extends another table
 java.lang.String getCreateScheme()
          Returns the scheme (SQL command) to use for creating a table
 java.util.Map getFieldNameMap()
          Returns the current mapping of disallowed fieldsnames (typically reserved words) and their replacement names.
 java.lang.String getForeignKeyScheme()
          Returns the scheme (SQL command) to use for creating a foreign key
protected  java.lang.String getFullTableName(java.lang.String tableName)
          Returns the fully expanded tablename (includes the MMbase basename prefix)
 JDBCInterface getJDBC()
          Returns the JDBC module used by this class to connect to the database.
 java.lang.String getKeyScheme()
          Returns the scheme (SQL command) to use for creating a key
 int getMaxDropSize()
          Returns the maximum table drop size.
 MMObjectNode getNode(MMObjectBuilder builder, int number)
          Select a node from a specified builder
abstract  MMObjectNode getNode(MMObjectBuilder builder, int number, Transaction trans)
          Select a node from a specified builder
 int getNodeType(int number)
          Returns the nodetype for a specified nodereference
abstract  int getNodeType(int number, Transaction trans)
          Returns the nodetype for a specified nodereference
 java.lang.String getNotNullScheme()
          Returns the scheme (SQL command) to use for creating a non-null field
 java.lang.String getNumberString()
          Maps the 'number' fieldname to a fieldname acceptable to the database.
 java.lang.String getPrimaryKeyScheme()
          Returns the scheme (SQL command) to use for creating a primary key
 boolean getStoreBinaryAsFile()
          Returns whether binary objects are stored as files (rather than in the database)
abstract  java.lang.String getText(MMObjectNode node, java.lang.String fieldname)
          Get text from blob
 java.util.Map getTypeMap()
          Obtains the type map.
 void init(MMBase mmb, XMLDatabaseReader document)
          Initializes the database layer.
 int insert(MMObjectNode node)
          This method inserts a new object, and registers the change.
abstract  int insert(MMObjectNode node, Transaction trans)
          This method inserts a new object within a transaction, and registers the change.
protected abstract  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.
abstract  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).
abstract  void loadFieldFromTable(MMObjectNode node, java.lang.String fieldname, java.sql.ResultSet rs, int i)
          Stores a field in a table ResultSet in a MMObjectNode.
 java.lang.String mapToMMBaseFieldName(java.lang.String fieldname)
          Maps a database fieldname to a fieldname as used by the MMbase system
 java.lang.String mapToTableFieldName(java.lang.String fieldname)
          Maps a MMBase fieldname to a fieldname acceptable to the database
protected  java.lang.String matchType(int type, int size)
          Map a MMBase Type to a database specific type.
 void registerChanged(MMObjectNode node, java.lang.String change)
          Registers the change to a node.
 void registerParentBuilder(MMObjectBuilder parent, MMObjectBuilder child)
          Registers a builder as a parent builder (that is, other builders can 'extend' this builder and its database tables).
abstract  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)
          Returns the SQL command to use for selecting data from a table.
protected  java.lang.String selectSQL(java.lang.String tableName, java.lang.String fieldNames, int number)
          Returns the SQL command to use for selecting data from one object.
protected  java.lang.String selectSQL(java.lang.String tableName, java.lang.String fieldNames, java.lang.String where, java.lang.String orderby)
          Returns the SQL command to use for selecting data from a table.
protected abstract  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.
 void setBinaryFilePath(java.lang.String path)
          Sets the filepath where binary objects are stored.
 void setCreateExtendedScheme(java.lang.String scheme)
          Sets the scheme (SQL command) to use for creating a table that extends another table An acceptable scheme is: CREATE TABLE {0} ({1}) EXTENDS ({2}) where {0} is replaced with the table name, [1} with the field definitions, and {2} with teh parent table name
 void setCreateScheme(java.lang.String scheme)
          Sets the scheme (SQL command) to use for creating a table An acceptable scheme is: CREATE TABLE {0} ({1}) where {0} is replaced with the table name and [1} with the field definitions.
abstract  void setDBByte(int i, java.sql.PreparedStatement stmt, byte[] bytes)
          Set byte array in database
abstract  void setDBText(int i, java.sql.PreparedStatement stmt, java.lang.String body)
          Set text array in database
 void setFieldNameMap(java.util.Map fieldmap)
          Sets the mapping of MMBase fieldnames (typically reserved words) to database fieldnames.
 void setForeignKeyScheme(java.lang.String scheme)
          Sets the scheme (SQL command) to use for creating a foreign key An acceptable scheme is: {0} {1} NOT NULL, FOREIGN KEY {0} ({0}) REFERENCES {2} (number) where {0} and [1} are replaced with the field name and type definition, and {2} is the table referenced.
 void setKeyScheme(java.lang.String scheme)
          Sets the scheme (SQL command) to use for creating a key An acceptable scheme is: {0} {1} NOT NULL, UNIQUE ({0}) where {0} and [1} are replaced with the field name and type definition.
 void setMaxDropSize(int value)
          Sets the maximum table drop size.
 void setNotNullScheme(java.lang.String scheme)
          Sets the scheme (SQL command) to use for creating a non-null field An acceptable scheme is: {0} {1} NOT NULL where {0} and [1} are replaced with the field name and type definition.
 void setPrimaryKeyScheme(java.lang.String scheme)
          Sets the scheme (SQL command) to use for creating a primary key.
 void setStoreBinaryAsFile(boolean value)
          Sets whether binary objects are stored as files (rather than in the database)
 void setTypeMap(java.util.Map typeMap)
          Sets the type map.
abstract  boolean setValuePreparedStatement(java.sql.PreparedStatement stmt, MMObjectNode node, java.lang.String key, int i)
          Set a prepared statement field i with value of key from the given node.
abstract  int size(MMObjectBuilder builder)
          Return number of objects in a builder
abstract  boolean supportsExtendedTables()
          Returns whether this storage layer supports extended tables.
abstract  boolean supportsRollback()
          Returns whether rollback on storage level is supported.
protected abstract  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.
abstract  boolean updateStorage(MMObjectBuilder builder)
          Changes the storage of a builder to match its new configuration.
 
Methods inherited from class org.mmbase.storage.database.Support2Storage
commit, createObjectTable, decodeDBnodeField, decodeDBnodeField, getAllowedField, getBytes, getConnection, getDBByte, getDBKey, getDBText, getDisallowedField, getMMNodeSearch2SQL, getOTypeString, getOwnerString, getShortedByte, getShortedText, getText, insert, readBytesFromFile, 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.module.database.support.MMJdbc2NodeInterface
created
 

Field Detail

mmb

protected MMBase mmb
The MMBase instance that uses this database
Constructor Detail

AbstractDatabaseStorage

protected AbstractDatabaseStorage()
Constructs the AbstractDatabaseSupport database layer support class
Method Detail

init

public void init(MMBase mmb,
                 XMLDatabaseReader document)
Initializes the database layer. This reads database specific content from the database configuration document. If needed, the code creates a 'numbertable' for mmbase to track number generation.
Specified by:
init in interface DatabaseStorage
Parameters:
mmb - the MBase instance that uses this database layer
document - the database configuration document

deployDatabaseDocument

public void deployDatabaseDocument(XMLDatabaseReader document)
This reads database specific content from the database configuration document.
Specified by:
deployDatabaseDocument in interface DatabaseStorage
Parameters:
document - the database configuration document

getStoreBinaryAsFile

public boolean getStoreBinaryAsFile()
Returns whether binary objects are stored as files (rather than in the database)
Specified by:
getStoreBinaryAsFile in interface DatabaseStorage
Overrides:
getStoreBinaryAsFile in class Support2Storage
Returns:
true if binary objects are stored as files

setStoreBinaryAsFile

public void setStoreBinaryAsFile(boolean value)
Sets whether binary objects are stored as files (rather than in the database)
Specified by:
setStoreBinaryAsFile in interface DatabaseStorage
Parameters:
value - if true, binary objects will be stored as files

getBinaryFilePath

public java.lang.String getBinaryFilePath()
Returns the filepath where binary objects are stored. Only applies if getStoreBinaryAsFile() returns true.
Specified by:
getBinaryFilePath in interface DatabaseStorage
Overrides:
getBinaryFilePath in class Support2Storage
Returns:
the file path

setBinaryFilePath

public void setBinaryFilePath(java.lang.String path)
Sets the filepath where binary objects are stored. Only applies if getStoreBinaryAsFile() returns true.
Specified by:
setBinaryFilePath in interface DatabaseStorage
Parameters:
path - the file path

setFieldNameMap

public void setFieldNameMap(java.util.Map fieldmap)
Sets the mapping of MMBase fieldnames (typically reserved words) to database fieldnames. This map is used to map MMBase fieldnames to fieldnames that are acceptable to the database, i.e. Oracle does not accept 'number' as a fieldname, though MMBase uses it as a field name.
Specified by:
setFieldNameMap in interface DatabaseStorage
Parameters:
fieldmap - Map of field mappings. The map contins a key value pairs where the key is the MMbase fieldname, and the value the replacement acceptable to the database.

getFieldNameMap

public java.util.Map getFieldNameMap()
Returns the current mapping of disallowed fieldsnames (typically reserved words) and their replacement names. Note that this is a copy. Changes made to this map will not affect the databse until set with setFieldNameMap(java.util.Map).
Specified by:
getFieldNameMap in interface DatabaseStorage
Returns:
a Map of field mappings.

setTypeMap

public void setTypeMap(java.util.Map typeMap)
Sets the type map. The type map is used to convert MMBase types to database types (needed for creating tables).
Specified by:
setTypeMap in interface DatabaseStorage
Parameters:
typemap - Map of MMBase types and their database type.

getTypeMap

public java.util.Map getTypeMap()
Obtains the type map. The type map is used to convert MMBase types to database types (needed for creating tables). Note that this is a copy. Changes made to this map will not affect the database until set with setTypeMap(java.util.Map). However, the individual map elements are not copies - changing the dTypeInfo objects wil affect the database layer directly.
Specified by:
getTypeMap in interface DatabaseStorage
Returns:
a Map of MMBase types and their database type.

setPrimaryKeyScheme

public void setPrimaryKeyScheme(java.lang.String scheme)
Sets the scheme (SQL command) to use for creating a primary key. An acceptable scheme is: {0} {1} NOT NULL, PRIMARY KEY ({0}) where {0} and [1} are replaced with the field name and type definition.
Specified by:
setPrimaryKeyScheme in interface DatabaseStorage
Parameters:
scheme - the scheme to use

getPrimaryKeyScheme

public java.lang.String getPrimaryKeyScheme()
Returns the scheme (SQL command) to use for creating a primary key
Specified by:
getPrimaryKeyScheme in interface DatabaseStorage

setNotNullScheme

public void setNotNullScheme(java.lang.String scheme)
Sets the scheme (SQL command) to use for creating a non-null field An acceptable scheme is: {0} {1} NOT NULL where {0} and [1} are replaced with the field name and type definition.
Specified by:
setNotNullScheme in interface DatabaseStorage
Parameters:
scheme - the scheme to use

getNotNullScheme

public java.lang.String getNotNullScheme()
Returns the scheme (SQL command) to use for creating a non-null field
Specified by:
getNotNullScheme in interface DatabaseStorage

setKeyScheme

public void setKeyScheme(java.lang.String scheme)
Sets the scheme (SQL command) to use for creating a key An acceptable scheme is: {0} {1} NOT NULL, UNIQUE ({0}) where {0} and [1} are replaced with the field name and type definition.
Specified by:
setKeyScheme in interface DatabaseStorage
Parameters:
scheme - the scheme to use

getKeyScheme

public java.lang.String getKeyScheme()
Returns the scheme (SQL command) to use for creating a key
Specified by:
getKeyScheme in interface DatabaseStorage

setForeignKeyScheme

public void setForeignKeyScheme(java.lang.String scheme)
Sets the scheme (SQL command) to use for creating a foreign key An acceptable scheme is: {0} {1} NOT NULL, FOREIGN KEY {0} ({0}) REFERENCES {2} (number) where {0} and [1} are replaced with the field name and type definition, and {2} is the table referenced.
Specified by:
setForeignKeyScheme in interface DatabaseStorage
Parameters:
scheme - the scheme to use

getForeignKeyScheme

public java.lang.String getForeignKeyScheme()
Returns the scheme (SQL command) to use for creating a foreign key
Specified by:
getForeignKeyScheme in interface DatabaseStorage

setCreateScheme

public void setCreateScheme(java.lang.String scheme)
Sets the scheme (SQL command) to use for creating a table An acceptable scheme is: CREATE TABLE {0} ({1}) where {0} is replaced with the table name and [1} with the field definitions.
Specified by:
setCreateScheme in interface DatabaseStorage
Parameters:
scheme - the scheme to use

getCreateScheme

public java.lang.String getCreateScheme()
Returns the scheme (SQL command) to use for creating a table
Specified by:
getCreateScheme in interface DatabaseStorage

setCreateExtendedScheme

public void setCreateExtendedScheme(java.lang.String scheme)
Sets the scheme (SQL command) to use for creating a table that extends another table An acceptable scheme is: CREATE TABLE {0} ({1}) EXTENDS ({2}) where {0} is replaced with the table name, [1} with the field definitions, and {2} with teh parent table name
Specified by:
setCreateExtendedScheme in interface DatabaseStorage
Parameters:
scheme - the scheme to use

getCreateExtendedScheme

public java.lang.String getCreateExtendedScheme()
Returns the scheme (SQL command) to use for creating a table that extends another table
Specified by:
getCreateExtendedScheme in interface DatabaseStorage

setMaxDropSize

public void setMaxDropSize(int value)
Sets the maximum table drop size.
Specified by:
setMaxDropSize in interface DatabaseStorage
Parameters:
value - the maximum size to set

getMaxDropSize

public int getMaxDropSize()
Returns the maximum table drop size.
Specified by:
getMaxDropSize in interface DatabaseStorage

supportsExtendedTables

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

getFullTableName

protected java.lang.String getFullTableName(java.lang.String tableName)
Returns the fully expanded tablename (includes the MMbase basename prefix)
Overrides:
getFullTableName in class Support2Storage
Parameters:
tableName - the table name to expand
Returns:
the expanded tablename

applyScheme

protected java.lang.String applyScheme(java.lang.String scheme,
                                       java.lang.String a1,
                                       java.lang.String a2,
                                       java.lang.String a3)
Applies a given scheme.
Parameters:
scheme - the scheme to apply
a1 - the first parameter to substitute in the scheme
a2 - the second parameter to substitute in the scheme
a3 - the third parameter to substitute in the scheme
Returns:
the applied scheme

applyPrimaryKeyScheme

protected java.lang.String applyPrimaryKeyScheme(java.lang.String fieldName,
                                                 java.lang.String fieldType)
Applies the primary key scheme (if available), and returns the result (a field type defintiton string)
Parameters:
fieldName - the database fieldname
fieldType - the database field type defintition
Returns:
the applied scheme

applyNotNullScheme

protected java.lang.String applyNotNullScheme(java.lang.String fieldName,
                                              java.lang.String fieldType)
Applies the not null scheme (if available), and returns the result (a field type defintiton string)
Parameters:
fieldName - the database fieldname
fieldType - the database field type defintition
Returns:
the applied scheme

applyKeyScheme

protected java.lang.String applyKeyScheme(java.lang.String fieldName,
                                          java.lang.String fieldType,
                                          java.lang.String indexName)
Applies the key scheme (if available), and returns the result (a field type defintiton string)
Parameters:
fieldName - the database fieldname
fieldType - the database field type defintition
indexName - the name for the index
Returns:
the applied scheme

applyForeignKeyScheme

protected java.lang.String applyForeignKeyScheme(java.lang.String fieldName,
                                                 java.lang.String fieldType,
                                                 java.lang.String reference)
Applies the foreign key scheme (if available), and returns the result (a field type defintiton string)
Parameters:
fieldName - the database fieldname
fieldType - the database field type defintition
reference - the name of the table refrenced
Returns:
the applied scheme

applyCreateScheme

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)
Parameters:
tableName - the table to create
fieldDefinitions - comma separated list of field definitions
parentTableName - the parent table (only used in OO databases)
Returns:
the applied scheme

createSQL

protected java.lang.String createSQL(java.lang.String tableName,
                                     java.lang.String fields)
Returns the SQL command to use for creating a specified table
Parameters:
tableName - the name of the table to create
fields - the definitions of the fields
Returns:
the sql query

createSQL

protected abstract 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. Implement this method to add a database-specific syntax or optimalization.
Parameters:
tableName - the name of the table to create
fields - the definitions of the fields
parentTableName - 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)
Returns:
the sql query

insertSQL

protected abstract 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. Implement this method to add a database-specific syntax or optimalization.
Parameters:
tableName - the name of the table where to insert
fieldNames - the names of the fields to insert
fieldValues - the values (generally '?' tokens that will be replaced) of the fields to insert
Returns:
the sql query

updateSQL

protected abstract 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. Implement this method to add a database-specific syntax or optimalization.
Parameters:
tableName - the name of the table where to update
setfields - the set-commands for the table fields, generally of the format 'field1=?, field2=? ...'
number - the number of the object to update
Returns:
the sql query

deleteSQL

protected abstract java.lang.String deleteSQL(java.lang.String tableName,
                                              int number)
Returns the SQL command to use for deleting an object in a table. Implement this method to add a database-specific syntax or optimalization.
Parameters:
tableName - the name of the table where to delete
number - the number of the object to delete
Returns:
the sql query

selectSQL

protected java.lang.String selectSQL(java.lang.String tableName,
                                     java.lang.String fieldNames,
                                     int number)
Returns the SQL command to use for selecting data from one object.
Parameters:
tableName - the name of the table where to update
fieldNames - commaseparated list of fieldnames to retrieve, can be null (retrieve all fields)
number - the number of the object to update
Returns:
the sql query

selectSQL

protected java.lang.String selectSQL(java.lang.String tableName,
                                     java.lang.String fieldNames)
Returns the SQL command to use for selecting data from a table.
Parameters:
tableName - the name of the table where to update
fieldNames - commaseparated list of fieldnames to retrieve, can be null (retrieve all fields)
Returns:
the sql query

selectSQL

protected java.lang.String selectSQL(java.lang.String tableName,
                                     java.lang.String fieldNames,
                                     java.lang.String where,
                                     java.lang.String orderby)
Returns the SQL command to use for selecting data from a table.
Parameters:
tableName - the name of the table where to update
fieldNames - 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)
Returns:
the sql query

selectSQL

protected abstract 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. Implement this method to add a database-specific syntax or optimalization.
Parameters:
tableName - the name of the table where to update
fieldNames - 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 max
max - maximum number of records, can be -1 (no max)
Returns:
the sql query

constructFieldDefinition

protected java.lang.String constructFieldDefinition(MMObjectBuilder builder,
                                                    FieldDefs field)
Constructs a creation definition segment for one field, to use in a CREATE TABLE sql comand
Parameters:
builder - the fields builder
field - the FieldDefs object to make a create definition for
Returns:
the create definition

matchType

protected java.lang.String matchType(int type,
                                     int size)
Map a MMBase Type to a database specific type. If the type cannot be determined the result is null
Parameters:
type - the MMBase type
size - the desired size (or -1 if unspecifed)
Returns:
the database type as a string, or null if it cannot be determined

constructFieldDefinition

protected java.lang.String constructFieldDefinition(java.lang.String tablename,
                                                    java.lang.String fieldname,
                                                    int type,
                                                    int size,
                                                    int keyType)
Constructs a creation definition segment for one field, to use in a CREATE TABLE sql comand
Parameters:
tablename - name of the table this field belongs to
fieldname - name of the field in MMBase
type - MMBase type of the field
size - size of the field (or -1 if n.a.)
keyType - one of KEY_NONE, KEY_PRIMARY, KEY_SECONDARY, KEY_FOREIGN, KEY_NOTNULL
Returns:
the create definition

mapToTableFieldName

public java.lang.String mapToTableFieldName(java.lang.String fieldname)
Maps a MMBase fieldname to a fieldname acceptable to the database
Specified by:
mapToTableFieldName in interface DatabaseStorage
Overrides:
mapToTableFieldName in class Support2Storage
Parameters:
fieldname - the fieldname to map

mapToMMBaseFieldName

public java.lang.String mapToMMBaseFieldName(java.lang.String fieldname)
Maps a database fieldname to a fieldname as used by the MMbase system
Specified by:
mapToMMBaseFieldName in interface DatabaseStorage
Overrides:
mapToMMBaseFieldName in class Support2Storage
Parameters:
fieldname - the fieldname to map

getNumberString

public java.lang.String getNumberString()
Maps the 'number' fieldname to a fieldname acceptable to the database.

isAllowedParentBuilder

public abstract 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). The default behavior is to disallow any object other than "object" or "insrel". Database layers that support other builders should override this mnethod.
Specified by:
isAllowedParentBuilder in interface Storage
Parameters:
builder - the builder to test
Returns:
true if the builder can be extended
Since:
MMBase-1.6

registerParentBuilder

public void registerParentBuilder(MMObjectBuilder parent,
                                  MMObjectBuilder child)
                           throws UnsupportedDatabaseOperationException
Registers a builder as a parent builder (that is, other builders can 'extend' this builder and its database tables). At the least, this code should check whether the builder is allowed as a parent builder, and throw an exception if this is not possible. This method can be overridden to allow for optimization of code regarding such builders.
Specified by:
registerParentBuilder in interface Storage
Parameters:
parent - the parent builder to register
child - the builder to register as the parent's child
Throws:
UnsupportedDatabaseOperationException - when the database layer does not allow extension of this builder
Since:
MMBase-1.6

loadFieldFromTable

public abstract void loadFieldFromTable(MMObjectNode node,
                                        java.lang.String fieldname,
                                        java.sql.ResultSet rs,
                                        int i)
Stores a field in a table ResultSet in a MMObjectNode.
Specified by:
loadFieldFromTable in interface DatabaseStorage
Overrides:
loadFieldFromTable in class Support2Storage
Parameters:
node - the node to store the field in
fieldname - the name of the field as it is known to MMBase
rs - the ResultSet containing the table row
i - the index of the field in the ResultSet

getText

public abstract java.lang.String getText(MMObjectNode node,
                                         java.lang.String fieldname)
Get text from blob
Specified by:
getText in interface Storage
Following copied from interface: org.mmbase.storage.Storage
Parameters:
node - the node to retrieve the text from
fieldname - the name of the field to retrieve
Returns:
the retrieved text

getBytes

public abstract byte[] getBytes(MMObjectNode node,
                                java.lang.String fieldname)
Get bytes from blob
Specified by:
getBytes in interface Storage
Following copied from interface: org.mmbase.storage.Storage
Parameters:
node - the node to retrieve the byte array from
fieldname - the name of the field to retrieve
Returns:
the retrieved byte array

setValuePreparedStatement

public abstract boolean setValuePreparedStatement(java.sql.PreparedStatement stmt,
                                                  MMObjectNode node,
                                                  java.lang.String key,
                                                  int i)
                                           throws java.sql.SQLException
Set a prepared statement field i with value of key from the given node.
Specified by:
setValuePreparedStatement in interface DatabaseStorage
Throws:
java.sql.SQLException - if an error occurred while filling in the fields

getJDBC

public JDBCInterface getJDBC()
Returns the JDBC module used by this class to connect to the database.
Specified by:
getJDBC in interface DatabaseStorage
Returns:
the JDBC Module.

supportsRollback

public abstract boolean supportsRollback()
Returns whether rollback on storage level is supported.
Specified by:
supportsRollback in interface Storage
Returns:
true if transactions are supported

createTransaction

public Transaction createTransaction()
                              throws StorageException
Returns a newly created transaction object. Override this method if you want to use your own transaction control.
Specified by:
createTransaction in interface Storage
Returns:
the new transaction
Throws:
StorageException - if an error occurred when creating the transaction

createDatabaseTransaction

public DatabaseTransaction createDatabaseTransaction()
                                              throws StorageException
Returns a newly created database transaction object. Override this method if you want to use your own transaction control.
Returns:
the new database transaction
Throws:
StorageException - if an error occurred when creating the transaction

createDatabaseTransaction

public DatabaseTransaction createDatabaseTransaction(boolean useRollback)
                                              throws StorageException
Returns a newly created database transaction object. Override this method if you want to use your own transaction control. You can explicitly turn off rollback facilities (which might slow down database access) for internal routines by specifying useRollbacka s false.
Parameters:
useRollback - if true, the transaction should use rollback facilities if the database supports them
Returns:
the new database transaction
Throws:
StorageException - if an error occurred when creating the transaction

registerChanged

public void registerChanged(MMObjectNode node,
                            java.lang.String change)
Registers the change to a node. Clears the change status of a node, then broadcasts changes to the node's parent builder. If the node is a relation, it also updates the relationcache and broadcasts these changes to the relation' s source and destination.
Specified by:
registerChanged in interface DatabaseStorage
Parameters:
node - the node to register
change - the type of change: "n": new, "c": commit, "d": delete

setDBText

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

setDBByte

public abstract void setDBByte(int i,
                               java.sql.PreparedStatement stmt,
                               byte[] bytes)
Set byte array in database

createKey

public int createKey()
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 Support2Storage
Returns:
unique number

createKey

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

insert

public int insert(MMObjectNode node)
This method inserts a new object, and registers the change. Only fields with states of DBSTATE_PERSISTENT or DBSTATE_SYSTEM are stored in the database tables.
Specified by:
insert in interface Storage
Overrides:
insert in class Support2Storage
Parameters:
node - The node to insert
Returns:
The (new) number for this node, or -1 if an error occurs.

insert

public abstract int insert(MMObjectNode node,
                           Transaction trans)
                    throws StorageException
This method inserts a new object within a transaction, and registers the change. Only fields with states of DBSTATE_PERSISTENT or DBSTATE_SYSTEM are stored in the database tables.
Specified by:
insert in interface Storage
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

commit

public boolean commit(MMObjectNode node)
Commit this node to the specified builder table.
Specified by:
commit in interface Storage
Overrides:
commit in class Support2Storage
Parameters:
builder - the builder to commit the node to. This can be a parentbuilder of the node's actual builder
node - The node to commit
Returns:
true of succesful, false otherwise

commit

public abstract boolean commit(MMObjectNode node,
                               Transaction trans)
                        throws StorageException
Commit this node to the specified builder table within a transaction.
Specified by:
commit in interface Storage
Parameters:
builder - the builder to commit the node to. This can be a parentbuilder of the node's actual builder
node - The node to commit
trans - the transaction to perform the insert in
Returns:
true of succesful, false otherwise
Throws:
StorageException - if an error occurred during commit

delete

public boolean delete(MMObjectNode node)
Delete a node
Specified by:
delete in interface Storage
Overrides:
delete in class Support2Storage
Parameters:
node - The node to delete
Returns:
true of succesful, false otherwise

delete

public abstract boolean delete(MMObjectNode node,
                               Transaction trans)
                        throws StorageException
Delete a node within a transaction
Specified by:
delete in interface Storage
Parameters:
node - The node to delete
trans - the transaction to perform the insert in
Throws:
StorageException - if an error occurred during delete

getNode

public MMObjectNode getNode(MMObjectBuilder builder,
                            int number)
Select a node from a specified builder
Specified by:
getNode in interface Storage
Parameters:
builder - The builder to select from
number - the number of the node
Returns:
the MMObjectNode that was found, or null f it doesn't exist

getNode

public abstract MMObjectNode getNode(MMObjectBuilder builder,
                                     int number,
                                     Transaction trans)
                              throws StorageException
Select a node from a specified builder
Specified by:
getNode in interface Storage
Parameters:
builder - The builder to select from
number - the number of the node
trans - the transaction to perform the insert in
Returns:
the MMObjectNode that was found, or null f it doesn't exist
Throws:
StorageException - if an error occurred during selection

getNodeType

public int getNodeType(int number)
Returns the nodetype for a specified nodereference
Specified by:
getNodeType in interface Storage
Parameters:
number - the number of the node
Returns:
int the object type or -1 if not found

getNodeType

public abstract int getNodeType(int number,
                                Transaction trans)
                         throws StorageException
Returns the nodetype for a specified nodereference
Specified by:
getNodeType in interface Storage
Parameters:
number - the number of the node
trans - the transaction to perform the insert in
Returns:
int the object type or -1 if not found
Throws:
StorageException - if an error occurred during selection

create

public boolean create(MMObjectBuilder builder)
Create a database table for the specified builder.
Specified by:
create in interface Storage
Parameters:
builder - the builder to create the table for\
Returns:
true if the table was succesfully created

create

public abstract boolean create(MMObjectBuilder builder,
                               Transaction trans)
                        throws StorageException
Create a database table for the specified builder.
Specified by:
create in interface Storage
Parameters:
builder - the builder to create the table for\
trans - the transaction to perform the insert in
Returns:
true if the table was succesfully created
Throws:
StorageException - if an error occurred during create

createObjectStorage

public boolean createObjectStorage()
Create the object table (the basic table for all objects).
Specified by:
createObjectStorage in interface Storage
Overrides:
createObjectStorage in class Support2Storage
Returns:
true if the table was succesfully created

createObjectStorage

public abstract boolean createObjectStorage(Transaction trans)
                                     throws StorageException
Create the object table (the basic table for all objects) within a transaction
Specified by:
createObjectStorage in interface Storage
Parameters:
trans - the transaction to perform the insert in
Returns:
true if the table was succesfully created
Throws:
StorageException - if an error occurred during craete

created

public abstract boolean created(MMObjectBuilder builder)
Tells if a table for the builder already exists
Specified by:
created in interface Storage
Parameters:
builder - the builder to check
Returns:
true if table exists, false if table doesn't exists

size

public abstract int size(MMObjectBuilder builder)
Return number of objects in a builder
Specified by:
size in interface Storage
Parameters:
builder - the builder whose objects to count
Returns:
the number of objects the builder has, or -1 if the builder does not exist.

drop

public abstract boolean drop(MMObjectBuilder builder)
Drops the table of this builder.
Specified by:
drop in interface Storage
Parameters:
builder - the builder whose table to drop
Returns:
true if succesful

addField

public abstract boolean addField(MMObjectBuilder builder,
                                 java.lang.String fieldname)
Adds a field to the table of this builder.
Specified by:
addField in interface Storage
Parameters:
builder - the builder whose table to change
fieldname - the name fo the field to add
Returns:
true if succesful

removeField

public abstract boolean removeField(MMObjectBuilder builder,
                                    java.lang.String fieldname)
Deletes a field from the table of this builder.
Specified by:
removeField in interface Storage
Parameters:
builder - the builder whose table to change
fieldname - the name fo the field to delete
Returns:
true if succesful

changeField

public abstract boolean changeField(MMObjectBuilder builder,
                                    java.lang.String fieldname)
Changes a field to the table of this builder.
Specified by:
changeField in interface Storage
Parameters:
builder - the builder whose table to change
fieldname - the name fo the field to change
Returns:
true if succesful

updateStorage

public abstract boolean updateStorage(MMObjectBuilder builder)
Changes the storage of a builder to match its new configuration.
Specified by:
updateStorage in interface Storage
Overrides:
updateStorage in class Support2Storage
Parameters:
builder - the builder whose table to change
Returns:
true if succesful


MMBase build 1.6.5.20030923