Example usage for org.springframework.dao DataIntegrityViolationException DataIntegrityViolationException

List of usage examples for org.springframework.dao DataIntegrityViolationException DataIntegrityViolationException

Introduction

In this page you can find the example usage for org.springframework.dao DataIntegrityViolationException DataIntegrityViolationException.

Prototype

public DataIntegrityViolationException(String msg) 

Source Link

Document

Constructor for DataIntegrityViolationException.

Usage

From source file:org.alfresco.repo.domain.propval.AbstractPropertyValueDAOImpl.java

public Pair<Long, Class<?>> getPropertyClassById(Long id) {
    if (id == null) {
        throw new IllegalArgumentException("Cannot look up entity by null ID.");
    }/*from  ww  w  .jav  a 2  s .co m*/
    Pair<Long, Class<?>> entityPair = propertyClassCache.getByKey(id);
    if (entityPair == null) {
        throw new DataIntegrityViolationException("No property class exists for ID " + id);
    }
    return entityPair;
}

From source file:org.alfresco.repo.domain.propval.AbstractPropertyValueDAOImpl.java

public Pair<Long, Date> getPropertyDateValueById(Long id) {
    if (id == null) {
        throw new IllegalArgumentException("Cannot look up entity by null ID.");
    }//w ww.j  a v  a  2 s.c o  m
    Pair<Long, Date> entityPair = propertyDateValueCache.getByKey(id);
    if (entityPair == null) {
        throw new DataIntegrityViolationException("No property date value exists for ID " + id);
    }
    return entityPair;
}

From source file:org.alfresco.repo.domain.propval.AbstractPropertyValueDAOImpl.java

public Pair<Long, String> getPropertyStringValueById(Long id) {
    if (id == null) {
        throw new IllegalArgumentException("Cannot look up entity by null ID.");
    }// w  w w. j a  va  2s  . com
    Pair<Long, String> entityPair = propertyStringValueCache.getByKey(id);
    if (entityPair == null) {
        throw new DataIntegrityViolationException("No property string value exists for ID " + id);
    }
    return entityPair;
}

From source file:org.alfresco.repo.domain.propval.AbstractPropertyValueDAOImpl.java

public Pair<Long, Double> getPropertyDoubleValueById(Long id) {
    if (id == null) {
        throw new IllegalArgumentException("Cannot look up entity by null ID.");
    }//w w w.  j a  v a  2s.c o m
    Pair<Long, Double> entityPair = propertyDoubleValueCache.getByKey(id);
    if (entityPair == null) {
        throw new DataIntegrityViolationException("No property double value exists for ID " + id);
    }
    return entityPair;
}

From source file:org.alfresco.repo.domain.propval.AbstractPropertyValueDAOImpl.java

public Pair<Long, Serializable> getPropertySerializableValueById(Long id) {
    if (id == null) {
        throw new IllegalArgumentException("Cannot look up entity by null ID.");
    }/*  www.  ja  v  a 2 s.c om*/
    Pair<Long, Serializable> entityPair = propertySerializableValueCache.getByKey(id);
    if (entityPair == null) {
        throw new DataIntegrityViolationException("No property serializable value exists for ID " + id);
    }
    return entityPair;
}

From source file:org.alfresco.repo.domain.propval.AbstractPropertyValueDAOImpl.java

public Pair<Long, Serializable> getPropertyValueById(Long id) {
    if (id == null) {
        throw new IllegalArgumentException("Cannot look up entity by null ID.");
    }//w ww.  j a va 2  s  . c o  m
    Pair<Long, Serializable> entityPair = propertyValueCache.getByKey(id);
    if (entityPair == null) {
        throw new DataIntegrityViolationException("No property value exists for ID " + id);
    }
    return entityPair;
}

From source file:org.alfresco.repo.domain.propval.AbstractPropertyValueDAOImpl.java

public Serializable getPropertyById(Long id) {
    if (id == null) {
        throw new IllegalArgumentException("Cannot look up entity by null ID.");
    }// w  w w  .jav a2 s. co m
    Pair<Long, Serializable> entityPair = propertyCache.getByKey(id);
    if (entityPair == null) {
        // Remove from cache
        propertyCache.removeByKey(id);

        throw new DataIntegrityViolationException("No property value exists for ID " + id);
    }
    return entityPair.getSecond();
}

From source file:org.alfresco.repo.domain.propval.AbstractPropertyValueDAOImpl.java

