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.rhq.enterprise.server.content.RepoManagerBean.java
@RequiredPermission(Permission.MANAGE_REPOSITORIES) @TransactionAttribute(TransactionAttributeType.REQUIRED) public void addRepoRelationship(Subject subject, int repoId, int relatedRepoId, String relationshipTypeName) { Repo repo = entityManager.find(Repo.class, repoId); Repo relatedRepo = entityManager.find(Repo.class, relatedRepoId); Query typeQuery = entityManager.createNamedQuery(RepoRelationshipType.QUERY_FIND_BY_NAME); typeQuery.setParameter("name", relationshipTypeName); RepoRelationshipType relationshipType = (RepoRelationshipType) typeQuery.getSingleResult(); RepoRelationship repoRelationship = new RepoRelationship(); repoRelationship.setRelatedRepo(relatedRepo); repoRelationship.setRepoRelationshipType(relationshipType); repoRelationship.addRepo(repo);/*from w w w . j a va2 s . c om*/ entityManager.persist(repoRelationship); relatedRepo.addRepoRelationship(repoRelationship); RepoRepoRelationship repoRepoRelationship = new RepoRepoRelationship(repo, repoRelationship); entityManager.persist(repoRepoRelationship); repo.addRepoRelationship(repoRelationship); }
From source file:org.cesecore.certificates.certificate.CertificateStoreSessionBean.java
License:asdf
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void setRevocationDate(AuthenticationToken authenticationToken, String certificateFingerprint, Date revocationDate) throws AuthorizationDeniedException { // Must be authorized to CA in order to change status is certificates issued by the CA final CertificateData certdata = CertificateData.findByFingerprint(this.entityManager, certificateFingerprint);/*from w w w .ja v a2s . co m*/ if (certdata.getStatus() != CertificateConstants.CERT_REVOKED) { throw new UnsupportedOperationException( "Attempted to set revocation date on an unrevoked certificate."); } if (certdata.getRevocationDate() != 0) { throw new UnsupportedOperationException("Attempted to overwrite revocation date"); } final Certificate certificate = certdata.getCertificate(this.entityManager); int caid = CertTools.getIssuerDN(certificate).hashCode(); authorizedToCA(authenticationToken, caid); certdata.setRevocationDate(revocationDate); final String username = certdata.getUsername(); final String serialNo = CertTools.getSerialNumberAsString(certificate); // for logging final String msg = INTRES.getLocalizedMessage("store.revocationdateset", username, certificateFingerprint, certdata.getSubjectDN(), certdata.getIssuerDN(), serialNo, revocationDate); Map<String, Object> details = new LinkedHashMap<String, Object>(); details.put("msg", msg); //Log this as CERT_REVOKED since this data should have been added then. this.logSession.log(EventTypes.CERT_REVOKED, EventStatus.SUCCESS, ModuleTypes.CERTIFICATE, ServiceTypes.CORE, authenticationToken.toString(), String.valueOf(caid), serialNo, username, details); }
From source file:com.flexive.ejb.beans.ScriptingEngineBean.java
/** * {@inheritDoc}/*from w w w .jav a 2 s. c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public FxScriptMappingEntry updateTypeScriptMappingForEvent(long scriptId, long typeId, FxScriptEvent event, 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, event, 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(event, scriptId, active, derivedUsage, typeId, derived); // Obtain a database connection con = Database.getDbConnection(); // 1 2 3 4 5 sql = "UPDATE " + TBL_SCRIPT_MAPPING_TYPES + " SET DERIVED_USAGE=?,ACTIVE=? WHERE TYPEDEF=? AND SCRIPT=? AND STYPE=?"; ps = con.prepareStatement(sql); ps.setBoolean(1, sm.isDerivedUsage()); ps.setBoolean(2, sm.isActive()); ps.setLong(3, sm.getId()); ps.setLong(4, sm.getScriptId()); 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 FxUpdateException(LOG, exc, "ex.scripting.mapping.type.update.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:com.flexive.ejb.beans.PhraseEngineBean.java
/** * {@inheritDoc}//from www.ja va 2 s. c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void clearPhrases(FxPhraseCategorySelection categories, long mandatorId) throws FxNoAccessException, FxEntryInUseException { if (categories.isAny()) { clearPhrases(mandatorId); return; } checkMandatorAccess(mandatorId, FxContext.getUserTicket()); Connection con = null; PreparedStatement ps = null; try { // Obtain a database connection con = Database.getDbConnection(); ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE_VALUES + " WHERE ID IN (SELECT DISTINCT ID FROM " + TBL_PHRASE + " WHERE MANDATOR=? AND CAT IN (" + categoriesList(categories) + "))"); ps.setLong(1, mandatorId); ps.executeUpdate(); ps.close(); ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE + " WHERE MANDATOR=? AND CAT IN (" + categoriesList(categories) + ")"); ps.setLong(1, mandatorId); ps.executeUpdate(); //sequencer can not be removed if categories is not any } catch (SQLException exc) { EJBUtils.rollback(ctx); throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException(); } finally { Database.closeObjects(PhraseEngineBean.class, con, ps); } }
From source file:org.cesecore.certificates.certificate.CertificateStoreSessionBean.java
License:asdf
/** Local interface only */ @Override/*from w w w .j a v a 2 s . c om*/ @TransactionAttribute(TransactionAttributeType.REQUIRED) public boolean setRevokeStatusNoAuth(AuthenticationToken admin, Certificate certificate, Date revokeDate, int reason, String userDataDN) throws CertificateRevokeException { if (certificate == null) { return false; } if (log.isTraceEnabled()) { log.trace(">private setRevokeStatusNoAuth(Certificate), issuerdn=" + CertTools.getIssuerDN(certificate) + ", serno=" + CertTools.getSerialNumberAsString(certificate)); } int caid = CertTools.getIssuerDN(certificate).hashCode(); // used for logging String fp = CertTools.getFingerprintAsString(certificate); CertificateData rev = CertificateData.findByFingerprint(entityManager, fp); if (rev == null) { String msg = INTRES.getLocalizedMessage("store.errorfindcertfp", fp, CertTools.getSerialNumberAsString(certificate)); log.info(msg); throw new CertificateRevokeException(msg); } final String username = rev.getUsername(); final Date now = new Date(); final String serialNo = CertTools.getSerialNumberAsString(certificate); // for logging boolean returnVal = false; // A normal revocation if ((rev.getStatus() != CertificateConstants.CERT_REVOKED || rev.getRevocationReason() == RevokedCertInfo.REVOCATION_REASON_CERTIFICATEHOLD) && reason != RevokedCertInfo.NOT_REVOKED && reason != RevokedCertInfo.REVOCATION_REASON_REMOVEFROMCRL) { if (rev.getStatus() != CertificateConstants.CERT_REVOKED) { rev.setStatus(CertificateConstants.CERT_REVOKED); rev.setRevocationDate(revokeDate); // keep date if certificate on hold. } rev.setUpdateTime(now.getTime()); rev.setRevocationReason(reason); final String msg = INTRES.getLocalizedMessage("store.revokedcert", username, rev.getFingerprint(), Integer.valueOf(reason), rev.getSubjectDN(), rev.getIssuerDN(), serialNo); Map<String, Object> details = new LinkedHashMap<String, Object>(); details.put("msg", msg); logSession.log(EventTypes.CERT_REVOKED, EventStatus.SUCCESS, ModuleTypes.CERTIFICATE, ServiceTypes.CORE, admin.toString(), String.valueOf(caid), serialNo, username, details); returnVal = true; // we did change status } else if (((reason == RevokedCertInfo.NOT_REVOKED) || (reason == RevokedCertInfo.REVOCATION_REASON_REMOVEFROMCRL)) && (rev.getRevocationReason() == RevokedCertInfo.REVOCATION_REASON_CERTIFICATEHOLD)) { // Unrevoke, can only be done when the certificate was previously revoked with reason CertificateHold // Only allow unrevocation if the certificate is revoked and the revocation reason is CERTIFICATE_HOLD int status = CertificateConstants.CERT_ACTIVE; rev.setStatus(status); // long revocationDate = -1L; // A null Date to setRevocationDate will result in -1 stored in long column rev.setRevocationDate(null); rev.setUpdateTime(now.getTime()); rev.setRevocationReason(RevokedCertInfo.REVOCATION_REASON_REMOVEFROMCRL); final String msg = INTRES.getLocalizedMessage("store.unrevokedcert", username, rev.getFingerprint(), Integer.valueOf(reason), rev.getSubjectDN(), rev.getIssuerDN(), serialNo); Map<String, Object> details = new LinkedHashMap<String, Object>(); details.put("msg", msg); logSession.log(EventTypes.CERT_REVOKED, EventStatus.SUCCESS, ModuleTypes.CERTIFICATE, ServiceTypes.CORE, admin.toString(), String.valueOf(caid), serialNo, username, details); returnVal = true; // we did change status } else { final String msg = INTRES.getLocalizedMessage("store.ignorerevoke", serialNo, Integer.valueOf(rev.getStatus()), Integer.valueOf(reason)); log.info(msg); returnVal = false; // we did _not_ change status in the database } if (log.isTraceEnabled()) { log.trace("<private setRevokeStatusNoAuth(), issuerdn=" + CertTools.getIssuerDN(certificate) + ", serno=" + CertTools.getSerialNumberAsString(certificate)); } return returnVal; }
From source file:org.nightlabs.jfire.accounting.AccountingManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("org.nightlabs.jfire.accounting.queryLocalAccountantDelegates") @Override// ww w . j a v a2s .c o m public Collection<LocalAccountantDelegateID> getTopLevelAccountantDelegates( final Class<? extends LocalAccountantDelegate> delegateClass) { final PersistenceManager pm = createPersistenceManager(); try { final Collection<? extends LocalAccountantDelegate> delegates = LocalAccountantDelegate .getTopLevelDelegates(pm, delegateClass); return NLJDOHelper.getObjectIDSet(delegates); } finally { pm.close(); } }
From source file:com.flexive.ejb.beans.structure.AssignmentEngineBean.java
/** * {@inheritDoc}// ww w . jav a 2s . co m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void removeGroup(long groupId) throws FxApplicationException { List<FxGroupAssignment> assignments = CacheAdmin.getEnvironment().getGroupAssignments(groupId, true); if (assignments.size() == 0) throw new FxNotFoundException("ex.structure.assignment.notFound.id", groupId); for (FxGroupAssignment a : assignments) { if (!a.isDerivedAssignment()) { removeAssignment(a.getId(), true, true, false, true); } } }
From source file:com.flexive.ejb.beans.PhraseEngineBean.java
/** * {@inheritDoc}/*from w ww .ja va2s . c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public FxPhraseTreeNode saveTreeNode(FxPhraseTreeNode node) throws FxNoAccessException, FxNotFoundException { Connection con = null; PreparedStatement ps = null; checkMandatorAccess(node.getMandatorId(), FxContext.getUserTicket()); //load the node's phrase to check if it exists FxPhrase checkPhrase = loadPhrase(node.getPhrase().getCategory(), node.getPhrase().getKey(), node.getPhrase().getMandator()); if (!checkPhrase.hasId()) throw new FxNotFoundException("ex.phrases.noId"); try { // Obtain a database connection con = Database.getDbConnection(); ps = con.prepareStatement( "SELECT ID, MANDATOR FROM " + TBL_PHRASE_TREE + " WHERE ID=? AND MANDATOR=? AND CAT=?"); ps.setInt(3, node.getCategory()); boolean newNode = node.isNew(); if (!node.isNew()) { //check if the node has an id set but does not exist yet ps.setLong(1, node.getId()); ps.setLong(2, node.getMandatorId()); ResultSet rs = ps.executeQuery(); newNode = !(rs != null && rs.next()); } if (node.hasParent()) { //check if the parent node exists ps.setLong(1, node.getParentNodeId()); ps.setLong(2, node.getParentNodeMandatorId()); ResultSet rs = ps.executeQuery(); if (!(rs != null && rs.next())) throw new FxNotFoundException("ex.phrase.tree.parent.notFound", node.getParentNodeId(), node.getParentNodeMandatorId()); } ps.close(); if (!newNode) { ps = con.prepareStatement("UPDATE " + TBL_PHRASE_TREE + " SET PARENTID=?,PARENTMANDATOR=?,PHRASEID=?,PMANDATOR=?,POS=? WHERE ID=? AND MANDATOR=? AND CAT=?"); if (node.hasParent()) { ps.setLong(1, node.getParentNodeId()); ps.setLong(2, node.getParentNodeMandatorId()); } else { ps.setNull(1, Types.NUMERIC); ps.setNull(2, Types.NUMERIC); } ps.setLong(3, checkPhrase.getId()); ps.setLong(4, checkPhrase.getMandator()); if (!node.hasPos()) node.setPos(getNextNodePos(con, node.getCategory(), node.getParentNodeId(), node.getParentNodeMandatorId(), node.getMandatorId())); ps.setLong(5, node.getPos()); ps.setLong(6, node.getId()); ps.setLong(7, node.getMandatorId()); ps.setInt(8, node.getCategory()); ps.executeUpdate(); node.getPhrase().setId(checkPhrase.getId()); return node; } else { ps = con.prepareStatement("INSERT INTO " + TBL_PHRASE_TREE + " (ID,MANDATOR,PARENTID,PARENTMANDATOR,PHRASEID,PMANDATOR,POS,CAT)VALUES(?,?,?,?,?,?,?,?)"); final long nodeId = node.isNew() ? fetchNextNodeId(node.getMandatorId(), node.getCategory()) : node.getId(); ps.setLong(1, nodeId); ps.setLong(2, node.getMandatorId()); if (node.hasParent()) { ps.setLong(3, node.getParentNodeId()); ps.setLong(4, node.getParentNodeMandatorId()); } else { ps.setNull(3, Types.NUMERIC); ps.setNull(4, Types.NUMERIC); } ps.setLong(5, checkPhrase.getId()); ps.setLong(6, checkPhrase.getMandator()); if (!node.hasPos()) node.setPos(getNextNodePos(con, node.getCategory(), node.getParentNodeId(), node.getParentNodeMandatorId(), node.getMandatorId())); ps.setLong(7, node.getPos()); ps.setInt(8, node.getCategory()); ps.executeUpdate(); node.setId(nodeId); node.getPhrase().setId(checkPhrase.getId()); return node; } } catch (SQLException exc) { EJBUtils.rollback(ctx); throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException(); } finally { Database.closeObjects(PhraseEngineBean.class, con, ps); } }
From source file:com.flexive.ejb.beans.structure.AssignmentEngineBean.java
/** * {@inheritDoc}//www . j a v a 2s. c om */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public long save(FxAssignment assignment, boolean createSubAssignments) throws FxApplicationException { FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.StructureManagement); long returnId; boolean reload = false; Connection con = null; try { con = Database.getDbConnection(); if (assignment instanceof FxPropertyAssignmentEdit) { if (((FxPropertyAssignmentEdit) assignment).isNew()) { returnId = createPropertyAssignment(con, null, (FxPropertyAssignmentEdit) assignment); } else { returnId = assignment.getId(); try { reload = updatePropertyAssignment(con, null, (FxPropertyAssignmentEdit) assignment); } catch (FxLoadException e) { EJBUtils.rollback(ctx); throw new FxUpdateException(e); } catch (FxNotFoundException e) { EJBUtils.rollback(ctx); throw new FxUpdateException(e); } } } else if (assignment instanceof FxGroupAssignmentEdit) { if (((FxGroupAssignmentEdit) assignment).isNew()) { returnId = createGroupAssignment(con, null, (FxGroupAssignmentEdit) assignment, createSubAssignments); } else { returnId = assignment.getId(); try { reload = updateGroupAssignment(con, (FxGroupAssignmentEdit) assignment); } catch (FxLoadException e) { EJBUtils.rollback(ctx); throw new FxUpdateException(e); } catch (FxNotFoundException e) { EJBUtils.rollback(ctx); throw new FxUpdateException(e); } } } else throw new FxInvalidParameterException("ASSIGNMENT", "ex.structure.assignment.noEditAssignment"); try { if (reload) { StructureLoader.reload(con); //clear instance cache CacheAdmin.expireCachedContents(); //check for possible side effects on the flat storage if (divisionConfig.isFlatStorageEnabled()) { //check if flattened assignments now are required to be unflattened final FxFlatStorage fs = FxFlatStorageManager.getInstance(); assignment = CacheAdmin.getEnvironment().getAssignment(returnId); //make sure we have the updated version if (assignment instanceof FxPropertyAssignment) { final FxPropertyAssignment pa = (FxPropertyAssignment) assignment; if (pa.isFlatStorageEntry() && !fs.isValidFlatStorageType(pa)) { fs.unflatten(con, pa); if (fs.isFlattenable(pa)) { // moved to other storage type, flatten again fs.flatten(con, pa.getFlatStorageMapping().getStorage(), pa); } StructureLoader.reload(con); } } else if (assignment instanceof FxGroupAssignment) { boolean needReload = false; for (FxAssignment as : ((FxGroupAssignment) assignment).getAllChildAssignments()) { if (!(as instanceof FxPropertyAssignment)) continue; final FxPropertyAssignment pa = (FxPropertyAssignment) as; if (pa.isFlatStorageEntry() && !fs.isValidFlatStorageType(pa)) { fs.unflatten(con, pa); if (fs.isFlattenable(pa)) { // moved to other storage type, flatten again fs.flatten(con, pa.getFlatStorageMapping().getStorage(), pa); } needReload = true; } } if (needReload) StructureLoader.reload(con); } if (divisionConfig.get(SystemParameters.FLATSTORAGE_AUTO)) { //check if some assignments can now be flattened FxFlatStorageManager.getInstance().flattenType(con, fs.getDefaultStorage(), assignment.getAssignedType(), null); StructureLoader.reload(con); } } } } catch (FxCacheException e) { EJBUtils.rollback(ctx); throw new FxCreateException(e, "ex.cache", e.getMessage()); } catch (FxLoadException e) { EJBUtils.rollback(ctx); throw new FxCreateException(e); } return returnId; } catch (SQLException e) { throw new FxUpdateException(LOG, e); } finally { Database.closeObjects(AssignmentEngineBean.class, con, null); } }
From source file:org.nightlabs.jfire.accounting.AccountingManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @RolesAllowed("org.nightlabs.jfire.accounting.queryLocalAccountantDelegates") @Override//from www. j a v a 2s.c om public Collection<LocalAccountantDelegateID> getChildAccountantDelegates( final LocalAccountantDelegateID delegateID) { final PersistenceManager pm = createPersistenceManager(); try { final Collection<? extends LocalAccountantDelegate> delegates = LocalAccountantDelegate .getChildDelegates(pm, delegateID.organisationID, delegateID.localAccountantDelegateID); return NLJDOHelper.getObjectIDSet(delegates); } finally { pm.close(); } }