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
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public Link createLink(String wskey, String key, String path, String target) throws CoreServiceException, KeyAlreadyExistsException, InvalidPathException, AccessDeniedException, PathNotFoundException, PathAlreadyExistsException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE,//from w w w . j a v a 2 s .c o m "create link with key [" + key + "] into workspace [" + wskey + "] at path [" + path + "]"); try { 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"); authorisation.checkPermission(target, subjects, "read"); LOGGER.log(Level.FINEST, "user [" + caller + "] has 'read' permissions on the target"); 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 create link in workspace with key [" + wskey + "] because it is read only"); } ws.setKey(wskey); LOGGER.log(Level.FINEST, "workspace loaded"); authorisation.checkPermission(ws.getHead(), subjects, "create"); LOGGER.log(Level.FINEST, "user [" + caller + "] has 'create' permission on the head collection of this workspace"); Collection parent = loadCollectionAtPath(ws.getHead(), ppath, ws.getClock()); LOGGER.log(Level.FINEST, "parent collection loaded for path " + ppath.build()); if (parent.containsElementName(npath.part())) { throw new PathAlreadyExistsException(npath.build()); } String ntarget = PathBuilder.fromPath(target).build(); Link link = new Link(); link.setId(UUID.randomUUID().toString()); link.setKey(key); link.setName(npath.part()); link.setClock(ws.getClock()); link.setTarget(ntarget); em.persist(link); Properties properties = new Properties(); properties.put(WORKSPACE_REGISTRY_PROPERTY_KEY, wskey); registry.register(key, link.getObjectIdentifier(), caller, properties); indexing.index(key); authorisation.clonePolicy(key, ws.getHead()); LOGGER.log(Level.FINEST, "security policy cloned from head collection to key [" + key + "]"); parent.addElement(new CollectionElement(Link.OBJECT_TYPE, link.getName(), System.currentTimeMillis(), 0, Link.MIME_TYPE, key)); em.merge(parent); registry.update(parent.getKey()); LOGGER.log(Level.FINEST, "link [" + key + "] added to parent [" + parent.getKey() + "]"); ws.setChanged(true); em.merge(ws); registry.update(ws.getKey()); LOGGER.log(Level.FINEST, "workspace set changed"); ArgumentsBuilder argsBuilder = new ArgumentsBuilder(3).addArgument("ws-alias", ws.getAlias()) .addArgument("key", key).addArgument("path", npath.build()); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, Link.OBJECT_TYPE, "create"), argsBuilder.build()); return link; } catch (KeyLockedException | KeyNotFoundException | RegistryServiceException | NotificationServiceException | IdentifierAlreadyRegisteredException | AuthorisationServiceException | MembershipServiceException | IndexingServiceException e) { LOGGER.log(Level.SEVERE, "unexpected error occurred during link creation", e); ctx.setRollbackOnly(); throw new CoreServiceException( "unable to create link into workspace [" + wskey + "] at path [" + path + "]", e); } }
From source file:com.flexive.ejb.beans.structure.AssignmentEngineBean.java
/** * {@inheritDoc}/*from w ww .j a v a 2 s . c om*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void removeAssignment(long assignmentId, boolean removeSubAssignments, boolean removeDerivedAssignments) throws FxApplicationException { removeAssignment(assignmentId, removeSubAssignments, removeDerivedAssignments, false, false); }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public Link readLink(String key) throws CoreServiceException, KeyNotFoundException, AccessDeniedException { LOGGER.log(Level.FINE, "reading link with key [" + key + "]"); try {/*ww w . j a v a 2 s . com*/ List<String> subjects = membership.getConnectedIdentifierSubjects(); OrtolangObjectIdentifier identifier = registry.lookup(key); checkObjectType(identifier, Link.OBJECT_TYPE); authorisation.checkPermission(key, subjects, "read"); Link link = em.find(Link.class, identifier.getId()); if (link == null) { throw new CoreServiceException( "unable to load link with id [" + identifier.getId() + "] from storage"); } link.setKey(key); return link; } catch (RegistryServiceException | MembershipServiceException | AuthorisationServiceException e) { LOGGER.log(Level.SEVERE, "unexpected error occurred while reading link", e); throw new CoreServiceException("unable to read link with key [" + key + "]", e); } }
From source file:com.flexive.ejb.beans.structure.AssignmentEngineBean.java
/** * {@inheritDoc}//from w ww . ja v a 2 s.co m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void removeAssignment(long assignmentId) throws FxApplicationException { removeAssignment(assignmentId, true, false, false, true); }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public Link updateLink(String wskey, String path, String target) throws CoreServiceException, InvalidPathException, AccessDeniedException, PathNotFoundException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE, "updating link into workspace [" + wskey + "] at path [" + path + "]"); try {//from w w w . j a va2s .co m 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 link 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, Link.OBJECT_TYPE); Link clink = em.find(Link.class, cidentifier.getId()); if (clink == null) { throw new CoreServiceException( "unable to load link with id [" + cidentifier.getId() + "] from storage"); } clink.setKey(current); LOGGER.log(Level.FINEST, "current link loaded"); String ntarget = PathBuilder.fromPath(target).build(); if (!ntarget.equals(clink.getTarget())) { 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, "link element found for name " + npath.part()); if (!element.getType().equals(Link.OBJECT_TYPE)) { throw new InvalidPathException("path [" + npath.build() + "] is not a link"); } 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"); } link.setKey(element.getKey()); link.setTarget(ntarget); if (link.getClock() < ws.getClock()) { Link clone = cloneLink(ws.getHead(), link, ws.getClock()); parent.removeElement(element); CollectionElement celement = new CollectionElement(Link.OBJECT_TYPE, clone.getName(), System.currentTimeMillis(), 0, Link.MIME_TYPE, clone.getKey()); parent.addElement(celement); link = clone; } em.merge(parent); em.merge(link); registry.update(parent.getKey()); registry.update(link.getKey()); indexing.index(link.getKey()); LOGGER.log(Level.FINEST, "link updated"); ws.setChanged(true); em.merge(ws); registry.update(ws.getKey()); LOGGER.log(Level.FINEST, "workspace set changed"); ArgumentsBuilder argsBuilder = new ArgumentsBuilder(4).addArgument("ws-alias", ws.getAlias()) .addArgument("key", link.getKey()).addArgument("okey", element.getKey()) .addArgument("path", npath.build()); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, Link.OBJECT_TYPE, "update"), argsBuilder.build()); return link; } else { LOGGER.log(Level.FINEST, "no changes detected with current link, nothing to do"); return clink; } } catch (KeyLockedException | KeyNotFoundException | RegistryServiceException | NotificationServiceException | AuthorisationServiceException | MembershipServiceException | CloneException | IndexingServiceException e) { LOGGER.log(Level.SEVERE, "unexpected error occurred while updating link", e); throw new CoreServiceException( "unable to update link into workspace [" + wskey + "] at path [" + path + "]", e); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public Link moveLink(String wskey, String source, String destination) throws CoreServiceException, KeyNotFoundException, InvalidPathException, AccessDeniedException, PathNotFoundException, PathAlreadyExistsException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE, "moving link into workspace [" + wskey + "] from path [" + source + "] to path [" + destination + "]"); try {/*from w w w . ja v a 2s . c om*/ 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 link 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 link element found for name " + spath.part()); OrtolangObjectIdentifier slidentifier = registry.lookup(selement.getKey()); checkObjectType(slidentifier, Link.OBJECT_TYPE); Link slink = em.find(Link.class, slidentifier.getId()); if (slink == null) { throw new CoreServiceException( "unable to load source link with id [" + slidentifier.getId() + "] from storage"); } slink.setKey(selement.getKey()); LOGGER.log(Level.FINEST, "source link 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()); indexing.index(sparent.getKey()); LOGGER.log(Level.FINEST, "parent [" + sparent.getKey() + "] has been updated"); if (!dpath.part().equals(spath.part())) { if (slink.getClock() < ws.getClock()) { slink = cloneLink(ws.getHead(), slink, ws.getClock()); } slink.setName(dpath.part()); em.merge(slink); registry.update(slink.getKey()); indexing.index(slink.getKey()); } dparent.addElement(new CollectionElement(Link.OBJECT_TYPE, slink.getName(), System.currentTimeMillis(), 0, Link.MIME_TYPE, slink.getKey())); em.merge(dparent); registry.update(dparent.getKey()); indexing.index(dparent.getKey()); LOGGER.log(Level.FINEST, "link [" + slink.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", slink.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, Link.OBJECT_TYPE, "move"), argsBuilder.build()); return slink; } catch (KeyLockedException | NotificationServiceException | RegistryServiceException | MembershipServiceException | AuthorisationServiceException | CloneException | IndexingServiceException e) { ctx.setRollbackOnly(); LOGGER.log(Level.SEVERE, "unexpected error while moving link", e); throw new CoreServiceException("unable to move link into workspace [" + wskey + "] from path [" + source + "] to path [" + destination + "]", e); } }
From source file:com.stratelia.webactiv.kmelia.control.ejb.KmeliaBmEJB.java
/** * This method is here to manage correctly transactional scope of EJB (conflict between EJB and * UserPreferences service)/*from www . j a v a 2 s . co m*/ * * @param pubPK * @return */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public PublicationDetail draftOutPublicationWithoutNotifications(PublicationPK pubPK, NodePK topicPK, String userProfile) { return draftOutPublication(pubPK, topicPK, userProfile, false, true); }
From source file:com.flexive.ejb.beans.PhraseEngineBean.java
/** * {@inheritDoc}//from w ww.j a va 2 s. c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void syncDivisionResources(long targetMandator, FxPhraseSearchValueConverter converter) throws FxApplicationException { final UserTicket userTicket = FxContext.getUserTicket(); checkMandatorAccess(targetMandator, userTicket); clearTree(targetMandator); clearPhrases(targetMandator); Connection con = null; PreparedStatement psFetch = null, psPhrase = null, psPhraseVal = null; try { // Obtain a database connection con = Database.getDbConnection(); psFetch = con.prepareStatement( "SELECT RKEY,LANG,RVAL FROM " + TBL_RESOURCES + " ORDER BY RKEY ASC, LANG ASC"); psPhrase = con.prepareStatement("INSERT INTO " + TBL_PHRASE + " (ID,MANDATOR,PKEY)VALUES(?,?,?)"); psPhrase.setLong(2, targetMandator); psPhraseVal = con.prepareStatement("INSERT INTO " + TBL_PHRASE_VALUES + " (ID,MANDATOR,LANG,PVAL,SVAL,TAG)VALUES(?,?,?,?,?,NULL)"); psPhraseVal.setLong(2, targetMandator); long currentId = 0; String currKey = null; ResultSet rs = psFetch.executeQuery(); while (rs != null && rs.next()) { if (currKey == null || !currKey.equals(rs.getString(1))) { currentId++; currKey = rs.getString(1); psPhrase.setLong(1, currentId); psPhraseVal.setLong(1, currentId); psPhrase.setString(3, currKey); psPhrase.executeUpdate(); } psPhraseVal.setLong(3, rs.getLong(2)); psPhraseVal.setString(4, rs.getString(3)); if (converter != null) psPhraseVal.setString(5, converter.convert(rs.getString(3), rs.getLong(2))); else psPhraseVal.setString(5, rs.getString(3).trim().toUpperCase()); psPhraseVal.executeUpdate(); } final String SEQ_NAME = "PhraseSeq_" + targetMandator; if (seq.sequencerExists(SEQ_NAME)) seq.removeSequencer(SEQ_NAME); seq.createSequencer(SEQ_NAME, false, currentId + 1); } catch (SQLException exc) { EJBUtils.rollback(ctx); throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException(); } finally { Database.closeObjects(PhraseEngineBean.class, psPhrase, psPhraseVal); Database.closeObjects(PhraseEngineBean.class, con, psFetch); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void deleteLink(String wskey, String path) throws CoreServiceException, KeyNotFoundException, InvalidPathException, AccessDeniedException, PathNotFoundException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE, "deleting link into workspace [" + wskey + "] at path [" + path + "]"); try {//from w ww.ja v a2 s . 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 link 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, "link element found for name " + npath.part()); OrtolangObjectIdentifier lidentifier = registry.lookup(element.getKey()); checkObjectType(lidentifier, Link.OBJECT_TYPE); Link leaf = em.find(Link.class, lidentifier.getId()); if (leaf == null) { throw new CoreServiceException( "unable to load link with id [" + lidentifier.getId() + "] from storage"); } leaf.setKey(element.getKey()); LOGGER.log(Level.FINEST, "link exists and loaded from storage"); parent.removeElement(element); em.merge(parent); registry.update(parent.getKey()); indexing.index(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, Link.OBJECT_TYPE, "delete"), argsBuilder.build()); } catch (KeyLockedException | NotificationServiceException | RegistryServiceException | MembershipServiceException | AuthorisationServiceException | IndexingServiceException e) { ctx.setRollbackOnly(); LOGGER.log(Level.SEVERE, "unexpected error while deleting link", e); throw new CoreServiceException( "unable to delete link into workspace [" + wskey + "] at path [" + path + "]", e); } }
From source file:com.flexive.ejb.beans.structure.AssignmentEngineBean.java
/** * {@inheritDoc}//from w ww . ja v a2 s . c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public long save(FxPropertyEdit property) throws FxApplicationException { FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.StructureManagement); long returnId = property.getId(); boolean reload; Connection con = null; try { con = Database.getDbConnection(); reload = updateProperty(con, property); if (reload) StructureLoader.reload(con); } catch (SQLException e) { EJBUtils.rollback(ctx); throw new FxCreateException(LOG, e, "ex.db.sqlError", e.getMessage()); } catch (FxCacheException e) { EJBUtils.rollback(ctx); throw new FxCreateException(e, "ex.cache", e.getMessage()); } catch (FxLoadException e) { EJBUtils.rollback(ctx); throw new FxCreateException(e); } finally { Database.closeObjects(AssignmentEngineBean.class, con, null); } return returnId; }