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.configuration.GlobalConfigurationEngineBean.java
/** * {@inheritDoc}//from ww w.j a v a 2 s.c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void registerCacheMBean(ObjectName name) throws MBeanRegistrationException, NotCompliantMBeanException, InstanceAlreadyExistsException { //TODO: some exception handling and cross checks for prev. registrations wouldn't hurt ... //TODO: maybe create a system beans and move this method there MBeanHelper.locateServer().registerMBean(new FxCache(), name); }
From source file:com.flexive.ejb.beans.TreeEngineBean.java
/** * {@inheritDoc}//from w ww .jav a 2 s. c om */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public long copy(FxTreeMode mode, long source, long destination, int destinationPosition, boolean deepReferenceCopy) throws FxApplicationException { Connection con = null; boolean success = false; try { con = Database.getDbConnection(); long nodeId = StorageManager.getTreeStorage().copy(con, seq, mode, source, destination, destinationPosition, deepReferenceCopy, "CopyOf_"); // call scripts final List<Long> scriptIds = scripting.getByScriptEvent(FxScriptEvent.AfterTreeNodeAdded); if (scriptIds.size() == 0) { success = true; return nodeId; } FxTreeNode parent = getTree(mode, nodeId, 1000); final FxScriptBinding binding = new FxScriptBinding(); for (long scriptId : scriptIds) executeScript(scriptId, parent, binding); success = true; return nodeId; } catch (FxApplicationException ae) { EJBUtils.rollback(ctx); throw ae; } catch (Throwable t) { EJBUtils.rollback(ctx); throw new FxUpdateException(LOG, t, "ex.tree.copy.failed", source, destination, destinationPosition); } finally { if (success) { StorageManager.getTreeStorage().checkTreeIfEnabled(con, mode); FxContext.get().setTreeWasModified(); } Database.closeObjects(TreeEngineBean.class, con, null); } }
From source file:com.flexive.ejb.beans.BriefcaseEngineBean.java
/** * {@inheritDoc}/*from w w w. java 2 s . c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public List<FxReferenceMetaData<FxPK>> getMetaData(long briefcaseId) throws FxApplicationException { load(briefcaseId); // check read permissions Connection con = null; try { con = Database.getDbConnection(); return loadMetaData(con, briefcaseId, -1, false); } catch (SQLException e) { throw new FxLoadException(LOG, e); } finally { Database.closeObjects(BriefcaseEngineBean.class, con, null); } }
From source file:com.flexive.ejb.beans.configuration.GenericConfigurationImpl.java
/** * {@inheritDoc}//from w w w. jav a 2s.co m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public <T extends Serializable> Collection<String> getKeys(Parameter<T> parameter) throws FxApplicationException { Connection conn = null; PreparedStatement stmt = null; final ParameterData<T> data = parameter.getData(); final List<String> keys = Lists.newArrayList(); try { conn = getConnection(); stmt = getSelectStatement(conn, data.getPath().getValue()); ResultSet rs = stmt.executeQuery(); while (rs != null && rs.next()) { keys.add(rs.getString(1)); } return keys; } catch (SQLException se) { throw new FxLoadException(LOG, se, "ex.db.sqlError", se.getMessage()); } finally { Database.closeObjects(GenericConfigurationImpl.class, conn, stmt); } }
From source file:com.flexive.ejb.beans.ScriptingEngineBean.java
/** * {@inheritDoc}/*w ww . ja va2 s .c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void remove(long scriptId) throws FxApplicationException { FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.ScriptManagement); Connection con = null; PreparedStatement ps = null; String sql; boolean success = false; final List<FxScriptSchedule> schedules = CacheAdmin.getEnvironment().getScriptSchedulesForScript(scriptId); try { // Obtain a database connection con = Database.getDbConnection(); sql = "DELETE FROM " + TBL_SCRIPT_MAPPING_ASSIGN + " WHERE SCRIPT=?"; ps = con.prepareStatement(sql); ps.setLong(1, scriptId); ps.executeUpdate(); ps.close(); sql = "DELETE FROM " + TBL_SCRIPT_MAPPING_TYPES + " WHERE SCRIPT=?"; ps = con.prepareStatement(sql); ps.setLong(1, scriptId); ps.executeUpdate(); ps.close(); sql = "DELETE FROM " + TBL_SCRIPT_SCHEDULES + " WHERE SCRIPT=?"; ps = con.prepareStatement(sql); ps.setLong(1, scriptId); ps.executeUpdate(); ps.close(); // 1 sql = "DELETE FROM " + TBL_SCRIPTS + " WHERE ID=?"; ps = con.prepareStatement(sql); ps.setLong(1, scriptId); ps.executeUpdate(); // remove script schedules from scheduler if (EJBLookup.getTimerService().isInstalled()) { for (FxScriptSchedule ss : schedules) { try { boolean deleteSuccess = EJBLookup.getTimerService().deleteScriptSchedule(ss); if (deleteSuccess) LOG.debug("Script schedule with id " + ss.getId() + " successfully deleted from scheduler"); else LOG.warn("Failed to delete script schedule with id " + ss.getId() + " from scheduler"); } catch (Exception e) { LOG.error("Error removing script schedule from scheduler", e); } } } success = true; } catch (SQLException exc) { throw new FxRemoveException(LOG, exc, "ex.scripting.remove.failed", scriptId, exc.getMessage()); } finally { Database.closeObjects(ScriptingEngineBean.class, con, ps); if (!success) EJBUtils.rollback(ctx); else StructureLoader.reloadScripting(FxContext.get().getDivisionId()); } }
From source file:com.flexive.ejb.beans.BriefcaseEngineBean.java
/** * {@inheritDoc}/*from w w w . j a va 2 s .c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void addItemData(long briefcaseId, BriefcaseItemData itemData) throws FxApplicationException { if (itemData == null) return; Briefcase br = load(briefcaseId); // check read permissions Connection con = null; PreparedStatement stmt = null; try { con = Database.getDbConnection(); // check if the item actually exists stmt = con.prepareStatement( "SELECT COUNT(*) FROM " + TBL_BRIEFCASE_DATA + " WHERE briefcase_id=? AND id=?"); stmt.setLong(1, briefcaseId); stmt.setLong(2, itemData.getId()); ResultSet rs = stmt.executeQuery(); if (rs == null || !rs.next() || rs.getLong(1) != 1) throw new FxNotFoundException(LOG, "ex.briefcase.notFound.item", itemData.getId(), br.getName()); stmt.close(); stmt = con.prepareStatement( "SELECT MAX(pos) FROM " + TBL_BRIEFCASE_DATA_ITEM + " WHERE briefcase_id=? AND id=?"); stmt.setLong(1, briefcaseId); stmt.setLong(2, itemData.getId()); rs = stmt.executeQuery(); int pos = rs.next() ? rs.getInt(1) : 0; stmt.close(); stmt = con.prepareStatement("INSERT INTO " + TBL_BRIEFCASE_DATA_ITEM + "(briefcase_id, id, pos, intflag1, intflag2, intflag3, longflag1, longflag2, metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setLong(1, briefcaseId); stmt.setLong(2, itemData.getId()); stmt.setLong(3, ++pos); if (itemData.isIntFlagSet(1)) stmt.setInt(4, itemData.getIntFlag1()); else stmt.setNull(4, Types.INTEGER); if (itemData.isIntFlagSet(2)) stmt.setInt(5, itemData.getIntFlag2()); else stmt.setNull(5, Types.INTEGER); if (itemData.isIntFlagSet(3)) stmt.setInt(6, itemData.getIntFlag3()); else stmt.setNull(6, Types.INTEGER); if (itemData.isLongFlagSet(1)) stmt.setLong(7, itemData.getLongFlag1()); else stmt.setNull(7, Types.BIGINT); if (itemData.isLongFlagSet(2)) stmt.setLong(8, itemData.getLongFlag2()); else stmt.setNull(8, Types.BIGINT); stmt.setString(9, itemData.getMetaData()); stmt.executeUpdate(); } catch (Exception e) { EJBUtils.rollback(ctx); throw new FxUpdateException(LOG, e, "ex.briefcase.addItemData", br.getName(), itemData.getId(), e.getMessage()); } finally { Database.closeObjects(BriefcaseEngineBean.class, con, stmt); } }
From source file:com.flexive.ejb.beans.PhraseEngineBean.java
/** * {@inheritDoc}/*from w ww . j av a2s .c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public int removePhrases(String phraseKeyPrefix, long mandator) throws FxNoAccessException, FxEntryInUseException { return removePhrases(FxPhraseCategorySelection.CATEGORY_DEFAULT, phraseKeyPrefix, mandator); }
From source file:com.flexive.ejb.beans.configuration.GenericConfigurationImpl.java
/** * {@inheritDoc}//from w ww. ja v a 2 s .c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public <T extends Serializable> void remove(Parameter<T> parameter, String key) throws FxApplicationException { Connection conn = null; PreparedStatement stmt = null; try { conn = getConnection(); stmt = getDeleteStatement(conn, parameter.getPath().getValue(), key); stmt.executeUpdate(); String cachePath = getCachePath(parameter.getPath().getValue()); if (cachePath != null) { // also remove from cache if (key == null) { // clear entire cache path deleteCache(cachePath); } else { // clear single value deleteCache(cachePath, key); } } if (key == null) EJBLookup.getHistoryTrackerEngine().track("history.parameter.remove.path", parameter.getScope().name(), parameter.getPath()); else EJBLookup.getHistoryTrackerEngine().track("history.parameter.remove.key", parameter.getScope().name(), parameter.getPath(), key); } catch (SQLException e) { throw new FxRemoveException(LOG, e, "ex.db.sqlError", e.getMessage()); } finally { Database.closeObjects(GenericConfigurationImpl.class, conn, stmt); } }
From source file:com.flexive.ejb.beans.PhraseEngineBean.java
/** * {@inheritDoc}//from w ww .java2 s .co m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public int removePhrases(int category, String phraseKeyPrefix, long mandator) throws FxNoAccessException, FxEntryInUseException { Connection con = null; PreparedStatement psResolve = null, ps = null; final UserTicket userTicket = FxContext.getUserTicket(); checkMandatorAccess(mandator, userTicket); checkPhraseKey(phraseKeyPrefix); int count = 0; try { // Obtain a database connection con = Database.getDbConnection(); psResolve = con.prepareStatement( "SELECT ID,PKEY FROM " + TBL_PHRASE + " WHERE PKEY LIKE ? AND MANDATOR=? AND CAT=?"); psResolve.setString(1, phraseKeyPrefix + "%"); psResolve.setLong(2, mandator); psResolve.setInt(3, category); ResultSet rsResolve = psResolve.executeQuery(); while (rsResolve != null && rsResolve.next()) { long id = rsResolve.getLong(1); String key = rsResolve.getString(2); if (ps != null) ps.close(); ps = con.prepareStatement( "SELECT ID FROM " + TBL_PHRASE_TREE + " WHERE PHRASEID=? AND PMANDATOR=? AND CAT=?"); ps.setLong(1, id); ps.setLong(2, mandator); ps.setInt(3, category); ResultSet rsCheck = ps.executeQuery(); if (rsCheck != null && rsCheck.next()) throw new FxEntryInUseException("ex.phrase.inUse.tree", key); if (rsCheck != null) rsCheck.close(); ps.close(); ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE_VALUES + " WHERE ID=? AND MANDATOR=?"); ps.setLong(1, id); ps.setLong(2, mandator); ps.execute(); ps.close(); ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE_MAP + " WHERE PHRASEID=? AND PMANDATOR=?"); ps.setLong(1, id); ps.setLong(2, mandator); ps.execute(); ps.close(); ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE + " WHERE ID=? AND MANDATOR=? AND CAT=?"); ps.setLong(1, id); ps.setLong(2, mandator); ps.setInt(3, category); count += ps.executeUpdate(); } if (rsResolve != null) rsResolve.close(); } catch (SQLException exc) { EJBUtils.rollback(ctx); throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException(); } finally { Database.closeObjects(PhraseEngineBean.class, ps); Database.closeObjects(PhraseEngineBean.class, con, psResolve); } return count; }
From source file:com.flexive.ejb.beans.TreeEngineBean.java
/** * {@inheritDoc}//from w w w .java2 s. co m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void activate(FxTreeMode mode, long nodeId, boolean includeChildren, boolean activateContents) throws FxApplicationException { Connection con = null; try { if (mode == FxTreeMode.Live) return; con = Database.getDbConnection(); final FxTreeNode srcNode = StorageManager.getTreeStorage().getNode(con, mode, nodeId); // if( !contentEngine.getContentVersionInfo(srcNode.getReference()).hasLiveVersion() ) // throw new FxTreeException("ex.tree.activate.failed.noLiveContent", srcNode.getPath()); if (!includeChildren) { //if the node is a leaf node, always activate with children to propagate removed subnodes if (srcNode.isLeaf()) includeChildren = true; } final List<Long> scriptBeforeIds = scripting.getByScriptEvent(FxScriptEvent.BeforeTreeNodeActivated); final List<Long> scriptAfterIds = scripting.getByScriptEvent(FxScriptEvent.AfterTreeNodeActivated); if (includeChildren) { if (scriptBeforeIds.size() > 0) { final FxScriptBinding binding = new FxScriptBinding(); FxTreeNode parent = getTree(FxTreeMode.Edit, nodeId, 1000); for (long scriptId : scriptBeforeIds) executeScript(scriptId, parent, binding); } StorageManager.getTreeStorage().activateSubtree(con, seq, contentEngine, mode, nodeId, activateContents); if (scriptAfterIds.size() > 0) { final FxScriptBinding binding = new FxScriptBinding(); FxTreeNode parent = getTree(FxTreeMode.Live, nodeId, 1000); for (long scriptId : scriptAfterIds) executeScript(scriptId, parent, binding); } } else { if (scriptBeforeIds.size() > 0) { final FxScriptBinding binding = new FxScriptBinding(); for (long scriptId : scriptBeforeIds) { binding.setVariable("node", getNode(FxTreeMode.Edit, nodeId)); scripting.runScript(scriptId, binding); } } StorageManager.getTreeStorage().activateNode(con, seq, contentEngine, mode, nodeId, activateContents); if (scriptAfterIds.size() > 0) { final FxScriptBinding binding = new FxScriptBinding(); for (long scriptId : scriptAfterIds) { binding.setVariable("node", getNode(FxTreeMode.Live, nodeId)); scripting.runScript(scriptId, binding); } } } StorageManager.getTreeStorage().checkTreeIfEnabled(con, mode); StorageManager.getTreeStorage().checkTreeIfEnabled(con, FxTreeMode.Live); FxContext.get().setTreeWasModified(); } catch (FxApplicationException ae) { EJBUtils.rollback(ctx); throw ae; } catch (Throwable t) { EJBUtils.rollback(ctx); throw new FxUpdateException(LOG, t, "ex.tree.activate.failed", nodeId, includeChildren, t.getMessage()); } finally { Database.closeObjects(TreeEngineBean.class, con, null); } }