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.accounting.AccountingManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRED)
@RolesAllowed("org.nightlabs.jfire.accounting.editInvoice")
@Override/*ww w  .j av  a  2  s .  co  m*/
public Invoice removeArticlesFromInvoice(final InvoiceID invoiceID, final Collection<ArticleID> articleIDs,
        final boolean validate, final boolean get, final String[] fetchGroups, final int maxFetchDepth)
        throws InvoiceEditException {
    final PersistenceManager pm = createPersistenceManager();
    try {
        pm.getExtent(Invoice.class);
        pm.getExtent(Article.class);
        final Invoice invoice = (Invoice) pm.getObjectById(invoiceID);
        final Collection<Article> articles = NLJDOHelper.getObjectList(pm, articleIDs, Article.class);
        //         Collection<Article> articles = new ArrayList<Article>(articleIDs.size());
        //         for (ArticleID articleID : articleIDs) {
        //         articles.add((Article) pm.getObjectById(articleID));
        //         }

        final Accounting accounting = Accounting.getAccounting(pm);
        accounting.removeArticlesFromInvoice(User.getUser(pm, getPrincipal()), invoice, articles);

        if (!get)
            return null;

        if (validate)
            accounting.validateInvoice(invoice);

        pm.getFetchPlan().setMaxFetchDepth(maxFetchDepth);
        if (fetchGroups != null)
            pm.getFetchPlan().setGroups(fetchGroups);

        return pm.detachCopy(invoice);
    } finally {
        pm.close();
    }
}

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

