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:org.nightlabs.jfire.accounting.AccountingManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("org.nightlabs.jfire.accounting.queryLocalAccountantDelegates") @Override// www. j ava 2 s . com public Map<ResolvedMapKey, ResolvedMapEntry> getResolvedMoneyFlowMappings(final ProductTypeID productTypeID, final String[] mappingFetchGroups, final int maxFetchDepth) { final PersistenceManager pm = createPersistenceManager(); try { final ProductType productType = (ProductType) pm.getObjectById(productTypeID); final LocalAccountantDelegate delegate = productType.getProductTypeLocal().getLocalAccountantDelegate(); if (delegate == null) { // TODO maybe we should have a DefaultLocalAccountantDelegate, similar to the Store logic, where there is a DefaultLocalStorekeeperDelegate. throw new IllegalArgumentException("The ProductType with id " + productTypeID + " does not have a LocalAccountantDelegate assigned to it."); } return getResolvedMoneyFlowMappings(pm, (LocalAccountantDelegateID) JDOHelper.getObjectId(delegate), productTypeID, mappingFetchGroups, maxFetchDepth); } finally { pm.close(); } }
From source file:com.flexive.ejb.beans.ContentEngineBean.java
/** * {@inheritDoc}//from w ww. ja v a 2 s.c om */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public FxLock extendLock(FxLock lock, long duration) throws FxLockException { Connection con = null; try { con = Database.getDbConnection(); FxLock newLock = StorageManager.getLockStorage().extend(con, lock, duration); FxCachedContent cachedContent = CacheAdmin.getCachedContent(lock.getLockedPK()); if (cachedContent != null) { cachedContent.updateLock(newLock); CacheAdmin.cacheContent(cachedContent); } return newLock; } catch (SQLException e) { throw new FxLockException(e, "ex.db.sqlError", e.getMessage()); } catch (FxNotFoundException e) { throw new FxLockException(e); } finally { Database.closeObjects(ContentEngineBean.class, con, null); } }
From source file:com.flexive.ejb.beans.ContentEngineBean.java
/** * {@inheritDoc}// w ww. j ava2 s . c om */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public FxLock extendLock(FxPK pk, long duration) throws FxLockException { Connection con = null; try { con = Database.getDbConnection(); final LockStorage lockStorage = StorageManager.getLockStorage(); final FxLock lock = lockStorage.getLock(con, pk); FxLock newLock; if (lock.isLocked()) newLock = lockStorage.extend(con, lock, duration); else newLock = lockStorage.lock(con, FxLockType.Loose, pk, duration); FxCachedContent cachedContent = CacheAdmin.getCachedContent(pk); if (cachedContent != null) { cachedContent.updateLock(newLock); CacheAdmin.cacheContent(cachedContent); } return newLock; } catch (SQLException e) { throw new FxLockException(e, "ex.db.sqlError", e.getMessage()); } catch (FxNotFoundException e) { throw new FxLockException(e); } finally { Database.closeObjects(ContentEngineBean.class, con, null); } }
From source file:org.nightlabs.jfire.accounting.AccountingManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("org.nightlabs.jfire.accounting.queryLocalAccountantDelegates") @Override/* www. j a va 2 s . c o m*/ public Map<ResolvedMapKey, ResolvedMapEntry> getResolvedMoneyFlowMappings(final ProductTypeID productTypeID, final LocalAccountantDelegateID delegateID, final String[] mappingFetchGroups, final int maxFetchDepth) { final PersistenceManager pm = createPersistenceManager(); try { if (mappingFetchGroups != null) pm.getFetchPlan().setGroups(mappingFetchGroups); return getResolvedMoneyFlowMappings(pm, delegateID, productTypeID, mappingFetchGroups, maxFetchDepth); } finally { pm.close(); } }
From source file:org.nightlabs.jfire.store.StoreManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("org.nightlabs.jfire.store.editDeliveryNote") @Override/* w w w.j ava 2 s. c o m*/ public DeliveryNote removeArticlesFromDeliveryNote(DeliveryNoteID deliveryNoteID, Collection<ArticleID> articleIDs, boolean validate, boolean get, String[] fetchGroups, int maxFetchDepth) throws DeliveryNoteEditException { PersistenceManager pm = createPersistenceManager(); try { pm.getExtent(DeliveryNote.class); pm.getExtent(Article.class); DeliveryNote deliveryNote = (DeliveryNote) pm.getObjectById(deliveryNoteID); Collection<Article> articles = new ArrayList<Article>(articleIDs.size()); for (Iterator<ArticleID> it = articleIDs.iterator(); it.hasNext();) { ArticleID articleID = it.next(); articles.add((Article) pm.getObjectById(articleID)); } Store store = Store.getStore(pm); store.removeArticlesFromDeliveryNote(User.getUser(pm, getPrincipal()), deliveryNote, articles); if (validate) store.validateDeliveryNote(deliveryNote); if (!get) return null; pm.getFetchPlan().setMaxFetchDepth(maxFetchDepth); if (fetchGroups != null) pm.getFetchPlan().setGroups(fetchGroups); return pm.detachCopy(deliveryNote); } finally { pm.close(); } }
From source file:org.nightlabs.jfire.accounting.AccountingManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("_Guest_") @Override// w w w. ja va2 s . c o m public Collection<PriceFragmentType> getPriceFragmentTypes( final Collection<PriceFragmentTypeID> priceFragmentTypeIDs, final String[] fetchGroups, final int maxFetchDepth) { final PersistenceManager pm = createPersistenceManager(); try { pm.getFetchPlan().setMaxFetchDepth(maxFetchDepth); if (fetchGroups != null) pm.getFetchPlan().setGroups(fetchGroups); return NLJDOHelper.getDetachedObjectList(pm, priceFragmentTypeIDs, PriceFragmentType.class, fetchGroups, maxFetchDepth); // if (priceFragmentTypeIDs == null) { // Query q = pm.newQuery(PriceFragmentType.class); // return pm.detachCopyAll((Collection<PriceFragmentType>)q.execute()); // } // Collection<PriceFragmentType> result = new LinkedList<PriceFragmentType>(); // for (Iterator iter = priceFragmentTypeIDs.iterator(); iter.hasNext();) { // PriceFragmentTypeID priceFragmentTypeID = (PriceFragmentTypeID) iter.next(); // PriceFragmentType pType = (PriceFragmentType)pm.getObjectById(priceFragmentTypeID); // result.add(pType); // } // return pm.detachCopyAll(result); } finally { pm.close(); } }
From source file:com.flexive.ejb.beans.ContentEngineBean.java
/** * {@inheritDoc}/*from w w w .java 2 s. c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void unlock(FxPK pk) throws FxLockException { Connection con = null; try { con = Database.getDbConnection(); final LockStorage lockStorage = StorageManager.getLockStorage(); final FxLock lock = lockStorage.getLock(con, pk); if (lock.isLocked()) lockStorage.unlock(con, pk); FxCachedContent cachedContent = CacheAdmin.getCachedContent(pk); if (cachedContent != null) { cachedContent.updateLock(FxLock.noLockPK()); CacheAdmin.cacheContent(cachedContent); } } catch (SQLException e) { throw new FxLockException(e, "ex.db.sqlError", e.getMessage()); } catch (FxNotFoundException e) { throw new FxLockException(e); } finally { Database.closeObjects(ContentEngineBean.class, con, null); } }
From source file:org.nightlabs.jfire.accounting.AccountingManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("_Guest_") @Override//from w ww . j a v a 2 s . c o m public Collection<PriceFragmentTypeID> getPriceFragmentTypeIDs() { final PersistenceManager pm = createPersistenceManager(); try { final Query q = pm.newQuery(PriceFragmentType.class); q.setResult("JDOHelper.getObjectId(this)"); final Collection<PriceFragmentTypeID> c = CollectionUtil.castCollection((Collection<?>) q.execute()); return new HashSet<PriceFragmentTypeID>(c); } finally { pm.close(); } }
From source file:com.flexive.ejb.beans.ContentEngineBean.java
/** * {@inheritDoc}//from w w w . ja v a 2s . co m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public List<FxLock> getLocks(FxLockType lockType, long userId, long typeId, String resource) throws FxLockException { Connection con = null; try { con = Database.getDbConnection(); final LockStorage lockStorage = StorageManager.getLockStorage(); return lockStorage.getLocks(con, lockType, userId, typeId, resource); } catch (SQLException e) { throw new FxLockException(e, "ex.db.sqlError", e.getMessage()); } catch (FxNotFoundException e) { throw new FxLockException(e); } finally { Database.closeObjects(ContentEngineBean.class, con, null); } }
From source file:com.flexive.ejb.beans.AccountEngineBean.java
/** * {@inheritDoc}/*w w w .java 2 s .c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void update(long accountId, String password, Long defaultNode, String name, String loginName, String email, Boolean isConfirmed, Boolean isActive, Date validFrom, Date validTo, Long lang, String description, Boolean allowMultiLogin, Long contactDataId) throws FxApplicationException { // Load the account to update Account account = load(accountId); StringBuilder sbHistory = new StringBuilder(1000); sbHistory.append("<original>\n").append(" <id>").append(accountId).append("</id>\n").append(" <mandator>") .append(CacheAdmin.getEnvironment().getMandator(account.getMandatorId()).getName()) .append("</mandator>\n").append(" <username>").append(account.getName()).append("</username>\n") .append(" <loginname>").append(account.getLoginName()).append("</loginname>\n").append(" <email>") .append(account.getEmail()).append("</email>\n").append(" <validfrom>") .append(account.getValidFromString()).append("</validfrom>\n").append(" <validto>") .append(account.getValidToString()).append("</validto>\n").append(" <description><![CDATA[") .append(account.getDescription()).append("]]></description>\n").append(" <active>") .append(account.isActive()).append("</active>\n").append(" <confirmed>") .append(account.isValidated()).append("</confirmed>\n").append(" <multilogin>") .append(account.isAllowMultiLogin()).append("</multilogin>\n").append("</original>\n"); final UserTicket ticket = FxContext.getUserTicket(); // Determine if only fields are accessed that the use may alter for himself final boolean protectedFields = (name != null || loginName != null || isConfirmed != null || isActive != null || validTo != null || validFrom != null || description != null); if (!protectedFields && ticket.getUserId() == accountId) { // passed } else { if (!_checkPermissions(account)[MAY_UPDATE]) throw new FxNoAccessException(LOG, "ex.account.update.noPermission", account.getName()); } // Parameter checks try { if (loginName != null) loginName = checkLoginName(loginName); if (email != null) email = FxFormatUtils.checkEmail(email); if (password != null) { password = FxFormatUtils.encodePassword(accountId, StringUtils.defaultString(loginName, account.getLoginName()), password.trim()); } if (lang != null && !language.isValid(lang)) throw new FxInvalidParameterException("LANGUAGE", "ex.account.languageInvalid", lang); } catch (FxInvalidParameterException pe) { if (LOG.isInfoEnabled()) LOG.info(pe); throw pe; } Connection con = null; PreparedStatement stmt = null; String curSql; if (name == null) name = account.getName(); if (loginName == null) loginName = account.getLoginName(); if (email == null) email = account.getEmail(); if (lang == null) lang = account.getLanguage().getId(); if (isActive == null) isActive = account.isActive(); if (isConfirmed == null) isConfirmed = account.isValidated(); if (description == null) description = account.getDescription(); if (defaultNode == null) defaultNode = account.getDefaultNode(); if (allowMultiLogin == null) allowMultiLogin = account.isAllowMultiLogin(); // Assign and check dates if (validFrom == null) validFrom = account.getValidFrom(); if (validTo == null) validTo = account.getValidTo(); checkDates(validFrom, validTo); if (defaultNode < 0) defaultNode = (long) 0; try { // Obtain a database connection con = Database.getDbConnection(); curSql = "UPDATE " + TBL_ACCOUNTS + " SET " + // 1 2 3 4 5 6 "EMAIL=?,LANG=?,VALID_FROM=?,VALID_TO=?,DESCRIPTION=?," + // 6 7 8 9 10 "MODIFIED_BY=?,MODIFIED_AT=?,IS_ACTIVE=?,IS_VALIDATED=?,DEFAULT_NODE=?," + // 11, 12 , 13 , 14 "USERNAME=?,LOGIN_NAME=?,ALLOW_MULTILOGIN=?" + ((password != null) ? ",PASSWORD=?" : "") + ((contactDataId != null) ? ",CONTACT_ID=?" : "") + " WHERE ID=" + accountId; stmt = con.prepareStatement(curSql); stmt.setString(1, email); stmt.setInt(2, lang.intValue()); stmt.setLong(3, validFrom.getTime()); stmt.setLong(4, validTo.getTime()); stmt.setString(5, description); stmt.setLong(6, ticket.getUserId()); stmt.setLong(7, System.currentTimeMillis()); stmt.setBoolean(8, isActive); stmt.setBoolean(9, isConfirmed); stmt.setLong(10, defaultNode); stmt.setString(11, name); stmt.setString(12, loginName); stmt.setBoolean(13, allowMultiLogin); int pos = 14; if (password != null) stmt.setString(pos++, password); if (contactDataId != null) stmt.setLong(pos/*++*/, contactDataId); stmt.executeUpdate(); if (contactDataId != null) { //make sure the user is the owner of his contact data stmt.close(); stmt = con.prepareStatement("UPDATE " + TBL_CONTENT + " SET CREATED_BY=? WHERE ID=?"); stmt.setLong(1, accountId); stmt.setLong(2, contactDataId); stmt.executeUpdate(); } // Log the user out of the system if he was made active if (!isActive || !isConfirmed) { UserTicketStore.removeUserId(accountId, null); } else { // Ensure any active ticket of the updated user are refreshed UserTicketStore.flagDirtyHavingUserId(account.getId()); } sbHistory.append("<new>\n").append(" <id>").append(accountId).append("</id>\n").append(" <mandator>") .append(CacheAdmin.getEnvironment().getMandator(account.getMandatorId()).getName()) .append("</mandator>\n").append(" <username>").append(name).append("</username>\n") .append(" <loginname>").append(loginName).append("</loginname>\n").append(" <email>") .append(email).append("</email>\n").append(" <validfrom>") .append(FxFormatUtils.toString(validFrom)).append("</validfrom>\n").append(" <validto>") .append(FxFormatUtils.toString(validTo)).append("</validto>\n") .append(" <description><![CDATA[").append(description).append("]]></description>\n") .append(" <active>").append(isActive).append("</active>\n").append(" <confirmed>") .append(isConfirmed).append("</confirmed>\n").append(" <multilogin>").append(allowMultiLogin) .append("</multilogin>\n").append("</new>"); EJBLookup.getHistoryTrackerEngine().trackData(sbHistory.toString(), "history.account.update", account.getLoginName()); } catch (SQLException exc) { final boolean uniqueConstraintViolation = StorageManager.isUniqueConstraintViolation(exc); EJBUtils.rollback(ctx); if (uniqueConstraintViolation) { throw new FxEntryExistsException(LOG, "ex.account.userExists", name, loginName); } else { throw new FxUpdateException(LOG, "ex.account.update.failed.sql", account.getLoginName(), exc.getMessage()); } } finally { Database.closeObjects(AccountEngineBean.class, con, stmt); } }