Search in sources :

Example 1 with UniqueConstraintViolationException

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

the class UniqueConstraintCheckerImpl method checkCreation.

@Override
public void checkCreation(final Collection<? extends IBeanData> beansData, final IExecutionCallback executionCallback) {
    final IFilter filter = createFilter(beansData);
    final SyncResultCallback<Integer> resultCallback = new SyncResultCallback<Integer>();
    final List<IBeanKey> parentBeanKeys = Collections.emptyList();
    this.readerService.count(resultCallback, parentBeanKeys, filter, null, executionCallback);
    final Integer result = resultCallback.getResultSynchronious();
    if (result != null && result.intValue() > 0) {
        throw new UniqueConstraintViolationException(propertyNames);
    }
}
Also used : IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IFilter(org.jowidgets.cap.common.api.filter.IFilter) SyncResultCallback(org.jowidgets.cap.common.tools.execution.SyncResultCallback) UniqueConstraintViolationException(org.jowidgets.cap.common.api.exception.UniqueConstraintViolationException)

Example 2 with UniqueConstraintViolationException

use of org.jowidgets.cap.common.api.exception.UniqueConstraintViolationException 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

UniqueConstraintViolationException (org.jowidgets.cap.common.api.exception.UniqueConstraintViolationException)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 PersistenceException (javax.persistence.PersistenceException)1 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)1 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)1 ForeignKeyConstraintViolationException (org.jowidgets.cap.common.api.exception.ForeignKeyConstraintViolationException)1 IFilter (org.jowidgets.cap.common.api.filter.IFilter)1 SyncResultCallback (org.jowidgets.cap.common.tools.execution.SyncResultCallback)1