Nuxeo ECM Projects 5.4.3-SNAPSHOT

org.nuxeo.ecm.core.storage.sql.jdbc
Class JDBCMapper

java.lang.Object
  extended by org.nuxeo.ecm.core.storage.sql.jdbc.JDBCConnection
      extended by org.nuxeo.ecm.core.storage.sql.jdbc.JDBCRowMapper
          extended by org.nuxeo.ecm.core.storage.sql.jdbc.JDBCMapper
All Implemented Interfaces:
XAResource, Mapper, RowMapper

public class JDBCMapper
extends JDBCRowMapper
implements Mapper

A JDBCMapper maps objects to and from a JDBC database. It is specific to a given database connection, as it computes statements.

The JDBCMapper does the mapping according to the policy defined by a Model, and generates SQL statements recorded in the SQLInfo.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.storage.sql.Mapper
Mapper.Identification
 
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.storage.sql.RowMapper
RowMapper.CopyResult, RowMapper.IdWithTypes, RowMapper.NodeInfo, RowMapper.RowBatch, RowMapper.RowUpdate
 
Field Summary
static String TEST_UPGRADE
           
static String TEST_UPGRADE_LAST_CONTRIBUTOR
           
static String TEST_UPGRADE_LOCKS
           
static String TEST_UPGRADE_VERSIONS
           
static Map<String,Serializable> testProps
           
 
Fields inherited from class org.nuxeo.ecm.core.storage.sql.jdbc.JDBCRowMapper
DEBUG_MAX_TREE, UPDATE_BATCH_SIZE
 
Fields inherited from class org.nuxeo.ecm.core.storage.sql.jdbc.JDBCConnection
connection, logger
 
Fields inherited from interface org.nuxeo.ecm.core.storage.sql.Mapper
CLOSE, GET_IDENTIFICATION
 
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
Constructor Summary
JDBCMapper(Model model, Session.PathResolver pathResolver, SQLInfo sqlInfo, XADataSource xadatasource, ClusterNodeHandler clusterNodeHandler, JDBCConnectionPropagator connectionPropagator)
          Creates a new Mapper.
 
Method Summary
 void commit(Xid xid, boolean onePhase)
           
 void createClusterNode()
          Informs the cluster that this node exists.
 void createDatabase()
          Creates the necessary structures in the database.
 void end(Xid xid, int flags)
           
 void forget(Xid xid)
           
 Set<Serializable> getAncestorsIds(Collection<Serializable> ids)
          Gets the ids for all the ancestors of the given row ids.
 Invalidations getClusterInvalidations()
          Gets the invalidations from other cluster nodes.
 Lock getLock(Serializable id)
          Gets the lock state of a document.
 Serializable getRootId(Serializable repositoryId)
          Gets the root id for a given repository, if registered.
 int getTableSize(String tableName)
           
 int getTransactionTimeout()
           
 void insertClusterInvalidations(Invalidations invalidations)
          Inserts the invalidation rows for the other cluster nodes.
 boolean isSameRM(XAResource xares)
           
 void markReferencedBinaries(BinaryGarbageCollector gc)
          Marks the binaries referenced by this mapper with the referenced binary garbage collector.
 int prepare(Xid xid)
           
 PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, boolean countTotal)
          Makes a NXQL query to the database.
 IterableQueryResult queryAndFetch(String query, String queryType, QueryFilter queryFilter, Object... params)
          Makes a query to the database and returns an iterable (which must be closed when done).
 void rebuildReadAcls()
           
 Xid[] recover(int flag)
           
 void removeClusterNode()
          Removes this node from the cluster.
 Lock removeLock(Serializable id, String owner, boolean force)
          Removes a lock from a document.
 Lock setLock(Serializable id, Lock lock)
          Sets a lock on a document.
 void setRootId(Serializable repositoryId, Serializable id)
          Records the newly generated root id for a given repository.
 boolean setTransactionTimeout(int seconds)
           
 void start(Xid xid, int flags)
           
 void updateReadAcls()
           
 
Methods inherited from class org.nuxeo.ecm.core.storage.sql.jdbc.JDBCRowMapper
clearCache, close, copy, isClusterReconnecting, read, readCollectionRowArray, readSelectionRows, readSimpleRow, receiveInvalidations, remove, rollback, sendInvalidations, write
 
