|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.mmbase.storage.implementation.database.DatabaseStorageManager
A JDBC implementation of an object related storage manager.
| 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 |
protected static final java.util.List sequenceKeys
protected static java.lang.Integer bufferSize
protected DatabaseStorageManagerFactory factory
protected javax.sql.DataSource dataSource
protected java.sql.Connection activeConnection
releaseActiveConnection()
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
protected int transactionIsolation
Attributes.TRANSACTION_ISOLATION_LEVEL attribute, which is commonly set
to the highest (most secure) transaction isolation level available.
protected java.util.Map changes
| Constructor Detail |
public DatabaseStorageManager()
| Method Detail |
protected final void logQuery(java.lang.String msg)
public double getVersion()
StorageManager
getVersion in interface StorageManager
public void init(StorageManagerFactory factory)
throws StorageException
StorageManager
init in interface StorageManagerfactory - the StorageManagerFactory instance that created this storage manager.
StorageException
protected java.sql.Connection getActiveConnection()
throws java.sql.SQLException
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.
java.sql.SQLException - if opening the connection failedprotected void releaseActiveConnection()
public void beginTransaction()
throws StorageException
StorageManager
beginTransaction in interface StorageManagerStorageException - if the transaction could not be created
public void commit()
throws StorageException
StorageManager
commit in interface StorageManagerStorageException - if a transaction is not currently active, or an error occurred while committing
public boolean rollback()
throws StorageException
StorageManager
rollback in interface StorageManagertrue if changes were rolled back, false if the transaction was
canceled but the storage does not support rollback
StorageException - if a transaction is not currently active, or an error occurred during rollback
protected void commitChange(MMObjectNode node,
java.lang.String change)
changes object (to be committed after the transaction ends).
Otherwise it directly commits and broadcasts the changes
node - the node to registerchange - the type of change: "n": new, "c": commit, "d": delete, "r" : relation changed
public int createKey()
throws StorageException
StorageManager
createKey in interface StorageManagerStorageException
public java.lang.String getStringValue(MMObjectNode node,
FieldDefs field)
throws StorageException
StorageManager
getStringValue in interface StorageManagernode - the node to retrieve the text fromfield - the FieldDefs of the field to retrieve
StorageException - if an error occurred while retrieving the text value
protected java.lang.String getStringValue(java.sql.ResultSet result,
int index,
FieldDefs field)
throws StorageException,
java.sql.SQLException
ResultSet.getString(int) to obtain text.
Override this method if you want to optimize retrieving large texts,
i.e by using clobs or streams.
result - the resultset to retrieve the text fromindex - the index of the text in the resultsetfield - the (MMBase) fieldtype. This value can be null
null if no text was stored
java.sql.SQLException - when a database error occurs
StorageException - when data is incompatible or the function is not supported
protected boolean shorten(FieldDefs field)
throws StorageException,
java.sql.SQLException
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.
field - the (MMBase) fieldtype
true if the field should be shortened
java.sql.SQLException - when a database error occurs
StorageException - when data is incompatible or the function is not supported
protected byte[] readBinaryFromDatabase(MMObjectNode node,
FieldDefs field)
node - the node the binary data belongs tofield - the binary field
null if no binary data was stored
public byte[] getBinaryValue(MMObjectNode node,
FieldDefs field)
throws StorageException
StorageManager
getBinaryValue in interface StorageManagernode - the node to retrieve the byte array fromfield - the FieldDefs of the field to retrieve
StorageException - if an error occurred while retrieving the binary value
protected byte[] getBinaryValue(java.sql.ResultSet result,
int index,
FieldDefs field)
throws StorageException,
java.sql.SQLException
ResultSet.getBytes(int) to obtain text.
Override this method if you want to optimize retrieving large objects,
i.e by using clobs or streams.
result - the resultset to retrieve the text fromindex - the index of the text in the resultsetfield - the (MMBase) fieldtype. This value can be null
null if no binary data was stored
java.sql.SQLException - when a database error occurs
StorageException - when data is incompatible or the function is not supported
protected java.io.File getBinaryFile(MMObjectNode node,
java.lang.String fieldName)
node - the node the binary data belongs tofieldName - the name of the binary field
protected void storeBinaryAsFile(MMObjectNode node,
FieldDefs field)
throws StorageException
node - the node the binary data belongs tofield - the binary field
StorageException
protected java.io.File checkFile(java.io.File binaryFile,
MMObjectNode node,
FieldDefs field)
protected byte[] readBinaryFromFile(MMObjectNode node,
FieldDefs field)
throws StorageException
node - the node the binary data belongs tofield - the binary field
null if no binary data was stored
StorageException
public int create(MMObjectNode node)
throws StorageException
StorageManager
create in interface StorageManagernode - The node to insert
StorageException - if an error occurred during insert
protected void create(MMObjectNode node,
MMObjectBuilder builder)
throws StorageException
node - The node to insert. The node already needs to have a (new) number assignedbuilder - the builder to store the node
StorageException - if an error occurred during creation
protected void executeUpdateCheckConnection(java.lang.String query,
MMObjectNode node,
java.util.List fields)
throws java.sql.SQLException
java.sql.SQLException - If something wrong with the query, or the database is down or could not be contacted.
protected void executeUpdate(java.lang.String query,
MMObjectNode node,
java.util.List fields)
throws java.sql.SQLException
executeUpdateCheckConnection(java.lang.String, org.mmbase.module.core.MMObjectNode, java.util.List) which in turn is called from
several spots in this class.
java.sql.SQLException
public void change(MMObjectNode node)
throws StorageException
StorageManager
change in interface StorageManagernode - The node to commit
StorageException - if an error occurred during commit
protected void change(MMObjectNode node,
MMObjectBuilder builder)
throws StorageException
node - The node to changebuilder - the builder to store the node
StorageException - if an error occurred during change
protected void setValue(java.sql.PreparedStatement statement,
int index,
MMObjectNode node,
FieldDefs field)
throws StorageException,
java.sql.SQLException
statement - the prepared statementindex - the index of the field in the prepared statementnode - the node from which to retrieve the valuefield - the MMBase field, containing meta-information
StorageException - if the fieldtype is invalid, or data is invalid or missing
java.sql.SQLException - if an error occurred while filling in the fields
protected boolean setNullValue(java.sql.PreparedStatement statement,
int index,
java.lang.Object value,
FieldDefs field,
int type)
throws StorageException,
java.sql.SQLException
statement - the prepared statementindex - the index of the field in the prepared statementvalue - the numeric value to store, which will be checked for null.field - the MMBase field, containing meta-informationtype - java.sql.Type constant
StorageException - if the data is invalid or missing
java.sql.SQLException - if an error occurred while filling in the fields
protected void setNumericValue(java.sql.PreparedStatement statement,
int index,
java.lang.Object value,
FieldDefs field)
throws StorageException,
java.sql.SQLException
statement - the prepared statementindex - the index of the field in the prepared statementvalue - 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
StorageException - if the data is invalid or missing
java.sql.SQLException - if an error occurred while filling in the fields
protected void setNodeValue(java.sql.PreparedStatement statement,
int index,
java.lang.Object node,
FieldDefs field)
throws StorageException,
java.sql.SQLException
statement - the prepared statementindex - the index of the field in the prepared statementnode - the node to storefield - the MMBase field, containing meta-information
StorageException - if the data is invalid or missing
java.sql.SQLException - if an error occurred while filling in the fields
protected void setBinaryValue(java.sql.PreparedStatement statement,
int index,
java.lang.Object objectValue,
FieldDefs field)
throws StorageException,
java.sql.SQLException
statement - the prepared statementindex - the index of the field in the prepared statementobjectValue - the data (byte array) to storefield - the MMBase field, containing meta-information. This value can be null
StorageException - if the data is invalid or missing
java.sql.SQLException - if an error occurred while filling in the fields
protected void setStringValue(java.sql.PreparedStatement statement,
int index,
java.lang.Object objectValue,
FieldDefs field)
throws StorageException,
java.sql.SQLException
PreparedStatement.setString(int, String) to set the data.
Override this method if you use another way to store large texts (i.e. Clobs).
statement - the prepared statementindex - the index of the field in the prepared statementobjectValue - the text to storefield - the MMBase field, containing meta-information
StorageException - if the data is invalid or missing
java.sql.SQLException - if an error occurred while filling in the fields
protected void setXMLValue(java.sql.PreparedStatement statement,
int index,
java.lang.Object objectValue,
FieldDefs field)
throws StorageException,
java.sql.SQLException
setStringValue(java.sql.PreparedStatement, int, java.lang.Object, org.mmbase.module.corebuilders.FieldDefs).
Override this method if you want to override this behavior.
StorageException
java.sql.SQLException
public void delete(MMObjectNode node)
throws StorageException
StorageManager
delete in interface StorageManagernode - The node to delete
true if succesful
StorageException - if an error occurred during delete
protected void delete(MMObjectNode node,
MMObjectBuilder builder)
throws StorageException
node - The node to delete
StorageException - if an error occurred during delete
public MMObjectNode getNode(MMObjectBuilder builder,
int number)
throws StorageException
StorageManager
getNode in interface StorageManagerbuilder - The builder to select fromnumber - the number of the node
StorageException - if an error occurred during the get
protected void fillNode(MMObjectNode node,
java.sql.ResultSet result,
MMObjectBuilder builder)
throws StorageException
result.isAfterLast returns false)
node - The MMObjectNode to be filledresult - the resultsetbuilder - the builder to use for creating the node
StorageException - if the resultset is exhausted or a database error occurred
protected java.lang.Object getValue(java.sql.ResultSet result,
int index,
FieldDefs field)
throws StorageException
result - the resultsetindex - the index of the field in the resultsetfield - the expected MMBase field type. This can be null
StorageException - if the value cannot be retrieved from the resultset
public int getNodeType(int number)
throws StorageException
StorageManager
getNodeType in interface StorageManagernumber - the number of the node
StorageException - if an error occurred during selectionprotected boolean tablesInheritFields()
protected boolean isPartOfBuilderDefinition(FieldDefs field)
public void create(MMObjectBuilder builder)
throws StorageException
StorageManager
create in interface StorageManagerbuilder - the builder to create the storage element for
StorageException - if an error occurred during the creation of the storage element
protected java.lang.String getFieldDefinition(FieldDefs field)
throws StorageException
field - the field
StorageException - if the field type cannot be mapped
protected java.lang.String getConstraintDefinition(FieldDefs field)
throws StorageException
field - the field for which to make the index definition
null if no definition is available
StorageException
protected java.lang.String getCompositeConstraintDefinition(MMObjectBuilder builder)
throws StorageException
builder - The builder for which to make the index definition
null if no definition is available
StorageException
public void change(MMObjectBuilder builder)
throws StorageException
StorageManager
change in interface StorageManagerbuilder - the builder whose storage to change
StorageException
public void delete(MMObjectBuilder builder)
throws StorageException
StorageManager
delete in interface StorageManagerbuilder - the builder whose storage to drop
StorageException
public void create()
throws StorageException
StorageManager
create in interface StorageManagertrue if the storage was succesfully created
StorageException - if an error occurred during the creation of the object storage
protected void createSequence()
throws StorageException
createKey().
StorageException - when the sequence can not be created
public boolean exists(MMObjectBuilder builder)
throws StorageException
StorageManager
exists in interface StorageManagerbuilder - the builder to check
true if the storage element exists, false if it doesn't
StorageException - if an error occurred while querying the storage
protected boolean exists(java.lang.String tableName)
throws StorageException
tableName - name of the table to look for
true if the table exists
StorageException - when the metadata could not be retrieved
public boolean exists()
throws StorageException
StorageManager
exists in interface StorageManagertrue if basic storage elements exist
StorageException - if an error occurred while querying the storage
public int size(MMObjectBuilder builder)
throws StorageException
StorageManager
size in interface StorageManagerbuilder - the builder whose objects to count
StorageException - if the storage element for the builder does not exists
public int size()
throws StorageException
StorageManager
size in interface StorageManagerStorageException - if the basic storage elements do not exist
protected int getJDBCtoMMBaseType(int jdbcType,
int mmbaseType)
public void verify(MMObjectBuilder builder)
throws StorageException
StorageException
protected void deleteCompositeIndex(MMObjectBuilder builder)
throws StorageException,
java.sql.SQLException
builder - the builder for which to drop the composite key
StorageException
java.sql.SQLException
protected void createCompositeIndex(MMObjectBuilder builder)
throws StorageException,
java.sql.SQLException
builder - the builder for which to add the composite key
StorageException
java.sql.SQLException
public void create(FieldDefs field)
throws StorageException
StorageManager
create in interface StorageManagerfield - the FieldDefs of the field to add
StorageException
public void change(FieldDefs field)
throws StorageException
StorageManager
change in interface StorageManagerfield - the FieldDefs of the field to change
StorageException
public void delete(FieldDefs field)
throws StorageException
StorageManager
delete in interface StorageManagerfield - the FieldDefs of the field to delete
StorageException
public int convertLegacyBinaryFiles()
throws SearchQueryException
SearchQueryException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||