Class JDBCRowMapper
- java.lang.Object
-
- org.nuxeo.ecm.core.storage.sql.jdbc.JDBCConnection
-
- org.nuxeo.ecm.core.storage.sql.jdbc.JDBCRowMapper
-
- All Implemented Interfaces:
RowMapper
- Direct Known Subclasses:
JDBCMapper
public class JDBCRowMapper extends JDBCConnection implements RowMapper
AJDBCRowMappermapsRows to and from a JDBC database.
-
-
Nested Class Summary
-
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 static StringCOLLECTION_DELETE_BEFORE_APPEND_PROPProperty to determine whether collection appends delete all then re-insert, or are optimized for append.static intDEBUG_MAX_TREEstatic intUPDATE_BATCH_SIZE-
Fields inherited from class org.nuxeo.ecm.core.storage.sql.jdbc.JDBCConnection
connection, countExecutes, dialect, executeCount, logger, model, setClientInfo, sqlInfo, supportsBatchUpdates
-
-
Constructor Summary
Constructors Constructor Description JDBCRowMapper(Model model, SQLInfo sqlInfo, VCSClusterInvalidator clusterInvalidator, VCSInvalidationsPropagator invalidationsPropagator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcleanupDeletedRows(int max, Calendar beforeTime)Clean up soft-deleted rows.voidclearCache()Clears the mapper's cache (if any)RowMapper.CopyResultcopy(RowMapper.IdWithTypes source, Serializable destParentId, String destName, Row overwriteRow, boolean excludeSpecialChildren, boolean excludeACL)Copies the hierarchy starting from a given row to a new parent with a new name.protected SerializablecopyHier(Serializable id, Serializable parentId, String name, boolean resetVersion, Map<Serializable,Serializable> idMap)Copies hierarchy from id to a new child of parentId.protected SerializablecopyHierRecursive(RowMapper.IdWithTypes source, Serializable parentId, String name, Serializable overwriteId, boolean resetVersion, Map<Serializable,Serializable> idMap, Map<Serializable,RowMapper.IdWithTypes> idToTypes, Set<Serializable> recordIds, boolean excludeSpecialChildren)Copies hierarchy from id to parentId, and recurses.protected BooleancopyRows(String tableName, Set<Serializable> ids, Map<Serializable,Serializable> idMap, Serializable overwriteId)Copy the rows from tableName with given ids into new ones with new ids given by idMap.protected voiddeleteRows(String tableName, Set<Serializable> ids)Deletes multiple rows, all for the same table.protected voiddeleteRowsDirect(String tableName, Collection<Serializable> ids)protected voiddeleteRowsSoft(List<RowMapper.NodeInfo> nodeInfos)protected voiddoSoftDeleteRows(List<Serializable> ids)SerializablegenerateNewId()Computes a new unique id.Map<String,String>getBinaryFulltext(RowId rowId)Gets the fulltext extracted from the binary fields.longgetCacheSize()Evaluate the cached elements sizeprotected List<RowMapper.IdWithTypes>getChildrenIdsWithTypes(Serializable id, boolean excludeSpecialChildren, boolean excludeRegularChildren)Gets the children ids and types of a node.protected List<RowMapper.NodeInfo>getChildrenNodeInfos(Collection<Serializable> ids)Gets the children of a node as a list of NodeInfo.protected CollectionIOgetCollectionIO(String tableName)List<RowMapper.NodeInfo>getDescendantsInfo(Serializable rootId)Gets descendants infos from a given root node.protected List<RowMapper.NodeInfo>getDescendantsInfoIterative(Serializable rootId)protected RowMapper.NodeInfogetNodeInfo(ResultSet rs, List<Column> columns)protected List<Row>getSelectRows(String tableName, SQLInfo.SQLInfoSelect select, Map<String,Serializable> criteriaMap, Map<String,Serializable> joinMap, boolean limitToOne)Fetches the rows for a select with fixed criteria given as two maps (a criteriaMap whose values and up in the returned rows, and a joinMap for other criteria).protected voidinsertCollectionRows(String tableName, List<RowMapper.RowUpdate> rowus)Updates multiple collection rows, all for the same table.protected voidinsertSimpleRows(String tableName, List<Row> rows)Inserts multiple rows, all for the same table.protected SerializablenewIdArray(Collection<Serializable> ids)List<? extends RowId>read(Collection<RowId> rowIds, boolean cacheOnly)Reads a set of rows for the givenRowIds.protected List<Row>readCollectionArrays(String tableName, Collection<Serializable> ids)Reads several collection rows, given a table name and the ids.Serializable[]readCollectionRowArray(RowId rowId)Gets an array for aCollectionFragmentfrom the database, given its table name and id.List<Row>readSelectionRows(SelectionType selType, Serializable selId, Serializable filter, Serializable criterion, boolean limitToOne)Reads the rows corresponding to a selection.Set<Serializable>readSelectionsIds(SelectionType selType, List<Serializable> values)Gets all the selection ids for a given list of values.RowreadSimpleRow(RowId rowId)Gets a row for aSimpleFragmentfrom the database, given its table name and id.protected List<Row>readSimpleRows(String tableName, Collection<Serializable> ids)Gets a list of rows forSimpleFragments from the database, given the table name and the ids.VCSInvalidationsreceiveInvalidations()Processes and returns the invalidations queued for processing by the cache (if any).voidremove(Serializable rootId, List<RowMapper.NodeInfo> nodeInfos)Deletes a hierarchy.voidrollback()Rollback the transaction.voidsendInvalidations(VCSInvalidations invalidations)Post-transaction invalidations notification.protected voidsetToPreparedStatementIdArray(PreparedStatement ps, int index, Serializable idArray)protected voidupdateCollectionRows(String tableName, List<RowMapper.RowUpdate> rowus)protected voidupdateSimpleRows(String tableName, List<RowMapper.RowUpdate> rows)Updates multiple simple rows, all for the same table.protected voidupdateSimpleRowWithValues(String tableName, Row row)Updates a row in the database with given explicit values.voidwrite(RowMapper.RowBatch batch)Writes a set of rows.protected voidwriteCreates(List<Row> creates)protected voidwriteDeletes(Collection<RowId> deletes)protected voidwriteUpdates(Set<RowMapper.RowUpdate> updates)-
Methods inherited from class org.nuxeo.ecm.core.storage.sql.jdbc.JDBCConnection
checkConcurrentUpdate, closeConnection, connect, countExecute, getDataSourceName, getIdentification, getRepositoryName
-
-
-
-
Field Detail
-
UPDATE_BATCH_SIZE
public static final int UPDATE_BATCH_SIZE
- See Also:
- Constant Field Values
-
DEBUG_MAX_TREE
public static final int DEBUG_MAX_TREE
- See Also:
- Constant Field Values
-
COLLECTION_DELETE_BEFORE_APPEND_PROP
public static final String COLLECTION_DELETE_BEFORE_APPEND_PROP
Property to determine whether collection appends delete all then re-insert, or are optimized for append.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JDBCRowMapper
public JDBCRowMapper(Model model, SQLInfo sqlInfo, VCSClusterInvalidator clusterInvalidator, VCSInvalidationsPropagator invalidationsPropagator)
-
-
Method Detail
-
receiveInvalidations
public VCSInvalidations receiveInvalidations()
Description copied from interface:RowMapperProcesses and returns the invalidations queued for processing by the cache (if any).Called pre-transaction by session start or transactionless save;
- Specified by:
receiveInvalidationsin interfaceRowMapper- Returns:
- the invalidations, or
null
-
sendInvalidations
public void sendInvalidations(VCSInvalidations invalidations)
Description copied from interface:RowMapperPost-transaction invalidations notification.Called post-transaction by session commit/rollback or transactionless save.
- Specified by:
sendInvalidationsin interfaceRowMapper- Parameters:
invalidations- the known invalidations to send to others, ornull
-
clearCache
public void clearCache()
Description copied from interface:RowMapperClears the mapper's cache (if any)Called after a rollback, or a manual clear through RepositoryStatus MBean.
- Specified by:
clearCachein interfaceRowMapper
-
getCacheSize
public long getCacheSize()
Description copied from interface:RowMapperEvaluate the cached elements size- Specified by:
getCacheSizein interfaceRowMapper
-
rollback
public void rollback()
Description copied from interface:RowMapperRollback the transaction.This is in the
RowMapperinterface because on rollback the cache must be invalidated.
-
getCollectionIO
protected CollectionIO getCollectionIO(String tableName)
-
generateNewId
public Serializable generateNewId()
Description copied from interface:RowMapperComputes a new unique id.- Specified by:
generateNewIdin interfaceRowMapper- Returns:
- a new unique id
-
read
public List<? extends RowId> read(Collection<RowId> rowIds, boolean cacheOnly)
Description copied from interface:RowMapper
-
readSimpleRows
protected List<Row> readSimpleRows(String tableName, Collection<Serializable> ids)
Gets a list of rows forSimpleFragments from the database, given the table name and the ids.- Parameters:
tableName- the table nameids- the ids- Returns:
- the list of rows, without the missing ones
-
readCollectionArrays
protected List<Row> readCollectionArrays(String tableName, Collection<Serializable> ids)
Reads several collection rows, given a table name and the ids.- Parameters:
tableName- the table nameids- the ids
-
getSelectRows
protected List<Row> getSelectRows(String tableName, SQLInfo.SQLInfoSelect select, Map<String,Serializable> criteriaMap, Map<String,Serializable> joinMap, boolean limitToOne)
Fetches the rows for a select with fixed criteria given as two maps (a criteriaMap whose values and up in the returned rows, and a joinMap for other criteria).
-
write
public void write(RowMapper.RowBatch batch)
Description copied from interface:RowMapperWrites a set of rows. This includes creating, updating and deleting rows.
-
writeCreates
protected void writeCreates(List<Row> creates)
-
writeUpdates
protected void writeUpdates(Set<RowMapper.RowUpdate> updates)
-
writeDeletes
protected void writeDeletes(Collection<RowId> deletes)
-
insertSimpleRows
protected void insertSimpleRows(String tableName, List<Row> rows)
Inserts multiple rows, all for the same table.
-
insertCollectionRows
protected void insertCollectionRows(String tableName, List<RowMapper.RowUpdate> rowus)
Updates multiple collection rows, all for the same table.
-
updateSimpleRows
protected void updateSimpleRows(String tableName, List<RowMapper.RowUpdate> rows)
Updates multiple simple rows, all for the same table.
-
updateCollectionRows
protected void updateCollectionRows(String tableName, List<RowMapper.RowUpdate> rowus)
-
deleteRows
protected void deleteRows(String tableName, Set<Serializable> ids)
Deletes multiple rows, all for the same table.
-
deleteRowsSoft
protected void deleteRowsSoft(List<RowMapper.NodeInfo> nodeInfos)
-
doSoftDeleteRows
protected void doSoftDeleteRows(List<Serializable> ids) throws SQLException
- Throws:
SQLException
-
newIdArray
protected Serializable newIdArray(Collection<Serializable> ids)
-
setToPreparedStatementIdArray
protected void setToPreparedStatementIdArray(PreparedStatement ps, int index, Serializable idArray) throws SQLException
- Throws:
SQLException
-
cleanupDeletedRows
public int cleanupDeletedRows(int max, Calendar beforeTime)
Clean up soft-deleted rows.Rows deleted more recently than the beforeTime are left alone. Only a limited number of rows may be deleted, to prevent transaction during too long.
- Parameters:
max- the maximum number of rows to delete at a timebeforeTime- the maximum deletion time of the rows to delete- Returns:
- the number of rows deleted
-
deleteRowsDirect
protected void deleteRowsDirect(String tableName, Collection<Serializable> ids)
-
readSimpleRow
public Row readSimpleRow(RowId rowId)
Description copied from interface:RowMapperGets a row for aSimpleFragmentfrom the database, given its table name and id. If the row doesn't exist,nullis returned.- Specified by:
readSimpleRowin interfaceRowMapper- Parameters:
rowId- the row id- Returns:
- the row, or
null
-
getBinaryFulltext
public Map<String,String> getBinaryFulltext(RowId rowId)
Description copied from interface:RowMapperGets the fulltext extracted from the binary fields.- Specified by:
getBinaryFulltextin interfaceRowMapper- Parameters:
rowId- the row id- Returns:
- the fulltext string representation or
nullif unsupported
-
readCollectionRowArray
public Serializable[] readCollectionRowArray(RowId rowId)
Description copied from interface:RowMapperGets an array for aCollectionFragmentfrom the database, given its table name and id. If no rows are found, an empty array is returned.- Specified by:
readCollectionRowArrayin interfaceRowMapper- Parameters:
rowId- the row id- Returns:
- the array
-
readSelectionRows
public List<Row> readSelectionRows(SelectionType selType, Serializable selId, Serializable filter, Serializable criterion, boolean limitToOne)
Description copied from interface:RowMapperReads the rows corresponding to a selection.- Specified by:
readSelectionRowsin interfaceRowMapper- Parameters:
selType- the selection typeselId- the selection id (parent id for a hierarchy selection)filter- the filter value (name for a hierarchy selection)criterion- an optional additional criterion depending on the selection type (complex prop flag for a hierarchy selection)limitToOne- whether to stop after one row retrieved- Returns:
- the list of rows
-
readSelectionsIds
public Set<Serializable> readSelectionsIds(SelectionType selType, List<Serializable> values)
Description copied from interface:RowMapperGets all the selection ids for a given list of values.- Specified by:
readSelectionsIdsin interfaceRowMapper
-
copy
public RowMapper.CopyResult copy(RowMapper.IdWithTypes source, Serializable destParentId, String destName, Row overwriteRow, boolean excludeSpecialChildren, boolean excludeACL)
Description copied from interface:RowMapperCopies the hierarchy starting from a given row to a new parent with a new name.If the new parent is
null, then this is a version creation, which doesn't recurse in regular children.If
overwriteRowis passed, the copy is done onto this existing node as its root (version restore) instead of creating a new node in the parent.- Specified by:
copyin interfaceRowMapper- Parameters:
source- the id, primary type and mixin types of the row to copydestParentId- the new parent id, ornulldestName- the new nameoverwriteRow- when notnull, the copy is done onto this existing row, and the values are set in hierarchyexcludeSpecialChildren- the flag to exclude special children from copyexcludeACL- the flag to exclude ACL from copy- Returns:
- info about the copy
-
updateSimpleRowWithValues
protected void updateSimpleRowWithValues(String tableName, Row row)
Updates a row in the database with given explicit values.
-
copyHierRecursive
protected Serializable copyHierRecursive(RowMapper.IdWithTypes source, Serializable parentId, String name, Serializable overwriteId, boolean resetVersion, Map<Serializable,Serializable> idMap, Map<Serializable,RowMapper.IdWithTypes> idToTypes, Set<Serializable> recordIds, boolean excludeSpecialChildren) throws SQLException
Copies hierarchy from id to parentId, and recurses.If name is
null, then the original name is kept.idMapis filled with info about the correspondence between original and copied ids.idToTypesis filled with the type of each (source) fragment.recordIdsis filled with the copied ids of documents that used to be records.TODO: this should be optimized to use a stored procedure.
- Parameters:
overwriteId- when notnull, the copy is done onto this existing node (skipped)- Returns:
- the new root id
- Throws:
SQLException
-
copyHier
protected Serializable copyHier(Serializable id, Serializable parentId, String name, boolean resetVersion, Map<Serializable,Serializable> idMap) throws SQLException
Copies hierarchy from id to a new child of parentId.If name is
null, then the original name is kept.idMapis filled with info about the correspondence between original and copied ids.- Returns:
- the new id
- Throws:
SQLException
-
getChildrenIdsWithTypes
protected List<RowMapper.IdWithTypes> getChildrenIdsWithTypes(Serializable id, boolean excludeSpecialChildren, boolean excludeRegularChildren) throws SQLException
Gets the children ids and types of a node.- Throws:
SQLException
-
copyRows
protected Boolean copyRows(String tableName, Set<Serializable> ids, Map<Serializable,Serializable> idMap, Serializable overwriteId) throws SQLException
Copy the rows from tableName with given ids into new ones with new ids given by idMap.A new row with id
overwriteIdis first deleted.- Returns:
Boolean.TRUEfor a modification or creation,Boolean.FALSEfor a deletion,nullotherwise (still absent)- Throws:
SQLException
-
remove
public void remove(Serializable rootId, List<RowMapper.NodeInfo> nodeInfos)
Description copied from interface:RowMapperDeletes a hierarchy.
-
getDescendantsInfo
public List<RowMapper.NodeInfo> getDescendantsInfo(Serializable rootId)
Description copied from interface:RowMapperGets descendants infos from a given root node. This does not include information about the root node itself.- Specified by:
getDescendantsInfoin interfaceRowMapper- Parameters:
rootId- the root node id from which to get descendants info- Returns:
- the list of descendant nodes info
-
getDescendantsInfoIterative
protected List<RowMapper.NodeInfo> getDescendantsInfoIterative(Serializable rootId)
-
getChildrenNodeInfos
protected List<RowMapper.NodeInfo> getChildrenNodeInfos(Collection<Serializable> ids)
Gets the children of a node as a list of NodeInfo.
-
getNodeInfo
protected RowMapper.NodeInfo getNodeInfo(ResultSet rs, List<Column> columns) throws SQLException
- Throws:
SQLException
-
-