Example usage for javax.ejb TransactionAttributeType SUPPORTS

List of usage examples for javax.ejb TransactionAttributeType SUPPORTS

Introduction

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

Prototype

TransactionAttributeType SUPPORTS

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

Click Source Link

Document

If the client calls with a transaction context, the container performs the same steps as described in the REQUIRED case.

Usage

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

/**
 * {@inheritDoc}//from   w w  w  . j  av  a 2s  . co m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxScriptResult runScript(String scriptName, FxScriptBinding binding) throws FxApplicationException {
    return runScript(CacheAdmin.getEnvironment().getScript(scriptName).getId(), binding);
}

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

/**
 * {@inheritDoc}/*from  w  w  w. j  ava  2s .  c  o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<ACLAssignment> loadGroupAssignments(long groupId) throws FxApplicationException {
    return loadAssignments(null, groupId);
}

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

/**
 * {@inheritDoc}/*w  ww .  ja va 2  s. c o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxScriptResult runScript(long scriptId, FxScriptBinding binding) throws FxApplicationException {
    FxScriptInfo si = CacheAdmin.getEnvironment().getScript(scriptId);

    if (!si.isActive()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(
                    "Script [" + si.getName() + "], Id " + si.getId() + " is deactivated and will not be run!");
        }
        return new FxScriptResult(binding, null);
    }

    if (!FxSharedUtils.isGroovyScript(si.getName()))
        return LocalScriptingCache.internal_runScript(si.getName(), binding, loadScriptCode(si.getId()));

    if (si.getEvent() == FxScriptEvent.Manual)
        FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.ScriptExecution);

    long timeStamp = CacheAdmin.getEnvironment().getTimeStamp();
    if (timeStamp != LocalScriptingCache.scriptCacheTimestamp)
        resetLocalCaches(timeStamp);
    Script script = LocalScriptingCache.groovyScriptCache.get(scriptId);
    if (script == null) {
        try {
            GroovyShell shell = new GroovyShell();
            script = shell.parse(loadScriptCode(scriptId));
        } catch (CompilationFailedException e) {
            throw new FxInvalidParameterException(si.getName(), LOG, "ex.general.scripting.compileFailed",
                    si.getName(), e.getMessage());
        } catch (Throwable t) {
            throw new FxInvalidParameterException(si.getName(), "ex.general.scripting.exception", si.getName(),
                    t.getMessage());
        }
        if (si.isCached()) {
            Script cachedScript = LocalScriptingCache.groovyScriptCache.putIfAbsent(scriptId, script);
            if (cachedScript != null) {
                script = cachedScript;
            }
        }
    }

    if (binding == null)
        binding = new FxScriptBinding();
    if (!binding.getProperties().containsKey("ticket"))
        binding.setVariable("ticket", FxContext.getUserTicket());
    if (!binding.getProperties().containsKey("environment"))
        binding.setVariable("environment", CacheAdmin.getEnvironment());
    binding.setVariable("scriptname", si.getName());

    synchronized (script) {
        try {
            Object result;
            script.setBinding(new Binding(binding.getProperties()));
            result = script.run();
            return new FxScriptResult(new FxScriptBinding(binding.getProperties()), result);
        } catch (Throwable e) {
            if (e instanceof FxApplicationException)
                throw (FxApplicationException) e;
            LOG.error("Scripting error: " + e.getMessage(), e);
            throw new FxInvalidParameterException(si.getName(), "ex.general.scripting.exception", si.getName(),
                    e.getMessage());
        } finally {
            // don't leave binding in script cache
            script.setBinding(null);
        }
    }
}

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

/**
 * {@inheritDoc}//from w ww.j  a va2s . c  om
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<ACLAssignment> loadAssignments(long aclId) throws FxApplicationException {
    return loadAssignments(aclId, null);
}

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

/**
 * {@inheritDoc}/*from   www.  j av a2 s  .c om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<FxTreeNode> getNodesWithReference(FxTreeMode mode, long reference) throws FxApplicationException {
    Connection con = null;
    try {
        con = Database.getDbConnection();
        return StorageManager.getTreeStorage().getNodesWithReference(con, mode, reference);
    } catch (FxApplicationException ae) {
        throw ae;
    } catch (Throwable t) {
        throw new FxUpdateException(LOG, t, "ex.tree.getNodesWithReference.failed", mode, reference);
    } finally {
        Database.closeObjects(TreeEngineBean.class, con, null);
    }
}

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

/**
 * {@inheritDoc}/*w  w w  . j av  a  2  s .  co m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxTreeNode getNode(FxTreeMode mode, long id) throws FxApplicationException {
    Connection con = null;
    try {
        con = Database.getDbConnection();
        return StorageManager.getTreeStorage().getNode(con, mode, id);
    } catch (FxApplicationException fx) {
        throw fx;
    } catch (Throwable t) {
        throw new FxLoadException(LOG, t, "ex.tree.load.failed.node", id, mode, t.getMessage());
    } finally {
        Database.closeObjects(TreeEngineBean.class, con, null);
    }
}

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

/**
 * {@inheritDoc}/* www.ja  v a 2 s .c o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<ACLAssignment> loadAssignments(Long aclId, Long groupId) throws FxApplicationException {
    Connection con = null;
    Statement stmt = null;
    String curSql;
    UserTicket ticket = FxContext.getUserTicket();

    // Permission & Exists check
    checkPermissions(ticket, groupId, aclId, false);
    try {
        // Obtain a database connection
        con = Database.getDbConnection();

        // load assignments
        //                   1             2       3         4         5           6           7
        curSql = "SELECT ass.USERGROUP,ass.ACL,ass.PREAD,ass.PEDIT,ass.PREMOVE,ass.PEXPORT,ass.PREL," +
        //   8        ,      9        10             11             12              13
                "ass.PCREATE,acl.CAT_TYPE,ass.CREATED_BY,ass.CREATED_AT,ass.MODIFIED_BY,ass.MODIFIED_AT "
                + "FROM " + TBL_ACLS_ASSIGNMENT + " ass, " + TBL_ACLS + " acl WHERE " + "ass.ACL=acl.ID AND "
                + ((groupId != null) ? "USERGROUP=" + groupId : "")
                + ((groupId != null && aclId != null) ? " AND " : "") + ((aclId != null) ? "ACL=" + aclId : "");

        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(curSql);

        // Read the data
        ArrayList<ACLAssignment> result = new ArrayList<ACLAssignment>(20);
        while (rs != null && rs.next())
            result.add(new ACLAssignment(rs.getLong(2), rs.getLong(1), 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 the found entries
        result.trimToSize();
        return result;
    } catch (SQLException exc) {
        throw new FxLoadException(LOG, exc, "ex.aclAssignment.loadFailed");
    } finally {
        Database.closeObjects(ACLEngineBean.class, con, stmt);
    }
}

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

/**
 * {@inheritDoc}/*from  w  w  w  .j  a va  2  s.c om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxScriptResult runScript(long scriptId) throws FxApplicationException {
    return runScript(scriptId, null);
}

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

/**
 * {@inheritDoc}/*ww  w . j a va2  s.c o m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<String> getPaths(FxTreeMode mode, long... ids) throws FxApplicationException {
    if (ids == null || ids.length == 0)
        return new ArrayList<String>(0);
    Connection con = null;
    try {
        con = Database.getDbConnection();
        List<String> res = new ArrayList<String>(ids.length);
        TreeStorage tree = StorageManager.getTreeStorage();
        for (long id : ids)
            res.add(tree.getPathById(con, mode, id));
        return res;
    } catch (FxApplicationException ae) {
        throw ae;
    } catch (Throwable t) {
        throw new FxTreeException(LOG, t, "ex.tree.getPaths.failed", Arrays.toString(ids), mode);
    } finally {
        Database.closeObjects(TreeEngineBean.class, con, null);
    }
}

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

/**
 * {@inheritDoc}/*  w  ww . j av  a 2 s. c o m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxString getResourceValue(String key, long defaultLanguage) throws FxApplicationException {
    if (StringUtils.isBlank(key)) {
        return null;
    }
    key = key.trim();
    Connection con = null;
    PreparedStatement ps = null;
    try {
        con = Database.getDbConnection();
        ps = con.prepareStatement("SELECT LANG,RVAL FROM " + TBL_RESOURCES + "  WHERE RKEY=?");
        ps.setString(1, key);
        ResultSet rs = ps.executeQuery();
        long firstLang = -1;
        Map<Long, String> trans = new HashMap<Long, String>(10);
        while (rs != null && rs.next()) {
            if (firstLang == -1)
                firstLang = rs.getLong(1);
            trans.put(rs.getLong(1), rs.getString(2));
        }
        return buildFxString(firstLang, defaultLanguage, trans);
    } catch (SQLException e) {
        throw new FxApplicationException(e, "ex.db.sqlError", e.getMessage());
    } finally {
        Database.closeObjects(DivisionConfigurationEngine.class, con, ps);
    }
}