Search in sources :

Example 1 with SerializationRelatedException

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);
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) SerializationRelatedException(com.evolveum.midpoint.repo.sql.SerializationRelatedException)

Example 2 with SerializationRelatedException

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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RepositoryContext(com.evolveum.midpoint.repo.sql.data.RepositoryContext) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) Method(java.lang.reflect.Method) SerializationRelatedException(com.evolveum.midpoint.repo.sql.SerializationRelatedException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PersistenceException(javax.persistence.PersistenceException) SystemException(com.evolveum.midpoint.util.exception.SystemException) RestartOperationRequestedException(com.evolveum.midpoint.repo.sql.RestartOperationRequestedException) SerializationRelatedException(com.evolveum.midpoint.repo.sql.SerializationRelatedException)

Aggregations

SerializationRelatedException (com.evolveum.midpoint.repo.sql.SerializationRelatedException)2 RestartOperationRequestedException (com.evolveum.midpoint.repo.sql.RestartOperationRequestedException)1 RepositoryContext (com.evolveum.midpoint.repo.sql.data.RepositoryContext)1 RObject (com.evolveum.midpoint.repo.sql.data.common.RObject)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 Method (java.lang.reflect.Method)1 SQLException (java.sql.SQLException)1 PersistenceException (javax.persistence.PersistenceException)1 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)1