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:com.flexive.ejb.beans.workflow.RouteEngineBean.java

/** {@inheritDoc} */
@Override/*  w  w  w. j  a  v a2s  .  c om*/
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void remove(long routeId) throws FxApplicationException {
    FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.WorkflowManagement);
    deleteRoute(routeId);
}

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

/**
 * {@inheritDoc}//from w w  w .  ja  va 2s  . c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void saveSystemDefault(QueryRootNode query) throws FxApplicationException {
    if (!FxContext.getUserTicket().isGlobalSupervisor()) {
        throw new FxNoAccessException(LOG, "ex.searchQuery.systemDefault.noAccess");
    }
    save(EJBLookup.getDivisionConfigurationEngine(), query, DEFAULT_QUERY_NAME);
}

From source file:com.sfs.ucm.controller.UseCaseFlowAction.java

/**
 * Action: add AlternativeFlow/* ww  w. j av a 2  s.  co  m*/
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void addAlternativeFlow() {

    logger.info("addAlternativeFlow called");

    // construct alternative setting starting step as the current basic flow step
    this.alternativeFlow = new Flow(this.basicFlowStep.getStepNumber());

}

From source file:com.sfs.ucm.controller.SpecificationAction.java

/**
 * File Upload Handler/* w w w  . ja  va  2 s  . c o  m*/
 * 
 * @param event
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void handleFileUpload(FileUploadEvent event) {

    // extract filename
    File file = new File(event.getFile().getFileName());

    logger.info("Uploading file: {}, type: {}", file.getName(), event.getFile().getContentType());
    this.attachment.setFilename(file.getName());
    this.attachment.setVersion(1);
    this.attachment.setContents(event.getFile().getContents());
    this.attachment.setContentType(event.getFile().getContentType());

    this.facesContextMessage.infoMessage("Uploaded file {0}", event.getFile().getFileName());

}

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

/**
 * {@inheritDoc}//from w w w  . j ava 2  s  .co m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void syncPhraseNodeSequencer(long mandatorId) {
    FxContext.startRunningAsSystem();
    final String seqPrefix = "PhraseNodeSeq_" + mandatorId + "_";
    try {
        for (String sname : seq.getCustomSequencerNames()) {
            if (!sname.startsWith(seqPrefix))
                continue;
            int category = Integer.parseInt(sname.substring(seqPrefix.length()));
            syncPhraseNodeSequencer(category, mandatorId);
        }
    } catch (FxApplicationException e) {
        EJBUtils.rollback(ctx);
        throw e.asRuntimeException();
    } finally {
        FxContext.stopRunningAsSystem();
    }
}

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

/**
 * {@inheritDoc}/*  www.  j ava2  s . c  o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void saveProject(Project project, PersistentObject... orphansToDelete)
        throws ProposalWorkflowException, InconsistentProjectStateException {

    LogUtil.logSubsystemEntry(LOG, project);
    checkIfProjectSaveAllowed(project);
    // make sure that an anonymous user cannot create a new project
    if (project.getId() == null && CaArrayUsernameHolder.getUser().equals(SecurityUtils.ANONYMOUS_USERNAME)) {
        throw new PermissionDeniedException(project, SecurityUtils.WRITE_PRIVILEGE,
                CaArrayUsernameHolder.getUser());
    }

    if (project.getId() == null) {
        // for the initial save, we will need to save experiment first since we need to assign a public
        // identifier, which requires the id to be set
        final Experiment exp = project.getExperiment();
        this.projectDao.save(exp);
        exp.setPublicIdentifier(PUBLIC_ID_PREFIX + String.valueOf(exp.getId()));
    }
    this.projectDao.save(project);
    for (final PersistentObject obj : orphansToDelete) {
        if (obj != null) {
            this.projectDao.remove(obj);
        }
    }
    LogUtil.logSubsystemExit(LOG);
}

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

/**
 * {@inheritDoc}/*from  w  w w . jav  a2  s. c  om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void remove(ResultLocation location, String name) throws FxApplicationException {
    configuration.remove(getConfigurationParameter(location), name);
}

From source file:gov.nih.nci.caarray.application.permissions.PermissionsManagementServiceBean.java

/**
 * {@inheritDoc}//from w  ww  .j  a va2  s  . c o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void saveAccessProfile(AccessProfile profile) {
    LogUtil.logSubsystemEntry(LOG, profile);
    this.collaboratorGroupDao.save(profile);
    LogUtil.logSubsystemExit(LOG);
}

From source file:com.sfs.ucm.controller.UseCaseFlowAction.java

/**
 * save alternative flow action/*from  w  w w. j  a  v  a2s. c  o m*/
 * 
 * @throws UCMException
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void saveAlternativeFlow() throws UCMException {
    try {
        if (validateAlternativeFlow()) {

            this.alternativeFlow.setModifiedBy(authUser.getUsername());
            if (this.alternativeFlow.getId() == null) {
                this.useCase.addAlternativeFlow(this.alternativeFlow);
            }

            em.persist(this.alternativeFlow);

            // force testcase update
            Timestamp now = new Timestamp(System.currentTimeMillis());
            this.useCase.setModifiedDate(now);

            em.persist(this.useCase);

            logger.info("Saved {}", this.alternativeFlow.getName());
            this.facesContextMessage.infoMessage("{0} saved successfully", this.alternativeFlow.getName());

            // refresh list of alternative flows
            loadAlternativeFlows();
        }
    } catch (Exception e) {
        throw new UCMException(e);
    }
}

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

