use of com.evolveum.midpoint.repo.sql.data.common.id.RContainerId in project midpoint by Evolveum.
the class LookupTableHelper method updateLookupTableData.
public void updateLookupTableData(Session session, String tableOid, Collection<? extends ItemDelta> modifications) throws SchemaException {
if (modifications.isEmpty()) {
return;
}
for (ItemDelta delta : modifications) {
if (delta.getPath().size() == 1) {
// whole row add/delete/replace
if (!(delta instanceof ContainerDelta)) {
throw new IllegalStateException("Wrong table delta sneaked into updateLookupTableData: class=" + delta.getClass() + ", path=" + delta.getPath());
}
// one "table" container modification
ContainerDelta containerDelta = (ContainerDelta) delta;
if (containerDelta.getValuesToDelete() != null) {
// todo do 'bulk' delete like delete from ... where oid=? and id in (...)
for (PrismContainerValue<LookupTableRowType> value : (Collection<PrismContainerValue>) containerDelta.getValuesToDelete()) {
if (value.getId() != null) {
deleteRowById(session, tableOid, value.getId());
} else if (value.asContainerable().getKey() != null) {
deleteRowByKey(session, tableOid, value.asContainerable().getKey());
} else {
// ignore (or throw an exception?)
}
}
}
if (containerDelta.getValuesToAdd() != null) {
int currentId = generalHelper.findLastIdInRepo(session, tableOid, "get.lookupTableLastId") + 1;
addLookupTableRows(session, tableOid, containerDelta.getValuesToAdd(), currentId, true);
}
if (containerDelta.getValuesToReplace() != null) {
deleteLookupTableRows(session, tableOid);
addLookupTableRows(session, tableOid, containerDelta.getValuesToReplace(), 1, false);
}
} else if (delta.getPath().size() == 3) {
// row segment modification (structure is already checked)
List<ItemPathSegment> segments = delta.getPath().getSegments();
Long rowId = ((IdItemPathSegment) segments.get(1)).getId();
QName name = ((NameItemPathSegment) segments.get(2)).getName();
RLookupTableRow row = (RLookupTableRow) session.get(RLookupTableRow.class, new RContainerId(RUtil.toInteger(rowId), tableOid));
LookupTableRowType rowType = row.toJAXB();
delta.setParentPath(ItemPath.EMPTY_PATH);
delta.applyTo(rowType.asPrismContainerValue());
if (!QNameUtil.match(name, LookupTableRowType.F_LAST_CHANGE_TIMESTAMP)) {
// in order to get filled in via toRepo call below
rowType.setLastChangeTimestamp(null);
}
RLookupTableRow rowUpdated = RLookupTableRow.toRepo(tableOid, rowType);
session.merge(rowUpdated);
}
}
}
Aggregations