public void updatePropertyUniqueContextKeys(Long id, Serializable value1, Serializable value2,
        Serializable value3) {//from ww  w. j av a 2s .c  o m
    /*
     * Use savepoints so that the PropertyUniqueConstraintViolation can be caught and handled in-transactioin
     */

    // Translate the properties.  Null values are acceptable
    Long id1 = getOrCreatePropertyValue(value1).getFirst();
    Long id2 = getOrCreatePropertyValue(value2).getFirst();
    Long id3 = getOrCreatePropertyValue(value3).getFirst();

    CachePucKey pucKey = getPucKey(id1, id2, id3);

    Savepoint savepoint = controlDAO.createSavepoint("updatePropertyUniqueContext");
    try {
        PropertyUniqueContextEntity entity = getPropertyUniqueContextById(id);
        if (entity == null) {
            // Remove from cache
            propertyUniqueContextCache.remove(pucKey);

            throw new DataIntegrityViolationException("No unique property context exists for id: " + id);
        }
        entity.setValue1PropId(id1);
        entity.setValue2PropId(id2);
        entity.setValue3PropId(id3);

        entity = updatePropertyUniqueContext(entity);

        controlDAO.releaseSavepoint(savepoint);

        // cache
        propertyUniqueContextCache.put(pucKey, entity);

        // Done
        if (logger.isDebugEnabled()) {
            logger.debug("Updated unique property context: \n" + "   ID: " + id + "\n" + "   Values: " + value1
                    + "-" + value2 + "-" + value3);
        }
        return;
    } catch (Throwable e) {
        // Remove from cache
        propertyUniqueContextCache.remove(pucKey);

        controlDAO.rollbackToSavepoint(savepoint);
        throw new PropertyUniqueConstraintViolation(value1, value2, value3, e);
    }
}

From source file:org.alfresco.repo.domain.propval.AbstractPropertyValueDAOImpl.java

public void updatePropertyUniqueContext(Serializable value1, Serializable value2, Serializable value3,
        Serializable propertyValue) {
    // Translate the properties.  Null values are acceptable
    Long id1 = getOrCreatePropertyValue(value1).getFirst();
    Long id2 = getOrCreatePropertyValue(value2).getFirst();
    Long id3 = getOrCreatePropertyValue(value3).getFirst();

    CachePucKey pucKey = getPucKey(id1, id2, id3);

    try {//from   www . j  a  va  2s.  c  o  m
        Pair<Long, Long> entityPair = getPropertyUniqueContext(value1, value2, value3);
        if (entityPair == null) {
            throw new DataIntegrityViolationException(
                    "No unique property context exists for values: " + value1 + "-" + value2 + "-" + value3);
        }

        long id = entityPair.getFirst();
        PropertyUniqueContextEntity entity = getPropertyUniqueContextById(id);
        if (entity == null) {
            throw new DataIntegrityViolationException("No unique property context exists for id: " + id);
        }

        Long propertyId = null;
        if (propertyValue != null) {
            propertyId = createProperty(propertyValue);
        }

        // Create a new property
        entity.setPropertyId(propertyId);

        entity = updatePropertyUniqueContext(entity);

        // cache
        propertyUniqueContextCache.put(pucKey, entity);

        // Done
        if (logger.isDebugEnabled()) {
            logger.debug("Updated unique property context: \n" + "   ID: " + id + "\n" + "   Property: "
                    + propertyId);
        }
    } catch (DataIntegrityViolationException e) {
        // Remove from cache
        propertyUniqueContextCache.remove(pucKey);
        throw e;
    } catch (ConcurrencyFailureException e) {
        // Remove from cache
        propertyUniqueContextCache.remove(pucKey);
        throw e;
    }
}

From source file:org.cloudfoundry.identity.uaa.approval.JdbcApprovalStore.java

public boolean refreshApproval(final Approval approval) {
    logger.debug(String.format("refreshing approval: [%s]", approval));
    int refreshed = jdbcTemplate.update(REFRESH_AUTHZ_SQL, new PreparedStatementSetter() {
        @Override//w  w w. j  a v  a 2 s.  c  o m
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setTimestamp(1, new Timestamp(approval.getLastUpdatedAt().getTime()));
            ps.setTimestamp(2, new Timestamp(approval.getExpiresAt().getTime()));
            ps.setString(3, (approval.getStatus() == null ? APPROVED : approval.getStatus()).toString());
            ps.setString(4, approval.getUserId());
            ps.setString(5, approval.getClientId());
            ps.setString(6, approval.getScope());
        }
    });
    if (refreshed != 1) {
        throw new DataIntegrityViolationException("Attempt to refresh non-existent authorization");
    }
    return true;
}