org.mmbase.storage.implementation.database
Class DatabaseStorageManager

java.lang.Object
  extended byorg.mmbase.storage.implementation.database.DatabaseStorageManager
All Implemented Interfaces:
StorageManager
Direct Known Subclasses:
RelationalDatabaseStorageManager

public class DatabaseStorageManager
extends java.lang.Object
implements StorageManager

A JDBC implementation of an object related storage manager.

Since:
MMBase-1.7
Version:
$Id: DatabaseStorageManager.java,v 1.63.2.9 2004/08/26 12:40:33 michiel Exp $
Author:
Pierre van Rooden
Warning: No Java Documentation Available.

Field Summary
protected  java.sql.Connection activeConnection
          The currently active Connection.
protected static java.lang.Integer bufferSize
           
protected  java.util.Map changes
          Pool of changed nodes in a transaction
protected  javax.sql.DataSource dataSource
          The datasource through which to access the database.
protected  DatabaseStorageManagerFactory factory
          The factory that created this manager
protected  boolean inTransaction
          true if a transaction has been started.
protected static java.util.List sequenceKeys
           
protected  int transactionIsolation
          The transaction issolation level to use when starting a transaction.
 
Constructor Summary
DatabaseStorageManager()
          Constructor
 
Method Summary
 void beginTransaction()
          Starts a transaction on this StorageManager instance.
 void change(FieldDefs field)
          Changes a field to the storage of this builder.
 void change(MMObjectBuilder builder)
          Changes the storage of a builder to match its new configuration.
 void change(MMObjectNode node)
          Commit this node to the specified builder.
protected  void change(MMObjectNode node, MMObjectBuilder builder)
          Change this node in the specified builder.
protected  java.io.File checkFile(java.io.File binaryFile, MMObjectNode node, FieldDefs field)
          Checks whether file is readable and existing.
 void commit()
          Closes any transaction that was started and commits all changes.
protected  void commitChange(MMObjectNode node, java.lang.String change)
          Commits the change to a node.
 int convertLegacyBinaryFiles()
          Convert legacy file
 void create()
          Create the basic elements for this storage
 void create(FieldDefs field)
          Creates a field and adds it to the storage of this builder.
 void create(MMObjectBuilder builder)
          Create a storage element to store the specified builder's objects.
 int create(MMObjectNode node)
          This method creates a new object in the storage, and registers the change.
protected  void create(MMObjectNode node, MMObjectBuilder builder)
          This method inserts a new object in a specific builder, and registers the change.
protected  void createCompositeIndex(MMObjectBuilder builder)
          Create a constraint for a composite index.
 int createKey()
          Gives an unique number for a new node, to be inserted in the storage.
protected  void createSequence()
          Creates a means for the database to pre-create keys with increasing numbers.
 void delete(FieldDefs field)
          Deletes a field from the storage of this builder.
 void delete(MMObjectBuilder builder)
          Drops the storage of this builder.
 void delete(MMObjectNode node)
          Delete a node
protected  void delete(MMObjectNode node, MMObjectBuilder builder)
          Delete a node from a specific builder This method makes it easier to implement relational databses, where you may need to remove the node in more than one builder.
protected  void deleteCompositeIndex(MMObjectBuilder builder)
          Drop a constraint for a composite index.
protected  void executeUpdate(java.lang.String query, MMObjectNode node, java.util.List fields)
          Executes an update query for given node and fields.
protected  void executeUpdateCheckConnection(java.lang.String query, MMObjectNode node, java.util.List fields)
          Executes an update query for given node and fields.
 boolean exists()
          Determine if the basic storage elements exist Basic storage elements include the 'object' storage (where all objects and their types are registered).
 boolean exists(MMObjectBuilder builder)
          Determine if a storage element exists for storing the given builder's objects
protected  boolean exists(java.lang.String tableName)
          Queries the database metadata to test whether a given table exists.
protected  void fillNode(MMObjectNode node, java.sql.ResultSet result, MMObjectBuilder builder)
          Fills a single Node from the resultset of a query.
protected  java.sql.Connection getActiveConnection()
          Obtains an active connection, opening a new one if needed.
