use of com.evolveum.midpoint.repo.sql.SerializationRelatedException in project midpoint by Evolveum.
the class ObjectUpdater method handleConstraintViolationException.
private void handleConstraintViolationException(Session session, ConstraintViolationException ex, OperationResult result) {
// BRUTAL HACK - in PostgreSQL, concurrent changes in parentRefOrg sometimes cause the following exception
// "duplicate key value violates unique constraint "XXXX". This is *not* an ObjectAlreadyExistsException,
// more likely it is a serialization-related one.
//
// TODO: somewhat generalize this approach - perhaps by retrying all operations not dealing with OID/name uniqueness
SQLException sqlException = baseHelper.findSqlException(ex);
if (sqlException != null) {
SQLException nextException = sqlException.getNextException();
LOGGER.debug("ConstraintViolationException = {}; SQL exception = {}; embedded SQL exception = {}", new Object[] { ex, sqlException, nextException });
String[] ok = new String[] { "duplicate key value violates unique constraint \"m_org_closure_pkey\"", "duplicate key value violates unique constraint \"m_reference_pkey\"" };
String msg1;
if (sqlException.getMessage() != null) {
msg1 = sqlException.getMessage();
} else {
msg1 = "";
}
String msg2;
if (nextException != null && nextException.getMessage() != null) {
msg2 = nextException.getMessage();
} else {
msg2 = "";
}
for (int i = 0; i < ok.length; i++) {
if (msg1.contains(ok[i]) || msg2.contains(ok[i])) {
baseHelper.rollbackTransaction(session, ex, result, false);
throw new SerializationRelatedException(ex);
}
}
}
}
use of com.evolveum.midpoint.repo.sql.SerializationRelatedException in project midpoint by Evolveum.
the class ObjectUpdater method createDataObjectFromJAXB.
public <T extends ObjectType> RObject createDataObjectFromJAXB(PrismObject<T> prismObject, PrismIdentifierGenerator idGenerator) throws SchemaException {
IdGeneratorResult generatorResult = idGenerator.generate(prismObject);
T object = prismObject.asObjectable();
RObject rObject;
Class<? extends RObject> clazz = ClassMapper.getHQLTypeClass(object.getClass());
try {
rObject = clazz.getConstructor().newInstance();
// Note that methods named "copyFromJAXB" that were _not_ called from this point were renamed e.g. to "fromJaxb",
// in order to avoid confusion with dynamically called "copyFromJAXB" method.
Method method = clazz.getMethod("copyFromJAXB", object.getClass(), clazz, RepositoryContext.class, IdGeneratorResult.class);
method.invoke(clazz, object, rObject, new RepositoryContext(repositoryService, prismContext, relationRegistry, extItemDictionary, baseHelper.getConfiguration()), generatorResult);
} catch (Exception ex) {
SerializationRelatedException serializationException = ExceptionUtil.findCause(ex, SerializationRelatedException.class);
if (serializationException != null) {
throw serializationException;
}
ConstraintViolationException cve = ExceptionUtil.findCause(ex, ConstraintViolationException.class);
if (cve != null && baseHelper.isSerializationRelatedConstraintViolationException(cve)) {
throw cve;
}
String message = ex.getMessage();
if (StringUtils.isEmpty(message) && ex.getCause() != null) {
message = ex.getCause().getMessage();
}
throw new SchemaException(message, ex);
}
return rObject;
}
Aggregations