List of usage examples for javax.ejb TransactionAttributeType REQUIRED
TransactionAttributeType REQUIRED
To view the source code for javax.ejb TransactionAttributeType REQUIRED.
Click Source Link
From source file:gov.nih.nci.caarray.application.permissions.PermissionsManagementServiceBean.java
/** * {@inheritDoc}/* ww w . j ava 2 s . c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void changeOwner(Long targetGroupId, String username) throws CSException { LogUtil.logSubsystemEntry(LOG, targetGroupId, username); final AuthorizationManager am = SecurityUtils.getAuthorizationManager(); final CollaboratorGroup cg = this.searchDao.retrieve(CollaboratorGroup.class, targetGroupId); final User newOwner = am.getUser(username); cg.setOwner(newOwner); SecurityUtils.changeOwner(cg, newOwner); this.collaboratorGroupDao.save(cg); LogUtil.logSubsystemExit(LOG); }
From source file:com.flexive.ejb.beans.workflow.StepDefinitionEngineBean.java
/** * {@inheritDoc}/*w ww . j ava 2s . c om*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void update(StepDefinition stepDefinition) throws FxApplicationException { final UserTicket ticket = FxContext.getUserTicket(); final FxContext ri = FxContext.get(); // Security checks FxPermissionUtils.checkRole(ticket, Role.WorkflowManagement); StepDefinition orgDefinition; try { // Lookup the stepDefinition, throws FxNotFoundException (+FxDbException) orgDefinition = getEnvironment().getStepDefinition(stepDefinition.getId()); } catch (Exception exc) { throw new FxUpdateException(exc.getMessage(), exc); } // Unique target checks boolean uniqueTargetAdded = stepDefinition.getId() != -1 && stepDefinition.getUniqueTargetId() != -1 && stepDefinition.getUniqueTargetId() != orgDefinition.getUniqueTargetId(); // Check the unique target, throws FxInvalidParameterException if target is invalid (+FxDbException) if (stepDefinition.getUniqueTargetId() != -1) { checkValidUniqueTarget(stepDefinition.getId(), stepDefinition.getUniqueTargetId()); } // Sanity checks if (stepDefinition.getLabel() == null || stepDefinition.getLabel().isEmpty()) { throw new FxInvalidParameterException("NAME", "ex.stepdefinition.name.empty"); } Connection con = null; PreparedStatement stmt = null; String sql; boolean success = false; try { // Obtain a database connection con = Database.getDbConnection(); // store label Database.storeFxString(stepDefinition.getLabel(), con, TBL_WORKFLOW_STEPDEFINITION, "name", "id", stepDefinition.getId()); sql = "UPDATE " + TBL_WORKFLOW_STEPDEFINITION + " SET NAME=?,UNIQUE_TARGET=? WHERE ID=?"; stmt = con.prepareStatement(sql); stmt.setString(1, stepDefinition.getName()); if (stepDefinition.getUniqueTargetId() != -1) { stmt.setLong(2, stepDefinition.getUniqueTargetId()); } else { stmt.setNull(2, Types.NUMERIC); } stmt.setLong(3, stepDefinition.getId()); int updateCount = stmt.executeUpdate(); if (updateCount == 0) { FxNotFoundException nfe = new FxNotFoundException("ex.stepdefinition.load.notFound", stepDefinition.getId()); if (LOG.isInfoEnabled()) LOG.info(nfe); throw nfe; } else if (updateCount != 1) { FxUpdateException dbe = new FxUpdateException("ex.stepdefinition.update.rows"); LOG.error(dbe); throw dbe; } // Unique target has to exist for every workflow long workflowId; if (uniqueTargetAdded) { try { ri.runAsSystem(); List<StepDefinition> stepDefinitionList = new ArrayList<StepDefinition>(); stepDefinitionList.add(stepDefinition); // Do this for all existing workflows .. for (Workflow workflow : getEnvironment().getWorkflows()) { workflowId = workflow.getId(); if (FxSharedUtils.getUsedStepDefinitions(workflow.getSteps(), stepDefinitionList) .size() > 0) { // create step IF the step definition is used by the workflow stepEngine.createStep( new Step(-1, stepDefinition.getUniqueTargetId(), workflowId, getEnvironment() .getStepByDefinition(workflowId, stepDefinition.getId()).getAclId())); } } } catch (Exception exc) { throw new FxUpdateException(LOG, "ex.stepdefinition.uniqueTarget.create"); } finally { ri.stopRunAsSystem(); } } success = true; } catch (SQLException exc) { if (StorageManager.isUniqueConstraintViolation(exc)) { FxEntryExistsException ee = new FxEntryExistsException("ex.stepdefinition.name.exists", stepDefinition.getName()); if (LOG.isDebugEnabled()) LOG.debug(ee); throw ee; } throw new FxUpdateException(LOG, exc, "ex.db.sqlError", exc.getMessage()); } finally { Database.closeObjects(StepDefinitionEngineBean.class, con, stmt); if (!success) { EJBUtils.rollback(ctx); } else { StructureLoader.reloadWorkflows(FxContext.get().getDivisionId()); } } }
From source file:com.sfs.ucm.controller.SpecificationAction.java
/** * Feature value change//from w w w. j a v a2 s. co m * <p> * Add this Specification to the selected Feature * * @param e */ @TransactionAttribute(TransactionAttributeType.REQUIRED) public void featureValueChange(ValueChangeEvent e) { Feature feature = (Feature) e.getNewValue(); feature.addSpecification(this.specification); }
From source file:com.flexive.ejb.beans.PhraseEngineBean.java
/** * {@inheritDoc}/*from ww w . j a va2 s . com*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void syncPhraseNodeSequencer(int category, long mandatorId) { FxContext.startRunningAsSystem(); Connection con = null; PreparedStatement ps = null; try { con = Database.getDbConnection(); ps = con.prepareStatement("SELECT MAX(ID) FROM " + TBL_PHRASE_TREE + " WHERE MANDATOR=? AND CAT=?"); ps.setLong(1, mandatorId); ps.setInt(2, category); ResultSet rs = ps.executeQuery(); if (rs != null && rs.next()) { long max = rs.getLong(1) + 1; final String SEQ_NAME = "PhraseNodeSeq_" + mandatorId + "_" + category; if (seq.sequencerExists(SEQ_NAME)) seq.removeSequencer(SEQ_NAME); seq.createSequencer(SEQ_NAME, false, max); } } catch (SQLException e) { EJBUtils.rollback(ctx); throw new FxDbException(LOG, e, "ex.db.sqlError", e.getMessage()).asRuntimeException(); } catch (FxApplicationException e) { EJBUtils.rollback(ctx); throw e.asRuntimeException(); } finally { FxContext.stopRunningAsSystem(); Database.closeObjects(PhraseEngineBean.class, con, ps); } }
From source file:com.flexive.ejb.beans.structure.SelectListEngineBean.java
/** * {@inheritDoc}// w w w. j av a2 s . co m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public long save(FxSelectListItemEdit item) throws FxApplicationException { long id = item.getId(); if (item.isNew()) id = createItem(item, null); else if (item.changes()) { FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.SelectListEditor); updateItem(item); } else return id; try { StructureLoader.reload(null); } catch (FxCacheException e1) { EJBUtils.rollback(ctx); throw new FxCreateException(LOG, e1, "ex.cache", e1.getMessage()); } return id; }
From source file:com.flexive.ejb.beans.MandatorEngineBean.java
/** * {@inheritDoc}/*from w w w . j a v a2 s.com*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void activate(long mandatorId) throws FxApplicationException { final UserTicket ticket = FxContext.getUserTicket(); final FxEnvironment environment; // Security FxPermissionUtils.checkRole(ticket, Role.GlobalSupervisor); environment = CacheAdmin.getEnvironment(); //exist check Mandator mand = environment.getMandator(mandatorId); if (mand.isActive()) return; //silently ignore Connection con = null; PreparedStatement ps = null; String sql; try { // Obtain a database connection con = Database.getDbConnection(); // 1 2 3 4 sql = "UPDATE " + TBL_MANDATORS + " SET IS_ACTIVE=?, MODIFIED_BY=?, MODIFIED_AT=? WHERE ID=?"; final long NOW = System.currentTimeMillis(); ps = con.prepareStatement(sql); ps.setBoolean(1, true); ps.setLong(2, ticket.getUserId()); ps.setLong(3, NOW); ps.setLong(4, mandatorId); ps.executeUpdate(); StructureLoader.updateMandator(FxContext.get().getDivisionId(), new Mandator(mand.getId(), mand.getName(), mand.getMetadataId(), true, new LifeCycleInfoImpl(mand.getLifeCycleInfo().getCreatorId(), mand.getLifeCycleInfo().getCreationTime(), ticket.getUserId(), NOW))); } catch (SQLException exc) { EJBUtils.rollback(ctx); throw new FxUpdateException(LOG, exc, "ex.mandator.updateFailed", mand.getName(), exc.getMessage()); } finally { Database.closeObjects(MandatorEngineBean.class, con, ps); } }
From source file:com.flexive.ejb.beans.BriefcaseEngineBean.java
/** * {@inheritDoc}// w ww. j a va 2 s. c om */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void remove(long id) throws FxApplicationException { // Lookup the briefcase Briefcase br = load(id); if (br == null) { throw new FxNotFoundException("ex.briefcase.notFound", ("#" + id)); } // Permission checks final UserTicket ticket = FxContext.getUserTicket(); if (!ticket.isGlobalSupervisor() && br.getMandator() != ticket.getMandatorId()) { if (!ticket.mayDeleteACL(br.getAcl(), br.getLifeCycleInfo().getCreatorId())) { throw new FxNotFoundException("ex.briefcase.noDeletePermission", br.getName()); } } // Delete operation Connection con = null; Statement stmt = null; try { // Obtain a database connection con = Database.getDbConnection(); stmt = con.createStatement(); stmt.addBatch("DELETE FROM " + TBL_BRIEFCASE_DATA_ITEM + " WHERE briefcase_id=" + id); stmt.addBatch("DELETE FROM " + TBL_BRIEFCASE_DATA + " WHERE briefcase_id=" + id); stmt.addBatch("DELETE FROM " + DatabaseConst.TBL_BRIEFCASE + " WHERE id=" + id); stmt.executeBatch(); } catch (SQLException exc) { throw new FxRemoveException(LOG, exc, "ex.briefcase.deleteFailed", br.getName()); } finally { closeObjects(BriefcaseEngineBean.class, con, stmt); } }
From source file:com.sfs.ucm.controller.UseCaseFlowAction.java
/** * Handler//ww w .j a va2s . c o m * * @throws UCMException */ @TransactionAttribute(TransactionAttributeType.REQUIRED) public void updateAlternativeFlowName() throws UCMException { try { if (this.alternativeFlow.getId() == null) { this.useCase.addAlternativeFlow(alternativeFlow); } logger.info("saving alt flow {}", this.alternativeFlow); // force testcase update Timestamp now = new Timestamp(System.currentTimeMillis()); this.useCase.setModifiedDate(now); em.persist(this.useCase); } catch (Exception e) { throw new UCMException(e); } }
From source file:gov.nih.nci.caarray.application.project.ProjectManagementServiceBean.java
/** * {@inheritDoc}/*from ww w . jav a2s. c om*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) @TransactionTimeout(DELETE_TIMEOUT) public void deleteProject(Project project) throws ProposalWorkflowException { LogUtil.logSubsystemEntry(LOG, project); if (!project.isOwner(CaArrayUsernameHolder.getCsmUser())) { LogUtil.logSubsystemExit(LOG); throw new PermissionDeniedException(project, SecurityUtils.WRITE_PRIVILEGE, CaArrayUsernameHolder.getUser()); } if (project.isLocked()) { LogUtil.logSubsystemExit(LOG); throw new ProposalWorkflowException("Cannot delete a locked project"); } // the data storage will get cleaned up by the reaper, so no need to delete explicitly // refresh project final Project freshProject = getSearchDao().retrieve(Project.class, project.getId()); // both hybridizations and project are trying to delete the saveAndEvict files via cascades, so explicitly // delete hybridizations (and their files) first for (final Hybridization hyb : freshProject.getExperiment().getHybridizations()) { this.projectDao.remove(hyb); } this.projectDao.remove(freshProject); LogUtil.logSubsystemExit(LOG); }
From source file:com.flexive.ejb.beans.LanguageBean.java
/** * {@inheritDoc}//from w w w . j a va 2s. com */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void activateLanguage(FxLanguage language) throws FxApplicationException { List<FxLanguage> available = loadAvailable(); if (available.contains(language)) { LOG.info("Language " + language + " is already active."); return; } available.add(language); setAvailable(available, false); }