Example usage for javax.ejb TransactionAttributeType REQUIRED

List of usage examples for javax.ejb TransactionAttributeType REQUIRED

Introduction

In this page you can find the example usage for javax.ejb TransactionAttributeType REQUIRED.

Prototype

TransactionAttributeType REQUIRED

To view the source code for javax.ejb TransactionAttributeType REQUIRED.

Click Source Link

Document

If a client invokes the enterprise bean's method while the client is associated with a transaction context, the container invokes the enterprise bean's method in the client's transaction context.

Usage

From source file:org.nightlabs.jfire.store.StoreManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRED)
@RolesAllowed("org.nightlabs.jfire.store.editDeliveryNote")
@Override/*  w  ww . j  a  v  a2s.  c om*/
public DeliveryNote createDeliveryNote(ArticleContainerID articleContainerID, String deliveryNoteIDPrefix,
        boolean get, String[] fetchGroups, int maxFetchDepth) throws DeliveryNoteEditException {
    PersistenceManager pm = createPersistenceManager();
    try {
        if (articleContainerID == null)
            throw new IllegalArgumentException("articleContainerID must not be null!");

        if (articleContainerID instanceof OrderID)
            pm.getExtent(Order.class);
        else if (articleContainerID instanceof OfferID)
            pm.getExtent(Offer.class);
        else if (articleContainerID instanceof InvoiceID)
            pm.getExtent(Invoice.class);
        else
            throw new IllegalArgumentException(
                    "articleContainerID must be an instance of OrderID, OfferID or InvoiceID, but is "
                            + articleContainerID.getClass().getName());

        ArticleContainer articleContainer = (ArticleContainer) pm.getObjectById(articleContainerID);

        User user = User.getUser(pm, getPrincipal());
        Trader trader = Trader.getTrader(pm);
        Store store = trader.getStore();

        if (articleContainer instanceof Offer) {
            Offer offer = (Offer) articleContainer;
            //            OfferLocal offerLocal = offer.getOfferLocal();
            trader.validateOffer(offer);
            trader.acceptOfferImplicitely(offer);
            //            trader.finalizeOffer(user, offer);
            //            trader.acceptOffer(user, offerLocal);
            //            trader.confirmOffer(user, offerLocal);
        } else {
            for (Iterator<Article> it = articleContainer.getArticles().iterator(); it.hasNext();) {
                Article article = it.next();
                Offer offer = article.getOffer();
                //               OfferLocal offerLocal = offer.getOfferLocal();
                trader.validateOffer(offer);
                trader.acceptOfferImplicitely(offer);
                //               trader.finalizeOffer(user, offer);
                //               trader.acceptOffer(user, offerLocal);
                //               trader.confirmOffer(user, offerLocal);
            }
        }

        DeliveryNote deliveryNote = store.createDeliveryNote(user, articleContainer, deliveryNoteIDPrefix);
        store.validateDeliveryNote(deliveryNote);

        if (get) {
            pm.getFetchPlan().setMaxFetchDepth(maxFetchDepth);
            pm.getFetchPlan()
                    .setDetachmentOptions(FetchPlan.DETACH_LOAD_FIELDS + FetchPlan.DETACH_UNLOAD_FIELDS);
            if (fetchGroups != null)
                pm.getFetchPlan().setGroups(fetchGroups);

            return pm.detachCopy(deliveryNote);
        }
        return null;
    } finally {
        pm.close();
    }
}

From source file:org.cesecore.certificates.certificate.CertificateStoreSessionBean.java

License:asdf

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void revokeAllCertByCA(AuthenticationToken admin, String issuerdn, int reason)
        throws AuthorizationDeniedException {
    int revoked = 0;

    // Must be authorized to CA in order to change status is certificates issued by the CA
    String bcdn = CertTools.stringToBCDNString(issuerdn);
    int caid = bcdn.hashCode();
    authorizedToCA(admin, caid);/*from  www.ja  v a2  s.  c om*/

    try {
        final int maxRows = 10000;
        int firstResult = 0;
        // Revoking all non revoked certificates.

        // Update 10000 records at a time
        firstResult = 0;
        List<CertificateData> list = CertificateData.findAllNonRevokedCertificates(entityManager, bcdn,
                firstResult, maxRows);
        while (list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                CertificateData d = list.get(i);
                d.setStatus(CertificateConstants.CERT_REVOKED);
                d.setRevocationDate(System.currentTimeMillis());
                d.setRevocationReason(reason);
                revoked++;
            }
            firstResult += maxRows;
            list = CertificateData.findAllNonRevokedCertificates(entityManager, bcdn, firstResult, maxRows);
        }
        final String msg = INTRES.getLocalizedMessage("store.revokedallbyca", issuerdn,
                Integer.valueOf(revoked), Integer.valueOf(reason));
        Map<String, Object> details = new LinkedHashMap<String, Object>();
        details.put("msg", msg);
        logSession.log(EventTypes.CERT_REVOKED, EventStatus.SUCCESS, ModuleTypes.CERTIFICATE, ServiceTypes.CORE,
                admin.toString(), String.valueOf(caid), null, null, details);
    } catch (Exception e) {
        final String msg = INTRES.getLocalizedMessage("store.errorrevokeallbyca", issuerdn);
        log.info(msg);
        throw new EJBException(e);
    }
}

From source file:com.flexive.ejb.beans.ScriptingEngineBean.java

