Example usage for javax.ejb TransactionAttributeType REQUIRED

List of usage examples for javax.ejb TransactionAttributeType REQUIRED

Introduction

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

Prototype

TransactionAttributeType REQUIRED

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

Click Source Link

Document

If a client invokes the enterprise bean's method while the client is associated with a transaction context, the container invokes the enterprise bean's method in the client's transaction context.

Usage

From source file:gov.nih.nci.caarray.application.file.FileManagementServiceBean.java

/**
 * {@inheritDoc}//from   w  w w.  j av a2s .com
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void reimportAndParseArrayDesign(Long arrayDesignId)
        throws InvalidDataFileException, IllegalAccessException {
    ArrayDesign arrayDesign = this.searchDao.retrieve(ArrayDesign.class, arrayDesignId);
    if (!arrayDesign.isUnparsedAndReimportable()) {
        throw new IllegalAccessException("This array design is not eligible for reimport");
    }

    final ArrayDesignService ads = ServiceLocatorFactory.getArrayDesignService();
    arrayDesign.getDesignFileSet().updateStatus(FileStatus.VALIDATING);
    try {
        arrayDesign = ads.saveArrayDesign(arrayDesign);
        ads.importDesign(arrayDesign);
        checkDesignFiles(arrayDesign.getDesignFileSet());
    } catch (final InvalidDataFileException e) {
        arrayDesign.getDesignFileSet().updateStatus(FileStatus.IMPORT_FAILED);
        throw e;
    } catch (final IllegalAccessException e) {
        arrayDesign.getDesignFileSet().updateStatus(FileStatus.IMPORT_FAILED);
        throw e;
    } catch (final Exception e) {
        arrayDesign.getDesignFileSet().updateStatus(FileStatus.IMPORT_FAILED);
        throw new UnhandledException(e);
    }

    importArrayDesignDetails(arrayDesign);
}

From source file:gov.nih.nci.caarray.application.project.ProjectManagementServiceBean.java

/**
 * {@inheritDoc}/*from  w  w  w  .j a  v  a 2s.  c om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void changeProjectLockStatus(long projectId, boolean newStatus) throws ProposalWorkflowException {
    LogUtil.logSubsystemEntry(LOG, projectId);
    final Project project = this.searchDao.retrieve(Project.class, projectId);
    if (!project.isOwner(CaArrayUsernameHolder.getCsmUser())) {
        LogUtil.logSubsystemExit(LOG);
        throw new PermissionDeniedException(project, "WORKFLOW_CHANGE", CaArrayUsernameHolder.getUser());
    }
    if (project.isLocked() == newStatus) {
        LogUtil.logSubsystemExit(LOG);
        throw new ProposalWorkflowException("project already " + (newStatus ? " locked" : "unlocked"));
    }
    project.setLocked(newStatus);

    this.projectDao.save(project);
    LogUtil.logSubsystemExit(LOG);
}

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

/**
 * {@inheritDoc}/*from   w w w . j  a  va 2s  .  c o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public long create(String name, String color, long mandatorId) throws FxApplicationException {
    final UserTicket ticket = FxContext.getUserTicket();
    // Permission checks
    try {
        if (!ticket.isGlobalSupervisor()) {
            if (ticket.getMandatorId() != mandatorId) {
                throw new FxNoAccessException("ex.usergroup.create.foreignMandator");
            }
            if (!ticket.isInRole(Role.MandatorSupervisor))
                FxPermissionUtils.checkRole(ticket, Role.AccountManagement);
        }
    } catch (FxNoAccessException nae) {
        if (LOG.isInfoEnabled())
            LOG.info(nae);
        throw nae;
    }

    Connection con = null;
    Statement stmt = null;
    PreparedStatement ps = null;
    String sql = null;
    try {

        // Sanity checks
        color = FxFormatUtils.processColorString("color", color);
        checkName(name);

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

        // Obtain a new id
        long groupId = seq.getId(FxSystemSequencer.GROUP);

        // Create the new group
        sql = "INSERT INTO " + TBL_USERGROUPS + " "
                + "(ID,MANDATOR,AUTOMANDATOR,ISSYSTEM,NAME,COLOR,CREATED_BY,CREATED_AT,MODIFIED_BY,MODIFIED_AT) VALUES ("
                + "?,?,?,?,?,?,?,?,?,?)";
        final long NOW = System.currentTimeMillis();
        ps = con.prepareStatement(sql);
        ps.setLong(1, groupId);
        ps.setLong(2, mandatorId);
        ps.setNull(3, java.sql.Types.NUMERIC);
        ps.setBoolean(4, false);
        ps.setString(5, name);
        ps.setString(6, color);
        ps.setLong(7, ticket.getUserId());
        ps.setLong(8, NOW);
        ps.setLong(9, ticket.getUserId());
        ps.setLong(10, NOW);
        ps.executeUpdate();

        StructureLoader.updateUserGroups(FxContext.get().getDivisionId(), loadAll(-1));

        // Return the new id
        return groupId;
    } catch (SQLException exc) {
        final boolean uniqueConstraintViolation = StorageManager.isUniqueConstraintViolation(exc);
        EJBUtils.rollback(ctx);
        if (uniqueConstraintViolation) {
            FxEntryExistsException eee = new FxEntryExistsException("ex.usergroup.create.groupExists", name);
            if (LOG.isInfoEnabled())
                LOG.info(eee);
            throw eee;
        } else {
            FxCreateException ce = new FxCreateException(exc, "ex.usergroup.sqlError", exc.getMessage(), sql);
            LOG.error(ce);
            throw ce;
        }
    } finally {
        Database.closeObjects(UserGroupEngineBean.class, null, ps);
        Database.closeObjects(UserGroupEngineBean.class, con, stmt);
    }
}

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

/**
 * {@inheritDoc}/*from w w w .j av  a 2 s.c  o m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void removeMetaData(int mandatorId) throws FxApplicationException {
    final UserTicket ticket = FxContext.getUserTicket();
    final FxEnvironment environment;
    final long metadataId = -1;
    // Security
    FxPermissionUtils.checkRole(ticket, Role.GlobalSupervisor);
    environment = CacheAdmin.getEnvironment();
    // check existance
    Mandator mand = environment.getMandator(mandatorId);
    Connection con = null;
    PreparedStatement ps = null;
    String sql;

    try {
        // get Database connection
        con = Database.getDbConnection(); //1            //2        //3
        sql = "UPDATE " + TBL_MANDATORS + " SET METADATA=NULL, MODIFIED_BY=?, MODIFIED_AT=? WHERE ID=?";
        final long NOW = System.currentTimeMillis();
        ps = con.prepareStatement(sql);
        ps.setLong(1, ticket.getUserId());
        ps.setLong(2, NOW);
        ps.setLong(3, mandatorId);
        ps.executeUpdate();
        StructureLoader.updateMandator(FxContext.get().getDivisionId(),
                new Mandator(mand.getId(), mand.getName(), metadataId, true,
                        new LifeCycleInfoImpl(mand.getLifeCycleInfo().getCreatorId(),
                                mand.getLifeCycleInfo().getCreationTime(), ticket.getUserId(), NOW)));
    } catch (SQLException e) {
        EJBUtils.rollback(ctx);
        throw new FxUpdateException(LOG, e, "ex.mandator.removeMetaDataFailed", mand.getMetadataId(),
                mand.getName(), mand.getId(), e.getMessage());
    } finally {
        Database.closeObjects(MandatorEngineBean.class, con, ps);
    }
}

From source file:com.flexive.ejb.beans.search.SearchEngineBean.java

/**
 * {@inheritDoc}/*from www. ja  v a  2  s  .  com*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void save(QueryRootNode query) throws FxApplicationException {
    save(configuration, query, query.getName());
}

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

/**
 * {@inheritDoc}/*w  ww  .ja v a2 s  . c om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void remove(long id) throws FxApplicationException {
    UserTicket ticket = FxContext.getUserTicket();
    ACL theACL = load(id);

    // Protected interal ACLs
    if (theACL.getId() <= ACL.MAX_INTERNAL_ID)
        throw new FxNoAccessException(LOG, "ex.acl.deleteFailed.internalACL", theACL.getName());

    // Security
    if (!ticket.isGlobalSupervisor()) {
        // Security
        if (!ticket.isInRole(Role.MandatorSupervisor) && !ticket.isInRole(Role.ACLManagement))
            throw new FxNoAccessException(LOG, "ex.acl.deleteFailed.noPermission", theACL.getName());
        if (ticket.getMandatorId() != theACL.getMandatorId())
            throw new FxNoAccessException(LOG, "ex.acl.deleteFailed.foreignMandator", theACL.getName());
    }

    Connection con = null;
    PreparedStatement stmt = null;
    String curSql;

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

        // Delete all ACLAssignments
        curSql = "DELETE FROM " + TBL_ACLS_ASSIGNMENT + " WHERE ACL=" + id;
        stmt = con.prepareStatement(curSql);
        stmt.executeUpdate();
        stmt.close();

        // Delete the label
        curSql = "DELETE FROM " + TBL_ACLS + ML + " WHERE ID=" + id;
        stmt = con.prepareStatement(curSql);
        stmt.executeUpdate();
        stmt.close();

        // Delete the ACL itself
        curSql = "DELETE FROM " + TBL_ACLS + " WHERE ID=" + id;
        stmt = con.prepareStatement(curSql);
        stmt.executeUpdate();

        // Refresh all UserTicket that are affected
        UserTicketStore.flagDirtyHavingACL(id);
        StructureLoader.removeACL(FxContext.get().getDivisionId(), id);
        EJBLookup.getHistoryTrackerEngine().trackData(ConversionEngine.getXStream().toXML(theACL),
                "history.acl.remove", theACL.getName());
    } catch (SQLException exc) {
        final boolean uniqueConstraintViolation = StorageManager.isUniqueConstraintViolation(exc);
        final boolean keyViolation = StorageManager.isForeignKeyViolation(exc);
        EJBUtils.rollback(ctx);
        if (uniqueConstraintViolation)
            throw new FxRemoveException(LOG, exc, "ex.acl.aclAlreadyExists", theACL.getName());
        else if (keyViolation)
            throw new FxRemoveException(LOG, exc, "ex.acl.deleteFailed.aclIsInUse", theACL.getName());
        else
            throw new FxRemoveException(LOG, exc, "ex.acl.deleteFailed", theACL.getName(), exc.getMessage());
    } finally {
        Database.closeObjects(ACLEngineBean.class, con, stmt);
    }
}

From source file:be.fedict.trust.service.bean.TrustServiceBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRED)
@SNMP(oid = SnmpConstants.VALIDATE_TSA)// ww  w  .  jav a  2  s  .c  o m
public ValidationResult validateTimestamp(String trustDomainName, byte[] encodedTimestampToken,
        boolean returnRevocationData) throws TSPException, IOException, CMSException, NoSuchAlgorithmException,
        NoSuchProviderException, CertStoreException, TrustDomainNotFoundException {

    LOG.debug("validate timestamp token");

    /*
     * Parse embedded certificate chain
     */
    List<X509Certificate> certificateChain = new LinkedList<X509Certificate>();
    TimeStampToken timestampToken = new TimeStampToken(new CMSSignedData(encodedTimestampToken));
    CertStore certStore = timestampToken.getCertificatesAndCRLs("Collection", "BC");
    Collection<? extends Certificate> certificates = certStore.getCertificates(null);
    for (Certificate certificate : certificates) {
        certificateChain.add((X509Certificate) certificate);
    }

    if (TrustValidator.isSelfSigned(certificateChain.get(0))) {
        Collections.reverse(certificateChain);
    }

    /*
     * Validate
     */
    TrustLinkerResult lastResult = null;
    RevocationData lastRevocationData = null;
    for (TrustDomainEntity trustDomain : getTrustDomains(trustDomainName)) {

        TrustValidator trustValidator = getTrustValidator(trustDomain, returnRevocationData);

        try {
            trustValidator.isTrusted(certificateChain);
        } catch (CertPathValidatorException ignored) {
        }

        if (trustValidator.getResult().isValid()) {
            LOG.debug("valid for trust domain: " + trustDomain.getName());
            harvest(trustDomain, certificateChain);
            return new ValidationResult(trustValidator.getResult(), trustValidator.getRevocationData());
        }

        lastResult = trustValidator.getResult();
        lastRevocationData = trustValidator.getRevocationData();
    }

    return new ValidationResult(lastResult, lastRevocationData);
}

From source file:com.flexive.ejb.beans.search.ResultPreferencesEngineBean.java

/** {@inheritDoc} */
@Override/*  w w w.ja  v  a  2  s.co  m*/
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void remove(long typeId, ResultViewType viewType, ResultLocation location)
        throws FxApplicationException {
    configuration.remove(SystemParameters.USER_RESULT_PREFERENCES, getKey(typeId, viewType, location));
}

From source file:be.fedict.eid.pkira.blm.model.usermgmt.RegistrationManagerBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void changeLocale(String userRRN, String locale) {
    User user = userHome.findByNationalRegisterNumber(userRRN);
    userHome.setInstance(user);/*from   w  ww.  j  a  v  a  2  s.c  o  m*/
    userHome.getInstance().setLocale(locale);
    userHome.update();
}

From source file:com.flexive.ejb.beans.search.SearchEngineBean.java

/**
 * {@inheritDoc}//from w w w.  j  a v a2s  .  com
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void saveDefault(QueryRootNode query) throws FxApplicationException {
    save(configuration, query, DEFAULT_QUERY_NAME);
}