org.mmbase.storage
Interface StorageManager

All Known Implementing Classes:
DatabaseStorageManager

public interface StorageManager

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,v 1.7 2005/10/02 16:16:43 michiel Exp $
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(StorageManagerFactory factory)
          Initializes the manager.
 boolean rollback()
          Cancels any transaction that was started and rollback changes if possible.
 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

public 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

public void init(StorageManagerFactory 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

public 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

public 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

public 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

public 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

public 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

public 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

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

create

public 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

public 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

public void delete(MMObjectNode node)
            throws StorageException
Delete a node

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

getNode

public 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

public 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

public 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

public 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

public 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

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

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

exists

public 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

public 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

public 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

public 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

public 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

public 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

public 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


MMBase build 1.8.1.20060716