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.TreeEngineBean.java

/**
 * {@inheritDoc}//from   ww w. j  av  a  2  s  . com
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxTreeNode findChild(FxTreeMode mode, long nodeId, long referenceId) throws FxApplicationException {
    for (FxTreeNode node : getTree(mode, nodeId, 1).getChildren())
        if (node.getReference().getId() == referenceId)
            return node;
    throw new FxNotFoundException("ex.tree.nodeNotFound.reference", referenceId, mode, nodeId);
}

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

/**
 * {@inheritDoc}//from  w ww  . ja va 2s.c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxPhrase loadPhrase(String phraseKey, long... mandators) throws FxNotFoundException {
    return loadPhrase(FxPhraseCategorySelection.CATEGORY_DEFAULT, phraseKey, mandators);
}

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 FxTreeNode findChild(FxTreeMode mode, long nodeId, FxPK pk) throws FxApplicationException {
    return findChild(mode, nodeId, pk.getId());
}

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

/**
 * {@inheritDoc}/*from w w  w  . j  a va  2s.  c o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxPhrase loadPhrase(int category, 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,v.TAG,p.ID,p.HID 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 p.CAT=?");
        ps.setString(1, phraseKey);
        ps.setInt(3, category);
        for (long mandator : mandators) {
            ps.setLong(2, mandator);
            ResultSet rs = ps.executeQuery();
            if (rs != null && rs.next()) {
                final long id = rs.getLong(4);
                final boolean hidden = rs.getBoolean(5);
                boolean ml = rs.getLong(1) != FxLanguage.SYSTEM_ID;
                FxString val = new FxString(ml, rs.getLong(1), rs.getString(2));
                FxString fxTag;
                String tag = rs.getString(3);
                boolean hasTag = false;
                if (rs.wasNull())
                    fxTag = new FxString(FxString.EMPTY).setEmpty();
                else {
                    fxTag = new FxString(ml, rs.getLong(1), tag);
                    hasTag = true;
                }
                while (rs.next()) {
                    val.setTranslation(rs.getLong(1), rs.getString(2));
                    if (hasTag)
                        fxTag.setTranslation(rs.getLong(1), rs.getString(3));
                }
                return new FxPhrase(mandator, phraseKey, val, fxTag).setId(id).flagHidden(hidden)
                        .flagCategory(category);
            }
            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.configuration.DivisionConfigurationEngineBean.java

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Set<String> getResourceKeysMatching(String keyMatch) throws FxApplicationException {
    FxSharedUtils.checkParameterNull(keyMatch, "keyPrefix");

    final Set<String> keys = Sets.newHashSet();
    Connection con = null;/*from  ww w .  j  a va  2s .  c om*/
    PreparedStatement ps = null;
    try {
        con = Database.getDbConnection();
        ps = con.prepareStatement("SELECT RKEY FROM " + TBL_RESOURCES + " WHERE RKEY LIKE ?");

        String queryValue = keyMatch.trim();
        if (queryValue.indexOf('%') == -1) {
            queryValue += "%";
        }

        ps.setString(1, queryValue);

        final ResultSet rs = ps.executeQuery();

        while (rs.next()) {
            keys.add(rs.getString(1));
        }

        return keys;
    } catch (SQLException e) {
        throw new FxApplicationException(e, "ex.db.sqlError", e.getMessage());
    } finally {
        Database.closeObjects(DivisionConfigurationEngineBean.class, con, ps);
    }
}

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

