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

/**
 * {@inheritDoc}
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public UserTicket getGuestTicket() {
    return UserTicketImpl.getGuestTicket();
}

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

/**
 * {@inheritDoc}/*from   w  ww. j a  va2 s . c o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<UserGroup> getGroups(long accountId) throws FxApplicationException {

    Connection con = null;
    Statement stmt = null;
    String curSql;
    final UserTicket ticket = getRequestTicket();
    try {
        // Obtain a database connection
        con = Database.getDbConnection();

        // Check the user
        long mandator = getMandatorForAccount(con, accountId);
        // Permission checks (2)
        if (!ticket.isGlobalSupervisor()) {
            // Read access for all within a mandator
            if (mandator != ticket.getMandatorId())
                throw new FxNoAccessException(LOG, "ex.account.groups.wrongMandator", accountId);
        }

        // Load the groups the account is assigned to
        curSql = "SELECT DISTINCT ass.USERGROUP,grp.NAME,grp.MANDATOR,grp.COLOR" + " FROM " + TBL_ASSIGN_GROUPS
                + " ass, " + TBL_USERGROUPS + " grp" + " WHERE grp.ID=ass.USERGROUP AND ass.ACCOUNT="
                + accountId;
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(curSql);
        final List<UserGroup> result = new ArrayList<UserGroup>(10);
        while (rs != null && rs.next()) {
            long id = rs.getLong(1);
            String grpName = rs.getString(2);
            long grpMandator = rs.getLong(3);
            String grpColor = rs.getString(4);
            final UserGroup aGroup = new UserGroup(id, grpName, grpMandator, grpColor);
            if (LOG.isDebugEnabled())
                LOG.debug("Found group for user [" + accountId + "]: " + aGroup);
            result.add(aGroup);
        }
        return result;
    } catch (SQLException exc) {
        throw new FxLoadException(LOG, exc, "ex.account.groups.loadFailed.sql", accountId, exc.getMessage());
    } finally {
        Database.closeObjects(AccountEngineBean.class, con, stmt);
    }

}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public void delete(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");
    }//  w ww .ja  va 2s .  c om
    try {
        Files.delete(path);
    } catch (Exception e) {
        throw new BinaryStoreServiceException(e);
    }
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public String generate(InputStream content) throws BinaryStoreServiceException {
    try {/*from   ww  w. ja va  2 s  .  c o  m*/
        HashedFilterInputStream input = factory.getHashedFilterInputStream(content);
        byte[] buffer = new byte[10240];
        while (input.read(buffer) >= 0) {
        }
        return input.getHash();
    } catch (Exception e) {
        throw new BinaryStoreServiceException("Unable to generate a hash for this content: " + e.getMessage(),
                e);
    }
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<BinaryStoreContent> systemBrowse(String name, String prefix) throws BinaryStoreServiceException {
    if (name == null || name.length() == 0) {
        List<BinaryStoreContent> vinfos = new ArrayList<BinaryStoreContent>();
        List<String> vnames = new ArrayList<String>();
        vnames.addAll(BinaryStoreVolumeMapper.listVolumes());
        vnames.add(WORK);/*from w ww  .  j a  v  a2 s  .co m*/
        for (String vname : vnames) {
            try {
                BinaryStoreContent volume = new BinaryStoreContent();
                Path vpath = Paths.get(base.toString(), vname);
                FileStore vstore = Files.getFileStore(vpath);
                volume.setPath(vname);
                volume.setType(Type.VOLUME);
                volume.setFsName(vstore.name());
                volume.setFsType(vstore.type());
                volume.setFsTotalSize(vstore.getTotalSpace());
                volume.setFsFreeSize(vstore.getUsableSpace());
                volume.setSize(Files.size(vpath));
                volume.setLastModificationDate(Files.getLastModifiedTime(vpath).toMillis());
                vinfos.add(volume);
            } catch (IOException e) {
                LOGGER.log(Level.WARNING,
                        "Unable to retrieve binary store volume information for volume: " + vname);
            }
        }
        return vinfos;
    } else {
        try {
            if (prefix == null) {
                prefix = "";
            }
            Path vpath = Paths.get(base.toString(), name, prefix);
            if (!Files.exists(vpath)) {
                throw new BinaryStoreServiceException(
                        "volume name does not point to an existing file or a directory");
            }
            return Files.list(vpath).map(this::pathToContent).collect(Collectors.toList());
        } catch (IOException e) {
            throw new BinaryStoreServiceException(e);
        }
    }
}

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

