List of usage examples for javax.ejb TransactionAttributeType REQUIRED
TransactionAttributeType REQUIRED
To view the source code for javax.ejb TransactionAttributeType REQUIRED.
Click Source Link
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) private Link cloneLink(String root, Link origin, int clock) throws CloneException { LOGGER.log(Level.FINE, "cloning link for origin [" + origin + "]"); try {// w w w. ja v a 2s . c o m String key = UUID.randomUUID().toString(); Link clone = new Link(); clone.setId(UUID.randomUUID().toString()); clone.setName(origin.getName()); clone.setTarget(origin.getTarget()); clone.setClock(clock); Set<MetadataElement> metadatas = new HashSet<MetadataElement>(); for (MetadataElement mde : origin.getMetadatas()) { MetadataObject mdclone = cloneMetadataObject(root, mde.getKey(), key); metadatas.add(new MetadataElement(mde.getName(), mdclone.getKey())); } clone.setMetadatas(metadatas); clone.setKey(key); em.persist(clone); registry.register(key, clone.getObjectIdentifier(), origin.getKey(), true); indexing.index(key); authorisation.clonePolicy(key, root); return clone; } catch (RegistryServiceException | IdentifierAlreadyRegisteredException | AuthorisationServiceException | KeyAlreadyExistsException | KeyNotFoundException | IndexingServiceException e) { throw new CloneException("unable to clone link with origin [" + origin + "]", e); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) private MetadataObject cloneMetadataObject(String root, String origin, String target) throws CloneException { LOGGER.log(Level.FINE, "clone metadata for origin [" + origin + "], target [" + target + "]"); try {/*from w w w .ja v a 2s . c o m*/ String key = UUID.randomUUID().toString(); OrtolangObjectIdentifier identifier = registry.lookup(origin); checkObjectType(identifier, MetadataObject.OBJECT_TYPE); MetadataObject meta = em.find(MetadataObject.class, identifier.getId()); if (meta == null) { throw new CoreServiceException( "unable to load metadata with id [" + identifier.getId() + "] from storage"); } MetadataObject clone = new MetadataObject(); clone.setId(UUID.randomUUID().toString()); clone.setName(meta.getName()); clone.setTarget(target); clone.setSize(meta.getSize()); clone.setFormat(meta.getFormat()); clone.setContentType(meta.getContentType()); clone.setStream(meta.getStream()); clone.setKey(key); em.persist(clone); registry.register(key, clone.getObjectIdentifier(), origin, true); indexing.index(target); authorisation.clonePolicy(key, root); return clone; } catch (RegistryServiceException | IdentifierAlreadyRegisteredException | AuthorisationServiceException | CoreServiceException | KeyNotFoundException | KeyAlreadyExistsException | IndexingServiceException e) { throw new CloneException( "unable to clone metadata with origin [" + origin + "] and target [" + target + "]", e); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) private void deleteCollectionContent(Collection collection, int clock) throws CoreServiceException, RegistryServiceException, KeyNotFoundException, KeyLockedException, IndexingServiceException { LOGGER.log(Level.FINE, "delete content for collection with id [" + collection.getId() + "]"); for (CollectionElement element : collection.getElements()) { switch (element.getType()) { case Collection.OBJECT_TYPE: { OrtolangObjectIdentifier identifier = registry.lookup(element.getKey()); checkObjectType(identifier, Collection.OBJECT_TYPE); Collection coll = em.find(Collection.class, identifier.getId()); if (coll == null) { throw new CoreServiceException( "unable to load collection with id [" + identifier.getId() + "] from storage"); }/*from w w w. j a v a2s .c o m*/ if (coll.getClock() == clock) { deleteCollectionContent(coll, clock); LOGGER.log(Level.FINEST, "collection clock [" + coll.getClock() + "] is the same, key can be deleted and unindexed"); for (MetadataElement mde : coll.getMetadatas()) { registry.delete(mde.getKey()); } registry.delete(element.getKey()); indexing.remove(element.getKey()); } break; } case DataObject.OBJECT_TYPE: { OrtolangObjectIdentifier identifier = registry.lookup(element.getKey()); checkObjectType(identifier, DataObject.OBJECT_TYPE); DataObject object = em.find(DataObject.class, identifier.getId()); if (object == null) { throw new CoreServiceException( "unable to load object with id [" + identifier.getId() + "] from storage"); } if (object.getClock() == clock) { LOGGER.log(Level.FINEST, "object clock [" + object.getClock() + "] is the same, key can be deleted and unindexed"); for (MetadataElement mde : object.getMetadatas()) { registry.delete(mde.getKey()); } registry.delete(element.getKey()); indexing.remove(element.getKey()); } break; } case Link.OBJECT_TYPE: { OrtolangObjectIdentifier identifier = registry.lookup(element.getKey()); checkObjectType(identifier, Link.OBJECT_TYPE); Link link = em.find(Link.class, identifier.getId()); if (link == null) { throw new CoreServiceException( "unable to load link with id [" + identifier.getId() + "] from storage"); } if (link.getClock() == clock) { LOGGER.log(Level.FINEST, "link clock [" + link.getClock() + "] is the same, key can be deleted and unindexed"); for (MetadataElement mde : link.getMetadatas()) { registry.delete(mde.getKey()); } registry.delete(element.getKey()); indexing.remove(element.getKey()); } break; } } } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) private void purgeChildrenMetadata(Collection collection, String wskey, String path, String name) throws OrtolangException, KeyNotFoundException, InvalidPathException, PathNotFoundException, WorkspaceReadOnlyException, CoreServiceException, RegistryServiceException { LOGGER.log(Level.FINE, "purging children metadata for path: " + path + " and name: " + name); MetadataElement metadataElement;//from w w w. ja v a2 s .c o m OrtolangObjectIdentifier identifier; for (CollectionElement collectionElement : collection.getElements()) { metadataElement = null; identifier = registry.lookup(collectionElement.getKey()); switch (collectionElement.getType()) { case Collection.OBJECT_TYPE: Collection subCollection = em.find(Collection.class, identifier.getId()); metadataElement = subCollection.findMetadataByName(name); LOGGER.log(Level.FINE, "path is a collection, calling recursively purgeChildrenMetadata()"); purgeChildrenMetadata(subCollection, wskey, path + "/" + subCollection.getName(), name); break; case DataObject.OBJECT_TYPE: DataObject dataObject = em.find(DataObject.class, identifier.getId()); metadataElement = dataObject.findMetadataByName(name); break; case Link.OBJECT_TYPE: Link link = em.find(Link.class, identifier.getId()); metadataElement = link.findMetadataByName(name); break; } if (metadataElement != null) { LOGGER.log(Level.FINE, "metadata to purge: " + metadataElement.getKey()); deleteMetadataObject(wskey, path + "/" + collectionElement.getName(), name, false); } } }