public class JDBCRowMapper extends JDBCConnection implements RowMapper
JDBCRowMapper
maps Row
s to and from a JDBC database.RowMapper.CopyResult, RowMapper.IdWithTypes, RowMapper.NodeInfo, RowMapper.RowBatch, RowMapper.RowUpdate
Modifier and Type | Field and Description |
---|---|
static String |
COLLECTION_DELETE_BEFORE_APPEND_PROP
Property to determine whether collection appends delete all then re-insert, or are optimized for append.
|
static int |
DEBUG_MAX_TREE |
static int |
UPDATE_BATCH_SIZE |
connection, countExecutes, dialect, executeCount, logger, model, noSharing, setClientInfo, sqlInfo, supportsBatchUpdates, xaresource
Constructor and Description |
---|
JDBCRowMapper(Model model,
SQLInfo sqlInfo,
ClusterInvalidator clusterInvalidator,
InvalidationsPropagator invalidationsPropagator,
boolean noSharing) |
Modifier and Type | Method and Description |
---|---|
int |
cleanupDeletedRows(int max,
Calendar beforeTime)
Clean up soft-deleted rows.
|
void |
clearCache()
Clears the mapper's cache (if any)
|
RowMapper.CopyResult |
copy(RowMapper.IdWithTypes source,
Serializable destParentId,
String destName,
Row overwriteRow)
Copies the hierarchy starting from a given row to a new parent with a new name.
|
protected Serializable |
copyHier(Serializable id,
Serializable parentId,
String name,
boolean resetVersion,
Map<Serializable,Serializable> idMap)
Copies hierarchy from id to a new child of parentId.
|
protected Serializable |
copyHierRecursive(RowMapper.IdWithTypes source,
Serializable parentId,
String name,
Serializable overwriteId,
boolean resetVersion,
Map<Serializable,Serializable> idMap,
Map<Serializable,RowMapper.IdWithTypes> idToTypes)
Copies hierarchy from id to parentId, and recurses.
|
protected Boolean |
copyRows(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 void |
deleteRows(String tableName,
Set<Serializable> ids)
Deletes multiple rows, all for the same table.
|
protected void |
deleteRowsDirect(String tableName,
Collection<Serializable> ids) |
protected void |
deleteRowsSoft(List<RowMapper.NodeInfo> nodeInfos) |
protected void |
doSoftDeleteRows(List<Serializable> ids) |
Serializable |
generateNewId()
Computes a new unique id.
|
Map<String,String> |
getBinaryFulltext(RowId rowId)
Gets the fulltext extracted from the binary fields.
|
long |
getCacheSize()
Evaluate the cached elements size
|
protected List<RowMapper.IdWithTypes> |
getChildrenIdsWithTypes(Serializable id,
boolean onlyComplex)
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 CollectionIO |
getCollectionIO(String tableName) |
protected List<RowMapper.NodeInfo> |
getDescendantsInfo(Serializable rootId) |
protected List<RowMapper.NodeInfo> |
getDescendantsInfoIterative(Serializable rootId) |
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 void |
insertCollectionRows(String tableName,
List<RowMapper.RowUpdate> rowus)
Updates multiple collection rows, all for the same table.
|
protected void |
insertSimpleRows(String tableName,
List<Row> rows)
Inserts multiple rows, all for the same table.
|
protected Serializable |
newIdArray(Collection<Serializable> ids) |
List<? extends RowId> |
read(Collection<RowId> rowIds,
boolean cacheOnly)
Reads a set of rows for the given
RowId s. |
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 a
CollectionFragment from 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.
|
Row |
readSimpleRow(RowId rowId)
Gets a row for a
SimpleFragment from the database, given its table name and id. |
protected List<Row> |
readSimpleRows(String tableName,
Collection<Serializable> ids)
Gets a list of rows for
SimpleFragment s from the database, given the table name and the ids. |
Invalidations |
receiveInvalidations()
Processes and returns the invalidations queued for processing by the cache (if any).
|
List<RowMapper.NodeInfo> |
remove(RowMapper.NodeInfo rootInfo)
Deletes a hierarchy and returns information to generate invalidations.
|
void |
rollback(Xid xid)
Rollback the XA Resource.
|
void |
sendInvalidations(Invalidations invalidations)
Post-transaction invalidations notification.
|
protected void |
setToPreparedStatementIdArray(PreparedStatement ps,
int index,
Serializable idArray) |
protected void |
updateCollectionRows(String tableName,
List<RowMapper.RowUpdate> rowus) |
protected void |
updateSimpleRows(String tableName,
List<RowMapper.RowUpdate> rows)
Updates multiple simple rows, all for the same table.
|
protected void |
updateSimpleRowWithValues(String tableName,
Row row)
Updates a row in the database with given explicit values.
|
void |
write(RowMapper.RowBatch batch)
Writes a set of rows.
|
protected void |
writeCreates(List<Row> creates) |
protected void |
writeDeletes(Collection<RowId> deletes) |
protected void |
writeUpdates(Set<RowMapper.RowUpdate> updates) |
checkConcurrentUpdate, close, closeConnections, closeStatement, closeStatement, countExecute, getDataSourceName, getIdentification, getRepositoryName, openBaseConnection, openConnections
public static final int UPDATE_BATCH_SIZE
public static final int DEBUG_MAX_TREE
public static final String COLLECTION_DELETE_BEFORE_APPEND_PROP
public JDBCRowMapper(Model model, SQLInfo sqlInfo, ClusterInvalidator clusterInvalidator, InvalidationsPropagator invalidationsPropagator, boolean noSharing)
public Invalidations receiveInvalidations()
RowMapper
Called pre-transaction by session start or transactionless save;
receiveInvalidations
in interface RowMapper
null
public void sendInvalidations(Invalidations invalidations)
RowMapper
Called post-transaction by session commit/rollback or transactionless save.
sendInvalidations
in interface RowMapper
invalidations
- the known invalidations to send to others, or null
public void clearCache()
RowMapper
Called after a rollback, or a manual clear through RepositoryStatus MBean.
clearCache
in interface RowMapper
public long getCacheSize()
RowMapper
getCacheSize
in interface RowMapper
public void rollback(Xid xid) throws XAException
RowMapper
This is in the RowMapper
interface because on rollback the cache must be invalidated.
rollback
in interface RowMapper
XAException
protected CollectionIO getCollectionIO(String tableName)
public Serializable generateNewId()
RowMapper
generateNewId
in interface RowMapper
public List<? extends RowId> read(Collection<RowId> rowIds, boolean cacheOnly)
RowMapper
protected List<Row> readSimpleRows(String tableName, Collection<Serializable> ids)
SimpleFragment
s from the database, given the table name and the ids.tableName
- the table nameids
- the idsprotected List<Row> readCollectionArrays(String tableName, Collection<Serializable> ids)
tableName
- the table nameids
- the idsprotected List<Row> getSelectRows(String tableName, SQLInfo.SQLInfoSelect select, Map<String,Serializable> criteriaMap, Map<String,Serializable> joinMap, boolean limitToOne)
public void write(RowMapper.RowBatch batch)
RowMapper
protected void writeCreates(List<Row> creates)
protected void writeUpdates(Set<RowMapper.RowUpdate> updates)
protected void writeDeletes(Collection<RowId> deletes)
protected void insertSimpleRows(String tableName, List<Row> rows)
protected void insertCollectionRows(String tableName, List<RowMapper.RowUpdate> rowus)
protected void updateSimpleRows(String tableName, List<RowMapper.RowUpdate> rows)
protected void updateCollectionRows(String tableName, List<RowMapper.RowUpdate> rowus)
protected void deleteRows(String tableName, Set<Serializable> ids)
protected void deleteRowsSoft(List<RowMapper.NodeInfo> nodeInfos)
protected void doSoftDeleteRows(List<Serializable> ids) throws SQLException
SQLException
protected Serializable newIdArray(Collection<Serializable> ids)
protected void setToPreparedStatementIdArray(PreparedStatement ps, int index, Serializable idArray) throws SQLException
SQLException
public int cleanupDeletedRows(int max, Calendar beforeTime)
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.
max
- the maximum number of rows to delete at a timebeforeTime
- the maximum deletion time of the rows to deleteprotected void deleteRowsDirect(String tableName, Collection<Serializable> ids)
public Row readSimpleRow(RowId rowId)
RowMapper
SimpleFragment
from the database, given its table name and id. If the row doesn't exist,
null
is returned.readSimpleRow
in interface RowMapper
rowId
- the row idnull
public Map<String,String> getBinaryFulltext(RowId rowId)
RowMapper
getBinaryFulltext
in interface RowMapper
rowId
- the row idnull
if unsupportedpublic Serializable[] readCollectionRowArray(RowId rowId)
RowMapper
CollectionFragment
from the database, given its table name and id. If no rows are
found, an empty array is returned.readCollectionRowArray
in interface RowMapper
rowId
- the row idpublic List<Row> readSelectionRows(SelectionType selType, Serializable selId, Serializable filter, Serializable criterion, boolean limitToOne)
RowMapper
readSelectionRows
in interface RowMapper
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 retrievedpublic RowMapper.CopyResult copy(RowMapper.IdWithTypes source, Serializable destParentId, String destName, Row overwriteRow)
RowMapper
If the new parent is null
, then this is a version creation, which doesn't recurse in regular children.
If overwriteRow
is passed, the copy is done onto this existing node as its root (version restore) instead
of creating a new node in the parent.
copy
in interface RowMapper
source
- the id, primary type and mixin types of the row to copydestParentId
- the new parent id, or null
destName
- the new nameoverwriteRow
- when not null
, the copy is done onto this existing row, and the values are set in
hierarchyprotected void updateSimpleRowWithValues(String tableName, Row row)
protected Serializable copyHierRecursive(RowMapper.IdWithTypes source, Serializable parentId, String name, Serializable overwriteId, boolean resetVersion, Map<Serializable,Serializable> idMap, Map<Serializable,RowMapper.IdWithTypes> idToTypes) throws SQLException
If name is null
, then the original name is kept.
idMap
is filled with info about the correspondence between original and copied ids. idType
is
filled with the type of each (source) fragment.
TODO: this should be optimized to use a stored procedure.
overwriteId
- when not null
, the copy is done onto this existing node (skipped)SQLException
protected Serializable copyHier(Serializable id, Serializable parentId, String name, boolean resetVersion, Map<Serializable,Serializable> idMap) throws SQLException
If name is null
, then the original name is kept.
idMap
is filled with info about the correspondence between original and copied ids. idType
is
filled with the type of each (source) fragment.
SQLException
protected List<RowMapper.IdWithTypes> getChildrenIdsWithTypes(Serializable id, boolean onlyComplex) throws SQLException
SQLException
protected Boolean copyRows(String tableName, Set<Serializable> ids, Map<Serializable,Serializable> idMap, Serializable overwriteId) throws SQLException
A new row with id overwriteId
is first deleted.
Boolean.TRUE
for a modification or creation, Boolean.FALSE
for a deletion, null
otherwise (still absent)SQLException
public List<RowMapper.NodeInfo> remove(RowMapper.NodeInfo rootInfo)
RowMapper
protected List<RowMapper.NodeInfo> getDescendantsInfo(Serializable rootId)
protected List<RowMapper.NodeInfo> getDescendantsInfoIterative(Serializable rootId)
protected List<RowMapper.NodeInfo> getChildrenNodeInfos(Collection<Serializable> ids)
Copyright © 2016 Nuxeo SA. All rights reserved.