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);
}
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);
}
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);
}
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;
}
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 + "'");
}
}
}
}
Aggregations