public class DbDataStore extends AbstractDataStore implements DatabaseAware, MultiDataStoreAware
<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.">
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MIN_RECORD_LENGTH
The default value for the minimum object size.
|
static java.lang.String |
STORE_SIZE_MAX
Call PreparedStatement.setBinaryStream(..., Integer.MAX_VALUE)
|
static java.lang.String |
STORE_SIZE_MINUS_ONE
Call PreparedStatement.setBinaryStream(..., -1)
|
static java.lang.String |
STORE_TEMP_FILE
Write to a temporary file to get the length (slow, but always works).
|
Constructor and Description |
---|
DbDataStore() |
Modifier and Type | Method and Description |
---|---|
DataRecord |
addRecord(java.io.InputStream stream)
Creates a new data record.
|
void |
clearInUse()
Clear the in-use list.
|
void |
close()
Close the data store
|
int |
deleteAllOlderThan(long min)
Delete objects that have a modified date older than the specified date.
|
void |
deleteRecord(DataIdentifier identifier)
Deletes a single DataRecord based on the given identifier.
|
java.util.Iterator<DataIdentifier> |
getAllIdentifiers()
Get all identifiers.
|
boolean |
getCopyWhenReading()
Is a stream copied to a temporary file before returning?
|
java.lang.String |
getDatabaseType()
Get the database type (if set).
|
java.lang.String |
getDataSourceName() |
java.lang.String |
getDriver()
Get the database driver
|
int |
getMaxConnections()
Deprecated.
|
int |
getMinRecordLength()
Get the minimum size of an object that should be stored in this data store.
|
java.lang.String |
getPassword()
Get the password.
|
DataRecord |
getRecordIfStored(DataIdentifier identifier)
Check if a record for the given identifier exists, and return it if yes.
|
java.lang.String |
getSchemaObjectPrefix()
Get the schema prefix.
|
java.lang.String |
getTablePrefix()
Get the table prefix.
|
java.lang.String |
getUrl()
Get the database URL.
|
java.lang.String |
getUser()
Get the user name.
|
void |
init(java.lang.String homeDir)
Initialized the data store
|
boolean |
isSchemaCheckEnabled() |
void |
setConnectionFactory(ConnectionFactory connnectionFactory) |
void |
setCopyWhenReading(boolean copyWhenReading)
The the copy setting.
|
void |
setDatabaseType(java.lang.String databaseType)
Set the database type.
|
void |
setDataSourceName(java.lang.String dataSourceName) |
void |
setDriver(java.lang.String driver)
Set the database driver class name.
|
void |
setMaxConnections(int maxConnections)
Deprecated.
|
void |
setMinRecordLength(int minRecordLength)
Set the minimum object length.
|
void |
setPassword(java.lang.String password)
Set the password.
|
void |
setSchemaCheckEnabled(boolean enabled) |
void |
setSchemaObjectPrefix(java.lang.String schemaObjectPrefix)
Set the schema object prefix.
|
void |
setTablePrefix(java.lang.String tablePrefix)
Set the new table prefix.
|
void |
setUrl(java.lang.String url)
Set the database URL.
|
void |
setUser(java.lang.String user)
Set the user name.
|
void |
updateModifiedDateOnAccess(long before)
From now on, update the modified date of an object even when accessing it.
|
getRecord, getRecordFromReference
public static final int DEFAULT_MIN_RECORD_LENGTH
public static final java.lang.String STORE_TEMP_FILE
public static final java.lang.String STORE_SIZE_MINUS_ONE
public static final java.lang.String STORE_SIZE_MAX
public void setConnectionFactory(ConnectionFactory connnectionFactory)
setConnectionFactory
in interface DatabaseAware
public DataRecord addRecord(java.io.InputStream stream) throws DataStoreException
DataStore
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(); }
addRecord
in interface DataStore
stream
- binary streamDataStoreException
- if the data store could not be accessedpublic void deleteRecord(DataIdentifier identifier) throws DataStoreException
MultiDataStoreAware
MultiDataStore.MoveDataTask
.deleteRecord
in interface MultiDataStoreAware
identifier
- data identifierDataStoreException
- if the data store could not be accessed, or if the given
identifier is invalidpublic int deleteAllOlderThan(long min) throws DataStoreException
DataStore
deleteAllOlderThan
in interface DataStore
min
- the minimum timeDataStoreException
public java.util.Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException
DataStore
getAllIdentifiers
in interface DataStore
DataStoreException
- if the list could not be readpublic int getMinRecordLength()
DataStore
getMinRecordLength
in interface DataStore
public void setMinRecordLength(int minRecordLength)
minRecordLength
- the lengthpublic DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException
DataStore
getRecordIfStored
in interface DataStore
identifier
- data identifierDataStoreException
- if the data store could not be accessedpublic void init(java.lang.String homeDir) throws DataStoreException
DataStore
init
in interface DataStore
homeDir
- the home directory of the repositoryDataStoreException
public void updateModifiedDateOnAccess(long before)
DataStore
updateModifiedDateOnAccess
in interface DataStore
before
- - update the modified date to the current time if it is older than this valuepublic java.lang.String getDatabaseType()
public void setDatabaseType(java.lang.String databaseType)
databaseType
- public java.lang.String getDriver()
public void setDriver(java.lang.String driver)
driver
- public java.lang.String getPassword()
public void setPassword(java.lang.String password)
password
- public java.lang.String getUrl()
public void setUrl(java.lang.String url)
url
- public java.lang.String getUser()
public void setUser(java.lang.String user)
user
- public final boolean isSchemaCheckEnabled()
public final void setSchemaCheckEnabled(boolean enabled)
enabled
- set whether the schema check is enabledpublic void close() throws DataStoreException
DataStore
close
in interface DataStore
DataStoreException
- if a problem occurredpublic void clearInUse()
DataStore
clearInUse
in interface DataStore
public int getMaxConnections()
public void setMaxConnections(int maxConnections)
maxConnections
- the new valuepublic boolean getCopyWhenReading()
public void setCopyWhenReading(boolean copyWhenReading)
copyWhenReading
- the new settingpublic java.lang.String getTablePrefix()
public void setTablePrefix(java.lang.String tablePrefix)
tablePrefix
- the new valuepublic java.lang.String getSchemaObjectPrefix()
public void setSchemaObjectPrefix(java.lang.String schemaObjectPrefix)
schemaObjectPrefix
- the new prefixpublic java.lang.String getDataSourceName()
public void setDataSourceName(java.lang.String dataSourceName)
Copyright © 2010 - 2020 Adobe. All Rights Reserved