|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.jackrabbit.core.persistence.AbstractPersistenceManager
org.apache.jackrabbit.core.persistence.db.DatabasePersistenceManager
public abstract class DatabasePersistenceManager
Abstract base class for database persistence managers. This class
contains common functionality for database persistence manager subclasses
that normally differ only in the way the database connection is acquired.
Subclasses should override the getConnection()
method to return
the configured database connection.
See the SimpleDbPersistenceManager
for a detailed description
of the available configuration options and database behaviour.
Constructor Summary | |
---|---|
DatabasePersistenceManager()
Creates a new DatabasePersistenceManager instance. |
Method Summary | |
---|---|
protected void |
buildSQLStatements()
Builds the SQL statements |
protected void |
checkSchema()
Checks if the required schema objects exist and creates them if they don't exist yet. |
void |
close()
Closes the persistence manager. |
protected void |
closeConnection(Connection connection)
Closes the given database connection. |
protected void |
closeResultSet(ResultSet rs)
|
protected void |
closeStatement(Statement stmt)
|
protected String |
createSchemaSql(String sql)
Replace wildcards and return the expanded SQL statement. |
void |
destroy(NodeReferences refs)
Destroy a node references object. |
void |
destroy(NodeState state)
Destroy a node state. |
void |
destroy(PropertyState state)
Destroy a property state. |
protected Statement |
executeStmt(String sql,
Object[] params)
Executes the given SQL statement with the specified parameters. |
boolean |
exists(NodeId id)
Checks whether the identified node exists. |
boolean |
exists(PropertyId id)
Checks whether the identified property exists. |
boolean |
existsReferencesTo(NodeId targetId)
Checks whether references of the identified target node exist. |
protected Connection |
getConnection()
Abstract factory method for creating a new database connection. |
String |
getSchema()
|
protected InputStream |
getSchemaDDL()
Returns an input stream to the schema DDL resource. |
String |
getSchemaObjectPrefix()
|
void |
init(PMContext context)
Initializes the persistence manager. |
protected void |
initConnection()
Initializes the database connection used by this persistence manager. |
protected void |
initPreparedStatements()
Initializes the map of prepared statements. |
boolean |
isExternalBLOBs()
|
boolean |
isSchemaCheckEnabled()
|
NodeState |
load(NodeId id)
Load the persistent members of a node state. |
PropertyState |
load(PropertyId id)
Load the persistent members of a property state. |
NodeReferences |
loadReferencesTo(NodeId targetId)
Load the persisted references to the node with the given identifier. |
protected void |
logException(String message,
SQLException se)
|
protected void |
prepareSchemaObjectPrefix()
Makes sure that schemaObjectPrefix does only consist of
characters that are allowed in names on the target database. |
protected boolean |
reestablishConnection()
Re-establishes the database connection. |
protected void |
resetStatement(PreparedStatement stmt)
Resets the given PreparedStatement by clearing the parameters
and warnings contained. |
void |
setExternalBLOBs(boolean externalBLOBs)
|
void |
setExternalBLOBs(String externalBLOBs)
|
void |
setSchema(String schema)
|
void |
setSchemaCheckEnabled(boolean enabled)
|
void |
setSchemaObjectPrefix(String schemaObjectPrefix)
|
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)
Store a references object. |
void |
store(NodeState state)
Store a node state. |
void |
store(PropertyState state)
Store a property state. |
Methods inherited from class org.apache.jackrabbit.core.persistence.AbstractPersistenceManager |
---|
checkConsistency, createNew, createNew |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final String SCHEMA_OBJECT_PREFIX_VARIABLE
protected boolean initialized
protected String schema
protected String schemaObjectPrefix
protected boolean externalBLOBs
protected static final int INITIAL_BUFFER_SIZE
protected Connection con
protected boolean autoReconnect
protected static final int SLEEP_BEFORE_RECONNECT
protected String nodeStateInsertSQL
protected String nodeStateUpdateSQL
protected String nodeStateSelectSQL
protected String nodeStateSelectExistSQL
protected String nodeStateDeleteSQL
protected String propertyStateInsertSQL
protected String propertyStateUpdateSQL
protected String propertyStateSelectSQL
protected String propertyStateSelectExistSQL
protected String propertyStateDeleteSQL
protected String nodeReferenceInsertSQL
protected String nodeReferenceUpdateSQL
protected String nodeReferenceSelectSQL
protected String nodeReferenceSelectExistSQL
protected String nodeReferenceDeleteSQL
protected String blobInsertSQL
protected String blobUpdateSQL
protected String blobSelectSQL
protected String blobSelectExistSQL
protected String blobDeleteSQL
protected FileSystem blobFS
externalBLOBs==true
)
protected BLOBStore blobStore
externalBLOBs==true
)
Constructor Detail |
---|
public DatabasePersistenceManager()
DatabasePersistenceManager
instance.
Method Detail |
---|
public String getSchemaObjectPrefix()
public void setSchemaObjectPrefix(String schemaObjectPrefix)
public String getSchema()
public void setSchema(String schema)
public boolean isExternalBLOBs()
public void setExternalBLOBs(boolean externalBLOBs)
public void setExternalBLOBs(String externalBLOBs)
public final boolean isSchemaCheckEnabled()
public final void setSchemaCheckEnabled(boolean enabled)
enabled
- set whether the schema check is enabledpublic 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.
context
- persistence manager context
Exception
- if the persistence manager initialization failedpublic 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.
Exception
- if the persistence manager failed to close properlypublic void store(ChangeLog changeLog) throws ItemStateException
store
in interface PersistenceManager
store
in class AbstractPersistenceManager
changeLog
- change log containing states that were changed
ItemStateException
- if the changes could not be savedpublic NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException
id
- node id
NoSuchItemStateException
- if the node state does not exist
ItemStateException
- if another error occurspublic PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException
id
- property id
NoSuchItemStateException
- if the property state does not exist
ItemStateException
- if another error occurspublic void store(NodeState state) throws ItemStateException
PreparedStatement
s which must
be executed 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 sychronized the shared
statements would have to be synchronized.
store
in class AbstractPersistenceManager
state
- node state to store
ItemStateException
- if an error occurspublic void store(PropertyState state) throws ItemStateException
PreparedStatement
s which must
be executed 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 sychronized the shared
statements would have to be synchronized.
store
in class AbstractPersistenceManager
state
- property state to store
ItemStateException
- if an error occurspublic void destroy(NodeState state) throws ItemStateException
destroy
in class AbstractPersistenceManager
state
- node state to destroy
ItemStateException
- if an error occurspublic void destroy(PropertyState state) throws ItemStateException
destroy
in class AbstractPersistenceManager
state
- property state to destroy
ItemStateException
- if an error occurspublic NodeReferences loadReferencesTo(NodeId targetId) throws NoSuchItemStateException, ItemStateException
targetId
- reference target node id
NoSuchItemStateException
- if the target node does not exist
ItemStateException
- if another error occurspublic void store(NodeReferences refs) throws ItemStateException
PreparedStatement
s which must
be executed 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 sychronized the shared
statements would have to be synchronized.
store
in class AbstractPersistenceManager
refs
- references object to store
ItemStateException
- if an error occurspublic void destroy(NodeReferences refs) throws ItemStateException
destroy
in class AbstractPersistenceManager
refs
- node references object to destroy
ItemStateException
- if an error occurspublic boolean exists(NodeId id) throws ItemStateException
id
- node id
true
if the node exists,
false
otherwise
ItemStateException
- on persistence manager errorspublic boolean exists(PropertyId id) throws ItemStateException
id
- property id
true
if the property exists,
false
otherwise
ItemStateException
- on persistence manager errorspublic boolean existsReferencesTo(NodeId targetId) throws ItemStateException
targetId
- target node id
true
if the references exist,
false
otherwise
ItemStateException
- on persistence manager errorsprotected void initConnection() throws Exception
Subclasses should normally override the getConnection()
method instead of this one. The default implementation calls
getConnection()
to get the database connection and disables
the autocommit feature.
Exception
- if an error occursprotected Connection getConnection() throws Exception
init(PMContext)
when the persistence
manager is started. The returned connection should come with the default
JDBC settings, as the init(PMContext)
method will explicitly
set the autoCommit
and other properties as needed.
Note that the returned database connection is kept during the entire
lifetime of the persistence manager, after which it is closed by
close()
using the closeConnection(Connection)
method.
Exception
- if an error occursprotected void closeConnection(Connection connection) throws Exception
close()
to close the connection acquired using
getConnection()
when the persistence manager was started.
The default implementation just calls the Connection.close()
method of the given connection, but subclasses can override this
method to provide more extensive database and connection cleanup.
connection
- database connection
Exception
- if an error occursprotected boolean reestablishConnection()
store(ChangeLog)
and executeStmt(String, Object[])
after a SQLException
had been encountered.
protected Statement executeStmt(String sql, Object[] params) throws SQLException
SQLException
is encountered and
autoReconnect==true
one attempt is made to re-establish
the database connection and re-execute the statement.
sql
- statement to executeparams
- parameters to set
Statement
object that had been executed
SQLException
- if an error occursprotected void resetStatement(PreparedStatement stmt)
PreparedStatement
by clearing the parameters
and warnings contained.
NOTE: This method MUST be called in a synchronized context as neither
this method nor the PreparedStatement
instance on which it
operates are thread safe.
stmt
- The PreparedStatement
to reset. If
null
this method does nothing.protected void closeResultSet(ResultSet rs)
protected void closeStatement(Statement stmt)
protected void logException(String message, SQLException se)
protected void prepareSchemaObjectPrefix() throws Exception
schemaObjectPrefix
does only consist of
characters that are allowed in names on the target database. Illegal
characters will be escaped as necessary.
Exception
- if an error occursprotected void checkSchema() throws Exception
Exception
- if an error occursprotected String createSchemaSql(String sql)
sql
- The SQL with embedded wildcards.
protected InputStream getSchemaDDL()
protected void buildSQLStatements()
protected void initPreparedStatements() throws SQLException
SQLException
- if an error occurs
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |