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 |
---|---|
protected ConnectionHelper |
conHelper
The
ConnectionHelper set in the init(String) method. |
protected boolean |
copyWhenReading
Copy the stream to a temp file before returning it.
|
protected String |
createTableSQL
This is the property 'createTable'
in the [databaseType].properties file, initialized with the default value.
|
protected String |
databaseType
The database type used.
|
protected String |
dataSourceName
The logical name of the DataSource to use.
|
static int |
DEFAULT_MIN_RECORD_LENGTH
The default value for the minimum object size.
|
protected String |
deleteOlderSQL
This is the property 'deleteOlder'
in the [databaseType].properties file, initialized with the default value.
|
protected String |
deleteSQL
This is the property 'delete'
in the [databaseType].properties file, initialized with the default value.
|
protected static String |
DIGEST
The digest algorithm used to uniquely identify records.
|
protected String |
driver
The database driver.
|
protected String |
insertTempSQL
This is the property 'insertTemp'
in the [databaseType].properties file, initialized with the default value.
|
protected Map<DataIdentifier,WeakReference<DataIdentifier>> |
inUse
All data identifiers that are currently in use are in this set until they are garbage collected.
|
protected long |
minModifiedDate
The minimum modified date.
|
protected int |
minRecordLength
The minimum size of an object that should be stored in this data store.
|
protected String |
password
The password
|
protected String |
schemaObjectPrefix
The prefix of the table names.
|
protected String |
selectAllSQL
This is the property 'selectAll'
in the [databaseType].properties file, initialized with the default value.
|
protected String |
selectDataSQL
This is the property 'selectData'
in the [databaseType].properties file, initialized with the default value.
|
protected String |
selectMetaSQL
This is the property 'selectMeta'
in the [databaseType].properties file, initialized with the default value.
|
static String |
STORE_SIZE_MAX
Call PreparedStatement.setBinaryStream(..., Integer.MAX_VALUE)
|
static String |
STORE_SIZE_MINUS_ONE
Call PreparedStatement.setBinaryStream(..., -1)
|
static String |
STORE_TEMP_FILE
Write to a temporary file to get the length (slow, but always works).
|
protected String |
storeStream
The stream storing mechanism used.
|
protected String |
tablePrefix
The prefix for the datastore table, empty by default.
|
protected String |
tableSQL
This is the property 'table'
in the [databaseType].properties file, initialized with the default value.
|
protected static String |
TEMP_PREFIX
The prefix used for temporary objects.
|
protected List<String> |
temporaryInUse
The temporary identifiers that are currently in use.
|
protected String |
updateDataSQL
This is the property 'updateData'
in the [databaseType].properties file, initialized with the default value.
|
protected String |
updateLastModifiedSQL
This is the property 'updateLastModified'
in the [databaseType].properties file, initialized with the default value.
|
protected String |
updateSQL
This is the property 'update'
in the [databaseType].properties file, initialized with the default value.
|
protected String |
url
The database URL used.
|
protected String |
user
The user name.
|
Constructor and Description |
---|
DbDataStore() |
Modifier and Type | Method and Description |
---|---|
DataRecord |
addRecord(InputStream stream)
Creates a new data record.
|
void |
clearInUse()
Clear the in-use list.
|
void |
close()
Close the data store
|
protected DataStoreException |
convert(String cause,
Exception e)
Convert an exception to a data store exception.
|
protected CheckSchemaOperation |
createCheckSchemaOperation()
This method is called from
init(String) after the
createConnectionHelper(DataSource) method, and returns a default CheckSchemaOperation . |
protected ConnectionHelper |
createConnectionHelper(DataSource dataSrc)
This method is called from the
init(String) method of this class and returns a
ConnectionHelper instance which is assigned to the conHelper field. |
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.
|
Iterator<DataIdentifier> |
getAllIdentifiers()
Get all identifiers.
|
boolean |
getCopyWhenReading()
Is a stream copied to a temporary file before returning?
|
String |
getDatabaseType()
Get the database type (if set).
|
String |
getDataSourceName() |
protected MessageDigest |
getDigest() |
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.
|
String |
getPassword()
Get the password.
|
protected String |
getProperty(Properties prop,
String key,
String defaultValue)
Get the expanded property value.
|
DataRecord |
getRecordIfStored(DataIdentifier identifier)
Check if a record for the given identifier exists, and return it if yes.
|
String |
getSchemaObjectPrefix()
Get the schema prefix.
|
String |
getTablePrefix()
Get the table prefix.
|
String |
getUrl()
Get the database URL.
|
String |
getUser()
Get the user name.
|
void |
init(String homeDir)
Initialized the data store
|
protected void |
initDatabaseType() |
boolean |
isSchemaCheckEnabled() |
void |
setConnectionFactory(ConnectionFactory connnectionFactory) |
void |
setCopyWhenReading(boolean copyWhenReading)
The the copy setting.
|
void |
setDatabaseType(String databaseType)
Set the database type.
|
void |
setDataSourceName(String dataSourceName) |
void |
setDriver(String driver)
Set the database driver class name.
|
void |
setMaxConnections(int maxConnections)
Deprecated.
|
void |
setMinRecordLength(int minRecordLength)
Set the minimum object length.
|
void |
setPassword(String password)
Set the password.
|
void |
setSchemaCheckEnabled(boolean enabled) |
void |
setSchemaObjectPrefix(String schemaObjectPrefix)
Set the schema object prefix.
|
void |
setTablePrefix(String tablePrefix)
Set the new table prefix.
|
void |
setUrl(String url)
Set the database URL.
|
void |
setUser(String user)
Set the user name.
|
void |
updateModifiedDateOnAccess(long before)
From now on, update the modified date of an object even when accessing it.
|
protected void |
usesIdentifier(DataIdentifier identifier) |
encodeHexString, getOrCreateReferenceKey, getRecord, getRecordFromReference, getReferenceFromIdentifier
public static final int DEFAULT_MIN_RECORD_LENGTH
public static final String STORE_TEMP_FILE
public static final String STORE_SIZE_MINUS_ONE
public static final String STORE_SIZE_MAX
protected static final String DIGEST
protected static final String TEMP_PREFIX
protected long minModifiedDate
protected String url
protected String driver
protected String user
protected String password
protected String databaseType
protected int minRecordLength
protected String tablePrefix
protected String schemaObjectPrefix
protected String dataSourceName
protected String tableSQL
protected String createTableSQL
protected String insertTempSQL
protected String updateDataSQL
protected String updateLastModifiedSQL
protected String updateSQL
protected String deleteSQL
protected String deleteOlderSQL
protected String selectMetaSQL
protected String selectAllSQL
protected String selectDataSQL
protected String storeStream
protected boolean copyWhenReading
protected Map<DataIdentifier,WeakReference<DataIdentifier>> inUse
protected List<String> temporaryInUse
protected ConnectionHelper conHelper
ConnectionHelper
set in the init(String)
method.public void setConnectionFactory(ConnectionFactory connnectionFactory)
setConnectionFactory
in interface DatabaseAware
public DataRecord addRecord(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 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(String homeDir) throws DataStoreException
DataStore
init
in interface DataStore
homeDir
- the home directory of the repositoryDataStoreException
protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
init(String)
method of this class and returns a
ConnectionHelper
instance which is assigned to the conHelper
field. Subclasses may
override it to return a specialized connection helper.dataSrc
- the DataSource
of this persistence managerConnectionHelper
Exception
- on errorprotected final CheckSchemaOperation createCheckSchemaOperation()
init(String)
after the
createConnectionHelper(DataSource)
method, and returns a default CheckSchemaOperation
.CheckSchemaOperation
instanceprotected void initDatabaseType() throws DataStoreException
DataStoreException
protected String getProperty(Properties prop, String key, String defaultValue)
prop
- the properties objectkey
- the keydefaultValue
- the default valueprotected DataStoreException convert(String cause, Exception e)
cause
- the messagee
- the root causepublic 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 String getDatabaseType()
public void setDatabaseType(String databaseType)
databaseType
- public String getDriver()
public void setDriver(String driver)
driver
- public String getPassword()
public void setPassword(String password)
password
- public String getUrl()
public void setUrl(String url)
url
- public String getUser()
public void setUser(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 occurredprotected void usesIdentifier(DataIdentifier identifier)
public void clearInUse()
DataStore
clearInUse
in interface DataStore
protected MessageDigest getDigest() throws DataStoreException
DataStoreException
public int getMaxConnections()
public void setMaxConnections(int maxConnections)
maxConnections
- the new valuepublic boolean getCopyWhenReading()
public void setCopyWhenReading(boolean copyWhenReading)
copyWhenReading
- the new settingpublic String getTablePrefix()
public void setTablePrefix(String tablePrefix)
tablePrefix
- the new valuepublic String getSchemaObjectPrefix()
public void setSchemaObjectPrefix(String schemaObjectPrefix)
schemaObjectPrefix
- the new prefixpublic String getDataSourceName()
public void setDataSourceName(String dataSourceName)
Copyright © 2004–2021 The Apache Software Foundation. All rights reserved.