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.stratelia.webactiv.kmelia.control.ejb.KmeliaBmEJB.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void addPublicationToTopicWithoutNotifications(PublicationPK pubPK, NodePK fatherPK, boolean isACreation) { SilverTrace.info("kmelia", "KmeliaBmEJB.addPublicationToTopic()", "root.MSG_GEN_ENTER_METHOD"); PublicationDetail pubDetail = getPublicationDetail(pubPK); if (!isACreation) { try {//from ww w.ja va 2 s . c o m Collection<NodePK> fathers = publicationBm.getAllFatherPK(pubPK); if (isPublicationInBasket(pubPK, fathers)) { publicationBm.removeFather(pubPK, new NodePK(NodePK.BIN_NODE_ID, fatherPK)); if (PublicationDetail.VALID.equalsIgnoreCase(pubDetail.getStatus())) { // index publication publicationBm.createIndex(pubPK); // index external elements indexExternalElementsOfPublication(pubDetail); // publication is accessible again updateSilverContentVisibility(pubDetail); } else if (PublicationDetail.TO_VALIDATE.equalsIgnoreCase(pubDetail.getStatus())) { // create validation todos for publishers createTodosForPublication(pubDetail, true); } } else if (fathers.isEmpty()) { // The publi have got no father // change the end date to make this publi visible pubDetail.setEndDate(null); publicationBm.setDetail(pubDetail); // publication is accessible again updateSilverContentVisibility(pubDetail); } } catch (Exception e) { throw new KmeliaRuntimeException("KmeliaBmEJB.addPublicationToTopic()", ERROR, "kmelia.EX_IMPOSSIBLE_DE_PLACER_LA_PUBLICATION_DANS_LE_THEME", e); } } try { publicationBm.addFather(pubPK, fatherPK); } catch (Exception e) { throw new KmeliaRuntimeException("KmeliaBmEJB.addPublicationToTopic()", ERROR, "kmelia.EX_IMPOSSIBLE_DE_PLACER_LA_PUBLICATION_DANS_LE_THEME", e); } }
From source file:org.nightlabs.jfire.store.StoreManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("org.nightlabs.jfire.store.queryDeliveryNotes") @Override//from www . j a v a 2s . c o m public List<DeliveryNote> getNonFinalizedDeliveryNotes(AnchorID vendorID, AnchorID customerID, String[] fetchGroups, int maxFetchDepth) { PersistenceManager pm = createPersistenceManager(); try { pm.getFetchPlan().setMaxFetchDepth(maxFetchDepth); if (fetchGroups != null) pm.getFetchPlan().setGroups(fetchGroups); return (List<DeliveryNote>) pm .detachCopyAll(DeliveryNote.getNonFinalizedDeliveryNotes(pm, vendorID, customerID)); } finally { pm.close(); } }
From source file:com.flexive.ejb.beans.PhraseEngineBean.java
/** * {@inheritDoc}// w w w . j a v a 2 s . c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void buildPhraseChildMapping(long mandator, int category) { rebuildPhraseChildMapping(null, mandator, category, -1, -1); }
From source file:org.nightlabs.jfire.store.StoreManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("org.nightlabs.jfire.store.editDeliveryNote") @Override/*from w w w .j a v a 2 s. com*/ public void signalDeliveryNote(DeliveryNoteID deliveryNoteID, String jbpmTransitionName) { PersistenceManager pm = createPersistenceManager(); try { Store.getStore(pm).signalDeliveryNote(deliveryNoteID, jbpmTransitionName); } finally { pm.close(); } }
From source file:org.nightlabs.jfire.accounting.AccountingManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("org.nightlabs.jfire.accounting.editInvoice") @Override/* w ww. j a va 2 s . co m*/ public void signalInvoice(final InvoiceID invoiceID, final String jbpmTransitionName) { final PersistenceManager pm = createPersistenceManager(); try { Accounting.getAccounting(pm).signalInvoice(invoiceID, jbpmTransitionName); } finally { pm.close(); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void deleteCollection(String workspace, String path) throws CoreServiceException, KeyNotFoundException, InvalidPathException, AccessDeniedException, CollectionNotEmptyException, PathNotFoundException, WorkspaceReadOnlyException { deleteCollection(workspace, path, false); }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void deleteCollection(String wskey, String path, boolean force) throws CoreServiceException, KeyNotFoundException, InvalidPathException, AccessDeniedException, CollectionNotEmptyException, PathNotFoundException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE, "deleting collection into workspace [" + wskey + "] at path [" + path + "]"); try {/*from w w w . j av a 2 s . co m*/ PathBuilder npath = PathBuilder.fromPath(path); if (npath.isRoot()) { throw new InvalidPathException("unable to delete the root collection"); } 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 collection 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, "collection element found for path " + npath.build() + ", key: " + element.getKey()); OrtolangObjectIdentifier cidentifier = registry.lookup(element.getKey()); checkObjectType(cidentifier, Collection.OBJECT_TYPE); Collection leaf = em.find(Collection.class, cidentifier.getId()); if (leaf == null) { throw new CoreServiceException( "unable to load collection with id [" + cidentifier.getId() + "] from storage"); } leaf.setKey(element.getKey()); LOGGER.log(Level.FINEST, "collection exists and loaded from storage"); if (!leaf.isEmpty() && !force) { throw new CollectionNotEmptyException(path); } 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()); } deleteCollectionContent(leaf, ws.getClock()); 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, Collection.OBJECT_TYPE, "delete"), argsBuilder.build()); } catch (KeyLockedException | NotificationServiceException | RegistryServiceException | MembershipServiceException | AuthorisationServiceException | IndexingServiceException e) { ctx.setRollbackOnly(); LOGGER.log(Level.SEVERE, "unexpected error while deleting collection", e); throw new CoreServiceException( "unable to delete collection into workspace [" + wskey + "] at path [" + path + "]", e); } }
From source file:com.flexive.ejb.beans.PhraseEngineBean.java
/** * {@inheritDoc}/*from www . j a v a 2 s . c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void moveTreeNodeAssignment(long assignmentOwner, long nodeId, long nodeMandatorId, long phraseId, long phraseMandator, int delta) throws FxNotFoundException, FxNoAccessException { moveTreeNodeAssignment(FxPhraseCategorySelection.CATEGORY_DEFAULT, assignmentOwner, nodeId, nodeMandatorId, phraseId, phraseMandator, delta); }
From source file:org.nightlabs.jfire.accounting.AccountingManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("org.nightlabs.jfire.accounting.manualMoneyTransfer") @Override//from ww w. j a v a 2 s .c o m public ManualMoneyTransfer createManualMoneyTransfer(final AnchorID fromID, final AnchorID toID, final CurrencyID currencyID, final long amount, final I18nText reason, final boolean get, final String[] fetchGroups, final int maxFetchDepth) { final PersistenceManager pm = createPersistenceManager(); try { // the JavaEE server knows who we are - get the User object corresponding to the currently working principal final User user = User.getUser(pm, getPrincipal()); // initialise meta-data for Account & Currency - not really necessary, but still safer pm.getExtent(Account.class); pm.getExtent(Currency.class); // load the objects for the given IDs final Account from = (Account) pm.getObjectById(fromID); final Account to = (Account) pm.getObjectById(toID); final Currency currency = (Currency) pm.getObjectById(currencyID); // delegate to Accounting for the actual creation + booking final ManualMoneyTransfer manualMoneyTransfer = Accounting.getAccounting(pm) .createManualMoneyTransfer(user, from, to, currency, amount, reason); // if the client doesn't need it, we simply return null here if (!get) return null; // otherwise, we set the desired fetch-plan pm.getFetchPlan().setMaxFetchDepth(maxFetchDepth); if (fetchGroups != null) pm.getFetchPlan().setGroups(fetchGroups); // and return the detached ManualMoneyTransfer return pm.detachCopy(manualMoneyTransfer); } finally { pm.close(); } }
From source file:com.flexive.ejb.beans.PhraseEngineBean.java
/** * {@inheritDoc}/* w w w . j a va 2s .co m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void moveTreeNodeAssignment(int category, long assignmentOwner, long nodeId, long nodeMandatorId, long phraseId, long phraseMandator, int delta) throws FxNotFoundException, FxNoAccessException { if (delta == 0) return; checkMandatorAccess(assignmentOwner, FxContext.getUserTicket()); Connection con = null; PreparedStatement ps = null; try { // Obtain a database connection con = Database.getDbConnection(); List<Long> positionsId = Lists.newArrayListWithCapacity(50); List<Long> positionsMandator = Lists.newArrayListWithCapacity(50); //0..phrase id, 1..phrase mandator,2..pos ps = con.prepareStatement("SELECT PHRASEID,PMANDATOR,POS FROM " + TBL_PHRASE_MAP + " WHERE MANDATOR=? AND NODEID=? AND NODEMANDATOR=? AND CAT=? ORDER BY POS"); ps.setLong(1, assignmentOwner); ps.setLong(2, nodeId); ps.setLong(3, nodeMandatorId); ps.setInt(4, category); ResultSet rs = ps.executeQuery(); long currPos = 1; int index = -1; while (rs != null && rs.next()) { if (index == -1 && phraseId == rs.getLong(1)) index = (int) currPos - 1; positionsId.add(rs.getLong(1)); positionsMandator.add(rs.getLong(2)); currPos++; } if (positionsId.size() < 2 || index == -1) //only one node or node not found, can not change position return; int newIndex = index + delta; if (newIndex < 0) newIndex = 0; if (delta > 0) newIndex++; if (newIndex > (positionsId.size() - 1)) newIndex = positionsId.size(); positionsId.add(newIndex, phraseId); positionsMandator.add(newIndex, phraseMandator); if (newIndex > index) { positionsId.remove(index); positionsMandator.remove(index); } else { positionsId.remove(index + 1); positionsMandator.remove(index + 1); } //write back new positionsId ps.close(); ps = con.prepareStatement("UPDATE " + TBL_PHRASE_MAP + " SET POS=? WHERE MANDATOR=? AND NODEID=? AND NODEMANDATOR=? AND PHRASEID=? AND PMANDATOR=? AND CAT=?"); ps.setLong(2, assignmentOwner); ps.setLong(3, nodeId); ps.setLong(4, nodeMandatorId); ps.setInt(7, category); for (int i = 1; i <= positionsId.size(); i++) { ps.setLong(1, i); ps.setLong(5, positionsId.get(i - 1)); ps.setLong(6, positionsMandator.get(i - 1)); ps.addBatch(); } ps.executeBatch(); } catch (SQLException exc) { EJBUtils.rollback(ctx); throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException(); } finally { Database.closeObjects(PhraseEngineBean.class, con, ps); } }