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

/**
 * {@inheritDoc}//from  www .ja v  a2s  .  co  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public ACL load(long id, boolean ignoreSecurity) throws FxApplicationException {
    Connection con = null;
    Statement stmt = null;
    String curSql;
    try {
        final FxEnvironment environment = CacheAdmin.getEnvironment();

        // Obtain a database connection
        con = Database.getDbConnection();
        //               1        2    3        4           5     6          7          8           9
        curSql = "SELECT MANDATOR,NAME,CAT_TYPE,DESCRIPTION,COLOR,CREATED_BY,CREATED_AT,MODIFIED_BY,MODIFIED_AT FROM "
                + TBL_ACLS + " WHERE ID=" + id;
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(curSql);

        if (rs == null || !rs.next())
            throw new FxNotFoundException("ex.acl.load.notFound", id);

        // Read the ACL
        long mandatorId = rs.getLong(1);
        String name = rs.getString(2);
        int cat = rs.getInt(3);
        String desc = rs.getString(4);
        if (rs.wasNull())
            desc = "";
        String color = rs.getString(5);
        if (rs.wasNull())
            color = "";
        FxString label = Database.loadFxString(con, TBL_ACLS, "LABEL", "ID=" + id);
        String sMandator = environment.getMandator(mandatorId).getName();
        ACL theACL = new ACL(id, name, label, mandatorId, sMandator, desc, color, ACLCategory.getById(cat),
                LifeCycleInfoImpl.load(rs, 6, 7, 8, 9));
        if (ignoreSecurity && mandatorId != FxContext.getUserTicket().getMandatorId())
            throw new FxNoAccessException(LOG, "ex.acl.loadFailed.foreignMandator", theACL.getName());
        // Return the ACL
        return theACL;
    } catch (SQLException exc) {
        throw new FxLoadException(LOG, "ex.acl.load.sqlError", id, exc.getMessage());
    } finally {
        Database.closeObjects(ACLEngineBean.class, con, stmt);
    }
}

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

/**
 * {@inheritDoc}//  ww w. j  a  v a  2s  . com
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public String getDatabaseDriverInfo() {
    return FxContext.get().getDivisionData().getDbDriverVersion();
}

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 boolean isFlatStorageEnabled() {
    return FxFlatStorageManager.getInstance().isEnabled();
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<String> findWorkspacesForProfile(String profile)
        throws CoreServiceException, AccessDeniedException {
    LOGGER.log(Level.FINE, "finding workspaces for profile");
    try {/*from w w  w . ja v a2s .  c  o  m*/
        List<String> subjects = membership.getConnectedIdentifierSubjects();
        authorisation.checkAuthentified(subjects);

        List<String> groups = membership.getProfileGroups(profile);
        return findWorkspacesForGroups(groups);
    } catch (MembershipServiceException | AuthorisationServiceException | RegistryServiceException
            | KeyNotFoundException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during finding workspaces for profile", e);
        throw new CoreServiceException("unable to find workspaces for profile", e);
    }
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<String> systemFindWorkspacesForProfile(String profile) throws CoreServiceException {
    LOGGER.log(Level.FINE, "#SYSTEM# finding workspaces for profile");
    try {//from  ww  w  . ja  v  a 2  s  . c o m
        List<String> groups = Arrays.asList(membership.systemReadProfile(profile).getGroups());
        return findWorkspacesForGroups(groups);
    } catch (MembershipServiceException | RegistryServiceException | KeyNotFoundException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during finding workspaces for profile", e);
        throw new CoreServiceException("unable to find workspaces for profile", e);
    }
}

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

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
private List<String> findWorkspacesForGroups(List<String> groups) throws RegistryServiceException {
    if (groups.isEmpty()) {
        return Collections.emptyList();
    }//from   w  ww  .j  a  v a  2  s  .c o  m
    List<String> keys = new ArrayList<>();
    TypedQuery<Workspace> query = em.createNamedQuery("findWorkspaceByMember", Workspace.class)
            .setParameter("groups", groups);
    List<Workspace> workspaces = query.getResultList();
    for (Workspace workspace : workspaces) {
        OrtolangObjectIdentifier identifier = workspace.getObjectIdentifier();
        try {
            keys.add(registry.lookup(identifier));
        } catch (IdentifierNotRegisteredException e) {
            LOGGER.log(Level.SEVERE,
                    "a workspace with an unregistered identifier has be found : " + identifier);
        }
    }
    return keys;
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<String> findWorkspacesAliasForProfile(String profile)
        throws CoreServiceException, AccessDeniedException {
    LOGGER.log(Level.FINE, "finding workspace alias for profile");
    try {// w  w w  .  j  a va  2  s. c o m
        List<String> subjects = membership.getConnectedIdentifierSubjects();
        authorisation.checkAuthentified(subjects);

        List<String> groups = membership.getProfileGroups(profile);
        if (groups.isEmpty()) {
            return Collections.emptyList();
        }

        List<String> aliases = new ArrayList<String>();
        TypedQuery<Workspace> query = em.createNamedQuery("findWorkspaceByMember", Workspace.class)
                .setParameter("groups", groups);
        List<Workspace> workspaces = query.getResultList();
        for (Workspace workspace : workspaces) {
            OrtolangObjectIdentifier identifier = workspace.getObjectIdentifier();
            try {
                if (workspace.getAlias() != null && workspace.getAlias().length() > 0) {
                    registry.lookup(identifier);
                    aliases.add(workspace.getAlias());
                }
            } catch (IdentifierNotRegisteredException e) {
                LOGGER.log(Level.SEVERE,
                        "a workspace with an unregistered identifier has be found : " + identifier);
            }
        }

        return aliases;
    } catch (MembershipServiceException | AuthorisationServiceException | RegistryServiceException
            | KeyNotFoundException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during finding workspaces for profile", e);
        throw new CoreServiceException("unable to find workspaces for profile", e);
    }
}

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

/**
 * {@inheritDoc}//from w ww.j av  a 2 s.c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<Role> getRoles(long groupId) throws FxApplicationException {
    Connection con = null;
    Statement stmt = null;
    final String sql = "SELECT DISTINCT ROLE FROM " + TBL_ROLE_MAPPING + " WHERE USERGROUP=" + groupId;

    final UserGroup aGroup = CacheAdmin.getEnvironment().getUserGroup(groupId);

    // Permission check
    if (!mayAccessGroup(aGroup)) {
        FxNoAccessException nae = new FxNoAccessException("ex.usergroup.noPermissionsToReadRoles",
                aGroup.getName());
        if (LOG.isInfoEnabled())
            LOG.info(nae);
        throw nae;
    }

    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        // Load the roles
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        List<Role> result = new ArrayList<Role>();
        while (rs != null && rs.next()) {
            result.add(Role.getById(rs.getByte(1)));
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Roles for group [" + groupId + "]: " + result);
        }
        return result;
    } catch (SQLException exc) {
        FxLoadException le = new FxLoadException(exc, "ex.usergroup.sqlError", exc.getMessage(), sql);
        LOG.error(le);
        throw le;
    } finally {
        Database.closeObjects(UserGroupEngineBean.class, con, stmt);
    }
}

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

/**
 * {@inheritDoc}//from  w w  w .  jav  a  2 s . c  o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxDivisionExportInfo getDivisionExportInfo(String localFileName) throws FxApplicationException {
    if (!FxContext.getUserTicket().isGlobalSupervisor())
        throw new FxNoAccessException("ex.import.noAccess");
    if (StringUtils.isEmpty(localFileName))
        throw new FxInvalidParameterException("localFileName", "ex.import.noFileProvided");
    File data = new File(localFileName);
    if (!data.exists() || !data.isFile())
        throw new FxInvalidParameterException("localFileName", "ex.import.noFile", localFileName);
    ZipFile zip;
    try {
        zip = new ZipFile(data);
    } catch (IOException e) {
        throw new FxInvalidParameterException("localFileName", "ex.import.noZIP", localFileName);
    }
    return StorageManager.getStorageImpl().getDivisionExportInfo(zip);
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<String> listAllWorkspaceAlias() throws CoreServiceException, AccessDeniedException {
    LOGGER.log(Level.FINE, "listing all workspaces alias");
    try {// w w  w  . j a va  2  s. co  m
        String caller = membership.getProfileKeyForConnectedIdentifier();
        authorisation.checkSuperUser(caller);
        TypedQuery<String> query = em.createNamedQuery("listAllWorkspaceAlias", String.class);
        return query.getResultList();
    } catch (AuthorisationServiceException e) {
        LOGGER.log(Level.SEVERE, "unable to list all workspace aliases", e);
        throw new CoreServiceException("unable to list all workspace aliases", e);
    }
}