org.mmbase.storage.implementation.database
Class PostgresqlLargeObjectStorageManager

java.lang.Object
  extended by org.mmbase.storage.implementation.database.DatabaseStorageManager
      extended by org.mmbase.storage.implementation.database.RelationalDatabaseStorageManager
          extended by org.mmbase.storage.implementation.database.PostgresqlLargeObjectStorageManager
All Implemented Interfaces:
StorageManager<DatabaseStorageManagerFactory>

public class PostgresqlLargeObjectStorageManager
extends RelationalDatabaseStorageManager

This class is responsible for handling binary objects using the PostgreSQL LargeObject API.

Author:
E-J. van der Laan, Finalist IT Group

Nested Class Summary
 
Nested classes/interfaces inherited from class org.mmbase.storage.implementation.database.DatabaseStorageManager
DatabaseStorageManager.InputStreamBlob
 
Field Summary
 
Fields inherited from class org.mmbase.storage.implementation.database.DatabaseStorageManager
activeConnection, changes, factory, inTransaction, OBJ2TYPE_MAX_SIZE, sequenceKeys, transactionIsolation, typeCache
 
Constructor Summary
PostgresqlLargeObjectStorageManager()
           
 
Method Summary
protected  void delete(MMObjectNode node, MMObjectBuilder builder, List<CoreField> blobFileField, String tablename)
          Deletes all references LargeObjects and calls the overridden method in its super class afterwards.
protected  void deleteLargeObjects(MMObjectNode node, MMObjectBuilder builder, List<CoreField> blobFileField)
          Delete all binary objects stored as large object.
protected  Connection getActiveConnection()
          Get the active connection.
protected  Blob getBlobValue(ResultSet result, int index, CoreField field, boolean mayShorten)
          Replaces it super class method and calls getBlobValueFromLargeObject(ResultSet, int, CoreField, boolean) instead.
protected  Blob getBlobValueFromLargeObject(ResultSet result, int index, CoreField field, boolean mayShorten)
          Retrieves a Blob from the database using the PostgreSQL LargeObject API.
protected  int getJDBCtoField(int jdbcType, int mmbaseType)
          Returns Field.TYPE_BINARY independent of the jdbcType.
protected  void setBinaryValue(PreparedStatement statement, int index, Object objectValue, CoreField field, MMObjectNode node)
          Writes the binary objectValue to to a LargeObject and stores the resulting oid as long in the statement.
 
Methods inherited from class org.mmbase.storage.implementation.database.RelationalDatabaseStorageManager
change, create, delete, getVersion, simpleCreate, tablesInheritFields
 
Methods inherited from class org.mmbase.storage.implementation.database.DatabaseStorageManager
addToTableNameCache, appendDirectory, appendField, beginTransaction, change, change, change, change, checkFile, commit, commitChange, convertLegacyBinaryFiles, create, create, create, create, create, create, createIndex, createIndices, createKey, createSequence, createTable, delete, delete, delete, delete, deleteIndices, executeQuery, executeUpdate, executeUpdateCheckConnection, exists, exists, exists, exists, exists, fillNode, getBinaryFile, getBinaryValue, getBlobFromDatabase, getBlobValue, getBlobValue, getBooleanValue, getConstraintDefinition, getDateTimeValue, getFactory, getFieldDefinition, getFieldList, getFieldTypeDefinition, getInputStreamValue, getLogStartTime, getNode, getNodeType, getStringValue, getStringValue, getValue, getXMLValue, init, isBinaryColumnType, isNull, isPartOfBuilderDefinition, isVerified, logQuery, refresh, releaseActiveConnection, rollback, setBooleanValue, setDateTimeValue, setDecimalValue, setListValue, setNodeType, setNodeTypeLeaveRelations, setNodeTypeRememberRelations, setNodeValue, setNullValue, setNumericValue, setStringValue, setValue, setXMLValue, shorten, size, size, storeBinaryAsFile, unloadShortedFields, verify, verifyTables
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PostgresqlLargeObjectStorageManager

public PostgresqlLargeObjectStorageManager()
Method Detail

delete

protected void delete(MMObjectNode node,
                      MMObjectBuilder builder,
                      List<CoreField> blobFileField,
                      String tablename)
Deletes all references LargeObjects and calls the overridden method in its super class afterwards. This method overrides its super class delete

Overrides:
delete in class DatabaseStorageManager
See Also:
DatabaseStorageManager.delete(MMObjectNode, MMObjectBuilder, List, String)

deleteLargeObjects

protected void deleteLargeObjects(MMObjectNode node,
                                  MMObjectBuilder builder,
                                  List<CoreField> blobFileField)
Delete all binary objects stored as large object. This excludes the binary fields stored as file. See DatabaseStorageManager.delete(MMObjectNode, MMObjectBuilder, List, String) for the arguments.

Parameters:
node -
builder -
blobFileField -

getActiveConnection

protected Connection getActiveConnection()
                                  throws SQLException
Get the active connection. This connection has auto-commit set to false always. This is required by the PostgreSQL LargeObject API.

Overrides:
getActiveConnection in class DatabaseStorageManager
Throws:
SQLException - if opening the connection failed

getBlobValue

protected Blob getBlobValue(ResultSet result,
                            int index,
                            CoreField field,
                            boolean mayShorten)
                     throws StorageException,
                            SQLException
Replaces it super class method and calls getBlobValueFromLargeObject(ResultSet, int, CoreField, boolean) instead.

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

getBlobValueFromLargeObject

protected Blob getBlobValueFromLargeObject(ResultSet result,
                                           int index,
                                           CoreField field,
                                           boolean mayShorten)
                                    throws StorageException,
                                           SQLException
Retrieves a Blob from the database using the PostgreSQL LargeObject API.

Parameters:
result - ResultSet holding the current record to read.
index - index of the blob field in the record set.
field - Field data for the blob.
mayShorten - if a Blob place holder must be returned instead of the real blob.
Returns:
null, SHORTED_BLOB, or a InputStreamBlob containing the inputstream returned by the LargeObject API.
Throws:
StorageException - when no LargeObject can be found when it should exist.
SQLException - can be thrown when acquiring the LargeObjectManager fails.

getJDBCtoField

protected int getJDBCtoField(int jdbcType,
                             int mmbaseType)
Returns Field.TYPE_BINARY independent of the jdbcType. In all other case it returns the result of the super class method. This is required because PostgreSQL returns jdbcType.INTEGER for OID fields.

Overrides:
getJDBCtoField in class DatabaseStorageManager

setBinaryValue

protected void setBinaryValue(PreparedStatement statement,
                              int index,
                              Object objectValue,
                              CoreField field,
                              MMObjectNode node)
                       throws StorageException,
                              SQLException
Writes the binary objectValue to to a LargeObject and stores the resulting oid as long in the statement. If the node already existed the existing LargeObject is deleted before creating a new one.

Overrides:
setBinaryValue in class DatabaseStorageManager
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
node - the node that contains the data. Used to update this node if the database layer makes changes to the data (i.e. creating a default value for a non-null field that had a null value)
Throws:
StorageException - if the data is invalid or missing
SQLException - if an error occurred while filling in the fields


MMBase 2.0-SNAPSHOT - null