org.mmbase.storage
Interface Storage

All Known Subinterfaces:
DatabaseStorage

public interface Storage

The Storage interface defines a storage device - a location where MMBase objects are kept, typically a database. The interface 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.6
Version:
$Id: Storage.java,v 1.2 2002/11/07 12:30:37 pierre Exp $
Author:
Pierre van Rooden

Method Summary
 boolean addField(MMObjectBuilder builder, java.lang.String fieldname)
          Adds a field to the storage of this builder.
 boolean changeField(MMObjectBuilder builder, java.lang.String fieldname)
          Changes a field to the storage of this builder.
 boolean commit(MMObjectNode node)
          Commit this node to the specified builder.
 boolean commit(MMObjectNode node, Transaction trans)
          Commit this node to the specified builder within a transaction.
 boolean create(MMObjectBuilder builder)
          Create a storage for the specified builder.
 boolean create(MMObjectBuilder builder, Transaction trans)
          Create a storage for the specified builder.
 boolean created(MMObjectBuilder builder)
          Tells if a storage for the builder already exists
 int createKey()
          Gives an unique number for a node to be inserted.
 int createKey(Transaction trans)
          Gives an unique number for a node to be inserted.
 boolean createObjectStorage()
          Create the object storage (the storage where to register all objects).
 boolean createObjectStorage(Transaction trans)
          Create the object storage (the storage where to register all objects) within a transaction
 Transaction createTransaction()
          Returns a newly created transaction object.
 boolean delete(MMObjectNode node)
          Delete a node
 boolean delete(MMObjectNode node, Transaction trans)
          Delete a node within a transaction
 boolean drop(MMObjectBuilder builder)
          Drops the storage of this builder.
 byte[] getBytes(MMObjectNode node, java.lang.String fieldname)
          Retrieve a large binary object (byte array) for a specified object field.
 MMObjectNode getNode(MMObjectBuilder builder, int number)
          Select a node from a specified builder
 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
 int getNodeType(int number, Transaction trans)
          Returns the nodetype for a specified nodereference
 java.lang.String getText(MMObjectNode node, java.lang.String fieldname)
          Retrieve a large text for a specified object field.
 int insert(MMObjectNode node)
          This method inserts a new object, and registers the change.
 int insert(MMObjectNode node, Transaction trans)
          This method inserts a new object within a transaction, and registers the change.
 boolean isAllowedParentBuilder(MMObjectBuilder builder)
          Returns whether this storage layer allows for builder to be a parent builder (that is, other builders can 'extend' this builder and its storage device).
 void registerParentBuilder(MMObjectBuilder parent, MMObjectBuilder child)
          Registers a builder as a parent builder (that is, other builders can 'extend' this builder and its storage device).
 boolean removeField(MMObjectBuilder builder, java.lang.String fieldname)
          Deletes a field from the storage of this builder.
 int size(MMObjectBuilder builder)
          Return number of objects in a builder
 boolean supportsRollback()
          Returns whether rollback on storage level is supported.
 boolean updateStorage(MMObjectBuilder builder)
          Changes the storage of a builder to match its new configuration.
 

Method Detail

isAllowedParentBuilder

public boolean isAllowedParentBuilder(MMObjectBuilder builder)
Returns whether this storage layer allows for builder to be a parent builder (that is, other builders can 'extend' this builder and its storage device).
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 StorageException
Registers a builder as a parent builder (that is, other builders can 'extend' this builder and its storage device). 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.
Parameters:
parent - the parent builder to register
child - the builder to register as the parent's child
Throws:
StorageException - when the support layer does not allow extension of this builder
Since:
MMBase-1.6

supportsRollback

public boolean supportsRollback()
Returns whether rollback on storage level is supported.
Returns:
true if transactions are supported

getText

public java.lang.String getText(MMObjectNode node,
                                java.lang.String fieldname)
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
fieldname - the name of the field to retrieve
Returns:
the retrieved text

getBytes

public byte[] getBytes(MMObjectNode node,
                       java.lang.String fieldname)
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
fieldname - the name of the field to retrieve
Returns:
the retrieved byte array

createTransaction

public Transaction createTransaction()
                              throws StorageException
Returns a newly created transaction object.
Returns:
the new transaction
Throws:
StorageException - if the transaction could not be created

createKey

public int createKey()
Gives an unique number for a node to be inserted. This method should work with multiple mmbases
Returns:
unique number

createKey

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

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.
Parameters:
node - The node to insert
Returns:
The (new) number for this node, or -1 if an error occurs.

insert

public 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.
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.
Parameters:
node - The node to commit
Returns:
true of succesful, false otherwise

commit

public boolean commit(MMObjectNode node,
                      Transaction trans)
               throws StorageException
Commit this node to the specified builder within a transaction.
Parameters:
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
Parameters:
node - The node to delete
Returns:
true if succesful

delete

public boolean delete(MMObjectNode node,
                      Transaction trans)
               throws StorageException
Delete a node within a transaction
Parameters:
node - The node to delete
trans - the transaction to perform the insert in
Returns:
true if succesful
Throws:
StorageException - if an error occurred during delete

getNode

public MMObjectNode getNode(MMObjectBuilder builder,
                            int number)
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

getNode

public MMObjectNode getNode(MMObjectBuilder builder,
                            int number,
                            Transaction trans)
                     throws StorageException
Select a node from a specified builder
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 the get

getNodeType

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

getNodeType

public int getNodeType(int number,
                       Transaction trans)
                throws StorageException
Returns the nodetype for a specified nodereference
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 storage for the specified builder.
Parameters:
builder - the builder to create the storage for
Returns:
true if the storage was succesfully created

create

public boolean create(MMObjectBuilder builder,
                      Transaction trans)
               throws StorageException
Create a storage for the specified builder.
Parameters:
builder - the builder to create the storage for
trans - the transaction to perform the create in
Returns:
true if the storage was succesfully created
Throws:
StorageException - if an error occurred during the creation fo the table

createObjectStorage

public boolean createObjectStorage()
Create the object storage (the storage where to register all objects).
Returns:
true if the storage was succesfully created

createObjectStorage

public boolean createObjectStorage(Transaction trans)
                            throws StorageException
Create the object storage (the storage where to register all objects) within a transaction
Parameters:
trans - the transaction to perform the create in
Returns:
true if the storage was succesfully created
Throws:
StorageException - if an error occurred during the caretion of the object storage

created

public boolean created(MMObjectBuilder builder)
Tells if a storage for the builder already exists
Parameters:
builder - the builder to check
Returns:
true if storage exists, false if storage doesn't exists

size

public int size(MMObjectBuilder builder)
Return number of objects in a builder
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 boolean drop(MMObjectBuilder builder)
Drops the storage of this builder.
Parameters:
builder - the builder whose storage to drop
Returns:
true if succesful

addField

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

removeField

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

changeField

public boolean changeField(MMObjectBuilder builder,
                           java.lang.String fieldname)
Changes a field to the storage of this builder.
Parameters:
builder - the builder whose storage to change
fieldname - the name fo the field to change
Returns:
true if succesful

updateStorage

public boolean updateStorage(MMObjectBuilder builder)
Changes the storage of a builder to match its new configuration.
Parameters:
builder - the builder whose storage to change
Returns:
true if succesful


MMBase build 1.6.5.20030923