use of gov.ca.cwds.data.persistence.PersistentObject in project cals-api by ca-cwds.
the class StateReferentialIntegrityForEachValidator method getPersistentObject.
@Override
protected <T extends PersistentObject> PersistentObject getPersistentObject(Session currentSession, T obj, Serializable primaryKey) {
PersistentObject found;
Query<StateType> query = currentSession.createNamedQuery(NAMED_QUERY_FIND_STATE_BY_CODE, StateType.class);
query.setParameter("stateCode", primaryKey);
found = query.uniqueResult();
return found;
}
use of gov.ca.cwds.data.persistence.PersistentObject in project cals-api by ca-cwds.
the class AbstractReferentialIntegrityValidator method getPersistentObject.
protected <T extends PersistentObject> PersistentObject getPersistentObject(Session currentSession, T obj, Serializable primaryKey) {
PersistentObject found;
found = currentSession.get(obj.getClass(), primaryKey);
return found;
}
use of gov.ca.cwds.data.persistence.PersistentObject in project api-core by ca-cwds.
the class ApiHibernateInterceptor method preFlush.
/**
* Called <strong>before</strong> the transaction commits.
*
* <p>
* The underlying iterator's container may share records with other threads, though those records
* are not visible here. To avoid concurrent modification exceptions, this method synchronizes
* briefly, converts the iterator to a list, and iterates the list.
* </p>
*/
@Override
@SuppressWarnings("rawtypes")
public void preFlush(Iterator iter) {
final List list = iterToList(iter);
for (Object obj : list) {
if (obj instanceof PersistentObject) {
// our object type
final PersistentObject entity = (PersistentObject) obj;
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("preFlush -> id={}, entity={}", entity.getPrimaryKey(), entity);
} else {
LOGGER.info("preFlush -> id={}, entityClass={}", entity.getPrimaryKey(), entity.getClass().getName());
}
logLimitedAccessRecord(obj, "preFlush");
final Class<?> klazz = entity.getClass();
if (handlers.containsKey(klazz)) {
LOGGER.info("handler for class {}", klazz);
handlers.get(klazz).accept(entity);
}
}
}
}
use of gov.ca.cwds.data.persistence.PersistentObject in project cals-api by ca-cwds.
the class StateReferentialIntegrityValidator method getPersistentObject.
@Override
protected <T extends PersistentObject> PersistentObject getPersistentObject(Session currentSession, T obj, Serializable primaryKey) {
PersistentObject found;
Query<StateType> query = currentSession.createNamedQuery(NAMED_QUERY_FIND_STATE_BY_CODE, StateType.class);
query.setParameter("stateCode", primaryKey);
found = query.uniqueResult();
return found;
}
use of gov.ca.cwds.data.persistence.PersistentObject in project cals-api by ca-cwds.
the class AbstractReferentialIntegrityValidator method checkReferentialIntegrity.
protected <T extends PersistentObject> boolean checkReferentialIntegrity(Session currentSession, T obj) {
PersistentObject found = null;
Serializable primaryKey = obj.getPrimaryKey();
if (primaryKey != null) {
found = getPersistentObject(currentSession, obj, primaryKey);
}
boolean valid = found != null;
if (valid && isCheckEqualityRequired()) {
valid = found.equals(obj);
}
if (valid && isEnrichmentRequired()) {
List<Field> fields = getAllFields(new LinkedList<>(), obj.getClass());
T finalFound = (T) found;
fields.stream().filter(field -> !Modifier.isStatic(field.getModifiers())).forEach(field -> {
try {
field.setAccessible(true);
field.set(obj, field.get(finalFound));
} catch (IllegalAccessException e) {
throw new IllegalArgumentException(e);
}
});
}
return valid;
}
Aggregations