protected  java.io.File getBinaryFile(MMObjectNode node, java.lang.String fieldName)
          Defines how binary (blob) data files must look like.
 byte[] getBinaryValue(MMObjectNode node, FieldDefs field)
          Retrieve a large binary object (byte array) for a specified object field.
protected  byte[] getBinaryValue(java.sql.ResultSet result, int index, FieldDefs field)
          Retrieve a large binary object (byte array) for a specified object field.
protected  java.lang.String getCompositeConstraintDefinition(MMObjectBuilder builder)
          Creates a composite index definition string (an index over one or more fields) to be passed when creating a table.
protected  java.lang.String getConstraintDefinition(FieldDefs field)
          Creates an index definition string to be passed when creating a table.
protected  java.lang.String getFieldDefinition(FieldDefs field)
          Creates a fielddefinition, of the format '[fieldname] [fieldtype] NULL' or '[fieldname] [fieldtype] NOT NULL' (depending on whether the field is nullable).
protected  int getJDBCtoMMBaseType(int jdbcType, int mmbaseType)
          Guess the (mmbase) type in storage using the JDNC type.
 MMObjectNode getNode(MMObjectBuilder builder, int number)
          Select a node from a specified builder
 int getNodeType(int number)
          Returns the nodetype for a specified nodereference
 java.lang.String getStringValue(MMObjectNode node, FieldDefs field)
          Retrieve a large text for a specified object field.
protected  java.lang.String getStringValue(java.sql.ResultSet result, int index, FieldDefs field)
          Retrieve a text for a specified object field.
protected  java.lang.Object getValue(java.sql.ResultSet result, int index, FieldDefs field)
          Attempts to return a single field value from the resultset of a query.
 double getVersion()
          Returns the version of this factory implementation.
 void init(StorageManagerFactory factory)
          Initializes the manager.
protected  boolean isPartOfBuilderDefinition(FieldDefs field)
          Determines whether the storage should make a field definition in a builder table for a specified field.
protected  void logQuery(java.lang.String msg)
           
protected  byte[] readBinaryFromDatabase(MMObjectNode node, FieldDefs field)
          Read a binary (blob) from a field in the database
protected  byte[] readBinaryFromFile(MMObjectNode node, FieldDefs field)
          Read a binary (blob) data file
protected  void releaseActiveConnection()
          Safely closes the active connection.
 boolean rollback()
          Cancels any transaction that was started and rollback changes if possible.
protected  void setBinaryValue(java.sql.PreparedStatement statement, int index, java.lang.Object objectValue, FieldDefs field)
          Store binary data of a field in a prepared statement.
protected  void setNodeValue(java.sql.PreparedStatement statement, int index, java.lang.Object node, FieldDefs field)
          Store a node value of a field in a prepared statement Nodes are stored in the database as numeric values.
protected  boolean setNullValue(java.sql.PreparedStatement statement, int index, java.lang.Object value, FieldDefs field, int type)
          Stores the 'null' value in the statement if appopriate (the value is null or unset, and the value may indeed be NULL, according to the configuration).
protected  void setNumericValue(java.sql.PreparedStatement statement, int index, java.lang.Object value, FieldDefs field)
          Store a numeric value of a field in a prepared statement The method uses the Casting class to convert to the appropriate value.
protected  void setStringValue(java.sql.PreparedStatement statement, int index, java.lang.Object objectValue, FieldDefs field)
          Store the text value of a field in a prepared statement.
protected  void setValue(java.sql.PreparedStatement statement, int index, MMObjectNode node, FieldDefs field)
          Store the value of a field in a prepared statement
protected  void setXMLValue(java.sql.PreparedStatement statement, int index, java.lang.Object objectValue, FieldDefs field)
          This default implementation calls setStringValue(java.sql.PreparedStatement, int, java.lang.Object, org.mmbase.module.corebuilders.FieldDefs).
protected  boolean shorten(FieldDefs field)
          Determine whether a field (such as a large text or a blob) should be shortened or not.
 int size()
          Return the total number of objects in the storage
 int size(MMObjectBuilder builder)
          Return the number of objects of a builder in the storage
protected  void storeBinaryAsFile(MMObjectNode node, FieldDefs field)
          Store a binary (blob) data file
