List of usage examples for org.springframework.dao DataIntegrityViolationException DataIntegrityViolationException
public DataIntegrityViolationException(String msg)
From source file:org.alfresco.repo.domain.node.AbstractNodeDAOImpl.java
private ParentAssocsInfo loadParentAssocs(NodeVersionKey nodeVersionKey) { Long nodeId = nodeVersionKey.getNodeId(); // Find out if it is a root or store root boolean isRoot = hasNodeAspect(nodeId, ContentModel.ASPECT_ROOT); boolean isStoreRoot = getNodeType(nodeId).equals(ContentModel.TYPE_STOREROOT); // Select all the parent associations List<ChildAssocEntity> assocs = selectParentAssocs(nodeId); // Build the cache object ParentAssocsInfo value = new ParentAssocsInfo(isRoot, isStoreRoot, assocs); // Now check if we are seeing the correct version of the node if (assocs.isEmpty()) { // No results. // Nodes without parents are root nodes or deleted nodes. The latter will not normally // be accessed here but it is possible. // To match earlier fixes of ALF-12393, we do a double-check of the node's details. NodeEntity nodeCheckFromDb = selectNodeById(nodeId); if (nodeCheckFromDb == null || !nodeCheckFromDb.getNodeVersionKey().equals(nodeVersionKey)) { // The node is gone or has moved on in version invalidateNodeCaches(nodeId); throw new DataIntegrityViolationException( "Detected stale node entry: " + nodeVersionKey + " (now " + nodeCheckFromDb + ")"); }//from w w w.j a v a2 s .c om } else { ChildAssocEntity childAssoc = assocs.get(0); // What is the real (at least to this txn) version of the child node? NodeVersionKey childNodeVersionKeyFromDb = childAssoc.getChildNode().getNodeVersionKey(); if (!childNodeVersionKeyFromDb.equals(nodeVersionKey)) { // This method was called with a stale version invalidateNodeCaches(nodeId); throw new DataIntegrityViolationException("Detected stale node entry: " + nodeVersionKey + " (now " + childNodeVersionKeyFromDb + ")"); } } return value; }
From source file:de.knurt.fam.core.util.mail.UserMailSender.java
private static boolean send(UserMail um) { boolean sendSucc = false; UserMailSender dse = getInstance();// w ww.ja v a 2 s .co m if (um.hasBeenSent() == false) { if (um.mustBeSendNow()) { // prepare SimpleEmail email = new SimpleEmail(); email.setHostName(dse.hostName); email.setSmtpPort(dse.smtpPort); // mail server using pass if (dse.authName != null) { email.setAuthentication(dse.authName, dse.authPass); } Map<String, String> headers = new Hashtable<String, String>(); // headers.put("Subject", um.getSubject()); email.setSubject(um.getSubject()); headers.put("Content-Type", "text/plain; charset=utf-8"); headers.put("Content-Transfer-Encoding", "base64"); email.setHeaders(headers); boolean creatingSucc = false; try { email.addTo(um.getTo(), um.getUsername()); email.setFrom(dse.fromMail, dse.fromName); email.setMsg(um.getMsg()); creatingSucc = true; } catch (EmailException ex) { FamLog.logException(UserMailSender.class, ex, "creating mail failed::" + um.getTo() + "::" + um.getUsername() + "::" + um.getId(), 200904031116l); } if (creatingSucc && FamConnector.isDev() == false) { try { email.send(); sendSucc = true; } catch (EmailException ex) { FamLog.exception("sending a mail failed: " + ex.getMessage() + "-" + dse.fromMail + "-" + dse.fromName, ex, 200904031018l); } } else { // just dev mode - do not send any mails sendSucc = true; } } } else { FamLog.logException(UserMailSender.class, new DataIntegrityViolationException("try to send a mail twice"), "try to send a mail twice", 200908201836l); } return sendSucc; }
From source file:it.doqui.index.ecmengine.business.personalization.splitting.SplittingDbNodeServiceImpl.java
/** * Checks the dictionary's definition of the association to assign a unique name to the child node. * * @param assocTypeQName the type of the child association * @param childNode the child node being added. The name will be extracted from it, if necessary. * @return Returns the value to be put on the child association for uniqueness, or null if *///from w ww.ja v a 2s . c om private void setChildUniqueName(Node childNode) { logger.debug("[SplittingDbNodeServiceImpl::setChildUniqueName] BEGIN"); try { Map<QName, PropertyValue> properties = childNode.getProperties(); PropertyValue nameValue = properties.get(ContentModel.PROP_NAME); String useName = null; useName = (nameValue == null) ? childNode.getUuid() : (String) nameValue.getValue(DataTypeDefinition.TEXT); // get all the parent assocs Collection<ChildAssoc> parentAssocs = nodeDaoService.getParentAssocs(childNode); for (ChildAssoc assoc : parentAssocs) { /* * TODO: se il nodo padre e` splittato il controllo dovrebbe essere propagato anche alle * altre parti per evitare che nel complesso ci possano essere figli duplicati. * * Questa modifica potrebbe richiedere una modifica alla API del nodeServiceDao. */ QName assocTypeQName = assoc.getTypeQName(); AssociationDefinition assocDef = dictionaryService.getAssociation(assocTypeQName); if (!assocDef.isChild()) { throw new DataIntegrityViolationException( "Child association has non-child type: " + assoc.getId()); } ChildAssociationDefinition childAssocDef = (ChildAssociationDefinition) assocDef; nodeDaoService.setChildNameUnique(assoc, (childAssocDef.getDuplicateChildNamesAllowed()) ? null : useName); } if (logger.isDebugEnabled()) { logger.debug("[SplittingDbNodeServiceImpl::setChildUniqueName] Unique name set for all " + parentAssocs.size() + " parent associations: \n" + " name: " + useName); } } finally { logger.debug("[SplittingDbNodeServiceImpl::setChildUniqueName] END"); } }
From source file:nl.strohalm.cyclos.services.ads.AdCategoryServiceImpl.java
@Override public int remove(final Long... ids) { final AdQuery adQuery = new AdQuery(); adQuery.setPageForCount();/* w ww . ja va 2 s. c o m*/ for (final Long id : ids) { adQuery.setCategory(EntityHelper.reference(AdCategory.class, id)); if (PageHelper.getTotalCount(adService.search(adQuery)) > 0) { throw new DaoException(new DataIntegrityViolationException("category")); } } invalidateCache(); return adCategoryDao.delete(ids); }
From source file:org.acegisecurity.acl.basic.jdbc.JdbcExtendedDaoImpl.java
public void create(BasicAclEntry basicAclEntry) throws DataAccessException { // Create acl_object_identity record if required createAclObjectIdentityIfRequired(basicAclEntry); // Only continue if a recipient is specifed (null recipient indicates // just wanted to ensure the acl_object_identity was created) if (basicAclEntry.getRecipient() == null) { return;/*from w w w .j av a2s. c o m*/ } // Retrieve acl_object_identity record details AclDetailsHolder aclDetailsHolder = lookupAclDetailsHolder(basicAclEntry.getAclObjectIdentity()); // Ensure there isn't an existing record for this recipient long permissionId = lookupPermissionId(aclDetailsHolder.getForeignKeyId(), basicAclEntry.getRecipient()); if (permissionId != -1) { throw new DataIntegrityViolationException( "Recipient '" + basicAclEntry.getRecipient() + "' already exists for aclObjectIdentity ID " + aclDetailsHolder.getForeignKeyId() + " (permission ID " + ")"); } // Create acl_permission aclPermissionInsert.insert(new Long(aclDetailsHolder.getForeignKeyId()), basicAclEntry.getRecipient().toString(), new Integer(basicAclEntry.getMask())); }
From source file:org.alfresco.repo.domain.audit.AbstractAuditDAOImpl.java
public void updateAuditApplicationModel(Long id, Long modelId) { AuditApplicationEntity entity = getAuditApplicationById(id); if (entity == null) { throw new DataIntegrityViolationException("No audit application exists for ID " + id); }// www . j a v a 2 s .com if (entity.getAuditModelId().equals(modelId)) { // There is nothing to update return; } // Update entity.setAuditModelId(modelId); updateAuditApplication(entity); }
From source file:org.alfresco.repo.domain.audit.AbstractAuditDAOImpl.java
@SuppressWarnings("unchecked") public void updateAuditApplicationDisabledPaths(Long id, Set<String> disabledPaths) { AuditApplicationEntity entity = getAuditApplicationById(id); if (entity == null) { throw new DataIntegrityViolationException("No audit application exists for ID " + id); }/* w ww .ja va 2 s . co m*/ // Resolve the current set Long disabledPathsId = entity.getDisabledPathsId(); Set<String> oldDisabledPaths = (Set<String>) propertyValueDAO.getPropertyById(disabledPathsId); if (oldDisabledPaths.equals(disabledPaths)) { // Nothing changed return; } // Update the property propertyValueDAO.updateProperty(disabledPathsId, (Serializable) disabledPaths); // Do a precautionary update to ensure that the application row is locked appropriately updateAuditApplication(entity); }
From source file:org.alfresco.repo.domain.contentdata.AbstractContentDataDAOImpl.java
@Override public Pair<Long, ContentData> getContentData(Long id) { if (id == null) { throw new IllegalArgumentException("Cannot look up ContentData by null ID."); }// ww w.ja v a 2s . c om Pair<Long, ContentData> entityPair = contentDataCache.getByKey(id); if (entityPair == null) { throw new DataIntegrityViolationException("No ContentData value exists for ID " + id); } return entityPair; }
From source file:org.alfresco.repo.domain.contentdata.AbstractContentDataDAOImpl.java
/** * Translates this instance into an externally-usable <code>ContentData</code> instance. *///from w w w.j ava 2 s .c o m 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; }
From source file:org.alfresco.repo.domain.contentdata.AbstractContentDataDAOImpl.java
/** * Translates the {@link ContentData} into persistable values using the helper DAOs */// w w w. j a v a2 s . c o m 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); }