List of usage examples for java.util ConcurrentModificationException ConcurrentModificationException
public ConcurrentModificationException(Throwable cause)
From source file:de.otto.jsonhome.example.products.ProductService.java
public Product createOrUpdateProduct(final Product product, final Product expected) { final boolean replaced = PRODUCTS.replace(product.getId(), expected, product); if (replaced) { return expected; } else {//from w w w . j av a 2 s . co m throw new ConcurrentModificationException("Product was concurrently modified"); } }
From source file:jobhunter.persistence.Persistence.java
private void _save(final File file, final Boolean rewrite) { if (wasModified(file) && !rewrite) throw new ConcurrentModificationException("File has been modified"); ApplicationState.changesPending(false); zip(file);/*from w w w . j av a2s. co m*/ }
From source file:com.appenginefan.toolkit.common.WebConnectionClient.java
/** * Starts a thread (through the executor) that connects to the server on a regular base *//*w w w . ja v a 2 s . c o m*/ public synchronized void open(Receiver receiver) { if (isStarted) { throw new ConcurrentModificationException("Cannot call open more than once!"); } isStarted = true; this.receiver = receiver; env.execute(this); }
From source file:org.libreplan.importers.OrderImporterMPXJ.java
private String getCode(EntityNameEnum entity) { String code = entitySequenceDAO.getNextEntityCode(entity); if (code == null) { throw new ConcurrentModificationException("Could not retrieve Code. Please, try again later"); }/*from w ww . ja v a2 s .c om*/ return code; }
From source file:de.otto.jsonhome.example.products.ProductsController.java
@RequestMapping(value = "/{productId}", method = RequestMethod.PUT, consumes = { "application/example-product", "application/json" }, produces = { "application/example-product", "application/json" }) @ResponseBody/* w w w . j a v a2 s . c o m*/ @Rel("/rel/product") @Hints(preconditionReq = ETAG) public Map<String, ?> putProduct(final @PathVariable long productId, final @RequestBody Map<String, String> document, final HttpServletRequest request, final HttpServletResponse response) throws IOException { final String expectedETag = request.getHeader("If-Match"); final Product expected = productService.findProduct(productId); if (expected == null || expectedETag.equals("*") || expected.getETag().equals(expectedETag)) { final Product product = jsonToProduct(productId, document); final Product previous = productService.createOrUpdateProduct(product, expected); response.setStatus(previous == null ? SC_CREATED : SC_OK); return productToJson(product, request.getContextPath()); } else { throw new ConcurrentModificationException("product was concurrently modified."); } }
From source file:org.libreplan.ws.resources.impl.ResourceServiceREST.java
private void setDefaultCode(EntityNameEnum entityName, IntegrationEntity entity) throws ConcurrentModificationException { String code = entitySequenceDAO.getNextEntityCode(entityName); if (code == null) { throw new ConcurrentModificationException("Could not get code, please try again later"); }//from w ww .j av a2 s. c o m entity.setCode(code); entity.setCodeAutogenerated(true); }
From source file:org.nuxeo.ecm.core.storage.sql.Fragment.java
/** * Checks that access to the fragment is possible. Called internally before * a get, so that invalidated fragments can be refetched. * * @throws StorageException/*from ww w. ja v a 2 s. c o m*/ */ protected void accessed() throws StorageException { switch (state) { case DETACHED: case ABSENT: case PRISTINE: case CREATED: case MODIFIED: case DELETED: break; case INVALIDATED_MODIFIED: State newState = refetch(); // logStateTransition(newState); state = newState; break; case INVALIDATED_DELETED: throw new ConcurrentModificationException("Accessing a concurrently deleted value"); } }
From source file:org.nuxeo.ecm.core.storage.sql.Fragment.java
/** * Marks the fragment modified. Called internally after a put/set. *///from w w w .ja va 2 s. c om protected void markModified() { switch (state) { case ABSENT: context.pristine.remove(id); context.modified.put(id, this); // logStateTransition(State.CREATED); // <--- state = State.CREATED; break; case INVALIDATED_MODIFIED: // can only happen if overwrite all invalidated (array) // fall through case PRISTINE: context.pristine.remove(id); context.modified.put(id, this); // logStateTransition(State.MODIFIED); state = State.MODIFIED; break; case DETACHED: case CREATED: case MODIFIED: case DELETED: break; case INVALIDATED_DELETED: throw new ConcurrentModificationException("Modifying a concurrently deleted value"); } }
From source file:org.zlogic.vogon.web.controller.TransactionsController.java
/** * Updates or creates a new transaction/*ww w .ja v a 2 s.c om*/ * * @param transaction the updated transaction * @param user the authenticated user * @return the transactions from database after update */ @RequestMapping(method = RequestMethod.POST, produces = "application/json") public @ResponseBody FinanceTransactionJson submitTransaction(@RequestBody FinanceTransactionJson transaction, @AuthenticationPrincipal VogonSecurityUser user) { FinanceTransaction existingTransaction = transactionRepository.findByOwnerAndId(user.getUser(), transaction.getId()); //Merge with database if (existingTransaction == null) existingTransaction = new FinanceTransaction(user.getUser(), transaction); else existingTransaction.merge(transaction); List<TransactionComponent> removedComponents = new LinkedList<>(existingTransaction.getComponents()); for (TransactionComponentJson newComponent : transaction.getComponentsJson()) { FinanceAccount existingAccount = accountRepository.findByOwnerAndId(user.getUser(), newComponent.getAccountId()); if (!existingTransaction.getComponents().contains(newComponent)) { TransactionComponent createdComponent = new TransactionComponent(existingAccount, existingTransaction, newComponent.getRawAmount()); em.persist(createdComponent); existingTransaction.addComponent(createdComponent); } else { TransactionComponent existingComponent = existingTransaction.getComponents() .get(existingTransaction.getComponents().indexOf(newComponent)); if (newComponent.getVersion() != existingComponent.getVersion()) throw new ConcurrentModificationException( messages.getString("TRANSACTION_WAS_ALREADY_UPDATED")); existingTransaction.updateComponentAccount(existingComponent, existingAccount); existingTransaction.updateComponentRawAmount(existingComponent, newComponent.getAmount()); removedComponents.remove(existingComponent); } existingTransaction = transactionRepository.save(existingTransaction); accountRepository.save(existingAccount); } //Remove deleted components for (TransactionComponent removedComponent : removedComponents) existingTransaction.removeComponent(removedComponent); existingTransaction = transactionRepository.saveAndFlush(existingTransaction); accountRepository.flush(); return initializationHelper.initializeTransaction(existingTransaction); }
From source file:org.springframework.data.neo4j.fieldaccess.DetachedEntityState.java
private void checkConcurrentModification(final Object entity, final Map.Entry<Neo4jPersistentProperty, ExistingValue> entry, final Neo4jPersistentProperty property, final MappingPolicy mappingPolicy) { final ExistingValue previousValue = entry.getValue(); if (previousValue.mustCheckConcurrentModification()) { final Object nodeValue = unwrap(delegate.getValue(property, mappingPolicy)); if (!ObjectUtils.nullSafeEquals(nodeValue, previousValue.value)) { throw new ConcurrentModificationException("Node " + entity + " field " + property + " changed in between previous " + previousValue + " current " + nodeValue); // todo or just overwrite }/* www .j av a 2 s . c om*/ } }