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:org.nightlabs.jfire.accounting.AccountingManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("org.nightlabs.jfire.accounting.editTariffMapping") @Override//w w w . ja va 2s. c om public TariffMapping createTariffMapping(final TariffID localTariffID, final TariffID partnerTariffID, final boolean get, final String[] fetchGroups, final int maxFetchDepth) { final PersistenceManager pm = createPersistenceManager(); try { pm.getFetchPlan().setMaxFetchDepth(maxFetchDepth); if (fetchGroups != null) pm.getFetchPlan().setGroups(fetchGroups); final TariffMapping tm = TariffMapping.create(pm, localTariffID, partnerTariffID); if (!get) return null; return pm.detachCopy(tm); } finally { pm.close(); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void systemTagWorkspace(String wskey, String tag, String snapshot) throws CoreServiceException, KeyNotFoundException { LOGGER.log(Level.FINE, "#SYSTEM# tagging workspace [" + wskey + "] and snapshot [" + snapshot + "]"); try {//ww w .j av a 2s.c o m String caller = membership.getProfileKeyForConnectedIdentifier(); OrtolangObjectIdentifier identifier = registry.lookup(wskey); checkObjectType(identifier, Workspace.OBJECT_TYPE); Workspace workspace = em.find(Workspace.class, identifier.getId()); if (workspace == null) { throw new CoreServiceException( "unable to load workspace with id [" + identifier.getId() + "] from storage"); } workspace.setKey(wskey); try { PathBuilder pname = PathBuilder.newInstance().path(tag); if (pname.depth() > 1) { throw new CoreServiceException("tag name is invalid: " + tag); } if (Arrays.asList(RESERVED_TAG_NAMES).contains(pname.part())) { throw new CoreServiceException(pname.part() + " is reserved and cannot be used as tag name"); } tag = pname.part(); TagElement tagElement = workspace.findTagByName(tag); if (tagElement != null) { workspace.removeTag(tagElement); String oldRoot = workspace.findSnapshotByName(tagElement.getSnapshot()).getKey(); indexing.remove(oldRoot); } if (!workspace.containsSnapshotName(snapshot)) { throw new CoreServiceException( "the snapshot with name '" + snapshot + "' does not exists in this workspace"); } workspace.addTag(new TagElement(tag, snapshot)); em.merge(workspace); registry.update(wskey); indexing.index(wskey); ArgumentsBuilder argsBuilder = new ArgumentsBuilder(2).addArgument("ws-alias", workspace.getAlias()) .addArgument("tag-name", tag); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, Workspace.OBJECT_TYPE, "tag"), argsBuilder.build()); } catch (InvalidPathException e) { throw new CoreServiceException("tag name is invalid: " + tag); } } catch (KeyLockedException | NotificationServiceException | RegistryServiceException | IndexingServiceException e) { ctx.setRollbackOnly(); LOGGER.log(Level.SEVERE, "unexpected error occurred while tagging workspace snapshot", e); throw new CoreServiceException("unable to tag workspace with key [" + wskey + "]", e); } }
From source file:com.stratelia.webactiv.kmelia.control.ejb.KmeliaBmEJB.java
/** * Delete a topic and all descendants. Delete all links between descendants and publications. This * publications will be visible in the Declassified zone. Delete All subscriptions and favorites * on this topics and all descendants/*w w w .java 2s . c om*/ * * @param pkToDelete the id of the topic to delete * @since 1.0 */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void deleteTopic(NodePK pkToDelete) { SilverTrace.info("kmelia", "KmeliaBmEJB.deleteTopic()", "root.MSG_GEN_ENTER_METHOD"); try { // get all nodes which will be deleted Collection<NodePK> nodesToDelete = nodeBm.getDescendantPKs(pkToDelete); nodesToDelete.add(pkToDelete); SilverTrace.info("kmelia", "KmeliaBmEJB.deleteTopic()", "root.MSG_GEN_PARAM_VALUE", "nodesToDelete = " + nodesToDelete); Iterator<PublicationPK> itPub; Collection<PublicationPK> pubsToCheck; // contains all PubPKs concerned by // the delete NodePK oneNodeToDelete; // current node to delete Collection<NodePK> pubFathers; // contains all fatherPKs to a given // publication PublicationPK onePubToCheck; // current pub to check Iterator<NodePK> itNode = nodesToDelete.iterator(); List<Alias> aliases = new ArrayList<Alias>(); while (itNode.hasNext()) { oneNodeToDelete = itNode.next(); // get pubs linked to current node (includes alias) pubsToCheck = publicationBm.getPubPKsInFatherPK(oneNodeToDelete); itPub = pubsToCheck.iterator(); // check each pub contained in current node while (itPub.hasNext()) { onePubToCheck = itPub.next(); if (onePubToCheck.getInstanceId().equals(oneNodeToDelete.getInstanceId())) { // get fathers of the pub pubFathers = publicationBm.getAllFatherPK(onePubToCheck); if (pubFathers.size() >= 2) { // the pub have got many fathers // delete only the link between pub and current node publicationBm.removeFather(onePubToCheck, oneNodeToDelete); SilverTrace.info("kmelia", "KmeliaBmEJB.deleteTopic()", "root.MSG_GEN_PARAM_VALUE", "RemoveFather(pubId, fatherId) with pubId = " + onePubToCheck.getId() + ", fatherId = " + oneNodeToDelete); } else { sendPublicationToBasket(onePubToCheck); SilverTrace.info("kmelia", "KmeliaBmEJB.deleteTopic()", "root.MSG_GEN_PARAM_VALUE", "RemoveAllFather(pubId) with pubId = " + onePubToCheck.getId()); } } else { // remove alias aliases.clear(); aliases.add(new Alias(oneNodeToDelete.getId(), oneNodeToDelete.getInstanceId())); publicationBm.removeAlias(onePubToCheck, aliases); } } } // Delete all subscriptions on this topic and on its descendants removeSubscriptionsByTopic(nodesToDelete); // Delete the topic nodeBm.removeNode(pkToDelete); } catch (Exception e) { throw new KmeliaRuntimeException("KmeliaBmEJB.deleteTopic()", ERROR, "kmelia.EX_IMPOSSIBLE_DE_SUPPRIMER_THEME", e); } SilverTrace.info("kmelia", "KmeliaBmEJB.deleteTopic()", "root.MSG_GEN_EXIT_METHOD"); }
From source file:com.flexive.ejb.beans.ScriptingEngineBean.java
/** * {@inheritDoc}/* w ww.j a v a 2s . c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public FxScriptMappingEntry createAssignmentScriptMapping(long scriptId, long typeId, boolean active, boolean derivedUsage) throws FxApplicationException { FxScriptInfo si = CacheAdmin.getEnvironment().getScript(scriptId); return createAssignmentScriptMapping(si.getEvent(), scriptId, typeId, active, derivedUsage); }
From source file:com.flexive.ejb.beans.TreeEngineBean.java
/** * {@inheritDoc}/* www . j ava 2s . c om*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public long[] getReverseIdChain(FxTreeMode mode, long id) throws FxApplicationException { long[] chain = getIdChain(mode, id); ArrayUtils.reverse(chain); return chain; }
From source file:com.flexive.ejb.beans.TreeEngineBean.java
/** * {@inheritDoc}/*from w ww. j a va 2 s. c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void setData(FxTreeMode mode, long nodeId, String data) { throw new UnsupportedOperationException("Not yet implemented"); // provisional implementation /* Connection con = null; try { con = Database.getDbConnection(); StorageManager.getTreeStorage().setData(con, mode, nodeId, data); FxContext.get().setTreeWasModified(); } catch (FxApplicationException e) { EJBUtils.rollback(ctx); throw e; } catch (Throwable t) { EJBUtils.rollback(ctx); throw new FxUpdateException(LOG, t, "ex.tree.setData.failed", data, nodeId, t.getMessage()); } finally { Database.closeObjects(TreeEngineBean.class, con, null); } */ }
From source file:com.flexive.ejb.beans.ScriptingEngineBean.java
/** * {@inheritDoc}/*from w w w . ja v a 2 s . c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public FxScriptMappingEntry createTypeScriptMapping(FxScriptEvent scriptEvent, long scriptId, long typeId, boolean active, boolean derivedUsage) throws FxApplicationException { FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.ScriptManagement); FxScriptMappingEntry sm; Connection con = null; PreparedStatement ps = null; String sql; boolean success = false; //check existance CacheAdmin.getEnvironment().getScript(scriptId); //check consistency checkTypeScriptConsistency(scriptId, typeId, scriptEvent, active, derivedUsage); try { long[] derived; if (!derivedUsage) derived = new long[0]; else { List<FxType> types = CacheAdmin.getEnvironment().getType(typeId).getDerivedTypes(); derived = new long[types.size()]; for (int i = 0; i < types.size(); i++) derived[i] = types.get(i).getId(); } sm = new FxScriptMappingEntry(scriptEvent, scriptId, active, derivedUsage, typeId, derived); // Obtain a database connection con = Database.getDbConnection(); sql = "INSERT INTO " + TBL_SCRIPT_MAPPING_TYPES + " (TYPEDEF,SCRIPT,DERIVED_USAGE,ACTIVE,STYPE) VALUES " + //1,2,3,4,5 "(?,?,?,?,?)"; ps = con.prepareStatement(sql); ps.setLong(1, sm.getId()); ps.setLong(2, sm.getScriptId()); ps.setBoolean(3, sm.isDerivedUsage()); ps.setBoolean(4, sm.isActive()); ps.setLong(5, sm.getScriptEvent().getId()); ps.executeUpdate(); success = true; } catch (SQLException exc) { if (StorageManager.isUniqueConstraintViolation(exc)) throw new FxEntryExistsException("ex.scripting.mapping.type.notUnique", scriptId, typeId); throw new FxCreateException(LOG, exc, "ex.scripting.mapping.type.create.failed", scriptId, typeId, exc.getMessage()); } finally { Database.closeObjects(ScriptingEngineBean.class, con, ps); if (!success) EJBUtils.rollback(ctx); else StructureLoader.reloadScripting(FxContext.get().getDivisionId()); } return sm; }
From source file:org.cesecore.keys.token.CryptoTokenManagementSessionBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @Override/*from w ww .j a v a2s. co m*/ public void createKeyPairWithSameKeySpec(final AuthenticationToken authenticationToken, final int cryptoTokenId, final String currentAlias, final String newAlias) throws AuthorizationDeniedException, CryptoTokenOfflineException, InvalidKeyException, InvalidAlgorithmParameterException { assertAuthorization(authenticationToken, cryptoTokenId, CryptoTokenRules.GENERATE_KEYS.resource() + "/" + cryptoTokenId); final CryptoToken cryptoToken = getCryptoTokenAndAssertExistence(cryptoTokenId); assertAliasNotInUse(cryptoToken, newAlias); final PublicKey publicKey = cryptoToken.getPublicKey(currentAlias); final String keyAlgorithm = AlgorithmTools.getKeyAlgorithm(publicKey); final String keySpecification; if (AlgorithmConstants.KEYALGORITHM_DSA.equals(keyAlgorithm)) { keySpecification = AlgorithmConstants.KEYALGORITHM_DSA + AlgorithmTools.getKeySpecification(publicKey); } else { keySpecification = AlgorithmTools.getKeySpecification(publicKey); } KeyTools.checkValidKeyLength(keySpecification); final Map<String, Object> details = new LinkedHashMap<String, Object>(); details.put("msg", "Generated new keypair in CryptoToken " + cryptoTokenId); details.put("keyAlias", newAlias); details.put("keySpecification", keySpecification); cryptoToken.generateKeyPair(keySpecification, newAlias); cryptoToken.testKeyPair(newAlias); try { cryptoTokenSession.mergeCryptoToken(cryptoToken); } catch (CryptoTokenNameInUseException e) { throw new RuntimeException(e); // We have not changed the name of the CrytpoToken here, so this should never happen } securityEventsLoggerSession.log(EventTypes.CRYPTOTOKEN_GEN_KEYPAIR, EventStatus.SUCCESS, ModuleTypes.CRYPTOTOKEN, ServiceTypes.CORE, authenticationToken.toString(), String.valueOf(cryptoTokenId), null, null, details); }
From source file:com.flexive.ejb.beans.ContentEngineBean.java
/** * {@inheritDoc}/*from w ww . ja v a2 s. co m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void removeVersion(FxPK pk) throws FxApplicationException { Connection con = null; PreparedStatement ps = null; try { ContentStorage storage = StorageManager.getContentStorage(pk.getStorageMode()); con = Database.getDbConnection(); //security check start FxContentSecurityInfo si = StorageManager.getContentStorage(pk.getStorageMode()) .getContentSecurityInfo(con, pk, null); FxType type = CacheAdmin.getEnvironment().getType(si.getTypeId()); FxPermissionUtils.checkMandatorExistance(si.getMandatorId()); FxPermissionUtils.checkTypeAvailable(type.getId(), false); FxPermissionUtils.checkPermission(FxContext.getUserTicket(), ACLPermission.DELETE, si, true); //security check end storage.contentRemoveVersion(con, type, pk); } catch (FxNotFoundException e) { EJBUtils.rollback(ctx); throw e; } catch (SQLException e) { EJBUtils.rollback(ctx); throw new FxRemoveException(LOG, e, "ex.db.sqlError", e.getMessage()); } finally { Database.closeObjects(ContentEngineBean.class, con, ps); if (!ctx.getRollbackOnly()) CacheAdmin.expireCachedContent(pk.getId()); } }
From source file:org.ejbca.core.ejb.ca.store.CertificateStoreSessionBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @Override//from w w w.ja v a2s. c o m public void addCertReqHistoryData(Admin admin, Certificate cert, UserDataVO useradmindata) { final String issuerDN = CertTools.getIssuerDN(cert); final String username = useradmindata.getUsername(); if (log.isTraceEnabled()) { log.trace(">addCertReqHistoryData(" + CertTools.getSerialNumberAsString(cert) + ", " + issuerDN + ", " + username + ")"); } try { entityManager.persist(new CertReqHistoryData(cert, issuerDN, useradmindata)); final String msg = intres.getLocalizedMessage("store.storehistory", username); logSession.log(admin, issuerDN.hashCode(), LogConstants.MODULE_CA, new Date(), username, cert, LogConstants.EVENT_INFO_STORECERTIFICATE, msg); } catch (Exception e) { final String msg = intres.getLocalizedMessage("store.errorstorehistory", useradmindata.getUsername()); logSession.log(admin, issuerDN.hashCode(), LogConstants.MODULE_CA, new Date(), username, cert, LogConstants.EVENT_ERROR_STORECERTIFICATE, msg); throw new EJBException(e); } if (log.isTraceEnabled()) { log.trace("<addCertReqHistoryData()"); } }