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

/**
 * {@inheritDoc}/*from   www.  j ava2s .  c om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public void track(Long mandator, String typeName, String loginname, String application, String session,
        String remoteHost, String message, String data, String key, Object... args) {
    Connection con = null;
    PreparedStatement ps = null;
    try {
        final UserTicket ticket = FxContext.getUserTicket();
        con = Database.getDbConnection();
        boolean hasMandator = mandator != null;
        ps = con.prepareStatement(
                StorageManager.escapeReservedWords(hasMandator ? HISTORY_INSERT_MANDATOR : HISTORY_INSERT));
        ps.setLong(1, ticket.getUserId());
        ps.setString(2, StringUtils.isBlank(loginname) ? ticket.getLoginName() : loginname);

        ps.setLong(3, System.currentTimeMillis());
        ps.setString(4, key);
        StorageManager.setBigString(ps, 5, StringUtils.join(args, '|'));
        try {
            if (StringUtils.isNotBlank(message))
                ps.setString(6, message);
            else
                ps.setString(6,
                        FxSharedUtils.getLocalizedMessage("History", FxLanguage.ENGLISH, "en", key, args));
        } catch (Exception e) {
            ps.setString(6, key);
        }
        FxContext si = FxContext.get();
        ps.setString(7, StringUtils.isNotBlank(session) ? session
                : (si.getSessionId() == null ? "<unknown>" : si.getSessionId()));
        ps.setString(8, StringUtils.isNotBlank(application) ? application
                : (si.getApplicationId() == null ? "<unknown>" : si.getApplicationId()));
        ps.setString(9, StringUtils.isNotBlank(remoteHost) ? remoteHost
                : (si.getRemoteHost() == null ? "<unknown>" : si.getRemoteHost()));
        if (StringUtils.isNotBlank(typeName)) {
            ps.setNull(10, java.sql.Types.NUMERIC);
            ps.setString(11, typeName);
        } else {
            ps.setNull(10, java.sql.Types.NUMERIC);
            ps.setNull(11, java.sql.Types.VARCHAR);
        }
        ps.setNull(12, java.sql.Types.NUMERIC);
        ps.setNull(13, java.sql.Types.NUMERIC);
        if (StringUtils.isNotBlank(data))
            StorageManager.setBigString(ps, 14, data);
        else
            ps.setNull(14, java.sql.Types.VARCHAR);
        if (hasMandator)
            ps.setLong(15, mandator);
        ps.executeUpdate();
    } catch (Exception ex) {
        LOG.error(ex.getMessage());
    } finally {
        Database.closeObjects(HistoryTrackerEngineBean.class, con, ps);
    }
}

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

/**
 * {@inheritDoc}//from www. j  av  a2 s  . c o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public UserGroup loadMandatorGroup(long mandatorId) throws FxApplicationException {
    Connection con = null;
    Statement stmt = null;
    String sql = "SELECT ID,MANDATOR,NAME,COLOR,AUTOMANDATOR,ISSYSTEM FROM " + TBL_USERGROUPS
            + " WHERE AUTOMANDATOR=" + mandatorId;

    try {

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

        // Create the new workflow instance
        stmt = con.createStatement();

        // Build statement
        ResultSet rs = stmt.executeQuery(sql);

        // Does the group exist at all?
        if (rs == null || !rs.next())
            throw new FxNotFoundException("ex.account.group.notFound.id", mandatorId);
        long autoMandator = rs.getLong(5);
        if (rs.wasNull())
            autoMandator = -1;
        return new UserGroup(rs.getLong(1), rs.getLong(2), autoMandator, rs.getBoolean(6), rs.getString(3),
                rs.getString(4));
    } catch (SQLException exc) {
        FxLoadException de = new FxLoadException(exc, "ex.usergroup.sqlError", exc.getMessage(), sql);
        LOG.error(de);
        throw de;
    } finally {
        Database.closeObjects(UserGroupEngineBean.class, con, stmt);
    }
}

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

/**
 * {@inheritDoc}//from w ww  . j a va  2  s  .  c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxLanguage load(String languageIsoCode) throws FxApplicationException {
    try {
        if (StringUtils.isBlank(languageIsoCode) || languageIsoCode.length() != 2)
            throw new FxInvalidLanguageException("ex.language.invalid", languageIsoCode);
        FxLanguage lang = (FxLanguage) CacheAdmin.getInstance().get(CacheAdmin.LANGUAGES_ISO, languageIsoCode);
        if (lang == null) {
            //check unavailable
            String check = languageIsoCode.toLowerCase();
            for (FxLanguage l : loadAll(false, false)) {
                if (l.getIso2digit().equals(check))
                    return l;
            }
            throw new FxInvalidLanguageException("ex.language.invalid", languageIsoCode);
        }
        return lang;
    } catch (FxCacheException e) {
        throw new FxLoadException(LOG, e);
    }
}

From source file:gov.nih.nci.caarray.application.translation.magetab.MageTabExporterBean.java

/**
 * {@inheritDoc}/*  w  w  w  .  j  a v a  2s.  c  o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public MageTabDocumentSet exportToMageTab(Experiment experiment, File idfFile, File sdrfFile) {
    LogUtil.logSubsystemEntry(LOG, experiment);

    final MageTabFileSet fileSet = new MageTabFileSet();
    fileSet.addIdf(new JavaIOFileRef(idfFile));
    fileSet.addSdrf(new JavaIOFileRef(sdrfFile));

    // Translate caArray domain object graph into MAGE-TAB object graph, and new_JavaIOFileRef MAGE-TAB documents.
    final MageTabDocumentSet mageTabDocumentSet = translateToMageTab(experiment, fileSet);

    // Ask the MAGE-TAB documents to export themselves into their respective files.
    mageTabDocumentSet.export();

    // Clear private caches.
    this.nodeCache.clear();
    this.termMap.clear();
    this.termSourceMap.clear();
    this.allSources.clear();
    this.allSamples.clear();
    this.allExtracts.clear();
    this.allLabeledExtracts.clear();
    this.allHybridizations.clear();
    this.allArrayDataFiles.clear();
    this.allDerivedArrayDataFiles.clear();
    this.allArrayDataMatrixFiles.clear();
    this.allDerivedArrayDataMatrixFiles.clear();

    LogUtil.logSubsystemExit(LOG);
    return mageTabDocumentSet;
}

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

/**
 * {@inheritDoc}/*from w w  w . j av  a2 s  .co  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxTreeNode getTree(FxTreeMode mode, long nodeId, int depth) throws FxApplicationException {
    Connection con = null;
    try {
        con = Database.getDbConnection();
        return StorageManager.getTreeStorage().getTree(con, contentEngine, mode, nodeId, depth, PARTIAL_LOADING,
                FxContext.getUserTicket().getLanguage());
    } catch (FxApplicationException fx) {
        throw fx;
    } catch (Throwable t) {
        throw new FxLoadException(LOG, t, "ex.tree.load.failed.node", nodeId, mode, t.getMessage());
    } finally {
        Database.closeObjects(TreeEngineBean.class, con, null);
    }
}

From source file:fr.ortolang.diffusion.store.binary.BinaryStoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public boolean contains(String identifier) throws BinaryStoreServiceException {
    try {//from  www.  jav a  2 s .c  o m
        Path path = getPathForIdentifier(identifier);
        return Files.exists(path);
    } catch (DataNotFoundException e) {
        return false;
    }
}

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

/**
 * {@inheritDoc}//from w w  w .  ja  va2s.  com
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<UserTicket> getActiveUserTickets() {
    return UserTicketStore.getTickets();
}

From source file:fr.ortolang.diffusion.store.binary.BinaryStoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public InputStream get(String identifier) throws BinaryStoreServiceException, DataNotFoundException {
    Path path = getPathForIdentifier(identifier);
    if (!Files.exists(path)) {
        throw new DataNotFoundException("Unable to find an object with id [" + identifier + "] in the storage");
    }//from w  w w  .  jav  a  2  s  . c o  m
    try {
        return Files.newInputStream(path);
    } catch (Exception e) {
        throw new BinaryStoreServiceException(e);
    }
}

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

/**
 * {@inheritDoc}//from   w  ww  .  j  a  va 2  s . c om
 */
@Override
@SuppressWarnings({ "unchecked" })
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<FxLanguage> loadAvailable() throws FxApplicationException {
    try {
        List<FxLanguage> available = (List<FxLanguage>) CacheAdmin.getInstance().get(CacheAdmin.LANGUAGES_ALL,
                CACHE_KEY_ALL_LANG_IDS);
        if (available == null) {
            loadAll(true, true);
            available = (List<FxLanguage>) CacheAdmin.getInstance().get(CacheAdmin.LANGUAGES_ALL,
                    CACHE_KEY_ALL_LANG_IDS);
            if (available == null)
                throw new FxInvalidLanguageException("ex.language.loadFailed");
        }
        return available;
    } catch (FxCacheException e) {
        throw new FxLoadException(LOG, e);
    }
}

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

/**
 * {@inheritDoc}// w  ww.  j av  a 2 s  .  c om
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public long getIdByPath(FxTreeMode mode, String path) throws FxApplicationException {
    return getIdByFQNPath(mode, FxTreeNode.ROOT_NODE, path);
}