public class BundleDbPersistenceManager extends AbstractBundlePersistenceManager implements DatabaseAware
NodePropBundle
s
in a database.
Configuration:
bundleCacheSize
" value="8"/>
consistencyCheck
" value="false"/>
consistencyFix
" value="false"/>
minBlobSize
" value="4096"/>
driver
" value=""/>
url
" value=""/>
user
" value=""/>
password
" value=""/>
databaseType
" value=""/>
schemaObjectPrefix
" value=""/>
errorHandling
" value=""/>
blockOnConnectionLoss
" value="false"/>
schemaCheckEnabled
" value="true"/>
Modifier and Type | Class and Description |
---|---|
protected static interface |
BundleDbPersistenceManager.CloseableBLOBStore
Helper interface for closeable stores
|
protected class |
BundleDbPersistenceManager.DbBlobStore
Implementation of a blob store that stores the data inside the database
|
protected class |
BundleDbPersistenceManager.FSBlobStore
own implementation of the filesystem blob store that uses a different
blob-id scheme.
|
Modifier and Type | Field and Description |
---|---|
protected BundleBinding |
binding
the bundle binding
|
protected BundleDbPersistenceManager.CloseableBLOBStore |
blobStore
file system where BLOB data is stored
|
protected boolean |
blockOnConnectionLoss
indicates whether to block if the database connection is lost
|
protected String |
bundleDeleteSQL |
protected String |
bundleInsertSQL |
protected String |
bundleSelectAllBundlesFromSQL |
protected String |
bundleSelectAllBundlesSQL |
protected String |
bundleSelectAllIdsFromSQL |
protected String |
bundleSelectAllIdsSQL |
protected String |
bundleSelectSQL |
protected String |
bundleUpdateSQL |
protected ConnectionHelper |
conHelper
the
ConnectionHelper set in the init(PMContext) method |
protected boolean |
consistencyCheck
flag indicating if a consistency check should be issued during startup
|
protected boolean |
consistencyFix
flag indicating if the consistency check should attempt to fix issues
|
protected String |
databaseType
the database type
|
protected String |
dataSourceName
the logical name of the data source to use
|
protected String |
driver
the jdbc driver name
|
protected ErrorHandling |
errorHandling
flag for error handling
|
protected boolean |
externalBLOBs
indicates if uses (filesystem) blob store
|
protected static int |
INITIAL_BUFFER_SIZE
initial size of buffer used to serialize objects
|
protected boolean |
initialized
flag indicating if this manager was initialized
|
protected String |
nodeReferenceDeleteSQL |
protected String |
nodeReferenceInsertSQL |
protected String |
nodeReferenceSelectSQL |
protected String |
nodeReferenceUpdateSQL |
protected String |
password
the jdbc password
|
protected String |
schemaObjectPrefix
the prefix for the database objects
|
static int |
SM_BINARY_KEYS
storage model modifier: binary keys
|
static int |
SM_LONGLONG_KEYS
storage model modifier: longlong keys
|
protected String |
url
the jdbc url string
|
protected String |
user
the jdbc user
|
context, NODEFILENAME, NODEREFSFILENAME, RES_NAME_INDEX, RES_NS_INDEX
ACCESS_INTERVAL
Constructor and Description |
---|
BundleDbPersistenceManager() |
Modifier and Type | Method and Description |
---|---|
protected void |
buildSQLStatements()
Initializes the SQL strings.
|
void |
close()
Closes the persistence manager.
|
protected BundleDbPersistenceManager.CloseableBLOBStore |
createBlobStore()
Creates a suitable blobstore
|
protected CheckSchemaOperation |
createCheckSchemaOperation()
This method is called from
init(PMContext) after the
createConnectionHelper(DataSource) method, and returns a default CheckSchemaOperation . |
protected ConnectionHelper |
createConnectionHelper(DataSource dataSrc)
This method is called from the
init(PMContext) method of this class and returns a
ConnectionHelper instance which is assigned to the conHelper field. |
protected BundleDbPersistenceManager.CloseableBLOBStore |
createDBBlobStore(PMContext context)
Creates a blob store that uses the database.
|
protected DbNameIndex |
createDbNameIndex()
Returns a new instance of a DbNameIndex.
|
protected BundleDbPersistenceManager.CloseableBLOBStore |
createLocalFSBlobStore(PMContext context)
Creates a blob store that is based on a local fs.
|
protected Object[] |
createParams(NodeId id,
Object p,
boolean before)
Creates a parameter array for an SQL statement that needs
(i) a node identifier, and (2) another parameter.
|
void |
destroy(NodeReferences refs)
Deletes the node references from the underlying system.
|
protected void |
destroyBundle(NodePropBundle bundle)
Deletes the bundle from the underlying system.
|
boolean |
existsReferencesTo(NodeId targetId)
Checks whether references of the identified target node exist.
|
List<NodeId> |
getAllNodeIds(NodeId bigger,
int maxCount)
Get all node ids.
|
Map<NodeId,NodeInfo> |
getAllNodeInfos(NodeId bigger,
int maxCount)
Get all
NodeInfo s. |
protected BLOBStore |
getBlobStore()
Returns the BLOB store used by this persistence manager.
|
String |
getBlockOnConnectionLoss() |
String |
getConsistencyCheck()
Checks if consistency check is enabled.
|
String |
getConsistencyFix()
Checks if consistency fix is enabled.
|
String |
getDatabaseType()
Returns the configured database type name.
|
String |
getDataSourceName() |
String |
getDriver()
Returns the class name of the JDBC driver.
|
String |
getErrorHandling()
Returns the error handling configuration of this manager
|
protected Object[] |
getKey(NodeId id)
Constructs a parameter list for a PreparedStatement
for the given node identifier.
|
String |
getMinBlobSize()
Returns the minimum blob size in bytes.
|
StringIndex |
getNameIndex()
Returns the local name index
|
String |
getPassword()
Returns the configured password that is used to establish JDBC connections.
|
String |
getSchema()
Deprecated.
This method is deprecated;
getDatabaseType should be used instead. |
String |
getSchemaObjectPrefix()
Returns the configured schema object prefix.
|
int |
getStorageModel()
returns the storage model
|
String |
getUrl()
Returns the configured JDBC connection url.
|
String |
getUser()
Returns the configured user that is used to establish JDBC connections.
|
void |
init(PMContext context)
Initializes the persistence manager.
|
boolean |
isExternalBLOBs()
Returns if uses external (filesystem) blob store.
|
boolean |
isSchemaCheckEnabled() |
protected NodePropBundle |
loadBundle(NodeId id)
Loads a bundle from the underlying system.
|
NodeReferences |
loadReferencesTo(NodeId targetId)
Load the persisted references to the node with the given identifier.
|
void |
setBlockOnConnectionLoss(String block) |
void |
setConnectionFactory(ConnectionFactory connectionFactory) |
void |
setConsistencyCheck(String consistencyCheck)
Defines if a consistency check is to be performed on initialization.
|
void |
setConsistencyFix(String consistencyFix)
Defines if the consistency check should attempt to fix issues that
it finds.
|
void |
setDatabaseType(String databaseType)
Sets the database type.
|
void |
setDataSourceName(String dataSourceName) |
void |
setDriver(String driver)
Sets the class name of the JDBC driver.
|
void |
setErrorHandling(String errorHandling)
Sets the error handling behaviour of this manager.
|
void |
setExternalBLOBs(boolean externalBLOBs)
Sets the flag for external (filesystem) blob store usage.
|
void |
setMinBlobSize(String minBlobSize)
Sets the minimum blob size.
|
void |
setPassword(String password)
Sets the password that will be used to establish JDBC connections.
|
void |
setSchema(String databaseType)
Deprecated.
This method is deprecated;
setDatabaseType should be used instead. |
void |
setSchemaCheckEnabled(boolean enabled) |
void |
setSchemaObjectPrefix(String schemaObjectPrefix)
Sets the schema object prefix.
|
void |
setUrl(String url)
Sets the JDBC connection URL.
|
void |
setUser(String user)
Sets the user name that will be used to establish JDBC connections.
|
void |
store(ChangeLog changeLog)
Right now, this iterates over all items in the changelog and
calls the individual methods that handle single item states
or node references objects.
|
void |
store(NodeReferences refs)
Stores a node references to the underlying system.
|
protected void |
storeBundle(NodePropBundle bundle)
Stores a bundle to the underlying system.
|
String |
toString() |
boolean |
useDbBlobStore()
Returns
true if the blobs are stored in the DB. |
boolean |
useLocalFsBlobStore()
Returns
true if the blobs are stored in the local fs. |
buildBlobFilePath, buildNodeFilePath, buildNodeFolderPath, buildNodeReferencesFilePath, buildPropFilePath, cacheAccessed, check, checkConsistency, createNew, createNew, disposeCache, evictBundle, exists, exists, getBundleCacheSize, getNsIndex, load, load, onExternalUpdate, setBundleCacheSize, setEventChannel
public static final int SM_BINARY_KEYS
public static final int SM_LONGLONG_KEYS
protected boolean initialized
protected String driver
protected String url
protected String user
protected String password
protected String databaseType
protected String dataSourceName
protected ConnectionHelper conHelper
ConnectionHelper
set in the init(PMContext)
methodprotected String schemaObjectPrefix
protected boolean consistencyCheck
protected boolean consistencyFix
protected static final int INITIAL_BUFFER_SIZE
protected boolean externalBLOBs
protected boolean blockOnConnectionLoss
protected String bundleInsertSQL
protected String bundleUpdateSQL
protected String bundleSelectSQL
protected String bundleDeleteSQL
protected String bundleSelectAllIdsFromSQL
protected String bundleSelectAllIdsSQL
protected String bundleSelectAllBundlesFromSQL
protected String bundleSelectAllBundlesSQL
protected String nodeReferenceInsertSQL
protected String nodeReferenceUpdateSQL
protected String nodeReferenceSelectSQL
protected String nodeReferenceDeleteSQL
protected BundleDbPersistenceManager.CloseableBLOBStore blobStore
protected ErrorHandling errorHandling
protected BundleBinding binding
public void setConnectionFactory(ConnectionFactory connectionFactory)
setConnectionFactory
in interface DatabaseAware
public String getUrl()
public void setUrl(String url)
url
- the url to set.public String getUser()
public void setUser(String user)
user
- the user name.public String getPassword()
public void setPassword(String password)
password
- the password for the connectionpublic String getDriver()
public void setDriver(String driver)
init
in order to assure the existence.
If no driver is specified, the default driver for the database is used.driver
- the class name of the driverpublic String getSchemaObjectPrefix()
public void setSchemaObjectPrefix(String schemaObjectPrefix)
schemaObjectPrefix
- the prefix for schema objects.public String getSchema()
getDatabaseType
should be used instead.public String getDatabaseType()
public void setSchema(String databaseType)
setDatabaseType
should be used instead.databaseType
- database type namepublic void setDatabaseType(String databaseType)
databaseType
- database type namepublic String getDataSourceName()
public void setDataSourceName(String dataSourceName)
public boolean isExternalBLOBs()
public void setExternalBLOBs(boolean externalBLOBs)
externalBLOBs
- a value of "true" indicates that an external blob
store is to be used.public String getConsistencyCheck()
true
if consistency check is enabled.public void setConsistencyCheck(String consistencyCheck)
consistencyCheck
- the consistency check flag.public String getConsistencyFix()
true
if consistency fix is enabled.public void setConsistencyFix(String consistencyFix)
consistencyFix
- the consistency fix flag.public String getMinBlobSize()
public void setMinBlobSize(String minBlobSize)
minBlobSize
- the minimum blob size in bytes.public void setErrorHandling(String errorHandling)
ErrorHandling
for details about the flags.errorHandling
- the error handling flagspublic String getErrorHandling()
public void setBlockOnConnectionLoss(String block)
public String getBlockOnConnectionLoss()
public boolean useDbBlobStore()
true
if the blobs are stored in the DB.true
if the blobs are stored in the DB.public boolean useLocalFsBlobStore()
true
if the blobs are stored in the local fs.true
if the blobs are stored in the local fs.public final boolean isSchemaCheckEnabled()
public final void setSchemaCheckEnabled(boolean enabled)
enabled
- set whether the schema check is enabledpublic void store(ChangeLog changeLog) throws ItemStateException
ConnectionHelper.RetryManager
.store
in interface PersistenceManager
store
in class AbstractBundlePersistenceManager
changeLog
- change log containing states that were changedItemStateException
- if the changes could not be savedpublic void init(PMContext context) throws Exception
An appropriate exception is thrown if the persistence manager initialization fails for whatever reason. In this case the state of the persistence manager is undefined and the instance should be discarded. Initializes the internal structures of this abstract persistence manager.
init
in interface PersistenceManager
init
in class AbstractBundlePersistenceManager
context
- persistence manager contextException
- if the persistence manager initialization failedprotected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
init(PMContext)
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 CheckSchemaOperation createCheckSchemaOperation()
init(PMContext)
after the
createConnectionHelper(DataSource)
method, and returns a default CheckSchemaOperation
.
Subclasses can overrride this implementation to get a customized implementation.CheckSchemaOperation
instanceprotected BLOBStore getBlobStore()
getBlobStore
in class AbstractBundlePersistenceManager
protected BundleDbPersistenceManager.CloseableBLOBStore createBlobStore() throws Exception
Exception
- if an unspecified error occurspublic StringIndex getNameIndex()
getNameIndex
in class AbstractBundlePersistenceManager
IllegalStateException
- if an error occurs.protected DbNameIndex createDbNameIndex() throws SQLException
SQLException
- if an SQL error occurs.public int getStorageModel()
protected BundleDbPersistenceManager.CloseableBLOBStore createLocalFSBlobStore(PMContext context) throws Exception
useLocalFsBlobStore()
returns true
.context
- the persistence manager contextException
- if an error occurs.protected BundleDbPersistenceManager.CloseableBLOBStore createDBBlobStore(PMContext context) throws Exception
useDbBlobStore()
returns true
.context
- the persistence manager contextException
- if an error occurs.public void close() throws Exception
An appropriate exception is thrown if the persistence manager could not be closed properly. In this case the state of the persistence manager is undefined and the instance should be discarded. Closes the persistence manager, release acquired resources.
close
in interface PersistenceManager
close
in class AbstractBundlePersistenceManager
Exception
- if the persistence manager failed to close properlyprotected Object[] getKey(NodeId id)
id
- the node idprotected Object[] createParams(NodeId id, Object p, boolean before)
id
- the node idp
- the other parameterbefore
- whether the other parameter should be before the uuid parameterpublic List<NodeId> getAllNodeIds(NodeId bigger, int maxCount) throws ItemStateException, RepositoryException
getAllNodeIds
in interface IterablePersistenceManager
bigger
- the lower limit, or null for no limit.maxCount
- the maximum number of node ids to return, or 0 for no limit.ItemStateException
- if an error while loading occurs.RepositoryException
- if a repository exception occurs.public Map<NodeId,NodeInfo> getAllNodeInfos(NodeId bigger, int maxCount) throws ItemStateException
NodeInfo
s.
A typical application will call this method multiple time, where 'after'
is the last row read previously. The maxCount parameter defines the maximum number of
node ids returned, 0 meaning no limit. The order of the node ids is specific for the
given persistence manager. Items that are added concurrently may not be included.getAllNodeInfos
in interface IterablePersistenceManager
getAllNodeInfos
in class AbstractBundlePersistenceManager
bigger
- the lower limit, or null for no limit.maxCount
- the maximum number of node infos to return, or 0 for no limit.ItemStateException
- if an error while loading occurs.protected NodePropBundle loadBundle(NodeId id) throws ItemStateException
loadBundle
in class AbstractBundlePersistenceManager
id
- the node id of the bundlenull
if the bundle does not
exist.ItemStateException
- if an error while loading occurs.protected void storeBundle(NodePropBundle bundle) throws ItemStateException
storeBundle
in class AbstractBundlePersistenceManager
bundle
- the bundle to storeItemStateException
- if an error while storing occurs.protected void destroyBundle(NodePropBundle bundle) throws ItemStateException
destroyBundle
in class AbstractBundlePersistenceManager
bundle
- the bundle to destroyItemStateException
- if an error while destroying occurs.public NodeReferences loadReferencesTo(NodeId targetId) throws NoSuchItemStateException, ItemStateException
loadReferencesTo
in interface PersistenceManager
targetId
- reference target node idNoSuchItemStateException
- if the target node does not existItemStateException
- if another error occurspublic void store(NodeReferences refs) throws ItemStateException
PreparedStatements
, which must
be used strictly sequentially. Because this method synchronizes on the
persistence manager instance, there is no need to synchronize on the
shared statement. If the method would not be synchronized, the shared
statement must be synchronized.store
in class AbstractBundlePersistenceManager
refs
- the node references to store.ItemStateException
- if an error while storing occurs.public void destroy(NodeReferences refs) throws ItemStateException
destroy
in class AbstractBundlePersistenceManager
refs
- the node references to destroy.ItemStateException
- if an error while destroying occurs.public boolean existsReferencesTo(NodeId targetId) throws ItemStateException
existsReferencesTo
in interface PersistenceManager
targetId
- target node idtrue
if the references exist,
false
otherwiseItemStateException
- on persistence manager errorsprotected void buildSQLStatements()
Copyright © 2004–2022 The Apache Software Foundation. All rights reserved.