protected  boolean tablesInheritFields()
          Returns whether tables inherit fields form parent tables.
 void verify(MMObjectBuilder builder)
          Tests whether a builder and the table present in the database match.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sequenceKeys

protected static final java.util.List sequenceKeys

bufferSize

protected static java.lang.Integer bufferSize

factory

protected DatabaseStorageManagerFactory factory
The factory that created this manager


dataSource

protected javax.sql.DataSource dataSource
The datasource through which to access the database.


activeConnection

protected java.sql.Connection activeConnection
The currently active Connection. This member is set by {!link #getActiveConnection()} and unset by releaseActiveConnection()


inTransaction

protected boolean inTransaction
true if a transaction has been started. This member is for state maitenance and may be true even if the storage does not support transactions


transactionIsolation

protected int transactionIsolation
The transaction issolation level to use when starting a transaction. This value is retrieved from the factory's Attributes.TRANSACTION_ISOLATION_LEVEL attribute, which is commonly set to the highest (most secure) transaction isolation level available.


changes

protected java.util.Map changes
Pool of changed nodes in a transaction

Constructor Detail

DatabaseStorageManager

public DatabaseStorageManager()
Constructor

Method Detail

logQuery

protected final void logQuery(java.lang.String msg)

getVersion

public double getVersion()
Description copied from interface: StorageManager
Returns the version of this factory implementation. The factory uses this number to verify whether it can handle storage configuration files that list version requirements.

Specified by:
getVersion in interface StorageManager
Returns:
the version as an integer

init

public void init(StorageManagerFactory factory)
          throws StorageException
Description copied from interface: StorageManager
Initializes the manager. Called by a StorageManagerFactory when instantiating the manager with the getStorageManager() method.

Specified by:
init in interface StorageManager
Parameters:
factory - the StorageManagerFactory instance that created this storage manager.
Throws:
StorageException

getActiveConnection

protected java.sql.Connection getActiveConnection()
                                           throws java.sql.SQLException
Obtains an active connection, opening a new one if needed. This method sets and then returns the activeConnection member. If an active connection was allready open, and the manager is in a database transaction, that connection is returned instead. Otherwise, the connection is closed before a new one is opened.

Throws:
java.sql.SQLException - if opening the connection failed

releaseActiveConnection

protected void releaseActiveConnection()
Safely closes the active connection. If a transaction has been started, the connection is not closed.


beginTransaction

public void beginTransaction()
                      throws StorageException
Description copied from interface: StorageManager
Starts a transaction on this StorageManager instance. All commands passed to the instance will be treated as being in this transaction. If transactions are not supported by the storage, no actual storage transaction is started, but the code continues as if it has.

Specified by:
beginTransaction in interface StorageManager
Throws:
StorageException - if the transaction could not be created

commit

public void commit()
            throws StorageException
Description copied from interface: StorageManager
Closes any transaction that was started and commits all changes. If transactions are not supported by the storage, nothing really happens (as changes are allready committed), but the code continues as if it has.

Specified by:
commit in interface StorageManager
Throws:
StorageException - if a transaction is not currently active, or an error occurred while committing

rollback

public boolean rollback()
                 throws StorageException
Description copied from interface: StorageManager
Cancels any transaction that was started and rollback changes if possible. If transactions are not supported by the storage, nothing really happens (as changes are allready committed), but the code continues as if it has (through in that case it will return false).

Specified by:
rollback in interface StorageManager
Returns:
true if changes were rolled back, false if the transaction was canceled but the storage does not support rollback
Throws:
StorageException - if a transaction is not currently active, or an error occurred during rollback

commitChange

protected void commitChange(MMObjectNode node,
                            java.lang.String change)
Commits the change to a node. If the manager is in a transaction (and supports it), the change is stored in a changes object (to be committed after the transaction ends). Otherwise it directly commits and broadcasts the changes

Parameters:
node - the node to register
change - the type of change: "n": new, "c": commit, "d": delete, "r" : relation changed

createKey

public int createKey()
              throws StorageException
Description copied from interface: StorageManager
Gives an unique number for a new node, to be inserted in the storage. This method should work with multiple mmbases

Specified by:
createKey in interface StorageManager
Returns:
unique number
Throws:
StorageException

getStringValue

public java.lang.String getStringValue(MMObjectNode node,
                                       FieldDefs field)
                                throws StorageException
Description copied from interface: StorageManager
Retrieve a large text for a specified object field. Implement this method to allow for optimization of storing and retrieving large texts.

Specified by:
getStringValue in interface StorageManager
Parameters:
node - the node to retrieve the text from
field - the FieldDefs of the field to retrieve
Returns:
the retrieved text
Throws:
StorageException - if an error occurred while retrieving the text value

getStringValue

protected java.lang.String getStringValue(java.sql.ResultSet result,
                                          int index,
                                          FieldDefs field)
                                   throws StorageException,
                                          java.sql.SQLException
Retrieve a text for a specified object field. The default method uses ResultSet.getString(int) to obtain text. Override this method if you want to optimize retrieving large texts, i.e by using clobs or streams.

Parameters:
result - the resultset to retrieve the text from
index - the index of the text in the resultset
field - the (MMBase) fieldtype. This value can be null
Returns:
the retrieved text, null if no text was stored
Throws:
java.sql.SQLException - when a database error occurs
StorageException - when data is incompatible or the function is not supported

shorten

protected boolean shorten(FieldDefs field)
                   throws StorageException,
                          java.sql.SQLException
Determine whether a field (such as a large text or a blob) should be shortened or not. A 'shortened' field contains a placeholder text ('$SHORTED') to indicate that the field is expected to be of large size and should be retrieved by an explicit call to getStringValue(MMObjectNode, FieldDefs) or. getBinaryValue(MMObjectNode, FieldDefs). The default implementation returns true for binaries, and false for other types. Override this method if you want to be able to change the placeholder strategy.

Parameters:
field - the (MMBase) fieldtype
Returns:
true if the field should be shortened
Throws:
java.sql.SQLException - when a database error occurs
StorageException - when data is incompatible or the function is not supported

readBinaryFromDatabase

protected byte[] readBinaryFromDatabase(MMObjectNode node,
                                        FieldDefs field)
Read a binary (blob) from a field in the database

Parameters:
node - the node the binary data belongs to
field - the binary field
Returns:
the byte array containing the binary data, null if no binary data was stored

getBinaryValue

public byte[] getBinaryValue(MMObjectNode node,
                             FieldDefs field)
                      throws StorageException
Description copied from interface: StorageManager
Retrieve a large binary object (byte array) for a specified object field. Implement this method to allow for optimization of storing and retrieving binary objects.

Specified by:
getBinaryValue in interface StorageManager
Parameters:
node - the node to retrieve the byte array from
field - the FieldDefs of the field to retrieve
Returns:
the retrieved byte array
Throws:
StorageException - if an error occurred while retrieving the binary value

getBinaryValue

protected byte[] getBinaryValue(java.sql.ResultSet result,
                                int index,
                                FieldDefs field)
                         throws StorageException,
                                java.sql.SQLException
Retrieve a large binary object (byte array) for a specified object field. The default method uses ResultSet.getBytes(int) to obtain text. Override this method if you want to optimize retrieving large objects, i.e by using clobs or streams.

Parameters:
result - the resultset to retrieve the text from
index - the index of the text in the resultset
field - the (MMBase) fieldtype. This value can be null
Returns:
the retrieved data, null if no binary data was stored
Throws:
java.sql.SQLException - when a database error occurs
StorageException - when data is incompatible or the function is not supported

getBinaryFile

protected java.io.File getBinaryFile(MMObjectNode node,
                                     java.lang.String fieldName)
Defines how binary (blob) data files must look like.

Parameters:
node - the node the binary data belongs to
fieldName - the name of the binary field
Returns:
The File where to store or read the binary data

storeBinaryAsFile

protected void storeBinaryAsFile(MMObjectNode node,
                                 FieldDefs field)
                          throws StorageException
Store a binary (blob) data file

Parameters:
node - the node the binary data belongs to
field - the binary field
Throws:
StorageException
To Do:
how to do this in a transaction???

checkFile

protected java.io.File checkFile(java.io.File binaryFile,
                                 MMObjectNode node,
                                 FieldDefs field)
Checks whether file is readable and existing. Warns if not. If non-existing it checks older locations.

Returns:
the file to be used, or null if no existing readable file could be found, also no 'legacy' one.

readBinaryFromFile

protected byte[] readBinaryFromFile(MMObjectNode node,
                                    FieldDefs field)
                             throws StorageException
Read a binary (blob) data file

Parameters:
node - the node the binary data belongs to
field - the binary field
Returns:
the byte array containing the binary data, null if no binary data was stored
Throws:
StorageException
To Do:
how to do this in a transaction???

create

public int create(MMObjectNode node)
           throws StorageException
Description copied from interface: StorageManager
This method creates a new object in the storage, and registers the change. Only fields with states of DBSTATE_PERSISTENT or DBSTATE_SYSTEM are stored.

Specified by:
create in interface StorageManager
Parameters:
node - The node to insert
Returns:
The (new) number for this node, or -1 if an error occurs.
Throws:
StorageException - if an error occurred during insert

create

protected void create(MMObjectNode node,
                      MMObjectBuilder builder)
               throws StorageException
This method inserts a new object in a specific builder, and registers the change. This method makes it easier to implement relational databases, where you may need to update the node in more than one builder. Call this method for all involved builders if you use a relational database.

Parameters:
node - The node to insert. The node already needs to have a (new) number assigned
builder - the builder to store the node
Throws:
StorageException - if an error occurred during creation

executeUpdateCheckConnection

protected void executeUpdateCheckConnection(java.lang.String query,
                                            MMObjectNode node,
                                            java.util.List fields)
                                     throws java.sql.SQLException
Executes an update query for given node and fields. It will close the connection which are no good, which it determins by trying "SELECT 1" after failure. If that happens, the connection is explicitely closed (in case the driver has not done that), which will render is unusable and at least GenericDataSource will automaticly try to get new ones.

Throws:
java.sql.SQLException - If something wrong with the query, or the database is down or could not be contacted.
Since:
MMBase-1.7.1

executeUpdate

protected void executeUpdate(java.lang.String query,
                             MMObjectNode node,
                             java.util.List fields)
                      throws java.sql.SQLException
Executes an update query for given node and fields. This is wrapped in a function because it is repeatedly called in executeUpdateCheckConnection(java.lang.String, org.mmbase.module.core.MMObjectNode, java.util.List) which in turn is called from several spots in this class.

Throws:
java.sql.SQLException
Since:
MMBase-1.7.1

change

public void change(MMObjectNode node)
            throws StorageException
Description copied from interface: StorageManager
Commit this node to the specified builder.

Specified by:
change in interface StorageManager
Parameters:
node - The node to commit
Throws:
StorageException - if an error occurred during commit

change

protected void change(MMObjectNode node,
                      MMObjectBuilder builder)
               throws StorageException
Change this node in the specified builder. This method makes it easier to implement relational databses, where you may need to update the node in more than one builder. Call this method for all involved builders if you use a relational database.

Parameters:
node - The node to change
builder - the builder to store the node
Throws:
StorageException - if an error occurred during change

setValue

protected void setValue(java.sql.PreparedStatement statement,
                        int index,
                        MMObjectNode node,
                        FieldDefs field)
                 throws StorageException,
                        java.sql.SQLException
Store the value of a field in a prepared statement

Parameters:
statement - the prepared statement
index - the index of the field in the prepared statement
node - the node from which to retrieve the value
field - the MMBase field, containing meta-information
Throws:
StorageException - if the fieldtype is invalid, or data is invalid or missing
java.sql.SQLException - if an error occurred while filling in the fields
To Do:
Note that this code contains some code that should really be implemented in FieldDefs. In particular, casting should be done in FieldDefs, IMO.

setNullValue

protected boolean setNullValue(java.sql.PreparedStatement statement,
                               int index,
                               java.lang.Object value,
                               FieldDefs field,
                               int type)
                        throws StorageException,
                               java.sql.SQLException
Stores the 'null' value in the statement if appopriate (the value is null or unset, and the value may indeed be NULL, according to the configuration). If the value is null or unset, but the value may not be NULL, then -1 is stored.

Parameters:
statement - the prepared statement
index - the index of the field in the prepared statement
value - the numeric value to store, which will be checked for null.
field - the MMBase field, containing meta-information
type - java.sql.Type constant
Returns:
true if a null value was set, false otherwise
Throws:
StorageException - if the data is invalid or missing
java.sql.SQLException - if an error occurred while filling in the fields
Since:
MMBase-1.7.1

setNumericValue

protected void setNumericValue(java.sql.PreparedStatement statement,
                               int index,
                               java.lang.Object value,
                               FieldDefs field)
                        throws StorageException,
                               java.sql.SQLException
Store a numeric value of a field in a prepared statement The method uses the Casting class to convert to the appropriate value. Null values are stored as NULL if possible, otherwise they are stored as -1. Override this method if you want to override this behavior.

Parameters:
statement - the prepared statement
index - the index of the field in the prepared statement
value - the numeric value to store. This may be a String, MMObjectNode, Numeric, or other value - the method will convert it to the appropriate value.
field - the MMBase field, containing meta-information
Throws:
StorageException - if the data is invalid or missing
java.sql.SQLException - if an error occurred while filling in the fields

setNodeValue

protected void setNodeValue(java.sql.PreparedStatement statement,
                            int index,
                            java.lang.Object node,
                            FieldDefs field)
                     throws StorageException,
                            java.sql.SQLException
Store a node value of a field in a prepared statement Nodes are stored in the database as numeric values. Since a node value can be a (referential) key (depending on implementation), Null values should be stored as NULL, not -1. If a field cannot be null when a value is not given, an exception is thrown. Override this method if you want to override this behavior.

Parameters:
statement - the prepared statement
index - the index of the field in the prepared statement
node - the node to store
field - the MMBase field, containing meta-information
Throws:
StorageException - if the data is invalid or missing
java.sql.SQLException - if an error occurred while filling in the fields

setBinaryValue

protected void setBinaryValue(java.sql.PreparedStatement statement,
                              int index,
                              java.lang.Object objectValue,
                              FieldDefs field)
                       throws StorageException,
                              java.sql.SQLException
Store binary data of a field in a prepared statement. This basic implementation uses a binary stream to set the data. Null values are stored as NULL if possible, otherwise they are stored as an empty byte-array. Override this method if you use another way to store binaries (i.e. Blobs).

Parameters:
statement - the prepared statement
index - the index of the field in the prepared statement
objectValue - the data (byte array) to store
field - the MMBase field, containing meta-information. This value can be null
Throws:
StorageException - if the data is invalid or missing
java.sql.SQLException - if an error occurred while filling in the fields

setStringValue

protected void setStringValue(java.sql.PreparedStatement statement,
                              int index,
                              java.lang.Object objectValue,
                              FieldDefs field)
                       throws StorageException,
                              java.sql.SQLException
Store the text value of a field in a prepared statement. Null values are stored as NULL if possible, otherwise they are stored as an empty string. If the FORCE_ENCODE_TEXT option is set, text is encoded (using the MMBase encoding) to a byte array and stored as a binary stream. Otherwise it uses PreparedStatement.setString(int, String) to set the data. Override this method if you use another way to store large texts (i.e. Clobs).

Parameters:
statement - the prepared statement
index - the index of the field in the prepared statement
objectValue - the text to store
field - the MMBase field, containing meta-information
Throws:
StorageException - if the data is invalid or missing
java.sql.SQLException - if an error occurred while filling in the fields

setXMLValue

protected void setXMLValue(java.sql.PreparedStatement statement,
                           int index,
                           java.lang.Object objectValue,
                           FieldDefs field)
                    throws StorageException,
                           java.sql.SQLException
This default implementation calls setStringValue(java.sql.PreparedStatement, int, java.lang.Object, org.mmbase.module.corebuilders.FieldDefs). Override this method if you want to override this behavior.

Throws:
StorageException
java.sql.SQLException
Since:
MMBase-1.7.1

delete

public void delete(MMObjectNode node)
            throws StorageException
Description copied from interface: StorageManager
Delete a node

Specified by:
delete in interface StorageManager
Parameters:
node - The node to delete
Returns:
true if succesful
Throws:
StorageException - if an error occurred during delete

delete

protected void delete(MMObjectNode node,
                      MMObjectBuilder builder)
               throws StorageException
Delete a node from a specific builder This method makes it easier to implement relational databses, where you may need to remove the node in more than one builder. Call this method for all involved builders if you use a relational database.

Parameters:
node - The node to delete
Throws:
StorageException - if an error occurred during delete

getNode

public MMObjectNode getNode(MMObjectBuilder builder,
                            int number)
                     throws StorageException
Description copied from interface: StorageManager
Select a node from a specified builder

Specified by:
getNode in interface StorageManager
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
Throws:
StorageException - if an error occurred during the get

fillNode

protected void fillNode(MMObjectNode node,
                        java.sql.ResultSet result,
                        MMObjectBuilder builder)
                 throws StorageException
Fills a single Node from the resultset of a query. You can use this method to iterate through a query, creating multiple nodes, provided the resultset still contains members (that is, result.isAfterLast returns false)

Parameters:
node - The MMObjectNode to be filled
result - the resultset
builder - the builder to use for creating the node
Returns:
void
Throws:
StorageException - if the resultset is exhausted or a database error occurred

getValue

protected java.lang.Object getValue(java.sql.ResultSet result,
                                    int index,
                                    FieldDefs field)
                             throws StorageException
Attempts to return a single field value from the resultset of a query.

Parameters:
result - the resultset
index - the index of the field in the resultset
field - the expected MMBase field type. This can be null
Returns:
the value
Throws:
StorageException - if the value cannot be retrieved from the resultset

getNodeType

public int getNodeType(int number)
                throws StorageException
Description copied from interface: StorageManager
Returns the nodetype for a specified nodereference

Specified by:
getNodeType in interface StorageManager
Parameters:
number - the number of the node
Returns:
int the object type or -1 if not found
Throws:
StorageException - if an error occurred during selection

tablesInheritFields

protected boolean tablesInheritFields()
Returns whether tables inherit fields form parent tables. this determines whether fields that are inherited in mmbase builders are redefined in the database tables.


isPartOfBuilderDefinition

protected boolean isPartOfBuilderDefinition(FieldDefs field)
Determines whether the storage should make a field definition in a builder table for a specified field.


create

public void create(MMObjectBuilder builder)
            throws StorageException
Description copied from interface: StorageManager
Create a storage element to store the specified builder's objects.

Specified by:
create in interface StorageManager
Parameters:
builder - the builder to create the storage element for
Throws:
StorageException - if an error occurred during the creation of the storage element

getFieldDefinition

protected java.lang.String getFieldDefinition(FieldDefs field)
                                       throws StorageException
Creates a fielddefinition, of the format '[fieldname] [fieldtype] NULL' or '[fieldname] [fieldtype] NOT NULL' (depending on whether the field is nullable). The fieldtype is taken from the type mapping in the factory.

Parameters:
field - the field
Returns:
the typedefiniton as a String
Throws:
StorageException - if the field type cannot be mapped

getConstraintDefinition

protected java.lang.String getConstraintDefinition(FieldDefs field)
                                            throws StorageException
Creates an index definition string to be passed when creating a table.

Parameters:
field - the field for which to make the index definition
Returns:
the index definition as a String, or null if no definition is available
Throws:
StorageException

getCompositeConstraintDefinition

protected java.lang.String getCompositeConstraintDefinition(MMObjectBuilder builder)
                                                     throws StorageException
Creates a composite index definition string (an index over one or more fields) to be passed when creating a table.

Parameters:
builder - The builder for which to make the index definition
Returns:
the index definition as a String, or null if no definition is available
Throws:
StorageException

change

public void change(MMObjectBuilder builder)
            throws StorageException
Description copied from interface: StorageManager
Changes the storage of a builder to match its new configuration.

Specified by:
change in interface StorageManager
Parameters:
builder - the builder whose storage to change
Throws:
StorageException

delete

public void delete(MMObjectBuilder builder)
            throws StorageException
Description copied from interface: StorageManager
Drops the storage of this builder.

Specified by:
delete in interface StorageManager
Parameters:
builder - the builder whose storage to drop
Throws:
StorageException

create

public void create()
            throws StorageException
Description copied from interface: StorageManager
Create the basic elements for this storage

Specified by:
create in interface StorageManager
Returns:
true if the storage was succesfully created
Throws:
StorageException - if an error occurred during the creation of the object storage

createSequence

protected void createSequence()
                       throws StorageException
Creates a means for the database to pre-create keys with increasing numbers. A sequence can be a database routine, a number table, or anything else that can be used to create unique numbers. Keys can be obtained from the sequence by calling createKey().

Throws:
StorageException - when the sequence can not be created

exists

public boolean exists(MMObjectBuilder builder)
               throws StorageException
Description copied from interface: StorageManager
Determine if a storage element exists for storing the given builder's objects

Specified by:
exists in interface StorageManager
Parameters:
builder - the builder to check
Returns:
true if the storage element exists, false if it doesn't
Throws:
StorageException - if an error occurred while querying the storage

exists

protected boolean exists(java.lang.String tableName)
                  throws StorageException
Queries the database metadata to test whether a given table exists.

Parameters:
tableName - name of the table to look for
Returns:
true if the table exists
Throws:
StorageException - when the metadata could not be retrieved

exists

public boolean exists()
               throws StorageException
Description copied from interface: StorageManager
Determine if the basic storage elements exist Basic storage elements include the 'object' storage (where all objects and their types are registered).

Specified by:
exists in interface StorageManager
Returns:
true if basic storage elements exist
Throws:
StorageException - if an error occurred while querying the storage

size

public int size(MMObjectBuilder builder)
         throws StorageException
Description copied from interface: StorageManager
Return the number of objects of a builder in the storage

Specified by:
size in interface StorageManager
Parameters:
builder - the builder whose objects to count
Returns:
the number of objects the builder has
Throws:
StorageException - if the storage element for the builder does not exists

size

public int size()
         throws StorageException
Description copied from interface: StorageManager
Return the total number of objects in the storage

Specified by:
size in interface StorageManager
Returns:
the number of objects
Throws:
StorageException - if the basic storage elements do not exist

getJDBCtoMMBaseType

protected int getJDBCtoMMBaseType(int jdbcType,
                                  int mmbaseType)
Guess the (mmbase) type in storage using the JDNC type. Because a JDBC type can represent more than one mmbase Type, the current type is also passed - if the current type matches, that type is returned, otherwise the method returns the closest matching MMBase type.


verify

public void verify(MMObjectBuilder builder)
            throws StorageException
Tests whether a builder and the table present in the database match.

Throws:
StorageException

deleteCompositeIndex

protected void deleteCompositeIndex(MMObjectBuilder builder)
                             throws StorageException,
                                    java.sql.SQLException
Drop a constraint for a composite index. You should have an active connection before calling this method.

Parameters:
builder - the builder for which to drop the composite key
Throws:
StorageException
java.sql.SQLException

createCompositeIndex

protected void createCompositeIndex(MMObjectBuilder builder)
                             throws StorageException,
                                    java.sql.SQLException
Create a constraint for a composite index.

Parameters:
builder - the builder for which to add the composite key
Throws:
StorageException
java.sql.SQLException

create

public void create(FieldDefs field)
            throws StorageException
Description copied from interface: StorageManager
Creates a field and adds it to the storage of this builder.

Specified by:
create in interface StorageManager
Parameters:
field - the FieldDefs of the field to add
Throws:
StorageException

change

public void change(FieldDefs field)
            throws StorageException
Description copied from interface: StorageManager
Changes a field to the storage of this builder.

Specified by:
change in interface StorageManager
Parameters:
field - the FieldDefs of the field to change
Throws:
StorageException

delete

public void delete(FieldDefs field)
            throws StorageException
Description copied from interface: StorageManager
Deletes a field from the storage of this builder.

Specified by:
delete in interface StorageManager
Parameters:
field - the FieldDefs of the field to delete
Throws:
StorageException

convertLegacyBinaryFiles

public int convertLegacyBinaryFiles()
                             throws SearchQueryException
Convert legacy file

Returns:
Number of converted fields. Or -1 if not storing binaries as files
Throws:
SearchQueryException


MMBase build 1.7.1.20041002