/**
 * {@inheritDoc}/*from ww w .j ava  2s .  co  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void updateUser(long accountId, String password, String name, String loginName, String email, Long lang)
        throws FxApplicationException {
    _updateUser(accountId, password, true, name, loginName, email, lang);
}

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

/**
 * {@inheritDoc}//from w w  w.j a va 2s.  co m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void updateUser(long accountId, String password, boolean hashPassword, String name, String loginName,
        String email, Long lang) throws FxApplicationException {
    _updateUser(accountId, password, hashPassword, name, loginName, email, lang);
}

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 moveTreeNode(long nodeId, long mandatorId, int delta)
        throws FxNoAccessException, FxNotFoundException {
    moveTreeNode(FxPhraseCategorySelection.CATEGORY_DEFAULT, nodeId, mandatorId, delta);
}

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

/**
 * {@inheritDoc}//from  w w w. j a v a  2  s.c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void removeTreeNode(long nodeId, long mandatorId) throws FxNoAccessException, FxNotFoundException {
    removeTreeNode(FxPhraseCategorySelection.CATEGORY_DEFAULT, nodeId, mandatorId);
}

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

/**
 * {@inheritDoc}/*ww  w .  j av  a  2s.c  o m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void removeTreeNode(int category, long nodeId, long mandatorId)
        throws FxNoAccessException, FxNotFoundException {
    checkMandatorAccess(mandatorId, FxContext.getUserTicket());
    Connection con = null;
    PreparedStatement ps = null, psUpdate = null;
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        ps = con.prepareStatement("SELECT PARENTID, PARENTMANDATOR FROM " + TBL_PHRASE_TREE
                + " WHERE ID=? AND MANDATOR=? AND CAT=?");
        ps.setLong(1, nodeId);
        ps.setLong(2, mandatorId);
        ps.setInt(3, category);
        ResultSet rs = ps.executeQuery();
        if (rs == null || !rs.next())
            throw new FxNotFoundException("ex.phrases.node.notFound.id", nodeId, mandatorId);
        long parentId = rs.getLong(1);
        if (rs.wasNull())
            parentId = -1L;
        long parentMandatorId = rs.getLong(2);
        if (rs.wasNull())
            parentMandatorId = -1L;
        rs.close();
        ps.close();
        psUpdate = con.prepareStatement("UPDATE " + TBL_PHRASE_TREE
                + " SET PARENTID=?, PARENTMANDATOR=?, POS=? WHERE ID=? AND MANDATOR=? AND CAT=?");
        psUpdate.setInt(6, category);
        long currPos = getNextNodePos(con, category, parentId, parentMandatorId, mandatorId);
        ps = con.prepareStatement("SELECT ID, MANDATOR FROM " + TBL_PHRASE_TREE
                + " WHERE PARENTID=? AND PARENTMANDATOR=? AND CAT=? ORDER BY POS");
        ps.setLong(1, nodeId);
        ps.setLong(2, mandatorId);
        ps.setInt(3, category);
        rs = ps.executeQuery();
        while (rs != null && rs.next()) {
            if (parentId != -1L) {
                psUpdate.setLong(1, parentId);
                psUpdate.setLong(2, parentMandatorId);
            } else {
                psUpdate.setNull(1, Types.NUMERIC);
                psUpdate.setNull(2, Types.NUMERIC);
            }
            psUpdate.setLong(3, currPos++);
            psUpdate.setLong(4, rs.getLong(1));
            psUpdate.setLong(5, rs.getLong(2));
            psUpdate.executeUpdate();
        }
        if (rs != null)
            rs.close();
        ps.close();

        ps = con.prepareStatement(
                "DELETE FROM " + TBL_PHRASE_MAP + " WHERE NODEID=? AND NODEMANDATOR=? AND CAT=?");
        ps.setLong(1, nodeId);
        ps.setLong(2, mandatorId);
        ps.setInt(3, category);
        ps.executeUpdate();
        ps.close();
        ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE_TREE + " WHERE ID=? AND MANDATOR=? AND CAT=?");
        ps.setLong(1, nodeId);
        ps.setLong(2, mandatorId);
        ps.setInt(3, category);
        ps.executeUpdate();
        rebuildPhraseChildMapping(con, mandatorId, category, -1, -1);
    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException();
    } finally {
        Database.closeObjects(PhraseEngineBean.class, psUpdate);
        Database.closeObjects(PhraseEngineBean.class, con, ps);
    }
}

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

License:asdf

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void updateLimitedCertificateDataStatus(final AuthenticationToken admin, final int caId,
        final String issuerDn, final BigInteger serialNumber, final Date revocationDate, final int reasonCode,
        final String caFingerprint) throws AuthorizationDeniedException {
    if (!accessSession.isAuthorizedNoLogging(admin, StandardRules.CAACCESS.resource() + caId)) {
        final String msg = INTRES.getLocalizedMessage("caadmin.notauthorizedtoca", admin.toString(), caId);
        throw new AuthorizationDeniedException(msg);
    }//from   www.j a va2  s  . co  m
    final CertificateInfo certificateInfo = findFirstCertificateInfo(issuerDn, serialNumber);
    final String limitedFingerprint = getLimitedCertificateDataFingerprint(issuerDn, serialNumber);
    final CertificateData limitedCertificateData = createLimitedCertificateData(admin, limitedFingerprint,
            issuerDn, serialNumber, revocationDate, reasonCode, caFingerprint);
    if (certificateInfo == null) {
        if (reasonCode == RevokedCertInfo.REVOCATION_REASON_REMOVEFROMCRL) {
            deleteLimitedCertificateData(limitedFingerprint);
        } else {
            // Create a limited entry
            log.info("Adding limited CertificateData entry with fingerprint=" + limitedFingerprint
                    + ", serialNumber=" + serialNumber.toString(16).toUpperCase() + ", issuerDn='" + issuerDn
                    + "'");
            entityManager.persist(limitedCertificateData);
        }
    } else if (limitedFingerprint.equals(certificateInfo.getFingerprint())) {
        if (reasonCode == RevokedCertInfo.REVOCATION_REASON_REMOVEFROMCRL) {
            deleteLimitedCertificateData(limitedFingerprint);
        } else {
            if (certificateInfo.getStatus() != limitedCertificateData.getStatus()
                    || certificateInfo.getRevocationDate().getTime() != limitedCertificateData
                            .getRevocationDate()
                    || certificateInfo.getRevocationReason() != limitedCertificateData.getRevocationReason()) {
                // Update the limited entry
                log.info("Updating limited CertificateData entry with fingerprint=" + limitedFingerprint
                        + ", serialNumber=" + serialNumber.toString(16).toUpperCase() + ", issuerDn='"
                        + issuerDn + "'");
                entityManager.merge(limitedCertificateData);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Limited CertificateData entry with fingerprint=" + limitedFingerprint
                            + ", serialNumber=" + serialNumber.toString(16).toUpperCase() + ", issuerDn='"
                            + issuerDn + "' was already up to date.");
                }
            }
        }
    } else {
        // Refuse to update a normal entry with this method
        throw new UnsupportedOperationException(
                "Only limited certificate entries can be updated using this method.");
    }
}

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

/**
 * {@inheritDoc}/*from ww w .j  av a  2  s .  co m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void clearTree(long mandatorId) throws FxNoAccessException {
    clearTree(FxPhraseCategorySelection.SELECTION_ANY, mandatorId);
}

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

/**
 * {@inheritDoc}/*from www .  jav  a2 s .c  om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public List<ACLAssignment> loadAccountAssignments(long accountId) throws FxApplicationException {
    Connection con = null;
    PreparedStatement stmt = null;
    String curSql;
    UserTicket ticket = getRequestTicket();

    // Security checks
    if (!ticket.isGlobalSupervisor()
            && (!(accountId == ticket.getUserId() || accountId == Account.USER_GUEST))) {
        try {
            Account usr = load(accountId);
            if (ticket.isMandatorSupervisor() && ticket.getMandatorId() == usr.getMandatorId()) {
                // MandatorSupervisor may access all users within his domain
            } else {
                FxNoAccessException nae = new FxNoAccessException(
                        "You may not access the ACLAssignment of user [" + accountId + "]");
                if (LOG.isInfoEnabled())
                    LOG.info(nae);
                throw nae;
            }
        } catch (FxNotFoundException exc) {
            return new ArrayList<ACLAssignment>(0);
        }
    }

    try {

        // Obtain a database connection
        con = Database.getDbConnection();

        // Fetch assignments
        //                            1             2       3         4         5           6           7
        curSql = "SELECT DISTINCT ass.USERGROUP,ass.ACL,ass.PREAD,ass.PEDIT,ass.PREMOVE,ass.PEXPORT,ass.PREL," +
        //   8
                "ass.PCREATE, " +
                // 9
                "(SELECT acl.CAT_TYPE FROM " + TBL_ACLS + " acl WHERE acl.ID=ass.ACL)" +
                // 10             11             12              13
                ",ass.CREATED_BY,ass.CREATED_AT,ass.MODIFIED_BY,ass.MODIFIED_AT " + "FROM "
                + TBL_ACLS_ASSIGNMENT + " ass " + "WHERE ass.USERGROUP IN (SELECT grp.USERGROUP FROM "
                + TBL_ASSIGN_GROUPS + " grp WHERE grp.ACCOUNT=?)" + " OR ass.USERGROUP="
                + UserGroup.GROUP_OWNER;

        stmt = con.prepareStatement(curSql);
        stmt.setLong(1, accountId);
        ResultSet rs = stmt.executeQuery();

        // Read the data
        List<ACLAssignment> result = new ArrayList<ACLAssignment>(50);
        while (rs != null && rs.next()) {
            long groupId = rs.getLong(1);
            result.add(new ACLAssignment(rs.getLong(2), groupId, rs.getBoolean(3), rs.getBoolean(4),
                    rs.getBoolean(7), rs.getBoolean(5), rs.getBoolean(6), rs.getBoolean(8),
                    ACLCategory.getById(rs.getByte(9)), LifeCycleInfoImpl.load(rs, 10, 11, 12, 13)));
        }
        return result;
    } catch (SQLException exc) {
        FxLoadException dbe = new FxLoadException(
                "Failed to load the ACL assignments for user [" + accountId + "]: " + exc.getMessage(), exc);
        LOG.error(dbe);
        throw dbe;
    } finally {
        Database.closeObjects(ACLEngineBean.class, con, stmt);
    }
}

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

/**
 * {@inheritDoc}/*from  w ww.j av a  2  s . co m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void clearTree(FxPhraseCategorySelection categories, long mandatorId) throws FxNoAccessException {
    checkMandatorAccess(mandatorId, FxContext.getUserTicket());
    Connection con = null;
    PreparedStatement ps = null;
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        if (categories.isAny()) {
            ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE_MAP + " WHERE MANDATOR=?");
            ps.setLong(1, mandatorId);
            ps.executeUpdate();
            ps.close();
            ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE_MAP + " WHERE NODEMANDATOR=?");
            ps.setLong(1, mandatorId);
            ps.executeUpdate();
            ps.close();
            ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE_MAP + " WHERE PMANDATOR=?");
            ps.setLong(1, mandatorId);
            ps.executeUpdate();
            ps.close();
            //fetch all categories for which node sequencers have to be removed
            ps = con.prepareStatement("SELECT DISTINCT CAT FROM " + TBL_PHRASE_TREE + " WHERE MANDATOR=?");
            ps.setLong(1, mandatorId);
            ResultSet rs = ps.executeQuery();
            List<Integer> cats = new ArrayList<Integer>(10);
            while (rs != null && rs.next()) {
                cats.add(rs.getInt(1));
            }
            if (rs != null)
                rs.close();
            ps.close();
            ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE_TREE + " WHERE MANDATOR=?");
            ps.setLong(1, mandatorId);
            ps.executeUpdate();
            for (int cat : cats)
                removeNodeSequencer(mandatorId, cat);
        } else {
            final String cat = categoriesList(categories);
            ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE_MAP
                    + " WHERE (MANDATOR=? OR NODEMANDATOR=? OR PMANDATOR=?) AND NODEID IN(SELECT DISTINCT ID FROM "
                    + TBL_PHRASE_TREE + " WHERE MANDATOR=? AND CAT IN(" + cat + ")) AND CAT IN(" + cat + ")");
            ps.setLong(1, mandatorId);
            ps.setLong(2, mandatorId);
            ps.setLong(3, mandatorId);
            ps.setLong(4, mandatorId);
            ps.executeUpdate();
            ps.close();
            ps = con.prepareStatement(
                    "DELETE FROM " + TBL_PHRASE_TREE + " WHERE MANDATOR=? AND CAT IN(" + cat + ")");
            ps.setLong(1, mandatorId);
            ps.executeUpdate();
            for (int category : categories.getCategories())
                removeNodeSequencer(mandatorId, category);
        }
    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException();
    } finally {
        Database.closeObjects(PhraseEngineBean.class, con, ps);
    }
}