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:com.flexive.ejb.beans.structure.TypeEngineBean.java
/** * {@inheritDoc}// ww w . j av a2 s . c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void flatten(long typeId, FlattenOptions options) throws FxApplicationException { Connection con = null; try { con = Database.getDbConnection(); final FxFlatStorage flatStorage = FxFlatStorageManager.getInstance(); flatStorage.flattenType(con, flatStorage.getDefaultStorage(), CacheAdmin.getEnvironment().getType(typeId), options); StructureLoader.reload(con); } catch (FxApplicationException e) { EJBUtils.rollback(ctx); throw e; } catch (Exception e) { EJBUtils.rollback(ctx); throw new FxUpdateException(e); } finally { Database.closeObjects(TypeEngineBean.class, con, null); } }
From source file:com.flexive.ejb.beans.configuration.GenericConfigurationImpl.java
/** * {@inheritDoc}// w ww . j a v a 2 s . c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public <T extends Serializable> T get(Parameter<T> parameter, String key) throws FxApplicationException { return get(parameter, key, false); }
From source file:com.flexive.ejb.beans.MandatorEngineBean.java
/** * {@inheritDoc}//from w w w .j av a2 s . c om */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void changeName(long mandatorId, String name) throws FxApplicationException { FxSharedUtils.checkParameterEmpty(name, "name"); final UserTicket ticket = FxContext.getUserTicket(); final FxEnvironment environment = CacheAdmin.getEnvironment(); // Security FxPermissionUtils.checkRole(ticket, Role.GlobalSupervisor); //exist check Mandator mand = environment.getMandator(mandatorId); Connection con = null; PreparedStatement ps = null; String sql; try { name = name.trim(); // Obtain a database connection con = Database.getDbConnection(); // 1 2 3 4 sql = "UPDATE " + TBL_MANDATORS + " SET NAME=?, MODIFIED_BY=?, MODIFIED_AT=? WHERE ID=?"; final long NOW = System.currentTimeMillis(); ps = con.prepareStatement(sql); ps.setString(1, name.trim()); ps.setLong(2, ticket.getUserId()); ps.setLong(3, NOW); ps.setLong(4, mandatorId); ps.executeUpdate(); ps.close(); sql = "UPDATE " + TBL_USERGROUPS + " SET NAME=? WHERE AUTOMANDATOR=?"; ps = con.prepareStatement(sql); ps.setString(1, "Everyone (" + name + ")"); ps.setLong(2, mandatorId); ps.executeUpdate(); StructureLoader.updateMandator(FxContext.get().getDivisionId(), new Mandator(mand.getId(), name, mand.getMetadataId(), mand.isActive(), new LifeCycleInfoImpl(mand.getLifeCycleInfo().getCreatorId(), mand.getLifeCycleInfo().getCreationTime(), ticket.getUserId(), NOW))); StructureLoader.updateUserGroups(FxContext.get().getDivisionId(), grp.loadAll(-1)); } catch (SQLException exc) { // check before rollback, because it might need an active transaciton final boolean uniqueConstraintViolation = StorageManager.isUniqueConstraintViolation(exc); EJBUtils.rollback(ctx); if (uniqueConstraintViolation) { throw new FxUpdateException(LOG, "ex.mandator.update.name.unique", name); } else { 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.TreeEngineBean.java
/** * {@inheritDoc}/*from w ww .ja v a 2s. com*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void remove(FxTreeNode node, FxTreeRemoveOp removeOp, boolean removeChildren) throws FxApplicationException { remove(node.getMode(), node.getId(), removeOp, removeChildren); }
From source file:com.flexive.ejb.beans.configuration.GlobalConfigurationEngineBean.java
/** * {@inheritDoc}/*w ww .j a v a 2 s . c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public DivisionData createDivisionData(int divisionId, String dataSource, String domainRegEx) { String dbVendor = "unknown"; String dbVersion = "unknown"; String dbDriverVersion = "unknown"; boolean available = false; Connection con = null; try { // lookup non-transactional datasource to avoid issues with the default JEE6 data source in Glassfish con = Database.getDataSource(dataSource + "NoTX").getConnection(); DatabaseMetaData dbmd = con.getMetaData(); dbVendor = dbmd.getDatabaseProductName(); dbVersion = dbmd.getDatabaseProductVersion(); dbDriverVersion = dbmd.getDriverName() + " " + dbmd.getDriverVersion(); available = true; } catch (NamingException e) { LOG.error("Failed to get datasource " + dataSource + " (flagged inactive)"); } catch (SQLException e) { if (LOG.isDebugEnabled()) { LOG.debug("Failed to get database meta information: " + e.getMessage(), e); } } finally { Database.closeObjects(GlobalConfigurationEngineBean.class, con, null); } return new DivisionData(divisionId, available, dataSource, domainRegEx, dbVendor, dbVersion, dbDriverVersion); }
From source file:com.flexive.ejb.beans.configuration.GenericConfigurationImpl.java
/** * {@inheritDoc}//w ww . ja v a2s. c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public <T extends Serializable> T get(Parameter<T> parameter, String key, boolean ignoreDefault) throws FxApplicationException { final Pair<Boolean, T> result = tryGet(parameter, key, ignoreDefault); if (result.getFirst()) { return result.getSecond(); } throw new FxNotFoundException("ex.configuration.parameter.notfound", parameter.getPath(), key); }
From source file:com.flexive.ejb.beans.BriefcaseEngineBean.java
/** * {@inheritDoc}/*from w w w . ja v a2 s.c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void updateItems(long id, Collection<FxPK> addContents, Collection<FxPK> removeContents) throws FxApplicationException { removeItems(id, removeContents); addItems(id, addContents); }
From source file:gov.nih.nci.caarray.application.project.ProjectManagementServiceBean.java
/** * {@inheritDoc}// w w w.j a va 2 s . c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public Sample copySample(Project project, long sampleId) throws ProposalWorkflowException, InconsistentProjectStateException { LogUtil.logSubsystemEntry(LOG, project, sampleId); checkIfProjectSaveAllowed(project); final Sample sample = this.searchDao.retrieve(Sample.class, sampleId); final Sample copy = new Sample(); copyInto(Sample.class, copy, sample); for (final Source source : sample.getSources()) { source.getSamples().add(copy); copy.getSources().add(source); } project.getExperiment().getSamples().add(copy); copy.setExperiment(project.getExperiment()); this.projectDao.save(project); LogUtil.logSubsystemExit(LOG); return copy; }
From source file:com.flexive.ejb.beans.TreeEngineBean.java
/** * {@inheritDoc}//from w w w. j a va2s. com */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void remove(FxTreeMode mode, long nodeId, FxTreeRemoveOp removeOp, boolean removeChildren) throws FxApplicationException { Connection con = null; if (nodeId < 0) { throw new FxInvalidParameterException("nodeId", "ex.tree.delete.nodeId"); } try { con = Database.getDbConnection(); final FxTreeNode subTree; final TreeStorage treeStorage = StorageManager.getTreeStorage(); if (removeOp == FxTreeRemoveOp.UnfileAll) { subTree = treeStorage.getNode(con, mode, nodeId); FxPK refPK = subTree.getReference(); List<FxTreeNode> nodes = treeStorage.getNodesWithReference(con, mode, refPK.getId()); for (FxTreeNode node : nodes) { try { treeStorage.removeNode(con, mode, contentEngine, node.getId(), removeChildren); } catch (FxApplicationException e) { LOG.warn("Could not unfile node " + node, e); } } treeStorage.checkTreeIfEnabled(con, mode); FxContext.get().setTreeWasModified(); return; } if (removeOp != FxTreeRemoveOp.Unfile) { subTree = removeChildren ? treeStorage.getTree(con, contentEngine, mode, nodeId, Integer.MAX_VALUE, PARTIAL_LOADING, FxContext.getUserTicket().getLanguage()) : treeStorage.getNode(con, mode, nodeId); } else { subTree = null; } treeStorage.removeNode(con, mode, contentEngine, nodeId, removeChildren); if (removeOp != FxTreeRemoveOp.Unfile) { for (FxTreeNode currNode : subTree) { if (currNode.getReference() != null) { long refCount = 0; if (removeOp == FxTreeRemoveOp.RemoveSingleFiled) { //reference count it only relevant if removeOp is RemoveSingleFiled refCount = contentEngine.getReferencedContentCount(currNode.getReference()); if (currNode.getId() == nodeId || removeChildren) refCount++; //include the reference from the already removed node } if (removeOp == FxTreeRemoveOp.Remove || (removeOp == FxTreeRemoveOp.RemoveSingleFiled && refCount == 1)) { // remove only contents that are not referenced elsewhere contentEngine.remove(currNode.getReference()); } } } } treeStorage.checkTreeIfEnabled(con, mode); FxContext.get().setTreeWasModified(); } catch (FxNotFoundException nf) { // Node does not exist and we wanted to delete it anyway .. so this is no error } catch (FxApplicationException ae) { EJBUtils.rollback(ctx); throw ae; } catch (Throwable t) { EJBUtils.rollback(ctx); throw new FxRemoveException(LOG, t, "ex.tree.delete.failed", nodeId, t.getMessage()); } finally { Database.closeObjects(TreeEngineBean.class, con, null); } }
From source file:com.flexive.ejb.beans.BriefcaseEngineBean.java
/** * {@inheritDoc}//from ww w . ja v a2 s.c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void setItems(long id, Collection<FxPK> objectIds) throws FxApplicationException { clear(id); addItems(id, objectIds); }