|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.jackrabbit.core.data.db.DbDataStore
public class DbDataStore
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=""/>
</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 | |
|---|---|
protected Pool |
connectionPool
A list of connections |
protected boolean |
copyWhenReading
Copy the stream to a temp file before returning it. |
protected java.lang.String |
createTableSQL
This is the property 'createTable' in the [databaseType].properties file, initialized with the default value. |
protected java.lang.String |
databaseType
The database type used. |
static int |
DEFAULT_MAX_CONNECTIONS
The default value for the maximum connections. |
static int |
DEFAULT_MIN_RECORD_LENGTH
The default value for the minimum object size. |
protected java.lang.String |
deleteOlderSQL
This is the property 'deleteOlder' in the [databaseType].properties file, initialized with the default value. |
protected java.lang.String |
deleteSQL
This is the property 'delete' in the [databaseType].properties file, initialized with the default value. |
protected static java.lang.String |
DIGEST
The digest algorithm used to uniquely identify records. |
protected java.lang.String |
driver
The database driver. |
protected java.lang.String |
insertTempSQL
This is the property 'insertTemp' in the [databaseType].properties file, initialized with the default value. |
protected java.util.Map |
inUse
All data identifiers that are currently in use are in this set until they are garbage collected. |
protected int |
maxConnections
The maximum number of open connections. |
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 java.lang.String |
password
The password |
protected java.lang.String |
selectAllSQL
This is the property 'selectAll' in the [databaseType].properties file, initialized with the default value. |
protected java.lang.String |
selectDataSQL
This is the property 'selectData' in the [databaseType].properties file, initialized with the default value. |
protected java.lang.String |
selectMetaSQL
This is the property 'selectMeta' in the [databaseType].properties file, initialized with the default value. |
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). |
protected java.lang.String |
storeStream
The stream storing mechanism used. |
protected java.lang.String |
tablePrefix
The prefix for the datastore table, empty by default. |
protected java.lang.String |
tableSQL
This is the property 'table' in the [databaseType].properties file, initialized with the default value. |
protected static java.lang.String |
TEMP_PREFIX
The prefix used for temporary objects. |
protected java.util.List |
temporaryInUse
The temporary identifiers that are currently in use. |
protected java.lang.String |
updateDataSQL
This is the property 'updateData' in the [databaseType].properties file, initialized with the default value. |
protected java.lang.String |
updateLastModifiedSQL
This is the property 'updateLastModified' in the [databaseType].properties file, initialized with the default value. |
protected java.lang.String |
updateSQL
This is the property 'update' in the [databaseType].properties file, initialized with the default value. |
protected java.lang.String |
url
The database URL used. |
protected java.lang.String |
user
The user name. |
| Constructor Summary | |
|---|---|
DbDataStore()
|
|
| Method Summary | |
|---|---|
DataRecord |
addRecord(java.io.InputStream stream)
Creates a new data record. |
void |
clearInUse()
Clear the in-use list. |
void |
close()
Close the data store |
protected DataStoreException |
convert(java.lang.String cause,
java.lang.Exception e)
Convert an exception to a data store exception. |
ConnectionRecoveryManager |
createNewConnection()
Create a new connection. |
int |
deleteAllOlderThan(long min)
Delete objects that have a modified date older than the specified date. |
java.util.Iterator |
getAllIdentifiers()
Get all identifiers. |
protected ConnectionRecoveryManager |
getConnection()
|
boolean |
getCopyWhenReading()
Is a stream copied to a temporary file before returning? |
java.lang.String |
getDatabaseType()
Get the database type (if set). |
protected java.security.MessageDigest |
getDigest()
|
java.lang.String |
getDriver()
Get the database driver |
int |
getMaxConnections()
Get the maximum number of concurrent connections. |
int |
getMinRecordLength()
Get the minimum size of an object that should be stored in this data store. |
java.lang.String |
getPassword()
Get the password. |
protected java.lang.String |
getProperty(java.util.Properties prop,
java.lang.String key,
java.lang.String defaultValue)
Get the expanded property value. |
DataRecord |
getRecord(DataIdentifier identifier)
Returns the identified data record. |
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 |
protected void |
initDatabaseType()
|
protected void |
putBack(ConnectionRecoveryManager conn)
|
void |
setCopyWhenReading(boolean copyWhenReading)
The the copy setting. |
void |
setDatabaseType(java.lang.String databaseType)
Set the database type. |
void |
setDriver(java.lang.String driver)
Set the database driver class name. |
void |
setMaxConnections(int maxConnections)
Set the maximum number of concurrent connections in the pool. |
void |
setMinRecordLength(int minRecordLength)
Set the minimum object length. |
void |
setPassword(java.lang.String password)
Set the password. |
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. |
protected void |
usesIdentifier(DataIdentifier identifier)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_MIN_RECORD_LENGTH
public static final int DEFAULT_MAX_CONNECTIONS
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
protected static final java.lang.String DIGEST
protected static final java.lang.String TEMP_PREFIX
protected long minModifiedDate
protected java.lang.String url
protected java.lang.String driver
protected java.lang.String user
protected java.lang.String password
protected java.lang.String databaseType
protected int minRecordLength
protected int maxConnections
protected Pool connectionPool
protected java.lang.String tablePrefix
protected java.lang.String tableSQL
protected java.lang.String createTableSQL
protected java.lang.String insertTempSQL
protected java.lang.String updateDataSQL
protected java.lang.String updateLastModifiedSQL
protected java.lang.String updateSQL
protected java.lang.String deleteSQL
protected java.lang.String deleteOlderSQL
protected java.lang.String selectMetaSQL
protected java.lang.String selectAllSQL
protected java.lang.String selectDataSQL
protected java.lang.String storeStream
protected boolean copyWhenReading
protected java.util.Map inUse
protected java.util.List temporaryInUse
| Constructor Detail |
|---|
public DbDataStore()
| Method Detail |
|---|
public DataRecord addRecord(java.io.InputStream stream)
throws DataStoreException
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 DataStorestream - binary stream
DataStoreException - if the data store could not be accessed
public int deleteAllOlderThan(long min)
throws DataStoreException
deleteAllOlderThan in interface DataStoremin - the minimum time
DataStoreException
public java.util.Iterator getAllIdentifiers()
throws DataStoreException
getAllIdentifiers in interface DataStoreDataStoreException - if the list could not be readpublic int getMinRecordLength()
getMinRecordLength in interface DataStorepublic void setMinRecordLength(int minRecordLength)
minRecordLength - the length
public DataRecord getRecord(DataIdentifier identifier)
throws DataStoreException
getRecord in interface DataStoreidentifier - data identifier
DataStoreException - if the data store could not be accessed,
or if the given identifier is invalid
public void init(java.lang.String homeDir)
throws DataStoreException
init in interface DataStorehomeDir - the home directory of the repository
DataStoreException
protected void initDatabaseType()
throws DataStoreException
DataStoreException
protected java.lang.String getProperty(java.util.Properties prop,
java.lang.String key,
java.lang.String defaultValue)
prop - the properties objectkey - the keydefaultValue - the default value
protected DataStoreException convert(java.lang.String cause,
java.lang.Exception e)
cause - the messagee - the root cause
public void updateModifiedDateOnAccess(long before)
updateModifiedDateOnAccess in interface DataStorebefore - - 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 void close()
close in interface DataStoreprotected void usesIdentifier(DataIdentifier identifier)
public void clearInUse()
clearInUse in interface DataStore
protected java.security.MessageDigest getDigest()
throws DataStoreException
DataStoreException
protected ConnectionRecoveryManager getConnection()
throws DataStoreException
DataStoreException
protected void putBack(ConnectionRecoveryManager conn)
throws DataStoreException
DataStoreExceptionpublic int getMaxConnections()
public void setMaxConnections(int maxConnections)
maxConnections - the new value
public ConnectionRecoveryManager createNewConnection()
throws javax.jcr.RepositoryException
javax.jcr.RepositoryExceptionpublic 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 value
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||