Search in sources :

Example 61 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project leopard by tanhaichao.

the class ErrorUtil method parseMessage.

/**
 * 获取异常信息.
 *
 * @param e
 * @return
 */
public static String parseMessage(Throwable e) {
    if (e == null) {
        throw new IllegalArgumentException("exception不能为空?");
    }
    String className = e.getClass().getName();
    String message = MESSAGE_MAP.get(className);
    if (message != null) {
        return message;
    }
    if (e instanceof GenericSignatureFormatError) {
        printStartupTime();
        return "更新程序后,还没有重启服务.";
    }
    if (e instanceof NoSuchMethodError) {
        printStartupTime();
        return "NoSuchMethodError:方法找不到.";
    }
    if (e instanceof SQLException) {
        return "操作数据库出错,请稍后重试.";
    }
    if (e instanceof DataIntegrityViolationException) {
        Exception exception = (Exception) e.getCause();
        if (exception instanceof MysqlDataTruncation) {
            return MessageParserImpl.parse((MysqlDataTruncation) exception);
        } else {
            return "操作数据库出错,请稍后重试.";
        }
    // try {
    // return parseDataIntegrityViolationException((DataIntegrityViolationException) e);
    // }
    // catch (Exception e1) {
    // e1.printStackTrace();
    // return "字段太长,请稍后重试.";
    // }
    }
    message = e.getMessage();
    if (message == null) {
        return null;
    }
    return fillterDebugInfo(message);
}
Also used : GenericSignatureFormatError(java.lang.reflect.GenericSignatureFormatError) MysqlDataTruncation(com.mysql.jdbc.MysqlDataTruncation) SQLException(java.sql.SQLException) SQLException(java.sql.SQLException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 62 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project alfresco-repository by Alfresco.

the class MimetypeDAOImpl method updateMimetypeEntity.

@Override
protected int updateMimetypeEntity(Long id, String newMimetype) {
    MimetypeEntity mimetypeEntity = getMimetypeEntity(id);
    if (mimetypeEntity == null) {
        throw new DataIntegrityViolationException("Cannot update mimetype as ID doesn't exist: " + id);
    }
    mimetypeEntity.incrementVersion();
    mimetypeEntity.setMimetype(newMimetype);
    return template.update(UPDATE_MIMETYPE, mimetypeEntity);
}
Also used : MimetypeEntity(org.alfresco.repo.domain.mimetype.MimetypeEntity) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 63 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project alfresco-repository by Alfresco.

the class AbstractContentDataDAOImpl method updateContentDataEntity.

/**
 * Translates the {@link ContentData} into persistable values using the helper DAOs
 */
protected int updateContentDataEntity(ContentDataEntity contentDataEntity, ContentData contentData) {
    // Resolve the content URL
    Long oldContentUrlId = contentDataEntity.getContentUrlId();
    ContentUrlEntity contentUrlEntity = null;
    if (oldContentUrlId != null) {
        Pair<Long, ContentUrlEntity> entityPair = contentUrlCache.getByKey(oldContentUrlId);
        if (entityPair == null) {
            throw new DataIntegrityViolationException("No ContentUrl value exists for ID " + oldContentUrlId);
        }
        contentUrlEntity = entityPair.getSecond();
    }
    String oldContentUrl = (contentUrlEntity != null ? contentUrlEntity.getContentUrl() : null);
    String newContentUrl = contentData.getContentUrl();
    if (!EqualsHelper.nullSafeEquals(oldContentUrl, newContentUrl)) {
        if (oldContentUrl != null) {
            // We have a changed value.  The old content URL has been dereferenced.
            registerDereferencedContentUrl(oldContentUrl);
        }
        if (newContentUrl != null) {
            if (contentUrlEntity == null) {
                contentUrlEntity = new ContentUrlEntity();
                contentUrlEntity.setContentUrl(newContentUrl);
            }
            Pair<Long, ContentUrlEntity> pair = contentUrlCache.getOrCreateByValue(contentUrlEntity);
            Long newContentUrlId = pair.getFirst();
            contentUrlEntity.setId(newContentUrlId);
            contentDataEntity.setContentUrlId(newContentUrlId);
        } else {
            contentDataEntity.setId(null);
            contentDataEntity.setContentUrlId(null);
        }
    }
    // Resolve the mimetype
    Long mimetypeId = null;
    String mimetype = contentData.getMimetype();
    if (mimetype != null) {
        mimetypeId = mimetypeDAO.getOrCreateMimetype(mimetype).getFirst();
    }
    // Resolve the encoding
    Long encodingId = null;
    String encoding = contentData.getEncoding();
    if (encoding != null) {
        encodingId = encodingDAO.getOrCreateEncoding(encoding).getFirst();
    }
    // Resolve the locale
    Long localeId = null;
    Locale locale = contentData.getLocale();
    if (locale != null) {
        localeId = localeDAO.getOrCreateLocalePair(locale).getFirst();
    }
    contentDataEntity.setMimetypeId(mimetypeId);
    contentDataEntity.setEncodingId(encodingId);
    contentDataEntity.setLocaleId(localeId);
    return updateContentDataEntity(contentDataEntity);
}
Also used : Locale(java.util.Locale) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 64 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project alfresco-repository by Alfresco.

the class AbstractContentDataDAOImpl method makeContentData.

/**
 * Translates this instance into an externally-usable <code>ContentData</code> instance.
 */
private ContentData makeContentData(ContentDataEntity contentDataEntity) {
    // Decode content URL
    Long contentUrlId = contentDataEntity.getContentUrlId();
    String contentUrl = null;
    if (contentUrlId != null) {
        Pair<Long, ContentUrlEntity> entityPair = contentUrlCache.getByKey(contentUrlId);
        if (entityPair == null) {
            throw new DataIntegrityViolationException("No ContentUrl value exists for ID " + contentUrlId);
        }
        ContentUrlEntity contentUrlEntity = entityPair.getSecond();
        contentUrl = contentUrlEntity.getContentUrl();
    }
    long size = contentDataEntity.getSize() == null ? 0L : contentDataEntity.getSize().longValue();
    // Decode mimetype
    Long mimetypeId = contentDataEntity.getMimetypeId();
    String mimetype = null;
    if (mimetypeId != null) {
        mimetype = mimetypeDAO.getMimetype(mimetypeId).getSecond();
    }
    // Decode encoding
    Long encodingId = contentDataEntity.getEncodingId();
    String encoding = null;
    if (encodingId != null) {
        encoding = encodingDAO.getEncoding(encodingId).getSecond();
    }
    // Decode locale
    Long localeId = contentDataEntity.getLocaleId();
    Locale locale = null;
    if (localeId != null) {
        locale = localeDAO.getLocalePair(localeId).getSecond();
    }
    // Build the ContentData
    ContentData contentData = new ContentData(contentUrl, mimetype, size, encoding, locale);
    // Done
    return contentData;
}
Also used : Locale(java.util.Locale) ContentData(org.alfresco.service.cmr.repository.ContentData) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 65 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project alfresco-repository by Alfresco.

the class ModelValidatorImpl method validateDeleteClass.

private void validateDeleteClass(final Tenant tenant, final ClassDefinition classDef) {
    final String classType = "TYPE";
    final QName className = classDef.getName();
    String tenantDomain = "for tenant [" + (tenant == null ? TenantService.DEFAULT_DOMAIN : tenant.getTenantDomain()) + "]";
    // We need a separate transaction to do the qname delete "check"
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            try {
                // try to delete it.
                if (qnameDAO.getQName(className) != null) {
                    qnameDAO.deleteQName(className);
                }
                throw new ModelNotInUseException("Class " + className + " not in use");
            } catch (DataIntegrityViolationException e) {
                // catch data integrity violation e.g. foreign key constraint exception
                logger.debug(e);
                throw new ModelInUseException("Cannot delete model, class " + className + " is in use");
            }
        }
    }, false, true);
    // check against workflow task usage
    for (WorkflowDefinition workflowDef : workflowService.getDefinitions()) {
        for (WorkflowTaskDefinition workflowTaskDef : workflowService.getTaskDefinitions(workflowDef.getId())) {
            TypeDefinition workflowTypeDef = workflowTaskDef.metadata;
            if (workflowTypeDef.getName().equals(className)) {
                throw new AlfrescoRuntimeException("Failed to validate model delete" + tenantDomain + " - found task definition in workflow " + workflowDef.getName() + " with " + classType + " '" + className + "'");
            }
        }
    }
}
Also used : QName(org.alfresco.service.namespace.QName) WorkflowTaskDefinition(org.alfresco.service.cmr.workflow.WorkflowTaskDefinition) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)117 Test (org.junit.Test)26 HashMap (java.util.HashMap)12 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Test (org.junit.jupiter.api.Test)10 Transactional (javax.transaction.Transactional)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 User (ca.corefacility.bioinformatics.irida.model.user.User)8 SQLException (java.sql.SQLException)8 ConstraintViolation (javax.validation.ConstraintViolation)8 HashSet (java.util.HashSet)7 Locale (java.util.Locale)6 ConstraintViolationException (javax.validation.ConstraintViolationException)6 Date (java.util.Date)5 List (java.util.List)5 Set (java.util.Set)5 EntityExistsException (ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException)4 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)4 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)4