|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.jackrabbit.core.state.AbstractPersistenceManager org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager
SimpleDbPersistenceManager
is a generic JDBC-based
PersistenceManager
for Jackrabbit that persists
ItemState
and NodeReferences
objects using a
simple custom binary serialization format (see Serializer
) and a
very basic non-normalized database schema (in essence tables with one 'key'
and one 'data' column).
driver
: the FQN name of the JDBC driver classurl
: the database url of the form jdbc:subprotocol:subname
user
: the database userpassword
: the user's passwordschema
: type of schema to be used
(e.g. mysql
, mssql
, etc.); schemaObjectPrefix
: prefix to be prepended to schema objectsexternalBLOBs
: if true
(the default) BINARY
values (BLOBs) are stored in the local file system;
if false
BLOBs are stored in the databasegetClass().getResourceAsStream(schema + ".ddl")
.
Every line in the specified .ddl file is executed separatly by calling
java.sql.Statement.execute(String)
where every occurence of the
the string "${schemaObjectPrefix}"
has been replaced with the
value of the property schemaObjectPrefix
.
The following is a fragment from a sample configuration using MySQL:
<PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager"> <param name="driver" value="com.mysql.jdbc.Driver"/> <param name="url" value="jdbc:mysql:///test"/> <param name="schema" value="mysql"/> <param name="schemaObjectPrefix" value="${wsp.name}_"/> <param name="externalBLOBs" value="false"/> </PersistenceManager>The following is a fragment from a sample configuration using Daffodil One$DB Embedded:
<PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager"> <param name="driver" value="in.co.daffodil.db.jdbc.DaffodilDBDriver"/> <param name="url" value="jdbc:daffodilDB_embedded:${wsp.name};path=${wsp.home}/../../databases;create=true"/> <param name="user" value="daffodil"/> <param name="password" value="daffodil"/> <param name="schema" value="daffodil"/> <param name="schemaObjectPrefix" value="${wsp.name}_"/> <param name="externalBLOBs" value="false"/> </PersistenceManager>The following is a fragment from a sample configuration using DB2:
<PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager"> <param name="driver" value="com.ibm.db2.jcc.DB2Driver"/> <param name="url" value="jdbc:db2:test"/> <param name="schema" value="db2"/> <param name="schemaObjectPrefix" value="${wsp.name}_"/> <param name="externalBLOBs" value="false"/> </PersistenceManager>The following is a fragment from a sample configuration using MSSQL:
<PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager"> <param name="driver" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/> <param name="url" value="jdbc:microsoft:sqlserver://localhost:1433;;DatabaseName=test;SelectMethod=Cursor;"/> <param name="schema" value="mssql"/> <param name="user" value="sa"/> <param name="password" value=""/> <param name="schemaObjectPrefix" value="${wsp.name}_"/> <param name="externalBLOBs" value="false"/> </PersistenceManager>The following is a fragment from a sample configuration using PostgreSQL:
<PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager"> <param name="driver" value="org.postgresql.Driver"/> <param name="url" value="jdbc:postgresql://localhost/test"/> <param name="schema" value="postgresql"/> <param name="user" value="postgres"/> <param name="password" value="postgres"/> <param name="schemaObjectPrefix" value="${wsp.name}_"/> <param name="externalBLOBs" value="false"/> </PersistenceManager>See also
DerbyPersistenceManager
.
Constructor Summary | |
SimpleDbPersistenceManager()
Creates a new SimpleDbPersistenceManager instance. |
Method Summary | |
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. The consistency of the persistent storage is guaranteed and all acquired resources are released. It is an error to invoke any methods on a closed persistence manager, and implementations are free to enforce this constraint by throwing IllegalStateExceptions in such cases. 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. |
protected void |
closeResultSet(ResultSet rs)
|
protected void |
closeStatement(Statement stmt)
|
protected void |
closeStream(InputStream in)
|
void |
destroy(NodeReferences refs)
Destroy a node references object. Subclass responsibility. |
void |
destroy(NodeState state)
Destroy a node state. Subclass responsibility. |
void |
destroy(PropertyState state)
Destroy a property state. Subclass responsibility. |
boolean |
exists(NodeId id)
Checks whether the identified node exists. |
boolean |
exists(NodeReferencesId targetId)
Checks whether references of the identified target node exist. |
boolean |
exists(PropertyId id)
Checks whether the identified property exists. |
String |
getDriver()
|
String |
getPassword()
|
String |
getSchema()
|
String |
getSchemaObjectPrefix()
|
String |
getUrl()
|
String |
getUser()
|
void |
init(PMContext context)
Initializes the persistence manager. The persistence manager is permanently bound to the given context, and any required external resources are acquired. 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. |
boolean |
isExternalBLOBs()
|
NodeState |
load(NodeId id)
Load the persistent members of a node state. |
NodeReferences |
load(NodeReferencesId targetId)
Load the persistent members of a node references object. |
PropertyState |
load(PropertyId id)
Load the persistent members of a property state. |
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 void |
resetStatement(PreparedStatement stmt)
Resets the given PreparedStatement by clearing the parameters
and warnings contained. |
void |
setDriver(String driver)
|
void |
setExternalBLOBs(boolean externalBLOBs)
|
void |
setExternalBLOBs(String externalBLOBs)
|
void |
setPassword(String password)
|
void |
setSchema(String schema)
|
void |
setSchemaObjectPrefix(String schemaObjectPrefix)
|
void |
setUrl(String url)
|
void |
setUser(String user)
|
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. Properly implemented, this method should ensure that changes are either written completely to the underlying persistence layer, or not at all. Atomically saves the given set of changes. |
void |
store(NodeReferences refs)
Store a references object. Subclass responsibility. This method uses shared PreparedStatement s which must
be executed strictly sequentially. |
void |
store(NodeState state)
Store a node state. Subclass responsibility. This method uses shared PreparedStatement s which must
be executed strictly sequentially. |
void |
store(PropertyState state)
Store a property state. Subclass responsibility. This method uses shared PreparedStatement s which must
be executed strictly sequentially. |
Methods inherited from class org.apache.jackrabbit.core.state.AbstractPersistenceManager |
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 driver
protected String url
protected String user
protected String password
protected String schema
protected String schemaObjectPrefix
protected boolean externalBLOBs
protected static final int INITIAL_BUFFER_SIZE
protected Connection con
protected PreparedStatement nodeStateInsert
protected PreparedStatement nodeStateUpdate
protected PreparedStatement nodeStateSelect
protected PreparedStatement nodeStateSelectExist
protected PreparedStatement nodeStateDelete
protected PreparedStatement propertyStateInsert
protected PreparedStatement propertyStateUpdate
protected PreparedStatement propertyStateSelect
protected PreparedStatement propertyStateSelectExist
protected PreparedStatement propertyStateDelete
protected PreparedStatement nodeReferenceInsert
protected PreparedStatement nodeReferenceUpdate
protected PreparedStatement nodeReferenceSelect
protected PreparedStatement nodeReferenceSelectExist
protected PreparedStatement nodeReferenceDelete
protected PreparedStatement blobInsert
protected PreparedStatement blobUpdate
protected PreparedStatement blobSelect
protected PreparedStatement blobSelectExist
protected PreparedStatement blobDelete
protected FileSystem blobFS
externalBLOBs==true
)
protected BLOBStore blobStore
externalBLOBs==true
)
Constructor Detail |
public SimpleDbPersistenceManager()
SimpleDbPersistenceManager
instance.
Method Detail |
public String getUrl()
public void setUrl(String url)
public String getUser()
public void setUser(String user)
public String getPassword()
public void setPassword(String password)
public String getDriver()
public void setDriver(String driver)
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 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 intialization 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
ItemStateException
public 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 load(NodeReferencesId targetId) throws NoSuchItemStateException, ItemStateException
targetId
- reference target node id
ItemStateException
- if another error occurs
NoSuchItemStateException
- if the target node does not existpublic 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 exists(NodeReferencesId targetId) throws ItemStateException
targetId
- target node id
true
if the references exist,
false
otherwise
ItemStateException
- on persistence manager errorsprotected 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 closeStream(InputStream in)
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 occurs
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |