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
AJDBCMappermaps objects to and from a JDBC database. It is specific to a given database connection, as it computes statements.The
JDBCMapperdoes 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 interfaceJDBCMapper.BiFunctionSQLException<T,U,R>protected classJDBCMapper.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>cursorResultsprotected static StringNOSCROLL_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 voidcheckForTimedoutScroll()voidclose()protected StringcomputeDistinctDocuments(String query, boolean distinctDocuments)voidcreateClusterNode(Serializable nodeId)Informs the cluster that this node exists.protected ScrollResult<String>defaultScroll(String query)protected voiddeleteClusterInvals(Serializable nodeId)protected QueryMakerfindQueryMaker(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.VCSInvalidationsgetClusterInvalidations(Serializable nodeId)Gets the invalidations from other cluster nodes.intgetClusterNodeIdType()SerializablegetRootId(String repositoryId)Gets the root id for a given repository, if registered.intgetTableSize(String tableName)voidinsertClusterInvalidations(Serializable nodeId, VCSInvalidations invalidations)Inserts the invalidation rows for the other cluster nodes.protected static Stringjoin(Collection<String> strings, char sep)voidmarkReferencedBinaries()Marks the binaries in use by passing them to the binary manager(s)'s GC mark() method.protected voidprepareUserReadAcls(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.IterableQueryResultqueryAndFetch(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)voidrebuildReadAcls()protected voidregisterCursor(String scrollId, PreparedStatement ps, ResultSet rs, int batchSize, int keepAliveSeconds)voidremoveClusterNode(Serializable nodeId)Removes this node from the cluster.ScrollResult<String>scroll(String scrollId)Get the next batch of results containing id of documents, thescrollIdis part of the previousScrollResultresponse.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 thekeepAliveSecondsdelay.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 thekeepAliveSecondsdelay.protected ScrollResult<String>scrollSearch(String query, QueryFilter queryFilter, int batchSize, int keepAliveSeconds)voidsetRootId(Serializable repositoryId, Serializable id)Records the newly generated root id for a given repository.intsetToPreparedStatement(PreparedStatement ps, int i, Serializable object)protected booleanunregisterCursor(String scrollId)voidupdateReadAcls()-
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:
getTableSizein interfaceMapper
-
getClusterNodeIdType
public int getClusterNodeIdType()
- Specified by:
getClusterNodeIdTypein interfaceMapper
-
createClusterNode
public void createClusterNode(Serializable nodeId)
Description copied from interface:MapperInforms the cluster that this node exists.- Specified by:
createClusterNodein interfaceMapper
-
removeClusterNode
public void removeClusterNode(Serializable nodeId)
Description copied from interface:MapperRemoves this node from the cluster.- Specified by:
removeClusterNodein interfaceMapper
-
deleteClusterInvals
protected void deleteClusterInvals(Serializable nodeId) throws SQLException
- Throws:
SQLException
-
insertClusterInvalidations
public void insertClusterInvalidations(Serializable nodeId, VCSInvalidations invalidations)
Description copied from interface:MapperInserts the invalidation rows for the other cluster nodes.- Specified by:
insertClusterInvalidationsin interfaceMapper
-
join
protected static String join(Collection<String> strings, char sep)
-
getClusterInvalidations
public VCSInvalidations getClusterInvalidations(Serializable nodeId)
Description copied from interface:MapperGets the invalidations from other cluster nodes.- Specified by:
getClusterInvalidationsin interfaceMapper
-
getRootId
public Serializable getRootId(String repositoryId)
Description copied from interface:MapperGets the root id for a given repository, if registered.
-
setRootId
public void setRootId(Serializable repositoryId, Serializable id)
Description copied from interface:MapperRecords 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:MapperMakes a NXQL query to the database.
-
query
public PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, long countUpTo)
Description copied from interface:MapperMakes a NXQL query to the database.- Specified by:
queryin 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:MapperMakes a query to the database and returns an iterable (which must be closed when done).- Specified by:
queryAndFetchin interfaceMapper- Parameters:
query- the queryqueryType- the query typequeryFilter- the query filterdistinctDocuments- iftruethen 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:MapperMakes a query to the database.- Specified by:
queryProjectionin interfaceMapper- Parameters:
query- the queryqueryType- the query typequeryFilter- the query filterdistinctDocuments- iftruethen 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:MapperExecutes the given query and returns the first batch of results containing id of documents, next batch must be requested within thekeepAliveSecondsdelay.
-
scroll
public ScrollResult<String> scroll(String query, QueryFilter queryFilter, int batchSize, int keepAliveSeconds)
Description copied from interface:MapperExecutes the given query and returns the first batch of results containing id of documents, next batch must be requested within thekeepAliveSecondsdelay.
-
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:MapperGet the next batch of results containing id of documents, thescrollIdis part of the previousScrollResultresponse.
-
getAncestorsIds
public Set<Serializable> getAncestorsIds(Collection<Serializable> ids)
Description copied from interface:MapperGets the ids for all the ancestors of the given row ids.- Specified by:
getAncestorsIdsin 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:
updateReadAclsin interfaceMapper
-
rebuildReadAcls
public void rebuildReadAcls()
- Specified by:
rebuildReadAclsin interfaceMapper
-
markReferencedBinaries
public void markReferencedBinaries()
Description copied from interface:MapperMarks the binaries in use by passing them to the binary manager(s)'s GC mark() method.- Specified by:
markReferencedBinariesin interfaceMapper
-
-