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:fr.ortolang.diffusion.core.CoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public String getLatestSnapshot(String wskey)
        throws CoreServiceException, KeyNotFoundException, AccessDeniedException {
    try {/*  ww  w.j  a va  2 s. c om*/
        List<String> subjects = membership.getConnectedIdentifierSubjects();

        OrtolangObjectIdentifier identifier = registry.lookup(wskey);
        checkObjectType(identifier, Workspace.OBJECT_TYPE);
        authorisation.checkPermission(wskey, subjects, "read");

        Workspace workspace = em.find(Workspace.class, identifier.getId());
        if (workspace == null) {
            throw new CoreServiceException(
                    "unable to load workspace with id [" + identifier.getId() + "] from storage");
        }

        return String.valueOf(workspace.getClock() - 1);
    } catch (MembershipServiceException | AuthorisationServiceException | RegistryServiceException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred while getting latest workspace snapshot", e);
        throw new CoreServiceException("unable to get latest snapshot for workspace with key [" + wskey + "]",
                e);
    }
}

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

/**
 * {@inheritDoc}//  ww w  . j ava2 s. c o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<String> getLabels(FxTreeMode mode, long... ids) throws FxApplicationException {
    return getLabels(mode, FxContext.getUserTicket().getLanguage(), ids);
}

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

/**
 * {@inheritDoc}//from   w  w w.  j a  va2  s  .c  o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<String> getLabels(FxTreeMode mode, FxLanguage language, long... ids) throws FxApplicationException {
    Connection con = null;
    try {
        con = Database.getDbConnection();
        return StorageManager.getTreeStorage().getLabels(con, mode, getCaptionPropertyId(), language, true,
                ids);
    } catch (FxApplicationException ae) {
        throw ae;
    } catch (Throwable t) {
        throw new FxUpdateException(LOG, t, "ex.tree.getLabels.failed", mode, language.getIso2digit(),
                t.getMessage());
    } finally {
        Database.closeObjects(TreeEngineBean.class, con, null);
    }
}

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

/**
 * {@inheritDoc}//from  ww w. j a  v  a  2  s.co  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public String loadPhraseValue(long language, String phraseKey, long... mandators) throws FxNotFoundException {
    Connection con = null;
    PreparedStatement ps = null;
    checkPhraseKey(phraseKey);
    if (mandators == null || mandators.length == 0)
        mandators = new long[] { FxContext.getUserTicket().getMandatorId() };
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        ps = con.prepareStatement("SELECT v.PVAL FROM " + TBL_PHRASE_VALUES + " v, " + TBL_PHRASE
                + " p WHERE p.PKEY=? AND p.MANDATOR=? AND v.ID=p.ID AND v.MANDATOR=p.MANDATOR AND v.LANG=?");
        ps.setString(1, phraseKey);
        ps.setLong(3, language);
        for (long mandator : mandators) {
            ps.setLong(2, mandator);
            ResultSet rs = ps.executeQuery();
            if (rs != null && rs.next()) {
                return rs.getString(1);
            }
            if (rs != null)
                rs.close();
        }
    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException();
    } finally {
        Database.closeObjects(PhraseEngineBean.class, con, ps);
    }
    throw new FxNotFoundException("ex.phrase.key.notFound", phraseKey);
}

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

/**
 * {@inheritDoc}//from w  ww . j  a v  a 2  s.com
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public boolean exist(FxTreeMode mode, long id) throws FxApplicationException {
    Connection con = null;
    try {
        con = Database.getDbConnection();
        return StorageManager.getTreeStorage().exists(con, mode, id);
    } catch (FxApplicationException ae) {
        throw ae;
    } catch (Throwable t) {
        throw new FxLoadException(LOG, t, "ex.tree.exist.failed", id, mode, t.getMessage());
    } finally {
        Database.closeObjects(TreeEngineBean.class, con, null);
    }
}

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

/**
 * {@inheritDoc}/*ww w  .  j ava  2s  .c  om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Map<String, FxString> getResourceValues(String keyPrefix, long defaultLanguage)
        throws FxApplicationException {
    return getResourceValuesLike(keyPrefix + "%", defaultLanguage);
}

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

/**
 * {@inheritDoc}//from  w ww  .  j  a va 2  s. c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Map<String, FxString> getResourceValuesContains(String keyMatch, long defaultLanguage)
        throws FxApplicationException {
    return getResourceValuesLike("%" + keyMatch + "%", defaultLanguage);
}

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

/**
 * {@inheritDoc}//w  w w. j av a2s.  c  om
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public String[] getDatas(FxTreeMode mode, long id) {
    throw new UnsupportedOperationException("Not yet implemented");
}

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

/**
 * {@inheritDoc}//from www. j  ava2 s . c o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxString loadPhraseValue(String phraseKey, long... mandators) throws FxNotFoundException {
    Connection con = null;
    PreparedStatement ps = null;
    checkPhraseKey(phraseKey);
    if (mandators == null || mandators.length == 0)
        mandators = new long[] { FxContext.getUserTicket().getMandatorId() };
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        ps = con.prepareStatement("SELECT v.LANG, v.PVAL FROM " + TBL_PHRASE_VALUES + " v, " + TBL_PHRASE
                + " p WHERE p.PKEY=? AND p.MANDATOR=? AND v.ID=p.ID AND v.MANDATOR=p.MANDATOR");
        ps.setString(1, phraseKey);
        for (long mandator : mandators) {
            ps.setLong(2, mandator);
            ResultSet rs = ps.executeQuery();
            if (rs != null && rs.next()) {
                boolean ml = rs.getLong(1) != FxLanguage.SYSTEM_ID;
                FxString val = new FxString(ml, rs.getLong(1), rs.getString(2));
                while (rs.next())
                    val.setTranslation(rs.getLong(1), rs.getString(2));
                return val;
            }
            if (rs != null)
                rs.close();
        }
    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException();
    } finally {
        Database.closeObjects(PhraseEngineBean.class, con, ps);
    }
    throw new FxNotFoundException("ex.phrase.key.notFound", phraseKey);
}

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

/**
 * {@inheritDoc}/*from   w  w w  .  j a  v a  2s.co  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxTreeNode findChild(FxTreeMode mode, long nodeId, String name) throws FxApplicationException {
    for (FxTreeNode node : getTree(mode, nodeId, 1).getChildren()) {
        if (node.getName().equals(name)) {
            return node;
        }
    }
    throw new FxNotFoundException("ex.tree.nodeNotFound.name", name, mode, nodeId);
}