/**
 * {@inheritDoc}/*from  w  w  w .  j  a  v a2s.  c om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxTreeNode findChild(FxTreeMode mode, long nodeId, FxReference reference) throws FxApplicationException {
    return findChild(mode, nodeId, reference.getBestTranslation().getId());
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Set<String> getResourceKeysMatching(String keyMatch, String valueMatch, long searchLanguage)
        throws FxApplicationException {
    FxSharedUtils.checkParameterNull(keyMatch, "keyMatch");
    FxSharedUtils.checkParameterNull(valueMatch, "valueMatch");

    final Set<String> keys = Sets.newHashSet();
    Connection con = null;//from   w ww . j av  a 2s .  com
    PreparedStatement ps = null;
    try {
        con = Database.getDbConnection();
        ps = con.prepareStatement(
                "SELECT RKEY FROM " + TBL_RESOURCES + " WHERE RKEY LIKE ? AND UPPER(RVAL) LIKE ? AND LANG=?");

        String keyQuery = keyMatch.trim();
        if (keyQuery.indexOf('%') == -1) {
            keyQuery += "%";
        }

        String valueQuery = valueMatch.trim();
        if (valueQuery.indexOf('%') == -1) {
            valueQuery += "%";
        }

        ps.setString(1, keyQuery);
        ps.setString(2, valueQuery.toUpperCase());
        ps.setLong(3, searchLanguage);

        final ResultSet rs = ps.executeQuery();

        while (rs.next()) {
            keys.add(rs.getString(1));
        }

        return keys;
    } catch (SQLException e) {
        throw new FxApplicationException(e, "ex.db.sqlError", e.getMessage());
    } finally {
        Database.closeObjects(DivisionConfigurationEngineBean.class, con, ps);
    }
}

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

/**
 * {@inheritDoc}/* w w  w.j  a va  2  s.c  o m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<FxPhrase> loadPhrases(String phraseKeyPrefix, long... _mandators) {
    return loadPhrases(FxPhraseCategorySelection.CATEGORY_DEFAULT, phraseKeyPrefix, _mandators);
}

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

/**
 * {@inheritDoc}/*from   w  w w. j  a  va2  s .  com*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<FxPhrase> loadPhrases(int category, String phraseKeyPrefix, long... _mandators) {
    Connection con = null;
    PreparedStatement ps = null;
    checkPhraseKey(phraseKeyPrefix);
    long[] mandators = checkMandatorFiltering(_mandators);

    List<FxPhrase> result = Lists.newArrayListWithExpectedSize(50);
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        if (mandators.length == 1) {
            //                                  1     2       3           4       5       6      7
            ps = con.prepareStatement("SELECT r.ID, r.PKEY, r.MANDATOR, v.LANG, v.PVAL, v.TAG, r.HID FROM "
                    + TBL_PHRASE_VALUES + " v, " + TBL_PHRASE
                    + " r WHERE r.PKEY LIKE ? AND r.MANDATOR=? AND r.CAT=? AND v.ID=r.ID AND v.MANDATOR=r.MANDATOR ORDER BY r.PKEY");
            ps.setString(1, phraseKeyPrefix + "%");
            ps.setLong(2, mandators[0]);
            ps.setInt(3, category);
        } else {
            //                                  1     2       3           4       5       6      7
            ps = con.prepareStatement("SELECT r.ID, r.PKEY, r.MANDATOR, v.LANG, v.PVAL, v.TAG, r.HID FROM "
                    + TBL_PHRASE_VALUES + " v, " + TBL_PHRASE +
                    //                    1                 2               3                                                                                    4            5
                    " r WHERE r.PKEY LIKE ? AND (r.MANDATOR=? OR(r.MANDATOR=? AND NOT EXISTS(SELECT r2.ID FROM FX_PHRASE r2 WHERE r2.PKEY=r.PKEY AND r2.MANDATOR=? AND r2.CAT=?)))"
                    +
                    //         6
                    "AND r.CAT=? AND v.ID=r.ID AND v.MANDATOR=r.MANDATOR ORDER BY r.PKEY");
            ps.setString(1, phraseKeyPrefix + "%");
            ps.setLong(2, mandators[0]);
            ps.setLong(3, mandators[1]);
            ps.setLong(4, mandators[0]);
            ps.setInt(5, category);
            ps.setInt(6, category);
        }

        ResultSet rs = ps.executeQuery();

        long currId = -1L;
        long currMandator;
        String currKey;
        FxPhrase currPhrase = null;

        boolean ml;
        FxString val = null;
        Boolean hasTag = null;
        FxString fxTag = null;

        while (rs != null && rs.next()) {
            final long lang = rs.getLong(4);
            if (currId != rs.getLong(1)) {
                if (currPhrase != null)
                    result.add(currPhrase);
                currId = rs.getLong(1);
                currKey = rs.getString(2);
                currMandator = rs.getLong(3);
                ml = lang != FxLanguage.SYSTEM_ID;
                final String tag = rs.getString(6);
                hasTag = rs.wasNull();
                fxTag = hasTag ? new FxString(ml, lang, tag) : new FxString(FxString.EMPTY).setEmpty();
                val = new FxString(ml, lang, rs.getString(5));
                currPhrase = new FxPhrase(currMandator, currKey, val, fxTag).flagCategory(category)
                        .flagHidden(rs.getBoolean(7));
            } else {
                val.setTranslation(lang, rs.getString(5));
                if (hasTag)
                    fxTag.setTranslation(lang, rs.getString(6));
            }
        }
        if (currPhrase != null)
            result.add(currPhrase);
    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException();
    } finally {
        Database.closeObjects(PhraseEngineBean.class, con, ps);
    }
    return result;
}

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

/**
 * {@inheritDoc}//from ww  w.  j  a v a 2s  .  c om
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<FxPK> getPKsForType(long typeId, boolean onePkPerInstance) throws FxApplicationException {
    if (!FxContext.getUserTicket().isGlobalSupervisor()) {
        throw new FxNoAccessException("ex.content.type.getAll.noPermission");
    }
    Connection con = null;
    try {
        con = Database.getDbConnection();
        return StorageManager.getContentStorage(TypeStorageMode.Hierarchical).getPKsForType(con,
                CacheAdmin.getEnvironment().getType(typeId), onePkPerInstance);
    } catch (Exception e) {
        throw new FxLoadException(LOG, e, "ex.db.sqlError", e.getMessage());
    } finally {
        Database.closeObjects(ContentEngineBean.class, con, null);
    }
}