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:com.flexive.ejb.beans.PhraseEngineBean.java

/**
 * {@inheritDoc}//  w  w w  .j av a  2  s  .c o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public long savePhrase(String phraseKey, FxString value, long mandator) throws FxNoAccessException {
    return savePhrase(FxPhraseCategorySelection.CATEGORY_DEFAULT, phraseKey, value, null, null, mandator);
}

From source file:ch.puzzle.itc.mobiliar.business.template.boundary.TemplateEditor.java

@TransactionAttribute(TransactionAttributeType.REQUIRED)
AbstractContext getOwnerOfTemplate(TemplateDescriptorEntity templateDescriptor) {
    // ContextEntity
    AbstractContext c;//  w  w w  . ja v  a 2 s.  c  o  m
    c = (AbstractContext) getSingleObjectOrNull(entityManager
            .createQuery("select distinct n from ContextEntity n where :templ member of n.templates")
            .setParameter("templ", templateDescriptor));
    if (c != null) {
        return c;
    }
    c = (AbstractContext) getSingleObjectOrNull(entityManager
            .createQuery("select distinct n from ContextTypeEntity n where :templ member of n.templates")
            .setParameter("templ", templateDescriptor));
    if (c != null) {
        return c;
    }
    c = (AbstractContext) getSingleObjectOrNull(entityManager
            .createQuery("select distinct n from ResourceContextEntity n where :templ member of n.templates")
            .setParameter("templ", templateDescriptor));
    if (c != null) {
        return c;
    }
    c = (AbstractContext) getSingleObjectOrNull(entityManager
            .createQuery(
                    "select distinct n from ResourceRelationContextEntity n where :templ member of n.templates")
            .setParameter("templ", templateDescriptor));
    if (c != null) {
        return c;
    }
    c = (AbstractContext) getSingleObjectOrNull(entityManager.createQuery(
            "select distinct n from ResourceRelationTypeContextEntity n where :templ member of n.templates")
            .setParameter("templ", templateDescriptor));
    if (c != null) {
        return c;
    }
    c = (AbstractContext) getSingleObjectOrNull(entityManager
            .createQuery(
                    "select distinct n from ResourceTypeContextEntity n where :templ member of n.templates")
            .setParameter("templ", templateDescriptor));
    if (c != null) {
        return c;
    }
    return null;

}

From source file:com.flexive.ejb.beans.configuration.GlobalConfigurationEngineBean.java

/**
 * {@inheritDoc}/* ww  w  . j  a  v  a  2s.  c om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public int[] getDivisionIds() throws FxApplicationException {
    try {
        // check cache
        int[] cachedDivisionIds = (int[]) getCache(getBeanPath(CACHE_DIVISIONS), "allDivisions");
        if (cachedDivisionIds != null) {
            return cachedDivisionIds;
        }
    } catch (FxCacheException e) {
        LOG.error("Cache failure (ignored): " + e.getMessage(), e);
    }

    // get list of all configured divisions
    Map<String, String> domainMappings = getAll(SystemParameters.GLOBAL_DIVISIONS_DOMAINS);
    int[] divisionIds = new int[domainMappings.keySet().size()];
    int ctr = 0;
    for (String divisionId : domainMappings.keySet()) {
        divisionIds[ctr++] = Integer.parseInt(divisionId);
    }
    Arrays.sort(divisionIds);
    putCache(getBeanPath(CACHE_DIVISIONS), "allDivisions", divisionIds, false);
    return divisionIds;
}

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

/**
 * {@inheritDoc}//from  ww w.j a v a 2s. c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public long savePhrase(int category, String phraseKey, FxString value, long mandator)
        throws FxNoAccessException {
    return savePhrase(category, phraseKey, value, null, null, mandator);
}

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

/**
 * {@inheritDoc}/*from   w w w .j  a v  a  2  s  . co  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void addItems(long id, Collection<FxPK> contents) throws FxApplicationException {
    Connection con = null;
    PreparedStatement stmt = null;
    final Briefcase br = load(id);
    checkEditBriefcase(br);
    try {
        con = Database.getDbConnection();

        // keep lookup table of existing items to avoid adding an item twice
        final Set<Long> existingItems = new HashSet<Long>();
        final long[] items = getItems(id);
        for (long item : items) {
            existingItems.add(item);
        }

        stmt = con.prepareStatement("SELECT MAX(pos) FROM " + TBL_BRIEFCASE_DATA + " WHERE briefcase_id=?");
        stmt.setLong(1, id);
        final ResultSet rs = stmt.executeQuery();
        int pos = rs.next() ? rs.getInt(1) : 0;
        stmt.close();
        stmt = con.prepareStatement(
                "INSERT INTO " + TBL_BRIEFCASE_DATA + "(briefcase_id, id, pos, amount) VALUES (?, ?, ?, 1)");
        stmt.setLong(1, id);
        for (FxPK pk : contents) {
            if (!existingItems.contains(pk.getId())) {
                stmt.setLong(2, pk.getId());
                stmt.setLong(3, ++pos);
                stmt.addBatch();
                existingItems.add(pk.getId());
            }
        }
        stmt.executeBatch();
    } catch (Exception e) {
        EJBUtils.rollback(ctx);
        throw new FxUpdateException(LOG, e, "ex.briefcase.addItems", br.getName(), e);
    } finally {
        closeObjects(BriefcaseEngineBean.class, con, stmt);
    }
}

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

/**
 * {@inheritDoc}//from  w  w w . ja v a 2 s  .c om
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void remove(long groupId) throws FxApplicationException {

    // Check special groups
    if (groupId == UserGroup.GROUP_UNDEFINED)
        return;

    // Load the group
    final UserGroup theGroup = CacheAdmin.getEnvironment().getUserGroup(groupId);

    if (theGroup == null) {
        throw new FxNotFoundException("ex.usergroup.groupNotFound.id", groupId);
    }

    // Check special groups
    if (theGroup.isSystem() && !FxContext.get().getRunAsSystem()) {
        FxNoAccessException nae = new FxNoAccessException("ex.usergroup.mayNotDeleteSystemGroups",
                theGroup.getName());
        LOG.error(nae);
        throw nae;
    }

    // Caller may delete the group?
    checkPermission(theGroup, "ex.usergroup.noDeletePerms");

    Connection con = null;
    Statement stmt = null;
    String sCurSql;
    try {

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

        // First of delete all user assignments to this group ..
        stmt = con.createStatement();
        sCurSql = "DELETE FROM " + TBL_ASSIGN_GROUPS + " WHERE USERGROUP=" + groupId;
        stmt.executeUpdate(sCurSql);
        stmt.close();

        // ... delete all roles assigned to this group
        stmt = con.createStatement();
        sCurSql = "DELETE FROM " + TBL_ROLE_MAPPING + " WHERE USERGROUP=" + groupId;
        stmt.executeUpdate(sCurSql);
        stmt.close();

        // ... then delete all ACL assignments to this group ..
        stmt = con.createStatement();
        sCurSql = "DELETE FROM " + TBL_ACLS_ASSIGNMENT + " WHERE USERGROUP=" + groupId;
        stmt.executeUpdate(sCurSql);
        stmt.close();

        // ... and finally delete the group itself;
        stmt = con.createStatement();
        sCurSql = "DELETE FROM " + TBL_USERGROUPS + " WHERE ID=" + groupId;
        stmt.executeUpdate(sCurSql);

        // Update all active user tickets that are affected
        UserTicketStore.flagDirtyHavingGroupId(groupId);

        StructureLoader.updateUserGroups(FxContext.get().getDivisionId(), loadAll(-1));

        // Log
        if (LOG.isDebugEnabled())
            LOG.debug("Group [" + theGroup + "] was successfully deleted.");
    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        FxRemoveException ce = new FxRemoveException(exc, "ex.usergroup.deleteSqlException",
                theGroup.getName());
        LOG.error(ce);
        throw ce;
    } finally {
        Database.closeObjects(UserGroupEngineBean.class, con, stmt);
    }

}

From source file:com.flexive.ejb.beans.configuration.GenericConfigurationImpl.java

/**
 * {@inheritDoc}//from w w w.  j av a  2 s .  c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public <T extends Serializable> void put(Parameter<T> parameter, T value) throws FxApplicationException {
    put(parameter, parameter.getData().getKey(), value);
}

From source file:com.flexive.ejb.beans.structure.SelectListEngineBean.java

/**
 * {@inheritDoc}//ww  w.j a va 2  s . c  o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void remove(FxSelectListItem item) throws FxApplicationException {
    //        System.out.println("Removing item " + item.getLabel());
    if (!(FxContext.getUserTicket().isInRole(Role.SelectListEditor) || FxContext.getUserTicket()
            .mayDeleteACL(item.getList().getCreateItemACL().getId(), FxContext.getUserTicket().getUserId())))
        throw new FxNoAccessException("ex.selectlist.item.remove.noPerm", item.getList().getLabel(),
                item.getAcl().getLabel());
    Connection con = null;
    PreparedStatement ps = null;
    try {
        con = Database.getDbConnection();
        //references (parent items)
        StringBuilder sb = new StringBuilder(500).append("UPDATE ").append(TBL_STRUCT_SELECTLIST_ITEM)
                .append(" SET PARENTID=? WHERE PARENTID=?");
        ps = con.prepareStatement(sb.toString());
        ps.setNull(1, java.sql.Types.INTEGER);
        ps.setLong(2, item.getId());
        ps.executeUpdate();
        ps.close();
        sb.setLength(0);
        //translations
        sb.append("DELETE FROM ").append(TBL_STRUCT_SELECTLIST_ITEM).append(ML).append(" WHERE ID=?");
        ps = con.prepareStatement(sb.toString());
        ps.setLong(1, item.getId());
        ps.executeUpdate();
        ps.close();
        sb.setLength(0);
        //the entry itself
        sb.append("DELETE FROM ").append(TBL_STRUCT_SELECTLIST_ITEM).append(" WHERE ID=?");
        ps = con.prepareStatement(sb.toString());
        ps.setLong(1, item.getId());
        ps.executeUpdate();
        StructureLoader.reload(null);
    } catch (SQLException e) {
        EJBUtils.rollback(ctx);
        throw new FxCreateException(LOG, e, "ex.db.sqlError", e.getMessage());
    } catch (FxCacheException e1) {
        EJBUtils.rollback(ctx);
        throw new FxCreateException(LOG, e1, "ex.cache", e1.getMessage());
    } finally {
        Database.closeObjects(TypeEngineBean.class, con, ps);
    }
}

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

/**
 * {@inheritDoc}/*from  www.j a  v a2  s .  c  o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public long savePhrase(String phraseKey, FxString value, FxPhraseSearchValueConverter converter, long mandator)
        throws FxNoAccessException {
    return savePhrase(FxPhraseCategorySelection.CATEGORY_DEFAULT, phraseKey, value, converter, null, mandator);
}

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

/**
 * {@inheritDoc}// ww w .j a  v  a  2  s  .c o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void remove(long mandatorId) throws FxApplicationException {
    final UserTicket ticket = FxContext.getUserTicket();
    final FxEnvironment environment = CacheAdmin.getEnvironment();
    // Security
    FxPermissionUtils.checkRole(ticket, Role.GlobalSupervisor);
    //exist check
    Mandator mand = environment.getMandator(mandatorId);
    Connection con = null;
    PreparedStatement ps = null;
    String sql;

    try {
        try {
            FxContext.get().runAsSystem();
            grp.remove(grp.loadMandatorGroup(mandatorId).getId());
        } finally {
            FxContext.get().stopRunAsSystem();
        }
        con = Database.getDbConnection();
        //                                                  1
        sql = "DELETE FROM " + TBL_USERGROUPS + " WHERE MANDATOR=? AND AUTOMANDATOR=1";
        ps = con.prepareStatement(sql);
        ps.setLong(1, mandatorId);
        ps.executeUpdate();
        ps.close();
        //                                                1
        sql = "DELETE FROM " + TBL_MANDATORS + " WHERE ID=?";
        ps = con.prepareStatement(sql);
        ps.setLong(1, mandatorId);
        ps.executeUpdate();
        StructureLoader.removeMandator(FxContext.get().getDivisionId(), mandatorId);
        StructureLoader.updateUserGroups(FxContext.get().getDivisionId(), grp.loadAll(-1));
    } catch (SQLException exc) {
        final boolean keyViolation = StorageManager.isForeignKeyViolation(exc);
        EJBUtils.rollback(ctx);
        if (keyViolation)
            throw new FxEntryInUseException(exc, "ex.mandator.removeFailed.inUse", mand.getName());
        throw new FxRemoveException(LOG, exc, "ex.mandator.removeFailed", mand.getName(), exc.getMessage());
    } finally {
        Database.closeObjects(MandatorEngineBean.class, con, ps);
    }
}