org.mmbase.storage
Interface StorageManager<SMF extends StorageManagerFactory>

All Known Implementing Classes:
DatabaseStorageManager, InformixStorageManager, PostgresqlLargeObjectStorageManager, RelationalDatabaseStorageManager, ViewDatabaseStorageManager

public interface StorageManager<SMF extends StorageManagerFactory>

The StorageManager interface defines how to access a storage device. It contains methods that can be used to query the storage, insert, update, or remove objects, or to change object definitions (adding fields, etc.).

Since:
MMBase-1.7
Version:
$Id: StorageManager.java 35391 2009-05-22 12:50:26Z michiel $
Author:
Pierre van Rooden

Method Summary
 void beginTransaction()
          Starts a transaction on this StorageManager instance.
 void change(CoreField 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.
 void commit()
          Closes any transaction that was started and commits all changes.
 void create()
          Create the basic elements for this storage
 void create(CoreField 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.
 int createKey()
          Gives an unique number for a new node, to be inserted in the storage.
 void delete(CoreField 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
 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
 byte[] getBinaryValue(MMObjectNode node, CoreField field)
          Retrieve a large binary object (byte array) for a specified object field.
 InputStream getInputStreamValue(MMObjectNode node, CoreField field)
           
 MMObjectNode getNode(MMObjectBuilder builder, int number)
          Select a node from a specified builder
 int getNodeType(int number)
          Returns the nodetype for a specified nodereference
 String getStringValue(MMObjectNode node, CoreField field)
          Retrieve a large text for a specified object field.
 double getVersion()
          Returns the version of this factory implementation.
 void init(SMF factory)
          Initializes the manager.
 boolean isNull(MMObjectNode node, CoreField field)
          Checks for null values for a field from the storage of this builder.
 boolean rollback()
          Cancels any transaction that was started and rollback changes if possible.
 int setNodeType(MMObjectNode node, MMObjectBuilder builder)
           
 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
 

Method Detail

getVersion

double getVersion()
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.

Returns:
the version as an integer

init

void init(SMF factory)
          throws StorageException
Initializes the manager. Called by a StorageManagerFactory when instantiating the manager with the getStorageManager() method.

Parameters:
factory - the StorageManagerFactory instance that created this storage manager.
Throws:
StorageConfigurationException - if the initialization failed
StorageException

beginTransaction

void beginTransaction()
                      throws StorageException
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.

Throws:
StorageException - if the transaction could not be created

commit

void commit()
            throws StorageException
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.

Throws:
StorageException - if a transaction is not currently active, or an error occurred while committing

rollback

boolean rollback()
                 throws StorageException
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).

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

createKey

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

Returns:
unique number
Throws:
StorageException

getStringValue

String getStringValue(MMObjectNode node,
                      CoreField field)
                      throws StorageException
Retrieve a large text for a specified object field. Implement this method to allow for optimization of storing and retrieving large texts.

Parameters:
node - the node to retrieve the text from
field - the Type of the field to retrieve
Returns:
the retrieved text
Throws:
StorageException - if an error occurred while retrieving the text value

getBinaryValue

byte[] getBinaryValue(MMObjectNode node,
                      CoreField field)
                      throws StorageException
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.

Parameters:
node - the node to retrieve the byte array from
field - the CoreField of the field to retrieve
Returns:
the retrieved byte array
Throws:
StorageException - if an error occurred while retrieving the binary value

getInputStreamValue

InputStream getInputStreamValue(MMObjectNode node,
                                CoreField field)
                                throws StorageException
Throws:
StorageException
Since:
MMBase-1.8

create

int create(MMObjectNode node)
           throws StorageException
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.

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

change

void change(MMObjectNode node)
            throws StorageException
Commit this node to the specified builder.

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

delete

void delete(MMObjectNode node)
            throws StorageException
Delete a node

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

setNodeType

int setNodeType(MMObjectNode node,
                MMObjectBuilder builder)
                throws StorageException
Throws:
StorageException
Since:
MMBase-1.9.1

getNode

MMObjectNode getNode(MMObjectBuilder builder,
                     int number)
                     throws StorageException
Select a node from a specified builder

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

getNodeType

int getNodeType(int number)
                throws StorageException
Returns the nodetype for a specified nodereference

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

create

void create(MMObjectBuilder builder)
            throws StorageException
Create a storage element to store the specified builder's objects.

Parameters:
builder - the builder to create the storage element for
Throws:
StorageException - if an error occurred during the creation of the storage element

create

void create()
            throws StorageException
Create the basic elements for this storage

Throws:
StorageException - if an error occurred during the creation of the object storage

change

void change(MMObjectBuilder builder)
            throws StorageException
Changes the storage of a builder to match its new configuration.

Parameters:
builder - the builder whose storage to change
Throws:
StorageException

delete

void delete(MMObjectBuilder builder)
            throws StorageException
Drops the storage of this builder.

Parameters:
builder - the builder whose storage to drop
Throws:
StorageException

exists

boolean exists(MMObjectBuilder builder)
               throws StorageException
Determine if a storage element exists for storing the given builder's objects

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

boolean exists()
               throws StorageException
Determine if the basic storage elements exist Basic storage elements include the 'object' storage (where all objects and their types are registered).

Returns:
true if basic storage elements exist
Throws:
StorageException - if an error occurred while querying the storage

size

int size(MMObjectBuilder builder)
         throws StorageException
Return the number of objects of a builder in the storage

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

int size()
         throws StorageException
Return the total number of objects in the storage

Returns:
the number of objects
Throws:
StorageException - if the basic storage elements do not exist

create

void create(CoreField field)
            throws StorageException
Creates a field and adds it to the storage of this builder.

Parameters:
field - the CoreField of the field to add
Throws:
StorageException

change

void change(CoreField field)
            throws StorageException
Changes a field to the storage of this builder.

Parameters:
field - the CoreField of the field to change
Throws:
StorageException

delete

void delete(CoreField field)
            throws StorageException
Deletes a field from the storage of this builder.

Parameters:
field - the CoreField of the field to delete
Throws:
StorageException

isNull

boolean isNull(MMObjectNode node,
               CoreField field)
               throws StorageException
Checks for null values for a field from the storage of this builder.

Parameters:
node - the node to check the value for
field - the CoreField
Returns:
true when value is null in storage
Throws:
StorageException - if an error occurred during the get


MMBase 2.0-SNAPSHOT - null