Example usage for javax.ejb TransactionAttributeType REQUIRES_NEW

List of usage examples for javax.ejb TransactionAttributeType REQUIRES_NEW

Introduction

In this page you can find the example usage for javax.ejb TransactionAttributeType REQUIRES_NEW.

Prototype

TransactionAttributeType REQUIRES_NEW

To view the source code for javax.ejb TransactionAttributeType REQUIRES_NEW.

Click Source Link

Document

The container must invoke an enterprise bean method whose transaction attribute is set to REQUIRES_NEW with a new transaction context.

Usage

From source file:org.oscm.identityservice.bean.IdentityServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public boolean removeInactiveOnBehalfUsersImpl() {
    ConfigurationSetting setting = cs.getConfigurationSetting(
            ConfigurationKey.PERMITTED_PERIOD_INACTIVE_ON_BEHALF_USERS, Configuration.GLOBAL_CONTEXT);
    long period = setting.getLongValue();
    Long lowerPeriodBound = Long.valueOf(System.currentTimeMillis() - period);
    List<OnBehalfUserReference> inactiveUsers = findInactiveOnBehalfUsers(lowerPeriodBound);
    for (OnBehalfUserReference toBeRemoved : inactiveUsers) {
        dm.remove(toBeRemoved);//from w w w. j ava  2 s .c om
    }
    return true;
}

From source file:org.oscm.identityservice.bean.IdentityServiceBean.java

@Override
@RolesAllowed("ORGANIZATION_ADMIN")
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public boolean addRevokeUserUnitAssignment(String unitName, List<VOUser> usersToBeAdded,
        List<VOUser> usersToBeRevoked) throws NonUniqueBusinessKeyException, ObjectNotFoundException,
        OperationNotPermittedException, MailOperationException {
    ArgumentValidator.notNull("unitName", unitName);
    ArgumentValidator.notNull("usersToBeAdded", usersToBeAdded);
    ArgumentValidator.notNull("usersToBeRevoked", usersToBeRevoked);

    List<PlatformUser> added = new ArrayList<>();
    List<PlatformUser> revoked = new ArrayList<>();
    Set<Long> onBehalfUserKeys = new HashSet<>();

    List<PlatformUser> platformUsers = dm.getCurrentUser().getOrganization().getPlatformUsers();
    UserGroup group = userGroupService.getUserGroupByName(unitName);
    for (PlatformUser user : platformUsers) {
        if (user.isOnBehalfUser()) {
            onBehalfUserKeys.add(Long.valueOf(user.getKey()));
        }/*from  w w w  . j av a 2 s .co  m*/
    }

    String currentUserTenant = dm.getCurrentUser().getTenantId();

    for (VOUser user : usersToBeAdded) {
        validateForOnBehalfUserGroupAssignment(user, onBehalfUserKeys);
        if (StringUtils.isBlank(user.getTenantId())) {
            user.setTenantId(currentUserTenant);
        }
        PlatformUser platformUser = new PlatformUser();
        platformUser.setUserId(user.getUserId());
        platformUser.setTenantId(user.getTenantId());
        added.add(platformUser);
    }
    for (VOUser user : usersToBeRevoked) {
        validateForOnBehalfUserGroupAssignment(user, onBehalfUserKeys);
        if (StringUtils.isBlank(user.getTenantId())) {
            user.setTenantId(currentUserTenant);
        }
        PlatformUser platformUser = new PlatformUser();
        platformUser.setUserId(user.getUserId());
        platformUser.setTenantId(user.getTenantId());
        revoked.add(platformUser);
    }

    if (!added.isEmpty() && group.isDefault()) {
        OperationNotPermittedException onpe = new OperationNotPermittedException();
        logger.logWarn(Log4jLogger.SYSTEM_LOG, onpe,
                LogMessageIdentifier.WARN_DEFAULT_USERGROUP_OPERATION_NOT_PERMITTED);
        throw onpe;
    }

    try {
        userGroupService.assignUsersToGroup(group, added);
        userGroupService.revokeUsersFromGroup(group, revoked);
    } catch (NonUniqueBusinessKeyException | MailOperationException | OperationNotPermittedException e) {
        sessionCtx.setRollbackOnly();
        throw e;
    }
    return true;
}

From source file:org.rhq.enterprise.server.content.ContentSourceManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@TransactionTimeout(45 * 60)//from   ww  w  .  j a  v  a  2s .  c o  m
public long outputDistributionFileBits(DistributionFile distFile, OutputStream outputStream) {

    long numBytes = 0L;
    InputStream bitStream = null;
    try {
        Distribution dist = distFile.getDistribution();
        log.info("Distribution has a basePath of " + dist.getBasePath());
        String distFilePath = dist.getBasePath() + "/" + distFile.getRelativeFilename();
        File f = getDistributionFileBitsLocalFilesystemFile(dist.getLabel(), distFilePath);
        log.info("Fetching: " + distFilePath + " on local file store from: " + f.getAbsolutePath());
        bitStream = new FileInputStream(f);
        numBytes = StreamUtil.copy(bitStream, outputStream);

    } catch (Exception e) {
        log.info(e);
    } finally {
        // close our stream but leave the output stream open
        try {
            bitStream.close();
        } catch (Exception closeError) {
            log.warn("Failed to close the bits stream", closeError);
        }
    }
    log.debug("Retrieved and sent [" + numBytes + "] bytes for [" + distFile.getRelativeFilename() + "]");
    return numBytes;
}

From source file:org.oscm.subscriptionservice.bean.SubscriptionServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public boolean expireSubscription(Subscription subscriptionToExpire) {
    return terminateBean.expireSubscription(subscriptionToExpire);
}