/**
 * {@inheritDoc}// w w w .  j  a v  a  2 s  .c o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void executeStartupScripts() {
    executeInitializerScripts("startup", "flexive", "fxresources", "[fleXive]", new NonFailingScriptExecutor());
}

From source file:org.nightlabs.jfire.accounting.AccountingManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRED)
@RolesAllowed("org.nightlabs.jfire.accounting.editLocalAccountantDelegate")
@Override/* w w w.  j  av a2s . c  o m*/
public MoneyFlowMapping storeMoneyFlowMapping(final MoneyFlowMapping mapping, final boolean get,
        final String[] fetchGroups, final int maxFetchDepth) {
    final PersistenceManager pm = createPersistenceManager();
    try {
        if (fetchGroups != null)
            pm.getFetchPlan().setGroups(fetchGroups);
        return NLJDOHelper.storeJDO(pm, mapping, get, fetchGroups, maxFetchDepth);
    } finally {
        pm.close();
    }
}

From source file:com.flexive.ejb.beans.ContentEngineBean.java

/**
 * {@inheritDoc}//w  w w  .j av a 2s. c om
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public FxLock lock(FxLockType lockType, FxPK pk, long duration) throws FxLockException {
    Connection con = null;
    try {
        con = Database.getDbConnection();
        FxLock lock = StorageManager.getLockStorage().lock(con, lockType, pk, duration);
        FxCachedContent cachedContent = CacheAdmin.getCachedContent(pk);
        if (cachedContent != null) {
            cachedContent.updateLock(lock);
            CacheAdmin.cacheContent(cachedContent);
        }
        return lock;
    } 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.ScriptingEngineBean.java

/**
 * {@inheritDoc}/*from   w  w w . j  a  v  a  2s . c  om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void executeDropStartupScripts(String dropName) throws FxApplicationException {
    if (!FxSharedUtils.getDrops().contains(dropName))
        throw new FxInvalidParameterException("dropName", "ex.scripting.drop.notFound", dropName);
    executeInitializerScripts("startup", dropName, dropName + "Resources", "drop " + dropName,
            new NonFailingScriptExecutor());
}

From source file:com.flexive.ejb.beans.ContentEngineBean.java

/**
 * {@inheritDoc}//from  ww  w.j  a  v a  2  s  .com
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public FxLock takeOverLock(FxLock lock) throws FxLockException {
    if (!lock.isContentLock())
        return lock;
    Connection con = null;
    try {
        con = Database.getDbConnection();
        FxLock newLock = StorageManager.getLockStorage().takeOver(con, lock);
        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.PhraseEngineBean.java

/**
 * {@inheritDoc}/*from w  ww .jav a2s . c o m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void setPhraseTreeNodeParent(long nodeId, long nodeMandator, long parentId, long parentMandator)
        throws FxNoAccessException, FxNotFoundException {
    Connection con = null;
    PreparedStatement ps = null;

    checkMandatorAccess(nodeMandator, FxContext.getUserTicket());
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        //check if the node and the parent node exists
        ps = con.prepareStatement(
                "SELECT ID, MANDATOR, CAT FROM " + TBL_PHRASE_TREE + " WHERE ID=? AND MANDATOR=?");
        ps.setLong(1, nodeId);
        ps.setLong(2, nodeMandator);
        ResultSet rs = ps.executeQuery();
        if (!(rs != null && rs.next()))
            throw new FxNotFoundException("ex.phrases.node.notFound.id", nodeId, nodeMandator);
        final int nodeCategory = rs.getInt(3);
        final int parentCategory;
        if (parentId != FxPhraseTreeNode.NOT_SET) {
            ps.setLong(1, parentId);
            ps.setLong(2, parentMandator);
            rs = ps.executeQuery();
            if (!(rs != null && rs.next()))
                throw new FxNotFoundException("ex.phrase.tree.parent.notFound", parentId, parentMandator);
            parentCategory = rs.getInt(3);
        } else
            parentCategory = nodeCategory;
        if (nodeCategory != parentCategory)
            throw new FxInvalidParameterException("parent", "ex.phrase.tree.category.mismatch")
                    .asRuntimeException();
        ps.close();
        ps = con.prepareStatement(
                "UPDATE " + TBL_PHRASE_TREE + " SET PARENTID=?,PARENTMANDATOR=? WHERE ID=? AND MANDATOR=?");
        if (parentId != FxPhraseTreeNode.NOT_SET) {
            ps.setLong(1, parentId);
            ps.setLong(2, parentMandator);
        } else {
            ps.setNull(1, Types.NUMERIC);
            ps.setNull(1, Types.NUMERIC);
        }
        ps.setLong(3, nodeId);
        ps.setLong(4, nodeMandator);
        ps.executeUpdate();
    } 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:com.flexive.ejb.beans.ContentEngineBean.java

/**
 * {@inheritDoc}//  ww w.  ja  v  a 2s . c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public FxLock takeOverLock(FxPK pk) 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.takeOver(con, lock);
        else
            newLock = lockStorage.lock(con, FxLockType.Loose, pk);
        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.store.StoreManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRED)
@RolesAllowed("org.nightlabs.jfire.store.editDeliveryNote")
@Override//from  w  w  w.j a va  2  s  .co  m
public DeliveryNote addArticlesToDeliveryNote(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);
        Trader trader = Trader.getTrader(pm);

        DeliveryNote deliveryNote = (DeliveryNote) pm.getObjectById(deliveryNoteID);
        Collection<Article> articles = new ArrayList<Article>(articleIDs.size());
        for (ArticleID articleID : articleIDs) {
            Article article = (Article) pm.getObjectById(articleID);
            Offer offer = article.getOffer();
            trader.validateOffer(offer);
            trader.acceptOfferImplicitely(offer);
            articles.add(article);
        }

        Store store = Store.getStore(pm);
        store.addArticlesToDeliveryNote(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();
    }
}