/**
 * {@inheritDoc}/*  w w  w.j  ava 2s  . c om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public <T extends Serializable> void put(Parameter<T> parameter, String key, T value)
        throws FxApplicationException {

    if (!parameter.isValid(value)) {
        throw new FxUpdateException("ex.configuration.parameter.value", parameter, value);
    }

    // put into DB config table
    Connection conn = null;
    PreparedStatement stmt = null;
    ParameterData<T> data = parameter.getData();
    String oldValue = null;
    try {
        conn = getConnection();
        stmt = getSelectStatement(conn, data.getPath().getValue(), key);
        ResultSet rs = stmt.executeQuery();
        boolean valueExists = rs.next();
        if (valueExists) {
            oldValue = rs.getString(1);
            if (!StringUtils.isEmpty(oldValue) && oldValue.equals(String.valueOf(value)))
                return; //no changes
        }
        stmt.close();

        try {
            writeParameter(conn, parameter, key, value, data, valueExists);
        } catch (SQLException e) {
            if (!valueExists && StorageManager.isUniqueConstraintViolation(e)) {
                // tried to insert record, but record exists - workaround for strange
                // bug on MySQL, where an ALTER TABLE on the configuration table messes up
                // subsequent SELECTs (DB schema version 1353)
                writeParameter(conn, parameter, key, value, data, true);
            } else {
                throw new FxUpdateException(LOG, e, "ex.db.sqlError", e.getMessage());
            }
        }

        // update cache?
        String cachePath = getCachePath(data.getPath().getValue());
        if (cachePath != null) {
            putCache(cachePath, key,
                    value != null ? (Serializable) SerializationUtils.clone(value) : new NullParameter(), true);
        }
        StringBuilder sbHistory = new StringBuilder(1000);
        sbHistory.append("<parameter type=\"").append(parameter.getScope().name()).append("\">\n");
        sbHistory.append("  <path><![CDATA[").append(parameter.getPath()).append("]]></path>\n");
        sbHistory.append("  <key><![CDATA[").append(key).append("]]></key>\n");
        if (oldValue != null)
            sbHistory.append("  <oldValue><![CDATA[").append(oldValue).append("]]></oldValue>\n");
        sbHistory.append("  <value><![CDATA[").append(String.valueOf(value)).append("]]></value>\n");
        sbHistory.append("</parameter>\n");
        EJBLookup.getHistoryTrackerEngine().trackData(sbHistory.toString(), "history.parameter.set",
                parameter.getScope().name(), parameter.getPath(), key);
    } catch (SQLException se) {
        FxUpdateException ue = new FxUpdateException(LOG, se, "ex.db.sqlError", se.getMessage());
        LOG.error(ue, se);
        throw ue;
    } finally {
        Database.closeObjects(GenericConfigurationImpl.class, conn, stmt);
    }
}