List of usage examples for org.springframework.dao ConcurrencyFailureException ConcurrencyFailureException
public ConcurrencyFailureException(String msg)
From source file:ar.com.zauber.commons.repository.BaseModifiableEntity.java
/** @see Modifiable#setVersion(Long) */ public final void setVersion(final Long version) { // The application must not alter the version number set up // by Hibernate in any way. // Permite implementar Optimistic Offline Lock pattern if (this.version != null && !this.version.equals(version)) { throw new ConcurrencyFailureException("Optimistic locking exception: versions differs"); }/*from w w w.j ava 2s. c o m*/ }
From source file:org.alfresco.module.daos.mongo.MongoNodeDAOImpl.java
@Override protected void insertNodeAspect(Long nodeId, Long qnameId) { // Get the current transaction ID. Long txnId = getCurrentTransactionId(true); // Resolve the QName QName qname = qnameDAO.getQName(qnameId).getSecond(); String qnameStr = qname.toString(); DBObject insertObj = BasicDBObjectBuilder.start().add(FIELD_NODE_ID, nodeId).add(FIELD_TXN_ID, txnId) .add(FIELD_QNAME, qnameStr).get(); WriteResult result = aspects.insert(insertObj); if (result.getError() != null) { throw new ConcurrencyFailureException("Failed to insert aspect: " + result + "\n" + " Node ID: " + nodeId + "\n" + " QName: " + qnameStr + "\n" + " Txn ID: " + txnId); }//ww w .j a v a 2 s .c o m if (duplicateToSql) { // Duplicate super.insertNodeAspect(nodeId, qnameId); } }
From source file:org.alfresco.repo.model.ml.MultilingualContentServiceImpl2.java
/** @inheritDoc */ public void deleteTranslationContainer(NodeRef mlContainerNodeRef) { if (!ContentModel.TYPE_MULTILINGUAL_CONTAINER.equals(nodeService.getType(mlContainerNodeRef))) { throw new IllegalArgumentException("Node type must be " + ContentModel.TYPE_MULTILINGUAL_CONTAINER); }/* ww w. j ava 2s . c o m*/ // get the translations Map<Locale, NodeRef> translations = this.getTranslations(mlContainerNodeRef); // remember the number of childs int translationCount = translations.size(); // remove the translations for (NodeRef translationToRemove : translations.values()) { if (!nodeService.exists(translationToRemove)) { // We've just queried for these throw new ConcurrencyFailureException( "Translation has been deleted externally: " + translationToRemove); } nodeService.deleteNode(translationToRemove); } // Keep track of the container for pre-commit deletion TransactionalResourceHelper.getSet(KEY_ML_CONTAINERS_TO_DELETE).add(mlContainerNodeRef); AlfrescoTransactionSupport.bindListener(mlContainerCleaner); // done if (logger.isDebugEnabled()) { logger.debug("ML container removed: \n" + " Container: " + mlContainerNodeRef + "\n" + " Number of translations: " + translationCount); } }
From source file:org.geowebcache.diskquota.jdbc.JDBCQuotaStore.java
public void addToQuotaAndTileCounts(final TileSet tileSet, final Quota quotaDiff, final Collection<PageStatsPayload> tileCountDiffs) throws InterruptedException { tt.execute(new TransactionCallbackWithoutResult() { @Override/* w w w . j ava 2 s .c o m*/ protected void doInTransactionWithoutResult(TransactionStatus status) { getOrCreateTileSet(tileSet); updateQuotas(tileSet, quotaDiff); if (tileCountDiffs != null) { // sort the payloads by page id as a deadlock avoidance measure, out // of order updates may result in deadlock with the addHitsAndSetAccessTime method List<PageStatsPayload> sorted = sortPayloads(tileCountDiffs); for (PageStatsPayload payload : sorted) { upsertTilePageFillFactor(payload); } } } private void updateQuotas(final TileSet tileSet, final Quota quotaDiff) { if (log.isDebugEnabled()) { log.info("Applying quota diff " + quotaDiff.getBytes() + " on tileset " + tileSet); } String updateQuota = dialect.getUpdateQuotaStatement(schema, "tileSetId", "bytes"); Map<String, Object> params = new HashMap<String, Object>(); params.put("tileSetId", tileSet.getId()); params.put("bytes", new BigDecimal(quotaDiff.getBytes())); jt.update(updateQuota, params); params.put("tileSetId", GLOBAL_QUOTA_NAME); jt.update(updateQuota, params); } private void upsertTilePageFillFactor(PageStatsPayload payload) { if (log.isDebugEnabled()) { log.info("Applying page stats payload " + payload); } // see http://en.wikipedia.org/wiki/Merge_(SQL) // Even the Merge command that some databases support is prone to race conditions // under concurrent load, but we don't want to lose data and it's difficult to // tell apart the race conditions from other failures, so we use tolerant commands // and loop over them. // Loop conditions: we find the page stats, but they are deleted before we can // update // them, we don't find the page stats, but they are inserted before we can do so, in // both cases we re-start from zero TilePage page = payload.getPage(); final byte level = page.getZoomLevel(); final BigInteger tilesPerPage = calculator.getTilesPerPage(tileSet, level); int modified = 0; int count = 0; while (modified == 0 && count < maxLoops) { try { count++; PageStats stats = getPageStats(page.getKey()); if (stats != null) { float oldFillFactor = stats.getFillFactor(); stats.addTiles(payload.getNumTiles(), tilesPerPage); // if no change, bail out early if (oldFillFactor == stats.getFillFactor()) { return; } // update the record in the db modified = updatePageFillFactor(page, stats, oldFillFactor); } else { // create the stats and update the fill factor stats = new PageStats(0); stats.addTiles(payload.getNumTiles(), tilesPerPage); modified = createNewPageStats(stats, page); } } catch (DeadlockLoserDataAccessException e) { if (log.isDebugEnabled()) { log.debug("Deadlock while updating page stats, will retry", e); } } } if (modified == 0) { throw new ConcurrencyFailureException("Failed to create or update page stats for page " + payload.getPage() + " after " + count + " attempts"); } } }); }
From source file:org.geowebcache.diskquota.jdbc.JDBCQuotaStore.java
@SuppressWarnings("unchecked") public Future<List<PageStats>> addHitsAndSetAccesTime(final Collection<PageStatsPayload> statsUpdates) { return executor.submit(new Callable<List<PageStats>>() { public List<PageStats> call() throws Exception { return (List<PageStats>) tt.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { List<PageStats> result = new ArrayList<PageStats>(); if (statsUpdates != null) { // sort the payloads by page id as a deadlock avoidance measure, out // of order updates may result in deadlock with the addHitsAndSetAccessTime method List<PageStatsPayload> sorted = sortPayloads(statsUpdates); for (PageStatsPayload payload : sorted) { // verify the stats are referring to an existing tile set id TileSet tset = payload.getTileSet(); if (tset == null) { String tileSetId = payload.getPage().getTileSetId(); tset = getTileSetByIdInternal(tileSetId); if (tset == null) { log.warn("Could not locate tileset with id " + tileSetId + ", skipping page stats update: " + payload); }/*from www . ja v a 2 s . c o m*/ } else { getOrCreateTileSet(tset); } // update the stats PageStats stats = upsertTilePageHitAccessTime(payload); result.add(stats); } } return result; } private PageStats upsertTilePageHitAccessTime(PageStatsPayload payload) { TilePage page = payload.getPage(); if (log.isDebugEnabled()) { log.info("Updating page " + page + " with payload " + payload); } int modified = 0; int count = 0; PageStats stats = null; while (modified == 0 && count < maxLoops) { try { count++; stats = getPageStats(page.getKey()); if (stats != null) { // gather the old values, we'll use them for the optimistic locking final BigInteger oldHits = stats.getNumHits(); final float oldFrequency = stats.getFrequencyOfUsePerMinute(); final int oldAccessTime = stats.getLastAccessTimeMinutes(); // update the page so that it computes the new stats updatePageStats(payload, page, stats); // update the record in the db String update = dialect.updatePageStats(schema, "key", "newHits", "oldHits", "newFrequency", "oldFrequency", "newAccessTime", "oldAccessTime"); Map<String, Object> params = new HashMap<String, Object>(); params.put("key", page.getKey()); params.put("newHits", new BigDecimal(stats.getNumHits())); params.put("oldHits", new BigDecimal(oldHits)); params.put("newFrequency", stats.getFrequencyOfUsePerMinute()); params.put("oldFrequency", oldFrequency); params.put("newAccessTime", stats.getLastAccessTimeMinutes()); params.put("oldAccessTime", oldAccessTime); modified = jt.update(update, params); } else { // create the new stats and insert it stats = new PageStats(0); updatePageStats(payload, page, stats); modified = createNewPageStats(stats, page); } } catch (DeadlockLoserDataAccessException e) { if (log.isDebugEnabled()) { log.debug("Deadlock while updating page stats, will retry", e); } } } if (modified == 0) { throw new ConcurrencyFailureException("Failed to create or update page stats for page " + payload.getPage() + " after " + count + " attempts"); } return stats; } private void updatePageStats(PageStatsPayload payload, TilePage page, PageStats stats) { final int addedHits = payload.getNumHits(); final int lastAccessTimeMinutes = (int) (payload.getLastAccessTime() / 1000 / 60); final int creationTimeMinutes = page.getCreationTimeMinutes(); stats.addHitsAndAccessTime(addedHits, lastAccessTimeMinutes, creationTimeMinutes); } }); } }); }
From source file:org.alfresco.repo.domain.node.AbstractNodeDAOImpl.java
@Override public void moveStore(StoreRef oldStoreRef, StoreRef newStoreRef) { StoreEntity store = getStoreNotNull(oldStoreRef); store.setProtocol(newStoreRef.getProtocol()); store.setIdentifier(newStoreRef.getIdentifier()); // Update it//from ww w .j a v a 2s. c om int count = updateStore(store); if (count != 1) { throw new ConcurrencyFailureException("Store not updated: " + oldStoreRef); } // Bring all the associated nodes into the current transaction Long txnId = getCurrentTransaction().getId(); Long storeId = store.getId(); updateNodesInStore(txnId, storeId); // All the NodeRef-based caches are invalid. ID-based caches are fine. rootNodesCache.removeByKey(oldStoreRef); allRootNodesCache.remove(oldStoreRef); nodesCache.clear(); if (isDebugEnabled) { logger.debug("Moved store: " + oldStoreRef + " --> " + newStoreRef); } }
From source file:org.alfresco.repo.domain.node.AbstractNodeDAOImpl.java
@Override public void setNodeAssocIndex(Long id, int assocIndex) { int updated = updateNodeAssoc(id, assocIndex); if (updated != 1) { throw new ConcurrencyFailureException("Expected to update exactly one row: " + id); }/*from ww w .ja va 2 s .c o m*/ }
From source file:org.alfresco.repo.domain.node.AbstractNodeDAOImpl.java
@Override public int removeNodeAssocs(List<Long> ids) { int toDelete = ids.size(); if (toDelete == 0) { return 0; }/*from w w w. j av a2 s. com*/ int deleted = deleteNodeAssocs(ids); if (toDelete != deleted) { throw new ConcurrencyFailureException("Deleted " + deleted + " but expected " + toDelete); } return deleted; }