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:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void updateWorkspace(String wskey, String name) throws CoreServiceException, KeyNotFoundException, AccessDeniedException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE, "updating workspace [" + wskey + "]"); try {/*from www.java2s.co m*/ String caller = membership.getProfileKeyForConnectedIdentifier(); List<String> subjects = membership.getConnectedIdentifierSubjects(); OrtolangObjectIdentifier identifier = registry.lookup(wskey); checkObjectType(identifier, Workspace.OBJECT_TYPE); authorisation.checkPermission(wskey, subjects, "update"); Workspace workspace = em.find(Workspace.class, identifier.getId()); if (workspace == null) { throw new CoreServiceException( "unable to load workspace with id [" + identifier.getId() + "] from storage"); } if (applyReadOnly(caller, subjects, workspace)) { throw new WorkspaceReadOnlyException( "unable to update workspace with key [" + wskey + "] because it is read only"); } workspace.setName(name); em.merge(workspace); registry.update(wskey); indexing.index(wskey); ArgumentsBuilder argsBuilder = new ArgumentsBuilder(2).addArgument("ws-alias", workspace.getAlias()) .addArgument("name", name); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, Workspace.OBJECT_TYPE, "update"), argsBuilder.build()); } catch (KeyLockedException | NotificationServiceException | RegistryServiceException | MembershipServiceException | AuthorisationServiceException | IndexingServiceException e) { ctx.setRollbackOnly(); LOGGER.log(Level.SEVERE, "unexpected error occurred while updating workspace", e); throw new CoreServiceException("unable to update workspace with key [" + wskey + "]", e); } }
From source file:com.flexive.ejb.beans.ContentEngineBean.java
/** * {@inheritDoc}/*from w w w . j a va2 s.co m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public int removeForType(long typeId) throws FxApplicationException { Connection con = null; try { FxType type = CacheAdmin.getEnvironment().getType(typeId); FxPermissionUtils.checkTypeAvailable(typeId, false); ContentStorage storage = StorageManager.getContentStorage(type.getStorageMode()); con = Database.getDbConnection(); long[] scriptsBefore = null; long[] scriptsAfter = null; FxScriptBinding binding = null; UserTicket ticket = FxContext.getUserTicket(); if (CacheAdmin.getEnvironment().getType(typeId) .getScriptMapping(FxScriptEvent.BeforeContentRemove) != null) scriptsBefore = CacheAdmin.getEnvironment().getType(typeId) .getScriptMapping(FxScriptEvent.BeforeContentRemove); if (CacheAdmin.getEnvironment().getType(typeId) .getScriptMapping(FxScriptEvent.AfterContentRemove) != null) scriptsAfter = CacheAdmin.getEnvironment().getType(typeId) .getScriptMapping(FxScriptEvent.AfterContentRemove); List<FxPK> pks = null; if (scriptsBefore != null || scriptsAfter != null || !ticket.isGlobalSupervisor() || type.isTrackHistory()) { binding = new FxScriptBinding(); pks = storage.getPKsForType(con, type, false); if (!ticket.isGlobalSupervisor() || scriptsBefore != null) { for (FxPK pk : pks) { //security check start FxContentSecurityInfo si = storage.getContentSecurityInfo(con, pk, null); if (!ticket.isGlobalSupervisor()) FxPermissionUtils.checkPermission(FxContext.getUserTicket(), ACLPermission.DELETE, si, true); //note: instances of deactivated mandators are silently ignored and erased on purposed! //security check end //scripting before start //type scripting if (scriptsBefore != null) { binding.setVariable("pk", pk); binding.setVariable("securityInfo", si); for (long script : scriptsBefore) scripting.runScript(script, binding); } //assignment scripting if (type.hasScriptedAssignments()) { binding = new FxScriptBinding(); binding.setVariable("pk", pk); for (FxAssignment as : type .getScriptedAssignments(FxScriptEvent.BeforeAssignmentDataDelete)) { binding.setVariable("assignment", as); for (long script : as.getScriptMapping(FxScriptEvent.BeforeAssignmentDataDelete)) { scripting.runScript(script, binding); } } } //scripting before end } } } int removed = storage.contentRemoveForType(con, type); if (scriptsAfter != null) { if (pks == null) pks = storage.getPKsForType(con, type, false); for (FxPK pk : pks) { binding.getProperties().remove("securityInfo"); //scripting after start //assignment scripting if (type.hasScriptedAssignments()) { binding = new FxScriptBinding(); binding.setVariable("pk", pk); for (FxAssignment as : type .getScriptedAssignments(FxScriptEvent.AfterAssignmentDataDelete)) { binding.setVariable("assignment", as); for (long script : as.getScriptMapping(FxScriptEvent.AfterAssignmentDataDelete)) { scripting.runScript(script, binding); } } } //type scripting if (scriptsBefore != null) { binding.setVariable("pk", pk); for (long script : scriptsAfter) scripting.runScript(script, binding); } //scripting after end } } if (type.isTrackHistory()) { HistoryTrackerEngine trackerEngine = EJBLookup.getHistoryTrackerEngine(); for (FxPK pk : pks) trackerEngine.track(type, pk, null, "history.content.removed"); } return removed; } catch (FxNotFoundException e) { EJBUtils.rollback(ctx); throw new FxRemoveException(e); } catch (SQLException e) { EJBUtils.rollback(ctx); throw new FxRemoveException(LOG, e, "ex.db.sqlError", e.getMessage()); } finally { Database.closeObjects(ContentEngineBean.class, con, null); if (!ctx.getRollbackOnly()) CacheAdmin.expireCachedContents(); } }
From source file:com.flexive.ejb.beans.TreeEngineBean.java
/** * {@inheritDoc}//www.j a va 2 s . co m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public long save(FxTreeNodeEdit node) throws FxApplicationException { if (node.isPartialLoaded()) throw new FxTreeException("ex.tree.partialnode.notAllowed", node.getMode(), node.getId()); if (node.isNew()) { long nodeId = createNode(node.getParentNodeId(), node.getName(), node.getLabel(), node.getPosition(), node.getReference(), node.getData(), node.getMode()); if ((node.getReference() == null || node.getReference().isNew()) && !Arrays.asList(ACLCategory.INSTANCE.getDefaultId()).equals(node.getACLIds())) { //requested a non-default ACL for a folder FxTreeNode created = getNode(node.getMode(), nodeId); FxContent co = contentEngine.load(created.getReference()); co.setAclIds(node.getACLIds()); contentEngine.save(co); } // call scripts final List<Long> scriptIds = scripting.getByScriptEvent(FxScriptEvent.AfterTreeNodeAdded); if (scriptIds.size() == 0) return nodeId; final FxScriptBinding binding = new FxScriptBinding(); binding.setVariable("node", getNode(node.getMode(), nodeId)); for (long scriptId : scriptIds) scripting.runScript(scriptId, binding); return nodeId; } else { FxTreeNode old = getNode(node.getOriginalMode(), node.getId()); if (node.getReference().getId() != old.getReference().getId()) { updateReference(node); FxContentSecurityInfo si = contentEngine.getContentSecurityInfo(old.getReference()); if (si.getTypeId() == CacheAdmin.getEnvironment().getType(FxType.FOLDER).getId()) { if (contentEngine.getReferencedContentCount(old.getReference()) == 0) contentEngine.remove(old.getReference()); } //need refresh with new reference data old = getNode(node.getOriginalMode(), node.getId()); } if (!old.getName().equals(node.getName()) || !old.getLabel().equals(node.getLabel())) renameNode(node.getId(), node.getOriginalMode(), node.getName(), node.getLabel()); if (old.getParentNodeId() != node.getParentNodeId() || old.getPosition() != node.getPosition()) move(node.getMode(), node.getId(), node.getParentNodeId(), node.getPosition()); if (node.isActivate() && node.getMode() != FxTreeMode.Live) activate(FxTreeMode.Edit, node.getId(), node.isActivateWithChildren(), true); if (!node.getACLIds().equals(old.getACLIds())) { FxContent co = contentEngine.load(node.getReference()); co.setAclIds(node.getACLIds()); contentEngine.save(co); } } return node.getId(); }
From source file:com.flexive.ejb.beans.ScriptingEngineBean.java
/** * {@inheritDoc}// ww w. ja v a2 s . com */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public FxScriptMappingEntry createTypeScriptMapping(long scriptId, long typeId, boolean active, boolean derivedUsage) throws FxApplicationException { FxScriptInfo si = CacheAdmin.getEnvironment().getScript(scriptId); return createTypeScriptMapping(si.getEvent(), scriptId, typeId, active, derivedUsage); }
From source file:org.cesecore.keys.token.CryptoTokenManagementSessionBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @Override// w w w . jav a 2s .com public void createKeyPairFromTemplate(AuthenticationToken authenticationToken, int cryptoTokenId, String alias, String keySpecification) throws AuthorizationDeniedException, CryptoTokenOfflineException, InvalidKeyException, InvalidAlgorithmParameterException { createKeyPair(authenticationToken, cryptoTokenId, alias, keySpecification); removeKeyPairPlaceholder(authenticationToken, cryptoTokenId, alias); }
From source file:org.nightlabs.jfire.accounting.AccountingManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("org.nightlabs.jfire.accounting.editTariff") @Override//from ww w.java 2s . c o m public Tariff storeTariff(final Tariff tariff, final boolean get, final String[] fetchGroups, final int maxFetchDepth) { final PersistenceManager pm = createPersistenceManager(); try { return NLJDOHelper.storeJDO(pm, tariff, get, fetchGroups, maxFetchDepth); } finally { pm.close(); } }
From source file:org.cesecore.certificates.ca.CaSessionBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @Override/*from w w w. ja v a 2s .c o m*/ public int mergeCa(final CA ca) { final int caId = ca.getCAId(); CAData caData = entityManager.find(CAData.class, caId); if (caData == null) { caData = new CAData(ca.getSubjectDN(), ca.getName(), ca.getStatus(), ca); } else { // It might be the case that the calling transaction has already loaded a reference to this object // and hence we need to get the same one and perform updates on this object instead of trying to // merge a new object. caData.setCA(ca); } caData = entityManager.merge(caData); // Since loading a CA is quite complex (populating CAInfo etc), we simple purge the cache here CaCache.INSTANCE.removeEntry(caId); return caId; }
From source file:com.flexive.ejb.beans.ScriptingEngineBean.java
/** * {@inheritDoc}//w w w . j a va 2 s.co m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void removeAssignmentScriptMapping(long scriptId, long assignmentId) throws FxApplicationException { FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.ScriptManagement); Connection con = null; PreparedStatement ps = null; String sql; boolean success = false; try { // Obtain a database connection con = Database.getDbConnection(); // 1 2 sql = "DELETE FROM " + TBL_SCRIPT_MAPPING_ASSIGN + " WHERE SCRIPT=? AND ASSIGNMENT=?"; ps = con.prepareStatement(sql); ps.setLong(1, scriptId); ps.setLong(2, assignmentId); ps.executeUpdate(); success = true; } catch (SQLException exc) { throw new FxRemoveException(LOG, exc, "ex.scripting.mapping.assign.remove.failed", scriptId, assignmentId, exc.getMessage()); } finally { Database.closeObjects(ScriptingEngineBean.class, con, ps); if (!success) EJBUtils.rollback(ctx); else StructureLoader.reloadScripting(FxContext.get().getDivisionId()); } }
From source file:org.ejbca.core.ejb.ca.store.CertificateStoreSessionBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @Override/* www . j a v a2 s . co m*/ public void removeCertReqHistoryData(Admin admin, String certFingerprint) { if (log.isTraceEnabled()) { log.trace(">removeCertReqHistData(" + certFingerprint + ")"); } try { String msg = intres.getLocalizedMessage("store.removehistory", certFingerprint); logSession.log(admin, admin.getCaId(), LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_INFO_STORECERTIFICATE, msg); CertReqHistoryData crh = CertReqHistoryData.findById(entityManager, certFingerprint); if (crh == null) { if (log.isDebugEnabled()) { log.debug("Trying to remove CertReqHistory that does not exist: " + certFingerprint); } } else { entityManager.remove(crh); } } catch (Exception e) { String msg = intres.getLocalizedMessage("store.errorremovehistory", certFingerprint); logSession.log(admin, admin.getCaId(), LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_ERROR_STORECERTIFICATE, msg); throw new EJBException(e); } log.trace("<removeCertReqHistData()"); }
From source file:org.nightlabs.jfire.store.StoreManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed({ "org.nightlabs.jfire.store.editUnconfirmedProductType", "org.nightlabs.jfire.store.editConfirmedProductType" }) @Override/*from ww w . ja v a 2s . co m*/ public ProductTypeStatusHistoryItem setProductTypeStatus_published(ProductTypeID productTypeID, boolean get, String[] fetchGroups, int maxFetchDepth) throws CannotPublishProductTypeException { PersistenceManager pm = createPersistenceManager(); try { if (get) { pm.getFetchPlan().setMaxFetchDepth(maxFetchDepth); if (fetchGroups != null) pm.getFetchPlan().setGroups(fetchGroups); } pm.getExtent(ProductType.class); Store store = Store.getStore(pm); ProductType productType = (ProductType) pm.getObjectById(productTypeID); ProductTypeStatusHistoryItem productTypeStatusHistoryItem = store .setProductTypeStatus_published(User.getUser(pm, getPrincipal()), productType); if (productTypeStatusHistoryItem == null || !get) return null; else return pm.detachCopy(productTypeStatusHistoryItem); } finally { pm.close(); } }