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:com.flexive.ejb.beans.PhraseEngineBean.java
/** * {@inheritDoc}// w w w.jav a 2 s. c om */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public List<FxPhraseTreeNodePosition> getAssignedNodes(int category, String phraseKey, long... _mandators) { final long ownMandator = FxContext.getUserTicket().getMandatorId(); Connection con = null; PreparedStatement ps = null; long[] mandators = checkMandatorFiltering(_mandators); try { // Obtain a database connection con = Database.getDbConnection(); List<FxPhraseTreeNodePosition> result = Lists.newArrayListWithCapacity(10); final String mandatorQuery = mandators.length == 1 ? "=" + mandators[0] : " IN(" + FxArrayUtils.toStringArray(mandators, ',') + ")"; ps = con.prepareStatement("SELECT m.NODEID,m.NODEMANDATOR,m.POS FROM " + TBL_PHRASE_MAP + " m," + TBL_PHRASE + " p WHERE p.PKEY=? AND p.MANDATOR" + mandatorQuery + " AND p.CAT=? AND m.PHRASEID=p.ID AND m.CAT=p.CAT AND m.DIRECT=? AND m.MANDATOR" + mandatorQuery + " ORDER BY m.NODEMANDATOR,m.NODEID,m.POS"); ps.setString(1, phraseKey); ps.setInt(2, category); ps.setBoolean(3, true); ResultSet rs = ps.executeQuery(); while (rs != null && rs.next()) { try { result.add(new FxPhraseTreeNodePosition(loadPhraseTreeNode(con, false, category, rs.getLong(1), rs.getLong(2), false, mandators), rs.getLong(3))); } catch (FxNotFoundException e) { LOG.error("Failed to load node " + rs.getLong(1) + " (mandator " + rs.getLong(2) + ") found! This should not be possible!"); } } return result; } catch (SQLException exc) { EJBUtils.rollback(ctx); throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException(); } finally { Database.closeObjects(PhraseEngineBean.class, con, ps); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public DataObject readDataObject(String key) throws CoreServiceException, KeyNotFoundException, AccessDeniedException { LOGGER.log(Level.FINE, "reading object with key [" + key + "]"); try {/* w w w . ja v a 2 s . c o m*/ List<String> subjects = membership.getConnectedIdentifierSubjects(); OrtolangObjectIdentifier identifier = registry.lookup(key); checkObjectType(identifier, DataObject.OBJECT_TYPE); authorisation.checkPermission(key, subjects, "read"); DataObject object = em.find(DataObject.class, identifier.getId()); if (object == null) { throw new CoreServiceException( "unable to load object with id [" + identifier.getId() + "] from storage"); } object.setKey(key); return object; } catch (RegistryServiceException | MembershipServiceException | AuthorisationServiceException e) { LOGGER.log(Level.SEVERE, "unexpected error occurred while reading object", e); throw new CoreServiceException("unable to read object with key [" + key + "]", e); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public DataObject updateDataObject(String wskey, String path, String hash) throws CoreServiceException, InvalidPathException, AccessDeniedException, PathNotFoundException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE, "updating object into workspace [" + wskey + "] at path [" + path + "]"); try {/*from w ww .jav a2 s . com*/ PathBuilder npath = PathBuilder.fromPath(path); if (npath.isRoot()) { throw new InvalidPathException("path is empty"); } PathBuilder ppath = npath.clone().parent(); String caller = membership.getProfileKeyForConnectedIdentifier(); List<String> subjects = membership.getConnectedIdentifierSubjects(); authorisation.checkAuthentified(subjects); LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified"); OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey); checkObjectType(wsidentifier, Workspace.OBJECT_TYPE); LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists"); Workspace ws = em.find(Workspace.class, wsidentifier.getId()); if (ws == null) { throw new CoreServiceException( "unable to load workspace with id [" + wsidentifier.getId() + "] from storage"); } if (applyReadOnly(caller, subjects, ws)) { throw new WorkspaceReadOnlyException("unable to update data object in workspace with key [" + wskey + "] because it is read only"); } ws.setKey(wskey); LOGGER.log(Level.FINEST, "workspace loaded"); authorisation.checkPermission(ws.getHead(), subjects, "update"); LOGGER.log(Level.FINEST, "user [" + caller + "] has 'update' permission on the head collection of this workspace"); String current = resolveWorkspacePath(wskey, Workspace.HEAD, npath.build()); OrtolangObjectIdentifier cidentifier = registry.lookup(current); checkObjectType(cidentifier, DataObject.OBJECT_TYPE); DataObject cobject = em.find(DataObject.class, cidentifier.getId()); if (cobject == null) { throw new CoreServiceException( "unable to load object with id [" + cidentifier.getId() + "] from storage"); } cobject.setKey(current); LOGGER.log(Level.FINEST, "current object loaded"); if (!hash.equals(cobject.getStream())) { Collection parent = loadCollectionAtPath(ws.getHead(), ppath, ws.getClock()); LOGGER.log(Level.FINEST, "parent collection loaded for path " + npath.build()); CollectionElement element = parent.findElementByName(npath.part()); if (element == null) { throw new PathNotFoundException(npath.build()); } LOGGER.log(Level.FINEST, "object element found for name " + npath.part()); if (!element.getType().equals(DataObject.OBJECT_TYPE)) { throw new InvalidPathException("path [" + npath.build() + "] is not a data object"); } 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"); } object.setKey(element.getKey()); if (object.getClock() < ws.getClock()) { DataObject clone = cloneDataObject(ws.getHead(), object, ws.getClock()); object = clone; } if (hash.length() > 0) { object.setSize(binarystore.size(hash)); object.setMimeType(binarystore.type(hash, object.getName())); object.setStream(hash); } else { object.setSize(0); object.setMimeType("application/octet-stream"); object.setStream(""); } parent.removeElement(element); CollectionElement celement = new CollectionElement(DataObject.OBJECT_TYPE, object.getName(), System.currentTimeMillis(), object.getSize(), object.getMimeType(), object.getKey()); parent.addElement(celement); em.merge(parent); em.merge(object); registry.update(parent.getKey()); registry.update(object.getKey()); indexing.index(object.getKey()); LOGGER.log(Level.FINEST, "object updated"); try { extraction.extract(object.getKey()); } catch (ExtractionServiceException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } ws.setChanged(true); em.merge(ws); registry.update(ws.getKey()); LOGGER.log(Level.FINEST, "workspace set changed"); ArgumentsBuilder argsBuilder = new ArgumentsBuilder(6).addArgument("ws-alias", ws.getAlias()) .addArgument("key", object.getKey()).addArgument("okey", element.getKey()) .addArgument("path", npath.build()).addArgument("hash", object.getStream()) .addArgument("mimetype", object.getMimeType()); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, DataObject.OBJECT_TYPE, "update"), argsBuilder.build()); return object; } else { LOGGER.log(Level.FINEST, "no changes detected with current object, nothing to do"); return cobject; } } catch (KeyLockedException | KeyNotFoundException | RegistryServiceException | NotificationServiceException | AuthorisationServiceException | MembershipServiceException | BinaryStoreServiceException | DataNotFoundException | CloneException | IndexingServiceException e) { LOGGER.log(Level.SEVERE, "unexpected error occurred while reading object", e); throw new CoreServiceException( "unable to read object into workspace [" + wskey + "] at path [" + path + "]", e); } }
From source file:com.flexive.ejb.beans.PhraseEngineBean.java
/** * {@inheritDoc}/*from w ww. jav a 2 s . c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public List<FxPhraseTreeNodePosition> getAssignedNodes(long phraseId, long phraseMandator, long... _mandators) { final long ownMandator = FxContext.getUserTicket().getMandatorId(); Connection con = null; PreparedStatement ps = null; long[] mandators = checkMandatorFiltering(_mandators); try { // Obtain a database connection con = Database.getDbConnection(); List<FxPhraseTreeNodePosition> result = Lists.newArrayListWithCapacity(10); final String mandatorQuery = mandators.length == 1 ? "=" + mandators[0] : " IN(" + FxArrayUtils.toStringArray(mandators, ',') + ")"; ps = con.prepareStatement("SELECT m.NODEID,m.NODEMANDATOR,m.POS,m.CAT FROM " + TBL_PHRASE_MAP + " m WHERE m.PHRASEID=? AND m.PMANDATOR=? AND m.DIRECT=? AND m.MANDATOR" + mandatorQuery + " ORDER BY m.NODEMANDATOR,m.NODEID,m.POS"); ps.setLong(1, phraseId); ps.setLong(2, phraseMandator); ps.setBoolean(3, true); ResultSet rs = ps.executeQuery(); while (rs != null && rs.next()) { try { result.add(new FxPhraseTreeNodePosition(loadPhraseTreeNode(con, false, rs.getInt(4), rs.getLong(1), rs.getLong(2), false, mandators), rs.getLong(3))); } catch (FxNotFoundException e) { LOG.error("Failed to load node " + rs.getLong(1) + " (mandator " + rs.getLong(2) + ") found! This should not be possible!"); } } return result; } catch (SQLException exc) { EJBUtils.rollback(ctx); throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException(); } finally { Database.closeObjects(PhraseEngineBean.class, con, ps); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public DataObject moveDataObject(String wskey, String source, String destination) throws CoreServiceException, KeyNotFoundException, InvalidPathException, AccessDeniedException, PathNotFoundException, PathAlreadyExistsException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE, "moving object into workspace [" + wskey + "] from path [" + source + "] to path [" + destination + "]"); try {/* w ww .j a v a 2 s.com*/ PathBuilder spath = PathBuilder.fromPath(source); if (spath.isRoot()) { throw new InvalidPathException("path is empty"); } PathBuilder sppath = spath.clone().parent(); PathBuilder dpath = PathBuilder.fromPath(destination); if (dpath.isRoot()) { throw new InvalidPathException("path is empty"); } PathBuilder dppath = dpath.clone().parent(); if (dpath.equals(spath)) { throw new InvalidPathException("unable to move into the same path"); } if (spath.isParent(dpath)) { throw new InvalidPathException("unable to move into a children of this path"); } String caller = membership.getProfileKeyForConnectedIdentifier(); List<String> subjects = membership.getConnectedIdentifierSubjects(); authorisation.checkAuthentified(subjects); LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified"); OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey); checkObjectType(wsidentifier, Workspace.OBJECT_TYPE); LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists"); Workspace ws = em.find(Workspace.class, wsidentifier.getId()); if (ws == null) { throw new CoreServiceException( "unable to load workspace with id [" + wsidentifier.getId() + "] from storage"); } if (applyReadOnly(caller, subjects, ws)) { throw new WorkspaceReadOnlyException( "unable to move data object in workspace with key [" + wskey + "] because it is read only"); } ws.setKey(wskey); LOGGER.log(Level.FINEST, "workspace loaded"); authorisation.checkPermission(ws.getHead(), subjects, "update"); LOGGER.log(Level.FINEST, "user [" + caller + "] has 'update' permission on the head collection of this workspace"); Collection sparent = loadCollectionAtPath(ws.getHead(), sppath, ws.getClock()); CollectionElement selement = sparent.findElementByName(spath.part()); if (selement == null) { throw new PathNotFoundException(spath.build()); } LOGGER.log(Level.FINEST, "source object element found for name " + spath.part()); OrtolangObjectIdentifier soidentifier = registry.lookup(selement.getKey()); checkObjectType(soidentifier, DataObject.OBJECT_TYPE); DataObject sobject = em.find(DataObject.class, soidentifier.getId()); if (sobject == null) { throw new CoreServiceException( "unable to load source object with id [" + soidentifier.getId() + "] from storage"); } sobject.setKey(selement.getKey()); LOGGER.log(Level.FINEST, "source object exists and loaded from storage"); Collection dparent = loadCollectionAtPath(ws.getHead(), dppath, ws.getClock()); if (dparent.containsElementName(dpath.part())) { throw new PathAlreadyExistsException(dpath.build()); } sparent.removeElement(selement); em.merge(sparent); registry.update(sparent.getKey()); LOGGER.log(Level.FINEST, "parent [" + sparent.getKey() + "] has been updated"); LOGGER.log(Level.FINEST, "destination element does not exists, creating it"); if (!dpath.part().equals(spath.part())) { if (sobject.getClock() < ws.getClock()) { sobject = cloneDataObject(ws.getHead(), sobject, ws.getClock()); } sobject.setName(dpath.part()); em.merge(sobject); registry.update(sobject.getKey()); } dparent.addElement(new CollectionElement(DataObject.OBJECT_TYPE, sobject.getName(), System.currentTimeMillis(), sobject.getSize(), sobject.getMimeType(), sobject.getKey())); em.merge(dparent); registry.update(dparent.getKey()); LOGGER.log(Level.FINEST, "object [" + sobject.getKey() + "] added to destination parent [" + dparent.getKey() + "]"); ws.setChanged(true); em.merge(ws); registry.update(ws.getKey()); LOGGER.log(Level.FINEST, "workspace set changed"); ArgumentsBuilder argsBuilder = new ArgumentsBuilder(5).addArgument("ws-alias", ws.getAlias()) .addArgument("key", sobject.getKey()).addArgument("okey", selement.getKey()) .addArgument("src-path", spath.build()).addArgument("dest-path", dpath.build()); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, DataObject.OBJECT_TYPE, "move"), argsBuilder.build()); return sobject; } catch (KeyLockedException | NotificationServiceException | RegistryServiceException | MembershipServiceException | AuthorisationServiceException | CloneException e) { ctx.setRollbackOnly(); LOGGER.log(Level.SEVERE, "unexpected error while moving object", e); throw new CoreServiceException("unable to move object into workspace [" + wskey + "] from path [" + source + "] to path [" + destination + "]", e); } }
From source file:org.nightlabs.jfire.store.StoreManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("org.nightlabs.jfire.store.editRepository") @Override/*from w ww .j av a 2 s .c o m*/ public Repository storeRepository(Repository repository, boolean get, String[] fetchGroups, int maxFetchDepth) { PersistenceManager pm = createPersistenceManager(); try { return NLJDOHelper.storeJDO(pm, repository, get, fetchGroups, maxFetchDepth); } finally { pm.close(); } }
From source file:org.nightlabs.jfire.store.StoreManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("_Guest_") @Override//from w w w . j ava 2 s . c o m public Unit storeUnit(Unit unit, boolean get, String[] fetchGroups, int maxFetchDepth) { PersistenceManager pm = createPersistenceManager(); try { return NLJDOHelper.storeJDO(pm, unit, get, fetchGroups, maxFetchDepth); } finally { pm.close(); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void deleteDataObject(String wskey, String path) throws CoreServiceException, KeyNotFoundException, InvalidPathException, AccessDeniedException, PathNotFoundException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE, "deleting object into workspace [" + wskey + "] at path [" + path + "]"); try {/* w w w . j a v a2s . c om*/ PathBuilder npath = PathBuilder.fromPath(path); if (npath.isRoot()) { throw new InvalidPathException("path is empty"); } PathBuilder ppath = npath.clone().parent(); String caller = membership.getProfileKeyForConnectedIdentifier(); List<String> subjects = membership.getConnectedIdentifierSubjects(); authorisation.checkAuthentified(subjects); LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified"); OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey); checkObjectType(wsidentifier, Workspace.OBJECT_TYPE); LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists"); Workspace ws = em.find(Workspace.class, wsidentifier.getId()); if (ws == null) { throw new CoreServiceException( "unable to load workspace with id [" + wsidentifier.getId() + "] from storage"); } if (applyReadOnly(caller, subjects, ws)) { throw new WorkspaceReadOnlyException("unable to delete data object in workspace with key [" + wskey + "] because it is read only"); } ws.setKey(wskey); LOGGER.log(Level.FINEST, "workspace loaded"); authorisation.checkPermission(ws.getHead(), subjects, "delete"); LOGGER.log(Level.FINEST, "user [" + caller + "] has 'delete' permission on the head collection of this workspace"); Collection parent = loadCollectionAtPath(ws.getHead(), ppath, ws.getClock()); CollectionElement element = parent.findElementByName(npath.part()); if (element == null) { throw new PathNotFoundException(npath.build()); } LOGGER.log(Level.FINEST, "object element found for path " + npath.build() + ", key: " + element.getKey()); OrtolangObjectIdentifier oidentifier = registry.lookup(element.getKey()); checkObjectType(oidentifier, DataObject.OBJECT_TYPE); DataObject leaf = em.find(DataObject.class, oidentifier.getId()); if (leaf == null) { throw new CoreServiceException( "unable to load object with id [" + oidentifier.getId() + "] from storage"); } leaf.setKey(element.getKey()); LOGGER.log(Level.FINEST, "object exists and loaded from storage"); parent.removeElement(element); em.merge(parent); registry.update(parent.getKey()); LOGGER.log(Level.FINEST, "parent [" + parent.getKey() + "] has been updated"); ws.setChanged(true); em.merge(ws); registry.update(ws.getKey()); LOGGER.log(Level.FINEST, "workspace set changed"); if (leaf.getClock() == ws.getClock()) { LOGGER.log(Level.FINEST, "leaf clock [" + leaf.getClock() + "] is the same than workspace, key can be deleted and unindexed"); for (MetadataElement mde : leaf.getMetadatas()) { registry.delete(mde.getKey()); } registry.delete(leaf.getKey()); indexing.remove(leaf.getKey()); } ArgumentsBuilder argsBuilder = new ArgumentsBuilder(3).addArgument("ws-alias", ws.getAlias()) .addArgument("key", leaf.getKey()).addArgument("path", npath.build()); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, DataObject.OBJECT_TYPE, "delete"), argsBuilder.build()); } catch (KeyLockedException | NotificationServiceException | RegistryServiceException | MembershipServiceException | AuthorisationServiceException | IndexingServiceException e) { ctx.setRollbackOnly(); LOGGER.log(Level.SEVERE, "unexpected error while deleting object", e); throw new CoreServiceException( "unable to delete object into workspace [" + wskey + "] at path [" + path + "]", e); } }
From source file:org.nightlabs.jfire.store.StoreManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("org.nightlabs.jfire.store.seeProductType") @Override//w ww . j a va 2s . c o m public Collection<ProductTypeGroup> getProductTypeGroups(Collection<ProductTypeGroupID> productTypeGroupIDs, String[] fetchGroups, int maxFetchDepth) { PersistenceManager pm = createPersistenceManager(); try { if (fetchGroups != null) pm.getFetchPlan().setGroups(fetchGroups); pm.getFetchPlan().setMaxFetchDepth(maxFetchDepth); pm.getExtent(ProductTypeGroup.class); ArrayList<ProductTypeGroup> productTypeGroups = new ArrayList<ProductTypeGroup>( productTypeGroupIDs.size()); for (ProductTypeGroupID productTypeGroupID : productTypeGroupIDs) { ProductTypeGroup productTypeGroup = (ProductTypeGroup) pm.getObjectById(productTypeGroupID); // The method ProductTypeGroup.getProductTypes() already filters the product-types by their // authorities. Therefore, we simply suppress those groups that contain no product type anymore after filtering. if (!productTypeGroup.getProductTypes().isEmpty()) productTypeGroups.add(productTypeGroup); } return pm.detachCopyAll(productTypeGroups); } finally { pm.close(); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public Link createLink(String workspace, String path, String target) throws CoreServiceException, KeyNotFoundException, InvalidPathException, AccessDeniedException, PathNotFoundException, PathAlreadyExistsException, WorkspaceReadOnlyException, KeyAlreadyExistsException { String key = UUID.randomUUID().toString(); try {//from w w w . ja va 2 s. c o m return createLink(workspace, key, path, target); } catch (KeyAlreadyExistsException e) { ctx.setRollbackOnly(); LOGGER.log(Level.WARNING, "the generated key already exists : " + key); throw e; } }