public class JDBCMapper extends JDBCRowMapper implements Mapper
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
.
Modifier and Type | Class and Description |
---|---|
protected static interface |
JDBCMapper.BiFunctionSQLException<T,U,R> |
protected class |
JDBCMapper.CursorResult |
Mapper.Identification
RowMapper.CopyResult, RowMapper.IdWithTypes, RowMapper.NodeInfo, RowMapper.RowBatch, RowMapper.RowUpdate
Modifier and Type | Field and Description |
---|---|
protected boolean |
clusteringEnabled |
protected static Map<String,JDBCMapper.CursorResult> |
cursorResults |
protected static String |
NOSCROLL_ID |
protected TableUpgrader |
tableUpgrader |
static String |
TEST_UPGRADE |
static String |
TEST_UPGRADE_LAST_CONTRIBUTOR |
static String |
TEST_UPGRADE_LOCKS |
static String |
TEST_UPGRADE_SYS_CHANGE_TOKEN |
static String |
TEST_UPGRADE_VERSIONS |
static Map<String,Serializable> |
testProps |
COLLECTION_DELETE_BEFORE_APPEND_PROP, DEBUG_MAX_TREE, UPDATE_BATCH_SIZE
connection, countExecutes, dialect, executeCount, logger, model, setClientInfo, sqlInfo, supportsBatchUpdates, xaresource
CLOSE, GET_IDENTIFICATION
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
Constructor and Description |
---|
JDBCMapper(Model model,
Session.PathResolver pathResolver,
SQLInfo sqlInfo,
ClusterInvalidator clusterInvalidator,
RepositoryImpl repository)
Creates a new Mapper.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkForTimedoutScroll() |
void |
commit(Xid xid,
boolean onePhase) |
protected String |
computeDistinctDocuments(String query,
boolean distinctDocuments) |
void |
connect(boolean noSharing) |
void |
createClusterNode(Serializable nodeId)
Informs the cluster that this node exists.
|
void |
createDatabase(String ddlMode)
Creates the necessary structures in the database.
|
protected void |
createTables(String ddlMode) |
protected ScrollResult |
defaultScroll(String query) |
protected void |
deleteClusterInvals(Serializable nodeId) |
void |
disconnect() |
void |
end(Xid xid,
int flags) |
protected QueryMaker |
findQueryMaker(String queryType) |
protected static Set<String> |
findTableNames(DatabaseMetaData metadata,
String schemaName)
Finds uppercase table names.
|
void |
forget(Xid xid) |
Set<Serializable> |
getAncestorsIds(Collection<Serializable> ids)
Gets the ids for all the ancestors of the given row ids.
|
protected Set<Serializable> |
getAncestorsIdsIterative(Collection<Serializable> ids)
Uses iterative parentid selection.
|
Invalidations |
getClusterInvalidations(Serializable nodeId)
Gets the invalidations from other cluster nodes.
|
int |
getClusterNodeIdType() |
Lock |
getLock(Serializable id)
Gets the lock state of a document.
|
Serializable |
getRootId(String repositoryId)
Gets the root id for a given repository, if registered.
|
protected String |
getTableName(String origName) |
int |
getTableSize(String tableName) |
int |
getTransactionTimeout() |
void |
insertClusterInvalidations(Serializable nodeId,
Invalidations invalidations)
Inserts the invalidation rows for the other cluster nodes.
|
boolean |
isConnected() |
boolean |
isSameRM(XAResource xares) |
protected static String |
join(Collection<String> strings,
char sep) |
void |
markReferencedBinaries()
Marks the binaries in use by passing them to the binary manager(s)'s GC mark() method.
|
int |
prepare(Xid xid) |
protected void |
prepareUserReadAcls(QueryFilter queryFilter) |
PartialList<Serializable> |
query(String query,
String queryType,
QueryFilter queryFilter,
boolean countTotal)
Makes a NXQL query to the database.
|
PartialList<Serializable> |
query(String query,
String queryType,
QueryFilter queryFilter,
long countUpTo)
Makes a NXQL query to the database.
|
IterableQueryResult |
queryAndFetch(String query,
String queryType,
QueryFilter queryFilter,
boolean distinctDocuments,
Object... params)
Makes a query to the database and returns an iterable (which must be closed when done).
|
PartialList<Map<String,Serializable>> |
queryProjection(String query,
String queryType,
QueryFilter queryFilter,
boolean distinctDocuments,
long countUpTo,
Object... params)
Makes a query to the database.
|
protected <T> PartialList<T> |
queryProjection(String query,
String queryType,
QueryFilter queryFilter,
long countUpTo,
JDBCMapper.BiFunctionSQLException<SQLInfo.SQLInfoSelect,ResultSet,T> extractor,
Object... params) |
void |
rebuildReadAcls() |
Xid[] |
recover(int flag) |
protected void |
registerCursor(String scrollId,
PreparedStatement ps,
ResultSet rs,
int batchSize,
int keepAliveSeconds) |
void |
removeClusterNode(Serializable nodeId)
Removes this node from the cluster.
|
Lock |
removeLock(Serializable id,
String owner,
boolean force)
Removes a lock from a document.
|
ScrollResult |
scroll(String scrollId)
Get the next batch of result, the
scrollId is part of the previous ScrollResult response. |
ScrollResult |
scroll(String query,
int batchSize,
int keepAliveSeconds)
Executes the given query and returns the first batch of results, next batch must be requested within the
keepAliveSeconds delay. |
protected ScrollResult |
scrollSearch(String query,
int batchSize,
int keepAliveSeconds) |
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.
|
int |
setToPreparedStatement(PreparedStatement ps,
int i,
Serializable object) |
boolean |
setTransactionTimeout(int seconds) |
void |
start(Xid xid,
int flags) |
protected static String |
systemToString(Object o) |
protected boolean |
unregisterCursor(String scrollId) |
void |
updateReadAcls() |
protected void |
upgradeTable(String tableKey,
List<Column> addedColumns,
String ddlMode,
SQLStatement.ListCollector ddlCollector) |
cleanupDeletedRows, clearCache, copy, copyHier, copyHierRecursive, copyRows, deleteRows, deleteRowsDirect, deleteRowsSoft, doSoftDeleteRows, generateNewId, getBinaryFulltext, getCacheSize, getChildrenIdsWithTypes, getChildrenNodeInfos, getCollectionIO, getDescendantsInfo, getDescendantsInfoIterative, getSelectRows, insertCollectionRows, insertSimpleRows, newIdArray, read, readCollectionArrays, readCollectionRowArray, readSelectionRows, readSelectionsIds, readSimpleRow, readSimpleRows, receiveInvalidations, remove, rollback, sendInvalidations, setToPreparedStatementIdArray, updateCollectionRows, updateSimpleRows, updateSimpleRowWithValues, write, writeCreates, writeDeletes, writeUpdates
checkConcurrentUpdate, close, closeConnections, countExecute, getDataSourceName, getIdentification, getRepositoryName, openBaseConnection, openConnections
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
cleanupDeletedRows, close, getIdentification
clearCache, copy, generateNewId, getBinaryFulltext, getCacheSize, getDescendantsInfo, read, readCollectionRowArray, readSelectionRows, readSelectionsIds, readSimpleRow, receiveInvalidations, remove, rollback, sendInvalidations, write
rollback
public static Map<String,Serializable> testProps
protected static Map<String,JDBCMapper.CursorResult> cursorResults
public static final String TEST_UPGRADE
public static final String TEST_UPGRADE_VERSIONS
public static final String TEST_UPGRADE_LAST_CONTRIBUTOR
public static final String TEST_UPGRADE_LOCKS
public static final String TEST_UPGRADE_SYS_CHANGE_TOKEN
protected TableUpgrader tableUpgrader
protected boolean clusteringEnabled
protected static final String NOSCROLL_ID
public JDBCMapper(Model model, Session.PathResolver pathResolver, SQLInfo sqlInfo, ClusterInvalidator clusterInvalidator, RepositoryImpl repository)
model
- the modelpathResolver
- the path resolver (used for startswith queries)sqlInfo
- the sql infoclusterInvalidator
- the cluster invalidatorrepository
- the repositorypublic int getTableSize(String tableName)
getTableSize
in interface Mapper
public void createDatabase(String ddlMode)
Mapper
createDatabase
in interface Mapper
ddlMode
- the DDL execution modeprotected String getTableName(String origName)
protected void createTables(String ddlMode) throws SQLException
SQLException
protected void upgradeTable(String tableKey, List<Column> addedColumns, String ddlMode, SQLStatement.ListCollector ddlCollector) throws SQLException
SQLException
protected static Set<String> findTableNames(DatabaseMetaData metadata, String schemaName) throws SQLException
SQLException
public int getClusterNodeIdType()
getClusterNodeIdType
in interface Mapper
public void createClusterNode(Serializable nodeId)
Mapper
createClusterNode
in interface Mapper
public void removeClusterNode(Serializable nodeId)
Mapper
removeClusterNode
in interface Mapper
protected void deleteClusterInvals(Serializable nodeId) throws SQLException
SQLException
public void insertClusterInvalidations(Serializable nodeId, Invalidations invalidations)
Mapper
insertClusterInvalidations
in interface Mapper
protected static String join(Collection<String> strings, char sep)
public Invalidations getClusterInvalidations(Serializable nodeId)
Mapper
getClusterInvalidations
in interface Mapper
public Serializable getRootId(String repositoryId)
Mapper
public void setRootId(Serializable repositoryId, Serializable id)
Mapper
protected QueryMaker findQueryMaker(String queryType)
protected void prepareUserReadAcls(QueryFilter queryFilter)
public PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, boolean countTotal)
Mapper
public PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, long countUpTo)
Mapper
query
in interface Mapper
query
- the queryqueryType
- the query typequeryFilter
- the query filtercountUpTo
- if -1
, count the total size without offset/limit.0
, don't count the total size.n
, count the total number if there are less than n documents otherwise set the size to
-1
.public IterableQueryResult queryAndFetch(String query, String queryType, QueryFilter queryFilter, boolean distinctDocuments, Object... params)
Mapper
queryAndFetch
in interface Mapper
query
- the queryqueryType
- the query typequeryFilter
- the query filterdistinctDocuments
- if true
then a maximum of one row per document will be returnedparams
- optional query-type-dependent parameterspublic PartialList<Map<String,Serializable>> queryProjection(String query, String queryType, QueryFilter queryFilter, boolean distinctDocuments, long countUpTo, Object... params)
Mapper
queryProjection
in interface Mapper
query
- the queryqueryType
- the query typequeryFilter
- the query filterdistinctDocuments
- if true
then a maximum of one row per document will be returnedcountUpTo
- if -1
, also count the total size without offset/limit.0
, don't count the total size.n
, count the total number if there are less than n documents otherwise set the size to
-1
.params
- optional query-type-dependent parametersprotected String computeDistinctDocuments(String query, boolean distinctDocuments)
protected <T> PartialList<T> queryProjection(String query, String queryType, QueryFilter queryFilter, long countUpTo, JDBCMapper.BiFunctionSQLException<SQLInfo.SQLInfoSelect,ResultSet,T> extractor, Object... params)
public int setToPreparedStatement(PreparedStatement ps, int i, Serializable object) throws SQLException
SQLException
public ScrollResult scroll(String query, int batchSize, int keepAliveSeconds)
Mapper
keepAliveSeconds
delay.protected void checkForTimedoutScroll()
protected ScrollResult scrollSearch(String query, int batchSize, int keepAliveSeconds)
protected void registerCursor(String scrollId, PreparedStatement ps, ResultSet rs, int batchSize, int keepAliveSeconds)
protected boolean unregisterCursor(String scrollId)
protected ScrollResult defaultScroll(String query)
public ScrollResult scroll(String scrollId)
Mapper
scrollId
is part of the previous ScrollResult
response.public Set<Serializable> getAncestorsIds(Collection<Serializable> ids)
Mapper
getAncestorsIds
in interface Mapper
ids
- the idsprotected Set<Serializable> getAncestorsIdsIterative(Collection<Serializable> ids)
public void updateReadAcls()
updateReadAcls
in interface Mapper
public void rebuildReadAcls()
rebuildReadAcls
in interface Mapper
public Lock getLock(Serializable id)
Mapper
If the document does not exist, null
is returned.
public Lock setLock(Serializable id, Lock lock)
Mapper
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).
public Lock removeLock(Serializable id, String owner, boolean force)
Mapper
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()
.
removeLock
in interface Mapper
id
- the document idowner
- the owner to check, or null
for no checkforce
- true
to just do the remove and not return the previous lockpublic void markReferencedBinaries()
Mapper
markReferencedBinaries
in interface Mapper
protected static String systemToString(Object o)
public void start(Xid xid, int flags) throws XAException
start
in interface XAResource
XAException
public void end(Xid xid, int flags) throws XAException
end
in interface XAResource
XAException
public int prepare(Xid xid) throws XAException
prepare
in interface XAResource
XAException
public void commit(Xid xid, boolean onePhase) throws XAException
commit
in interface XAResource
XAException
public void forget(Xid xid) throws XAException
forget
in interface XAResource
XAException
public Xid[] recover(int flag) throws XAException
recover
in interface XAResource
XAException
public boolean setTransactionTimeout(int seconds) throws XAException
setTransactionTimeout
in interface XAResource
XAException
public int getTransactionTimeout() throws XAException
getTransactionTimeout
in interface XAResource
XAException
public boolean isSameRM(XAResource xares) throws XAException
isSameRM
in interface XAResource
XAException
public boolean isConnected()
isConnected
in interface Mapper
public void disconnect()
disconnect
in interface Mapper
Copyright © 2017 Nuxeo. All rights reserved.