List of usage examples for javax.ejb TransactionAttributeType SUPPORTS
TransactionAttributeType SUPPORTS
To view the source code for javax.ejb TransactionAttributeType SUPPORTS.
Click Source Link
REQUIRED
case. From source file:org.ejbca.core.ejb.services.ServiceSessionBean.java
@TransactionAttribute(TransactionAttributeType.SUPPORTS) @Override/* w w w.ja v a 2 s .c om*/ public List<String> getServicesUsingCertificateProfile(Integer certificateProfileId) { List<String> result = new ArrayList<String>(); //Since the service types are embedded in the data objects there is no more elegant way to to this. List<ServiceData> allServices = serviceDataSession.findAll(); for (ServiceData service : allServices) { String certificateProfiles = service.getServiceConfiguration().getWorkerProperties() .getProperty(BaseWorker.PROP_CERTIFICATE_PROFILE_IDS_TO_CHECK); if (certificateProfiles != null && !certificateProfiles.equals("")) { for (String certificateProfile : certificateProfiles.split(";")) { if (certificateProfile.equals(certificateProfileId.toString())) { result.add(service.getName()); break; } } } } return result; }
From source file:org.javabeanstack.data.DBManager.java
/** * Devuelve un entityManager, lo crea si no existe en la unidad de persistencia solicitada * @param key id thread//from www. j av a 2 s . c om * @return Devuelve un entityManager */ @Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public EntityManager getEntityManager(String key) { try { if (key == null || "".equals(key)) { return null; } EntityManager em; if (entityManagers.containsKey(key)) { em = entityManagers.get(key).em; entityManagers.get(key).lastRef = Dates.now(); LOGGER.debug("EntityManager ya existe: " + key); } else { em = this.createEntityManager(key); } purgeEntityManager(); return em; } catch (Exception ex) { ErrorManager.showError(ex, LOGGER); } return null; }
From source file:org.javabeanstack.data.DBManager.java
/** * Crea un entitymanager dentro de un Map utiliza la unidad de persistencia * y el threadid o sessionid del usuario como clave * /*from w ww. jav a2 s . c o m*/ * @param key id thread o sessionid del usuario * @return el entity manager creado. */ @Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) @Lock(LockType.WRITE) public EntityManager createEntityManager(String key) { EntityManager em; try { String persistentUnit = key.substring(0, key.indexOf(':')).toLowerCase(); em = (EntityManager) context.lookup("java:comp/env/persistence/" + persistentUnit); Data data = new Data(); data.em = em; entityManagers.put(key, data); LOGGER.debug("--------- Se ha creado un nuevo EntityManager --------- " + key); return em; } catch (Exception ex) { ErrorManager.showError(ex, LOGGER); } return null; }
From source file:org.nightlabs.jfire.store.StoreManagerBean.java
@TransactionAttribute(TransactionAttributeType.SUPPORTS) @RolesAllowed("_Guest_") @Override/* w w w. ja va2s . c o m*/ public Set<ProductTypePermissionFlagSetID> getMyProductTypePermissionFlagSetIDs( Collection<? extends ProductTypeID> productTypeIDs) { PersistenceManager pm = createPersistenceManager(); try { User user = User.getUser(pm, getPrincipal()); Collection<? extends ProductType> productTypes = CollectionUtil .castCollection(pm.getObjectsById(productTypeIDs)); Set<ProductTypePermissionFlagSetID> result = new HashSet<ProductTypePermissionFlagSetID>(); for (ProductType productType : productTypes) { ProductTypePermissionFlagSet productTypePermissionFlagSet = ProductTypePermissionFlagSet .getProductTypePermissionFlagSet(pm, productType, user, false); if (productTypePermissionFlagSet == null) continue; result.add((ProductTypePermissionFlagSetID) JDOHelper.getObjectId(productTypePermissionFlagSet)); } return result; } finally { pm.close(); } }
From source file:org.nightlabs.jfire.store.StoreManagerBean.java
@TransactionAttribute(TransactionAttributeType.SUPPORTS) @RolesAllowed("_Guest_") @Override//from w w w. jav a 2s . c o m public Collection<ProductTypePermissionFlagSet> getProductTypePermissionFlagSets( Collection<? extends ProductTypePermissionFlagSetID> productTypePermissionFlagSetIDs) { PersistenceManager pm = createPersistenceManager(); try { User user = User.getUser(pm, getPrincipal()); List<ProductTypePermissionFlagSet> result = new ArrayList<ProductTypePermissionFlagSet>(); Collection<? extends ProductTypePermissionFlagSet> ptpfss = CollectionUtil .castCollection(pm.getObjectsById(productTypePermissionFlagSetIDs)); for (ProductTypePermissionFlagSet ptpfs : ptpfss) { if (user.equals(ptpfs.getUser())) result.add(ptpfs); } pm.getFetchPlan().setMaxFetchDepth(1); pm.getFetchPlan().setGroup(FetchPlan.DEFAULT); return pm.detachCopyAll(result); } finally { pm.close(); } }
From source file:org.rhq.enterprise.server.content.ContentSourceManagerBean.java
@TransactionAttribute(TransactionAttributeType.SUPPORTS) // we really want NEVER, but support tests that might be in a tx public RepoSyncResults mergeDistributionSyncReport(ContentSource contentSource, DistributionSyncReport report, RepoSyncResults syncResults) {//w ww. j a v a 2 s . c om try { StringBuilder progress = new StringBuilder(); if (syncResults.getResults() != null) { progress.append(syncResults.getResults()); } ////////////////// // REMOVE syncResults = contentSourceManager._mergeDistributionSyncReportREMOVE(contentSource, report, syncResults, progress); ////////////////// // ADD syncResults = contentSourceManager._mergeDistributionSyncReportADD(contentSource, report, syncResults, progress); // if we added/updated/deleted anything, change the last modified time of all repos // that get content from this content source if ((report.getDistributions().size() > 0) || (report.getDeletedDistributions().size() > 0)) { contentSourceManager._mergePackageSyncReportUpdateRepo(contentSource.getId()); } // let our sync results object know that we completed the merge // don't mark it as successful yet, let the caller do that progress.append(new Date()).append(": ").append("MERGE COMPLETE.\n"); syncResults.setResults(progress.toString()); syncResults = repoManager.mergeRepoSyncResults(syncResults); } catch (Throwable t) { // ThrowableUtil will dump SQL nextException messages, too String errorMsg = "Could not process sync report from [" + contentSource + "]. Cause: " + ThrowableUtil.getAllMessages(t); log.error(errorMsg, t); throw new RuntimeException(errorMsg, t); } return syncResults; }
From source file:org.rhq.enterprise.server.content.ContentSourceManagerBean.java
@TransactionAttribute(TransactionAttributeType.SUPPORTS) // we really want NEVER, but support tests that might be in a tx public RepoSyncResults mergePackageSyncReport(ContentSource contentSource, Repo repo, PackageSyncReport report, Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous, RepoSyncResults syncResults) {/*from www .j a va 2 s . c om*/ try { StringBuilder progress = new StringBuilder(); if (syncResults.getResults() != null) { progress.append(syncResults.getResults()); } // First remove any old package versions no longer available, // then add new package versions that didn't exist before // then update package versions that have changed since the last sync. // We do these each in their own, new tx - if one fails we'd at least keep the changes from the previous. // Note that we do the ADD in chunks since it could take a very long time with a large list of packages. // The typical content source rarely removed or updates packages, so we do that in one big tx // (consider chunking those two in the future, if we see the need). ////////////////// // REMOVE syncResults = contentSourceManager._mergePackageSyncReportREMOVE(contentSource, repo, report, previous, syncResults, progress); ////////////////// // ADD List<ContentProviderPackageDetails> newPackages; newPackages = new ArrayList<ContentProviderPackageDetails>(report.getNewPackages()); int chunkSize = 200; int fromIndex = 0; int toIndex = chunkSize; int newPackageCount = newPackages.size(); int addedCount = 0; // running tally of what we actually added into DB progress.append(new Date()).append(": ").append("Adding"); syncResults.setResults(progress.toString()); syncResults = repoManager.mergeRepoSyncResults(syncResults); while (fromIndex < newPackageCount) { if (toIndex > newPackageCount) { toIndex = newPackageCount; } List<ContentProviderPackageDetails> pkgs = newPackages.subList(fromIndex, toIndex); syncResults = contentSourceManager._mergePackageSyncReportADD(contentSource, repo, pkgs, previous, syncResults, progress, fromIndex); addedCount += pkgs.size(); fromIndex += chunkSize; toIndex += chunkSize; } progress.append("...").append(addedCount).append('\n'); syncResults.setResults(progress.toString()); syncResults = repoManager.mergeRepoSyncResults(syncResults); ////////////////// // UPDATE syncResults = contentSourceManager._mergePackageSyncReportUPDATE(contentSource, report, previous, syncResults, progress); // if we added/updated/deleted anything, change the last modified time of all repos // that get content from this content source if ((report.getNewPackages().size() > 0) || (report.getUpdatedPackages().size() > 0) || (report.getDeletedPackages().size() > 0)) { contentSourceManager._mergePackageSyncReportUpdateRepo(contentSource.getId()); } // let our sync results object know that we completed the merge // don't mark it as successful yet, let the caller do that progress.append(new Date()).append(": ").append("MERGE COMPLETE.\n"); syncResults.setResults(progress.toString()); syncResults = repoManager.mergeRepoSyncResults(syncResults); } catch (Throwable t) { // ThrowableUtil will dump SQL nextException messages, too String errorMsg = "Could not process sync report from [" + contentSource + "]. Cause: " + ThrowableUtil.getAllMessages(t); log.error(errorMsg, t); throw new RuntimeException(errorMsg, t); } return syncResults; }
From source file:org.rhq.enterprise.server.content.ContentSourceManagerBean.java
@TransactionAttribute(TransactionAttributeType.SUPPORTS) // we really want NEVER, but support tests that might be in a tx public RepoSyncResults mergeAdvisorySyncReport(ContentSource contentSource, AdvisorySyncReport report, RepoSyncResults syncResults) {/* w w w . j a v a 2s . c o m*/ try { StringBuilder progress = new StringBuilder(); if (syncResults.getResults() != null) { progress.append(syncResults.getResults()); } syncResults = contentSourceManager._mergeAdvisorySyncReportREMOVE(contentSource, report, syncResults, progress); syncResults = contentSourceManager._mergeAdvisorySyncReportADD(contentSource, report, syncResults, progress); // if we added/updated/deleted anything, change the last modified time of all repos // that get content from this content source if ((report.getAdvisory().size() > 0) || (report.getDeletedAdvisorys().size() > 0)) { contentSourceManager._mergePackageSyncReportUpdateRepo(contentSource.getId()); } // let our sync results object know that we completed the merge // don't mark it as successful yet, let the caller do that progress.append(new Date()).append(": ").append("MERGE COMPLETE.\n"); syncResults.setResults(progress.toString()); syncResults = repoManager.mergeRepoSyncResults(syncResults); } catch (Throwable t) { // ThrowableUtil will dump SQL nextException messages, too String errorMsg = "Could not process sync report from [" + contentSource + "]. Cause: " + ThrowableUtil.getAllMessages(t); log.error(errorMsg, t); throw new RuntimeException(errorMsg, t); } return syncResults; }
From source file:org.rhq.enterprise.server.content.RepoManagerBean.java
@TransactionAttribute(TransactionAttributeType.SUPPORTS) // TEMPORARY TIMEOUT DEFINED WHILE WE PROPERLY FIGURE OUT TIMEOUTS @TransactionTimeout(86400)/*from w ww.j a va 2s . co m*/ public int internalSynchronizeRepos(Subject subject, Integer[] repoIds) throws InterruptedException { ContentServerPluginContainer pc; try { pc = ContentManagerHelper.getPluginContainer(); } catch (Exception e) { throw new RuntimeException(e); } ContentProviderManager providerManager = pc.getAdapterManager(); int syncCount = 0; for (Integer id : repoIds) { boolean syncExecuted = providerManager.synchronizeRepo(id); if (syncExecuted) { syncCount++; } } return syncCount; }
From source file:org.rhq.enterprise.server.core.EmailManagerBean.java
@TransactionAttribute(TransactionAttributeType.SUPPORTS) public Map<String, String> getAlertEmailMessage(String resourceHierarchy, String resourceName, String alertName, String priority, String timestamp, String conditionLogs, String alertUrl) { InputStream templateStream = this.getClass().getClassLoader() .getResourceAsStream("alert-email-template.txt"); String template = new String(StreamUtil.slurp(templateStream)); // the resource hierarchy could have backslash characters from new lines and/or resource names template = template.replaceAll(TEMPLATE_TOKEN_RESOURCE_HIERARCHY, cleanse(resourceHierarchy, "?Unknown Resource Hierarchy?")); // resource names will have backslashes in them when they represent some windows file system service template = template.replaceAll(TEMPLATE_TOKEN_RESOURCE_NAME, cleanse(resourceName, "?Unknown Resource?")); // nothing preventing a user from creating an alert definition named "my\cool?definition" template = template.replaceAll(TEMPLATE_TOKEN_ALERT_NAME, cleanse(alertName, "?Unknown Alert?")); //if the priority enum for alerts changes in the future, we'll be safe template = template.replaceAll(TEMPLATE_TOKEN_PRIORITY, cleanse(priority, "Medium")); // better to be paranoid and on the safe side than risk it just to save one line of code template = template.replaceAll(TEMPLATE_TOKEN_TIMESTAMP, cleanse(timestamp, new Date().toString())); // if replacements lookup from the message bundle fails, these will look like "?some.dot.delimited.property?" template = template.replaceAll(TEMPLATE_TOKEN_CONDITIONS, cleanse(conditionLogs, "?Unknown Condition Logs?")); // better to be paranoid and on the safe side than risk it just to save one line of code template = template.replaceAll(TEMPLATE_TOKEN_ALERT_URL, cleanse(alertUrl, "?Unknown URL?")); String subject = "[" + RHQConstants.PRODUCT_NAME + "] Alert"; if (template.startsWith("Subject:")) { try {/*from w w w . j a va 2s . c om*/ subject = template.substring("Subject:".length(), template.indexOf('\n')); } catch (RuntimeException ignore) { LOG.warn("Bad alert template file - can't determine the subject, using a default"); } } Map<String, String> message = new HashMap<String, String>(1); message.put(subject, template); return message; }