Class DbDataStore
- java.lang.Object
-
- org.apache.jackrabbit.core.data.AbstractDataStore
-
- org.apache.jackrabbit.core.data.db.DbDataStore
-
- All Implemented Interfaces:
DataStore,MultiDataStoreAware,DatabaseAware
- Direct Known Subclasses:
DerbyDataStore
public class DbDataStore extends AbstractDataStore implements DatabaseAware, MultiDataStoreAware
A data store implementation that stores the records in a database using JDBC. Configuration:<DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore"> <param name="url" value="jdbc:postgresql:test"/> <param name="user" value="sa"/> <param name="password" value="sa"/> <param name="databaseType" value="postgresql"/> <param name="driver" value="org.postgresql.Driver"/> <param name="minRecordLength" value="1024"/> <param name="maxConnections" value="2"/> <param name="copyWhenReading" value="true"/> <param name="tablePrefix" value=""/> <param name="schemaObjectPrefix" value=""/> <param name="schemaCheckEnabled" value="true"/> </DataStore>Only URL, user name and password usually need to be set. The remaining settings are generated using the database URL sub-protocol from the database type resource file.
JNDI can be used to get the connection. In this case, use the javax.naming.InitialContext as the driver, and the JNDI name as the URL. If the user and password are configured in the JNDI resource, they should not be configured here. Example JNDI settings:
<param name="driver" value="javax.naming.InitialContext" /> <param name="url" value="java:comp/env/jdbc/Test" />
For Microsoft SQL Server 2005, there is a problem reading large BLOBs. You will need to use the JDBC driver version 1.2 or newer, and append ;responseBuffering=adaptive to the database URL. Don't append ;selectMethod=cursor, otherwise it can still run out of memory. Example database URL: jdbc:sqlserver://localhost:4220;DatabaseName=test;responseBuffering=adaptive
By default, the data is copied to a temp file when reading, to avoid problems when reading multiple blobs at the same time.
The tablePrefix can be used to specify a schema and / or catalog name: <param name="tablePrefix" value="ds.">
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MIN_RECORD_LENGTHThe default value for the minimum object size.static java.lang.StringSTORE_SIZE_MAXCall PreparedStatement.setBinaryStream(..., Integer.MAX_VALUE)static java.lang.StringSTORE_SIZE_MINUS_ONECall PreparedStatement.setBinaryStream(..., -1)static java.lang.StringSTORE_TEMP_FILEWrite to a temporary file to get the length (slow, but always works).
-
Constructor Summary
Constructors Constructor Description DbDataStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description DataRecordaddRecord(java.io.InputStream stream)Creates a new data record.voidclearInUse()Clear the in-use list.voidclose()Close the data storeintdeleteAllOlderThan(long min)Delete objects that have a modified date older than the specified date.voiddeleteRecord(DataIdentifier identifier)Deletes a single DataRecord based on the given identifier.java.util.Iterator<DataIdentifier>getAllIdentifiers()Get all identifiers.booleangetCopyWhenReading()Is a stream copied to a temporary file before returning?java.lang.StringgetDatabaseType()Get the database type (if set).java.lang.StringgetDataSourceName()java.lang.StringgetDriver()Get the database driverintgetMaxConnections()Deprecated.intgetMinRecordLength()Get the minimum size of an object that should be stored in this data store.java.lang.StringgetPassword()Get the password.DataRecordgetRecordIfStored(DataIdentifier identifier)Check if a record for the given identifier exists, and return it if yes.java.lang.StringgetSchemaObjectPrefix()Get the schema prefix.java.lang.StringgetTablePrefix()Get the table prefix.java.lang.StringgetUrl()Get the database URL.java.lang.StringgetUser()Get the user name.voidinit(java.lang.String homeDir)Initialized the data storebooleanisSchemaCheckEnabled()voidsetConnectionFactory(ConnectionFactory connnectionFactory)voidsetCopyWhenReading(boolean copyWhenReading)The the copy setting.voidsetDatabaseType(java.lang.String databaseType)Set the database type.voidsetDataSourceName(java.lang.String dataSourceName)voidsetDriver(java.lang.String driver)Set the database driver class name.voidsetMaxConnections(int maxConnections)Deprecated.voidsetMinRecordLength(int minRecordLength)Set the minimum object length.voidsetPassword(java.lang.String password)Set the password.voidsetSchemaCheckEnabled(boolean enabled)voidsetSchemaObjectPrefix(java.lang.String schemaObjectPrefix)Set the schema object prefix.voidsetTablePrefix(java.lang.String tablePrefix)Set the new table prefix.voidsetUrl(java.lang.String url)Set the database URL.voidsetUser(java.lang.String user)Set the user name.voidupdateModifiedDateOnAccess(long before)From now on, update the modified date of an object even when accessing it.-
Methods inherited from class org.apache.jackrabbit.core.data.AbstractDataStore
getRecord, getRecordFromReference
-
-
-
-
Field Detail
-
DEFAULT_MIN_RECORD_LENGTH
public static final int DEFAULT_MIN_RECORD_LENGTH
The default value for the minimum object size.- See Also:
- Constant Field Values
-
STORE_TEMP_FILE
public static final java.lang.String STORE_TEMP_FILE
Write to a temporary file to get the length (slow, but always works). This is the default setting.- See Also:
- Constant Field Values
-
STORE_SIZE_MINUS_ONE
public static final java.lang.String STORE_SIZE_MINUS_ONE
Call PreparedStatement.setBinaryStream(..., -1)- See Also:
- Constant Field Values
-
STORE_SIZE_MAX
public static final java.lang.String STORE_SIZE_MAX
Call PreparedStatement.setBinaryStream(..., Integer.MAX_VALUE)- See Also:
- Constant Field Values
-
-
Method Detail
-
setConnectionFactory
public void setConnectionFactory(ConnectionFactory connnectionFactory)
- Specified by:
setConnectionFactoryin interfaceDatabaseAware
-
addRecord
public DataRecord addRecord(java.io.InputStream stream) throws DataStoreException
Description copied from interface:DataStoreCreates a new data record. The given binary stream is consumed and a binary record containing the consumed stream is created and returned. If the same stream already exists in another record, then that record is returned instead of creating a new one.The given stream is consumed and not closed by this method. It is the responsibility of the caller to close the stream. A typical call pattern would be:
InputStream stream = ...; try { record = store.addRecord(stream); } finally { stream.close(); }- Specified by:
addRecordin interfaceDataStore- Parameters:
stream- binary stream- Returns:
- data record that contains the given stream
- Throws:
DataStoreException- if the data store could not be accessed
-
deleteRecord
public void deleteRecord(DataIdentifier identifier) throws DataStoreException
Description copied from interface:MultiDataStoreAwareDeletes a single DataRecord based on the given identifier. Delete will only be used by theMultiDataStore.MoveDataTask.- Specified by:
deleteRecordin interfaceMultiDataStoreAware- Parameters:
identifier- data identifier- Throws:
DataStoreException- if the data store could not be accessed, or if the given identifier is invalid
-
deleteAllOlderThan
public int deleteAllOlderThan(long min) throws DataStoreExceptionDescription copied from interface:DataStoreDelete objects that have a modified date older than the specified date.- Specified by:
deleteAllOlderThanin interfaceDataStore- Parameters:
min- the minimum time- Returns:
- the number of data records deleted
- Throws:
DataStoreException
-
getAllIdentifiers
public java.util.Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException
Description copied from interface:DataStoreGet all identifiers.- Specified by:
getAllIdentifiersin interfaceDataStore- Returns:
- an iterator over all DataIdentifier objects
- Throws:
DataStoreException- if the list could not be read
-
getMinRecordLength
public int getMinRecordLength()
Description copied from interface:DataStoreGet the minimum size of an object that should be stored in this data store. Depending on the overhead and configuration, each store may return a different value.- Specified by:
getMinRecordLengthin interfaceDataStore- Returns:
- the minimum size in bytes
-
setMinRecordLength
public void setMinRecordLength(int minRecordLength)
Set the minimum object length. The maximum value is around 32000.- Parameters:
minRecordLength- the length
-
getRecordIfStored
public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException
Description copied from interface:DataStoreCheck if a record for the given identifier exists, and return it if yes. If no record exists, this method returns null.- Specified by:
getRecordIfStoredin interfaceDataStore- Parameters:
identifier- data identifier- Returns:
- the record if found, and null if not
- Throws:
DataStoreException- if the data store could not be accessed
-
init
public void init(java.lang.String homeDir) throws DataStoreExceptionDescription copied from interface:DataStoreInitialized the data store- Specified by:
initin interfaceDataStore- Parameters:
homeDir- the home directory of the repository- Throws:
DataStoreException
-
updateModifiedDateOnAccess
public void updateModifiedDateOnAccess(long before)
Description copied from interface:DataStoreFrom now on, update the modified date of an object even when accessing it. Usually, the modified date is only updated when creating a new object, or when a new link is added to an existing object. When this setting is enabled, even getLength() will update the modified date.- Specified by:
updateModifiedDateOnAccessin interfaceDataStore- Parameters:
before- - update the modified date to the current time if it is older than this value
-
getDatabaseType
public java.lang.String getDatabaseType()
Get the database type (if set).- Returns:
- the database type
-
setDatabaseType
public void setDatabaseType(java.lang.String databaseType)
Set the database type. By default the sub-protocol of the JDBC database URL is used if it is not set. It must match the resource file [databaseType].properties. Example: mysql.- Parameters:
databaseType-
-
getDriver
public java.lang.String getDriver()
Get the database driver- Returns:
- the driver
-
setDriver
public void setDriver(java.lang.String driver)
Set the database driver class name. If not set, the default driver class name for the database type is used, as set in the [databaseType].properties resource; key 'driver'.- Parameters:
driver-
-
getPassword
public java.lang.String getPassword()
Get the password.- Returns:
- the password
-
setPassword
public void setPassword(java.lang.String password)
Set the password.- Parameters:
password-
-
getUrl
public java.lang.String getUrl()
Get the database URL.- Returns:
- the URL
-
setUrl
public void setUrl(java.lang.String url)
Set the database URL. Example: jdbc:postgresql:test- Parameters:
url-
-
getUser
public java.lang.String getUser()
Get the user name.- Returns:
- the user name
-
setUser
public void setUser(java.lang.String user)
Set the user name.- Parameters:
user-
-
isSchemaCheckEnabled
public final boolean isSchemaCheckEnabled()
- Returns:
- whether the schema check is enabled
-
setSchemaCheckEnabled
public final void setSchemaCheckEnabled(boolean enabled)
- Parameters:
enabled- set whether the schema check is enabled
-
close
public void close() throws DataStoreExceptionDescription copied from interface:DataStoreClose the data store- Specified by:
closein interfaceDataStore- Throws:
DataStoreException- if a problem occurred
-
clearInUse
public void clearInUse()
Description copied from interface:DataStoreClear the in-use list. This is only used for testing to make the the garbage collection think that objects are no longer in use.- Specified by:
clearInUsein interfaceDataStore
-
getMaxConnections
public int getMaxConnections()
Deprecated.Get the maximum number of concurrent connections.- Returns:
- the maximum number of connections.
-
setMaxConnections
public void setMaxConnections(int maxConnections)
Deprecated.Set the maximum number of concurrent connections in the pool. At least 3 connections are required if the garbage collection process is used.- Parameters:
maxConnections- the new value
-
getCopyWhenReading
public boolean getCopyWhenReading()
Is a stream copied to a temporary file before returning?- Returns:
- the setting
-
setCopyWhenReading
public void setCopyWhenReading(boolean copyWhenReading)
The the copy setting. If enabled, a stream is always copied to a temporary file when reading a stream.- Parameters:
copyWhenReading- the new setting
-
getTablePrefix
public java.lang.String getTablePrefix()
Get the table prefix.- Returns:
- the table prefix.
-
setTablePrefix
public void setTablePrefix(java.lang.String tablePrefix)
Set the new table prefix. The default is empty. The table name is constructed like this: ${tablePrefix}${schemaObjectPrefix}${tableName}- Parameters:
tablePrefix- the new value
-
getSchemaObjectPrefix
public java.lang.String getSchemaObjectPrefix()
Get the schema prefix.- Returns:
- the schema object prefix
-
setSchemaObjectPrefix
public void setSchemaObjectPrefix(java.lang.String schemaObjectPrefix)
Set the schema object prefix. The default is empty. The table name is constructed like this: ${tablePrefix}${schemaObjectPrefix}${tableName}- Parameters:
schemaObjectPrefix- the new prefix
-
getDataSourceName
public java.lang.String getDataSourceName()
-
setDataSourceName
public void setDataSourceName(java.lang.String dataSourceName)
-
-