Search in sources :

Example 1 with ForeignKeyConstraintViolationException

use of org.jowidgets.cap.common.api.exception.ForeignKeyConstraintViolationException in project jo-client-platform by jo-source.

the class HibernateOracleExceptionDecoratorImpl method decorate.

@Override
public Throwable decorate(final Throwable original) {
    if (original instanceof PersistenceException) {
        final PersistenceException persistenceException = (PersistenceException) original;
        final Throwable cause = persistenceException.getCause();
        if (cause instanceof ConstraintViolationException) {
            final String constraintName = getConstraintName((ConstraintViolationException) cause);
            if (!EmptyCheck.isEmpty(constraintName)) {
                final ConstraintType constraintType = getConstraintType(constraintName);
                if (constraintType == ConstraintType.FK) {
                    return new ForeignKeyConstraintViolationException();
                } else if (constraintType != ConstraintType.UNSUPPORTED) {
                    final List<String> properties = getViolatedProperties(constraintName, constraintType);
                    if (!EmptyCheck.isEmpty(properties)) {
                        return new UniqueConstraintViolationException(properties);
                    }
                }
            }
        }
    }
    return original;
}
Also used : PersistenceException(javax.persistence.PersistenceException) UniqueConstraintViolationException(org.jowidgets.cap.common.api.exception.UniqueConstraintViolationException) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) ForeignKeyConstraintViolationException(org.jowidgets.cap.common.api.exception.ForeignKeyConstraintViolationException) List(java.util.List) LinkedList(java.util.LinkedList) ForeignKeyConstraintViolationException(org.jowidgets.cap.common.api.exception.ForeignKeyConstraintViolationException) UniqueConstraintViolationException(org.jowidgets.cap.common.api.exception.UniqueConstraintViolationException)

Aggregations

LinkedList (java.util.LinkedList)1 List (java.util.List)1 PersistenceException (javax.persistence.PersistenceException)1 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)1 ForeignKeyConstraintViolationException (org.jowidgets.cap.common.api.exception.ForeignKeyConstraintViolationException)1 UniqueConstraintViolationException (org.jowidgets.cap.common.api.exception.UniqueConstraintViolationException)1