Methods inherited from class org.nuxeo.ecm.core.storage.sql.jdbc.JDBCConnection
getIdentification
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.nuxeo.ecm.core.storage.sql.Mapper
close, getIdentification
 
Methods inherited from interface org.nuxeo.ecm.core.storage.sql.RowMapper
clearCache, copy, isClusterReconnecting, read, readCollectionRowArray, readSelectionRows, readSimpleRow, receiveInvalidations, remove, rollback, sendInvalidations, write
 
Methods inherited from interface javax.transaction.xa.XAResource
rollback
 

Field Detail

testProps

public static Map<String,Serializable> testProps

TEST_UPGRADE

public static final String TEST_UPGRADE
See Also:
Constant Field Values

TEST_UPGRADE_VERSIONS

public static final String TEST_UPGRADE_VERSIONS
See Also:
Constant Field Values

TEST_UPGRADE_LAST_CONTRIBUTOR

public static final String TEST_UPGRADE_LAST_CONTRIBUTOR
See Also:
Constant Field Values

TEST_UPGRADE_LOCKS

public static final String TEST_UPGRADE_LOCKS
See Also:
Constant Field Values
Constructor Detail

JDBCMapper

public JDBCMapper(Model model,
                  Session.PathResolver pathResolver,
                  SQLInfo sqlInfo,
                  XADataSource xadatasource,
                  ClusterNodeHandler clusterNodeHandler,
                  JDBCConnectionPropagator connectionPropagator)
           throws StorageException
Creates a new Mapper.

Parameters:
model - the model
pathResolver - the path resolver (used for startswith queries)
sqlInfo - the sql info
xadatasource - the XA datasource to use to get connections
clusterNodeHandler - the cluster node handler
connectionPropagator - the connection propagator
Throws:
StorageException
Method Detail

getTableSize

public int getTableSize(String tableName)
Specified by:
getTableSize in interface Mapper

createDatabase

public void createDatabase()
                    throws StorageException
Description copied from interface: Mapper
Creates the necessary structures in the database.

Specified by:
createDatabase in interface Mapper
Throws:
StorageException

createClusterNode

public void createClusterNode()
                       throws StorageException
Description copied from interface: Mapper
Informs the cluster that this node exists.

Specified by:
createClusterNode in interface Mapper
Throws:
StorageException

removeClusterNode

public void removeClusterNode()
                       throws StorageException
Description copied from interface: Mapper
Removes this node from the cluster.

Specified by:
removeClusterNode in interface Mapper
Throws:
StorageException

insertClusterInvalidations

public void insertClusterInvalidations(Invalidations invalidations)
                                throws StorageException
Description copied from interface: Mapper
Inserts the invalidation rows for the other cluster nodes.

Specified by:
insertClusterInvalidations in interface Mapper
Throws:
StorageException

getClusterInvalidations

public Invalidations getClusterInvalidations()
                                      throws StorageException
Description copied from interface: Mapper
Gets the invalidations from other cluster nodes.

Specified by:
getClusterInvalidations in interface Mapper
Throws:
StorageException

getRootId

public Serializable getRootId(Serializable repositoryId)
                       throws StorageException
Description copied from interface: Mapper
Gets the root id for a given repository, if registered.

Specified by:
getRootId in interface Mapper
Parameters:
repositoryId - the repository id, usually 0
Returns:
the root id, or null if not found
Throws:
StorageException

setRootId

public void setRootId(Serializable repositoryId,
                      Serializable id)
               throws StorageException
Description copied from interface: Mapper
Records the newly generated root id for a given repository.

Specified by:
setRootId in interface Mapper
Parameters:
repositoryId - the repository id, usually 0
id - the root id
Throws:
StorageException

query

public PartialList<Serializable> query(String query,
                                       String queryType,
                                       QueryFilter queryFilter,
                                       boolean countTotal)
                                throws StorageException
Description copied from interface: Mapper
Makes a NXQL query to the database.

Specified by:
query in interface Mapper
Parameters:
query - the query
queryFilter - the query filter
countTotal - if true, count the total size without limit/offset
Returns:
the list of matching document ids
Throws:
StorageException

