Class JDBCMapper
- java.lang.Object
-
- org.nuxeo.ecm.core.storage.sql.jdbc.JDBCConnection
-
- org.nuxeo.ecm.core.storage.sql.jdbc.JDBCRowMapper
-
- org.nuxeo.ecm.core.storage.sql.jdbc.JDBCMapper
-
public class JDBCMapper extends JDBCRowMapper implements Mapper
AJDBCMapper
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 aModel
, and generates SQL statements recorded in theSQLInfo
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
JDBCMapper.BiFunctionSQLException<T,U,R>
protected class
JDBCMapper.CursorResult
-
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
Fields Modifier and Type Field Description protected static Map<String,JDBCMapper.CursorResult>
cursorResults
protected static String
NOSCROLL_ID
-
Fields inherited from class org.nuxeo.ecm.core.storage.sql.jdbc.JDBCRowMapper
COLLECTION_DELETE_BEFORE_APPEND_PROP, DEBUG_MAX_TREE, UPDATE_BATCH_SIZE
-
Fields inherited from class org.nuxeo.ecm.core.storage.sql.jdbc.JDBCConnection
connection, countExecutes, dialect, executeCount, logger, model, setClientInfo, sqlInfo, supportsBatchUpdates
-
Fields inherited from interface org.nuxeo.ecm.core.storage.sql.Mapper
CLOSE, GET_IDENTIFICATION
-
-
Constructor Summary
Constructors Constructor Description JDBCMapper(Model model, Session.PathResolver pathResolver, SQLInfo sqlInfo, VCSClusterInvalidator clusterInvalidator, RepositoryImpl repository)
Creates a new Mapper.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkForTimedoutScroll()
void
close()
protected String
computeDistinctDocuments(String query, boolean distinctDocuments)
void
createClusterNode(Serializable nodeId)
Informs the cluster that this node exists.protected ScrollResult<String>
defaultScroll(String query)
protected void
deleteClusterInvals(Serializable nodeId)
protected QueryMaker
findQueryMaker(String queryType)
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.VCSInvalidations
getClusterInvalidations(Serializable nodeId)
Gets the invalidations from other cluster nodes.int
getClusterNodeIdType()
Serializable
getRootId(String repositoryId)
Gets the root id for a given repository, if registered.int
getTableSize(String tableName)
void
insertClusterInvalidations(Serializable nodeId, VCSInvalidations invalidations)
Inserts the invalidation rows for the other cluster nodes.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.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()
protected void
registerCursor(String scrollId, PreparedStatement ps, ResultSet rs, int batchSize, int keepAliveSeconds)
void
removeClusterNode(Serializable nodeId)
Removes this node from the cluster.ScrollResult<String>
scroll(String scrollId)
Get the next batch of results containing id of documents, thescrollId
is part of the previousScrollResult
response.ScrollResult<String>
scroll(String query, int batchSize, int keepAliveSeconds)
Executes the given query and returns the first batch of results containing id of documents, next batch must be requested within thekeepAliveSeconds
delay.ScrollResult<String>
scroll(String query, QueryFilter queryFilter, int batchSize, int keepAliveSeconds)
Executes the given query and returns the first batch of results containing id of documents, next batch must be requested within thekeepAliveSeconds
delay.protected ScrollResult<String>
scrollSearch(String query, QueryFilter queryFilter, int batchSize, int keepAliveSeconds)
void
setRootId(Serializable repositoryId, Serializable id)
Records the newly generated root id for a given repository.int
setToPreparedStatement(PreparedStatement ps, int i, Serializable object)
protected boolean
unregisterCursor(String scrollId)
void
updateReadAcls()
-
Methods inherited from class org.nuxeo.ecm.core.storage.sql.jdbc.JDBCRowMapper
cleanupDeletedRows, clearCache, copy, copyHier, copyHierRecursive, copyRows, deleteRows, deleteRowsDirect, deleteRowsSoft, doSoftDeleteRows, generateNewId, getBinaryFulltext, getCacheSize, getChildrenIdsWithTypes, getChildrenNodeInfos, getCollectionIO, getDescendantsInfo, getDescendantsInfoIterative, getNodeInfo, getSelectRows, insertCollectionRows, insertSimpleRows, newIdArray, read, readCollectionArrays, readCollectionRowArray, readSelectionRows, readSelectionsIds, readSimpleRow, readSimpleRows, receiveInvalidations, remove, rollback, sendInvalidations, setToPreparedStatementIdArray, updateCollectionRows, updateSimpleRows, updateSimpleRowWithValues, write, writeCreates, writeDeletes, writeUpdates
-
Methods inherited from class org.nuxeo.ecm.core.storage.sql.jdbc.JDBCConnection
checkConcurrentUpdate, closeConnection, connect, countExecute, getDataSourceName, getIdentification, getRepositoryName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuxeo.ecm.core.storage.sql.Mapper
cleanupDeletedRows, getIdentification
-
Methods inherited from interface org.nuxeo.ecm.core.storage.sql.RowMapper
clearCache, copy, copy, generateNewId, getBinaryFulltext, getCacheSize, getDescendantsInfo, read, readCollectionRowArray, readSelectionRows, readSelectionsIds, readSimpleRow, receiveInvalidations, remove, rollback, sendInvalidations, write
-
-
-
-
Field Detail
-
cursorResults
protected static Map<String,JDBCMapper.CursorResult> cursorResults
-
NOSCROLL_ID
protected static final String NOSCROLL_ID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JDBCMapper
public JDBCMapper(Model model, Session.PathResolver pathResolver, SQLInfo sqlInfo, VCSClusterInvalidator clusterInvalidator, RepositoryImpl repository)
Creates a new Mapper.- Parameters:
model
- the modelpathResolver
- the path resolver (used for startswith queries)sqlInfo
- the sql infoclusterInvalidator
- the cluster invalidatorrepository
- the repository
-
-
Method Detail
-
getTableSize
public int getTableSize(String tableName)
- Specified by:
getTableSize
in interfaceMapper
-
getClusterNodeIdType
public int getClusterNodeIdType()
- Specified by:
getClusterNodeIdType
in interfaceMapper
-
createClusterNode
public void createClusterNode(Serializable nodeId)
Description copied from interface:Mapper
Informs the cluster that this node exists.- Specified by:
createClusterNode
in interfaceMapper
-
removeClusterNode
public void removeClusterNode(Serializable nodeId)
Description copied from interface:Mapper
Removes this node from the cluster.- Specified by:
removeClusterNode
in interfaceMapper
-
deleteClusterInvals
protected void deleteClusterInvals(Serializable nodeId) throws SQLException
- Throws:
SQLException
-
insertClusterInvalidations
public void insertClusterInvalidations(Serializable nodeId, VCSInvalidations invalidations)
Description copied from interface:Mapper
Inserts the invalidation rows for the other cluster nodes.- Specified by:
insertClusterInvalidations
in interfaceMapper
-
join
protected static String join(Collection<String> strings, char sep)
-
getClusterInvalidations
public VCSInvalidations getClusterInvalidations(Serializable nodeId)
Description copied from interface:Mapper
Gets the invalidations from other cluster nodes.- Specified by:
getClusterInvalidations
in interfaceMapper
-
getRootId
public Serializable getRootId(String repositoryId)
Description copied from interface:Mapper
Gets the root id for a given repository, if registered.
-
setRootId
public void setRootId(Serializable repositoryId, Serializable id)
Description copied from interface:Mapper
Records the newly generated root id for a given repository.
-
findQueryMaker
protected QueryMaker findQueryMaker(String queryType)
-
prepareUserReadAcls
protected void prepareUserReadAcls(QueryFilter queryFilter)
-
query
public PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, boolean countTotal)
Description copied from interface:Mapper
Makes a NXQL query to the database.
-
query
public PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, long countUpTo)
Description copied from interface:Mapper
Makes a NXQL query to the database.- Specified by:
query
in interfaceMapper
- Parameters:
query
- the queryqueryType
- the query typequeryFilter
- the query filtercountUpTo
- if-1
, count the total size without offset/limit.
If0
, don't count the total size.
Ifn
, count the total number if there are less than n documents otherwise set the size to-1
.- Returns:
- the list of matching document ids
-
queryAndFetch
public IterableQueryResult queryAndFetch(String query, String queryType, QueryFilter queryFilter, boolean distinctDocuments, Object... params)
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 interfaceMapper
- Parameters:
query
- the queryqueryType
- the query typequeryFilter
- the query filterdistinctDocuments
- iftrue
then a maximum of one row per document will be returnedparams
- optional query-type-dependent parameters- Returns:
- an iterable, which must be closed when done
-
queryProjection
public PartialList<Map<String,Serializable>> queryProjection(String query, String queryType, QueryFilter queryFilter, boolean distinctDocuments, long countUpTo, Object... params)
Description copied from interface:Mapper
Makes a query to the database.- Specified by:
queryProjection
in interfaceMapper
- Parameters:
query
- the queryqueryType
- the query typequeryFilter
- the query filterdistinctDocuments
- iftrue
then a maximum of one row per document will be returnedcountUpTo
- if-1
, also count the total size without offset/limit.
If0
, don't count the total size.
Ifn
, count the total number if there are less than n documents otherwise set the size to-1
.params
- optional query-type-dependent parameters- Returns:
- a projection
-
computeDistinctDocuments
protected String computeDistinctDocuments(String query, boolean distinctDocuments)
-
queryProjection
protected <T> PartialList<T> queryProjection(String query, String queryType, QueryFilter queryFilter, long countUpTo, JDBCMapper.BiFunctionSQLException<SQLInfo.SQLInfoSelect,ResultSet,T> extractor, Object... params)
-
setToPreparedStatement
public int setToPreparedStatement(PreparedStatement ps, int i, Serializable object) throws SQLException
- Throws:
SQLException
-
scroll
public ScrollResult<String> scroll(String query, int batchSize, int keepAliveSeconds)
Description copied from interface:Mapper
Executes the given query and returns the first batch of results containing id of documents, next batch must be requested within thekeepAliveSeconds
delay.
-
scroll
public ScrollResult<String> scroll(String query, QueryFilter queryFilter, int batchSize, int keepAliveSeconds)
Description copied from interface:Mapper
Executes the given query and returns the first batch of results containing id of documents, next batch must be requested within thekeepAliveSeconds
delay.
-
checkForTimedoutScroll
protected void checkForTimedoutScroll()
-
scrollSearch
protected ScrollResult<String> scrollSearch(String query, QueryFilter queryFilter, int batchSize, int keepAliveSeconds)
-
registerCursor
protected void registerCursor(String scrollId, PreparedStatement ps, ResultSet rs, int batchSize, int keepAliveSeconds)
-
unregisterCursor
protected boolean unregisterCursor(String scrollId)
-
defaultScroll
protected ScrollResult<String> defaultScroll(String query)
-
scroll
public ScrollResult<String> scroll(String scrollId)
Description copied from interface:Mapper
Get the next batch of results containing id of documents, thescrollId
is part of the previousScrollResult
response.
-
getAncestorsIds
public Set<Serializable> getAncestorsIds(Collection<Serializable> ids)
Description copied from interface:Mapper
Gets the ids for all the ancestors of the given row ids.- Specified by:
getAncestorsIds
in interfaceMapper
- Parameters:
ids
- the ids- Returns:
- the set of ancestor ids
-
getAncestorsIdsIterative
protected Set<Serializable> getAncestorsIdsIterative(Collection<Serializable> ids)
Uses iterative parentid selection.
-
updateReadAcls
public void updateReadAcls()
- Specified by:
updateReadAcls
in interfaceMapper
-
rebuildReadAcls
public void rebuildReadAcls()
- Specified by:
rebuildReadAcls
in interfaceMapper
-
markReferencedBinaries
public void markReferencedBinaries()
Description copied from interface:Mapper
Marks the binaries in use by passing them to the binary manager(s)'s GC mark() method.- Specified by:
markReferencedBinaries
in interfaceMapper
-
-