/**
 * {@inheritDoc}/*from  w  w w  .  j av  a2s . c  o m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<Long> getByScriptEvent(FxScriptEvent scriptEvent) {
    long timeStamp = CacheAdmin.getEnvironment().getTimeStamp();
    if (timeStamp != LocalScriptingCache.scriptCacheTimestamp)
        resetLocalCaches(timeStamp);
    List<Long> cached = LocalScriptingCache.scriptsByEvent.get(scriptEvent);
    if (cached != null)
        return cached;
    Connection con = null;
    PreparedStatement ps = null;
    String sql;
    List<Long> ret = new ArrayList<Long>(10);
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        //                                                              1
        sql = "SELECT DISTINCT ID FROM " + TBL_SCRIPTS + " WHERE STYPE=? ORDER BY ID";
        ps = con.prepareStatement(sql);
        ps.setLong(1, scriptEvent.getId());
        ResultSet rs = ps.executeQuery();
        while (rs != null && rs.next())
            ret.add(rs.getLong(1));
    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException();
    } finally {
        Database.closeObjects(ScriptingEngineBean.class, con, ps);
    }
    LocalScriptingCache.scriptsByEvent.put(scriptEvent, Collections.unmodifiableList(ret));
    return ret;
}

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

/**
 * {@inheritDoc}/* ww w. j  a va2  s.c  o m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<Role> getRoles(long accountId, RoleLoadMode mode) throws FxApplicationException {
    Connection con = null;
    Statement stmt = null;
    String curSql;
    final UserTicket ticket = getRequestTicket();

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

        // Check the user
        long mandator = getMandatorForAccount(con, accountId);
        // Permission checks (2)
        if (!ticket.isGlobalSupervisor()) {
            if (mandator != ticket.getMandatorId())
                throw new FxNoAccessException("ex.account.roles.wrongMandator", accountId);
        }

        // Load the roles
        curSql = "SELECT DISTINCT ROLE FROM " + TBL_ROLE_MAPPING + " WHERE "
                + ((mode == RoleLoadMode.ALL || mode == RoleLoadMode.FROM_USER_ONLY) ? "ACCOUNT=" + accountId
                        : "")
                + ((mode == RoleLoadMode.ALL) ? " OR " : "")
                + ((mode == RoleLoadMode.ALL || mode == RoleLoadMode.FROM_GROUPS_ONLY)
                        ? " USERGROUP IN (SELECT USERGROUP FROM "
                                + TBL_ASSIGN_GROUPS + " WHERE ACCOUNT=" + accountId + " )"
                        : "");
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(curSql);
        List<Role> result = new ArrayList<Role>(15);
        while (rs != null && rs.next())
            result.add(Role.getById(rs.getByte(1)));

        if (LOG.isDebugEnabled())
            LOG.debug("Role for user [" + accountId + "]: " + result);
        return result;
    } catch (SQLException exc) {
        throw new FxLoadException(LOG, exc, "ex.account.roles.loadFailed.sql", accountId, exc.getMessage());
    } finally {
        Database.closeObjects(AccountEngineBean.class, con, stmt);
    }
}

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

/**
 * {@inheritDoc}/*  w w w .j a va 2  s  .  co  m*/
 */
@Override
@SuppressWarnings({ "unchecked" })
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<FxScriptRunInfo> getRunOnceInformation() throws FxApplicationException {
    if (LocalScriptingCache.runOnceInfos != null) {
        return Lists.newArrayList(LocalScriptingCache.runOnceInfos);
    } else {
        return getDivisionConfigurationEngine().get(SystemParameters.DIVISION_RUNONCE_INFOS);
    }
}

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Workspace readWorkspace(String wskey)
        throws CoreServiceException, KeyNotFoundException, AccessDeniedException {
    LOGGER.log(Level.FINE, "reading workspace [" + wskey + "]");
    try {//w w w . ja  v  a  2s  .  com
        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");
        }
        workspace.setKey(wskey);
        return workspace;
    } catch (RegistryServiceException | MembershipServiceException | AuthorisationServiceException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred while reading workspace", e);
        throw new CoreServiceException("unable to read workspace with key [" + wskey + "]", e);
    }
}

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

/**
 * {@inheritDoc}//from  w ww . j  a  v  a 2 s  .c o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public String getDatabaseInfo() {
    final DivisionData divisionData = FxContext.get().getDivisionData();
    return "Division #" + divisionData.getId() + " - " + divisionData.getDbVendor() + " "
            + divisionData.getDbVersion();
}