queryAndFetch

public IterableQueryResult queryAndFetch(String query,
                                         String queryType,
                                         QueryFilter queryFilter,
                                         Object... params)
                                  throws StorageException
Description copied from interface: Mapper
Makes a query to the database and returns an iterable (which must be closed when done).

Specified by:
queryAndFetch in interface Mapper
Parameters:
query - the query
queryType - the query type
queryFilter - the query filter
params - optional query-type-dependent parameters
Returns:
an iterable, which must be closed when done
Throws:
StorageException

getAncestorsIds

public Set<Serializable> getAncestorsIds(Collection<Serializable> ids)
                                  throws StorageException
Description copied from interface: Mapper
Gets the ids for all the ancestors of the given row ids.

Specified by:
getAncestorsIds in interface Mapper
Parameters:
ids - the ids
Returns:
the set of ancestor ids
Throws:
StorageException

updateReadAcls

public void updateReadAcls()
                    throws StorageException
Specified by:
updateReadAcls in interface Mapper
Throws:
StorageException

rebuildReadAcls

public void rebuildReadAcls()
                     throws StorageException
Specified by:
rebuildReadAcls in interface Mapper
Throws:
StorageException

getLock

public Lock getLock(Serializable id)
             throws StorageException
Description copied from interface: Mapper
Gets the lock state of a document.

If the document does not exist, null is returned.

Specified by:
getLock in interface Mapper
Parameters:
id - the document id
Returns:
the existing lock, or null when there is no lock
Throws:
StorageException

setLock

public Lock setLock(Serializable id,
                    Lock lock)
             throws StorageException
Description copied from interface: Mapper
Sets a lock on a document.

If the document is already locked, returns its existing lock status (there is no re-locking, Mapper.removeLock(java.io.Serializable, java.lang.String, boolean) must be called first).

Specified by:
setLock in interface Mapper
Parameters:
id - the document id
lock - the lock object to set
Returns:
null if locking succeeded, or the existing lock if locking failed, or a
Throws:
StorageException

removeLock

public Lock removeLock(Serializable id,
                       String owner,
                       boolean force)
                throws StorageException
Description copied from interface: Mapper
Removes a lock from a document.

The previous lock is returned.

If owner is null then the lock is unconditionally removed.

If owner is not null, it must match the existing lock owner for the lock to be removed. If it doesn't match, the returned lock will return true for Lock.getFailed().

Specified by:
removeLock in interface Mapper
Parameters:
id - the document id
force - true to just do the remove and not return the previous lock
Returns:
the previous lock
Throws:
StorageException

markReferencedBinaries

public void markReferencedBinaries(BinaryGarbageCollector gc)
                            throws StorageException
Description copied from interface: Mapper
Marks the binaries referenced by this mapper with the referenced binary garbage collector.

Specified by:
markReferencedBinaries in interface Mapper
Parameters:
gc - the binary garbage collector
Throws:
StorageException

start

public void start(Xid xid,
                  int flags)
           throws XAException
Specified by:
start in interface XAResource
Throws:
XAException

end

public void end(Xid xid,
                int flags)
         throws XAException
Specified by:
end in interface XAResource
Throws:
XAException

prepare

public int prepare(Xid xid)
            throws XAException
Specified by:
prepare in interface XAResource
Throws:
XAException

commit

public void commit(Xid xid,
                   boolean onePhase)
            throws XAException
Specified by:
commit in interface XAResource
Throws:
XAException

forget

public void forget(Xid xid)
            throws XAException
Specified by:
forget in interface XAResource
Throws:
XAException

recover

public Xid[] recover(int flag)
              throws XAException
Specified by:
recover in interface XAResource
Throws:
XAException

setTransactionTimeout

public boolean setTransactionTimeout(int seconds)
                              throws XAException
Specified by:
setTransactionTimeout in interface XAResource
Throws:
XAException

getTransactionTimeout

public int getTransactionTimeout()
                          throws XAException
Specified by:
getTransactionTimeout in interface XAResource
Throws:
XAException

isSameRM

public boolean isSameRM(XAResource xares)
                 throws XAException
Specified by:
isSameRM in interface XAResource
Throws:
XAException

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.