List of usage examples for javax.ejb TransactionAttributeType REQUIRES_NEW
TransactionAttributeType REQUIRES_NEW
To view the source code for javax.ejb TransactionAttributeType REQUIRES_NEW.
Click Source Link
REQUIRES_NEW
with a new transaction context. From source file:org.rhq.enterprise.server.resource.metadata.ResourceMetadataManagerBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void updateDriftMetadata(ResourceType existingType, ResourceType resourceType) { existingType = entityManager.find(ResourceType.class, existingType.getId()); ///*from w w w . j a v a 2 s . c om*/ // Only if one or more drift definitions are different do we have to do anything to the persisted metadata. // Set<DriftDefinitionTemplate> existingDriftTemplates = existingType.getDriftDefinitionTemplates(); // We are only concerned with the plugin defined templates, user defined templates are not affected. Set<DriftDefinitionTemplate> existingPluginDriftTemplates = new HashSet<DriftDefinitionTemplate>( existingDriftTemplates.size()); for (DriftDefinitionTemplate existingTemplate : existingDriftTemplates) { if (!existingTemplate.isUserDefined()) { existingPluginDriftTemplates.add(existingTemplate); } } Set<DriftDefinitionTemplate> newPluginDriftTemplates = resourceType.getDriftDefinitionTemplates(); // note: the size of the sets are typically really small (usually between 1 and 3), // so iterating through them is fast. // look at all the configs to ensure we detect any changes to individual settings on the templates Set<String> existingNames = new HashSet<String>(existingPluginDriftTemplates.size()); DriftDefinitionComparator dirComp = new DriftDefinitionComparator( CompareMode.ONLY_DIRECTORY_SPECIFICATIONS); for (Iterator<DriftDefinitionTemplate> i = existingDriftTemplates.iterator(); i.hasNext();) { DriftDefinitionTemplate existingTemplate = i.next(); String existingName = existingTemplate.getName(); DriftDefinition existingDef = existingTemplate.getTemplateDefinition(); Set<DriftDefinition> attachedDefs = existingTemplate.getDriftDefinitions(); boolean noAttachedDefs = (null == attachedDefs || attachedDefs.isEmpty()); boolean notPinned = !existingTemplate.isPinned(); boolean stillDefined = false; // for later to determine if any existing templates are no longer defined in the plugin existingNames.add(existingName); for (DriftDefinitionTemplate newTemplate : newPluginDriftTemplates) { String newName = newTemplate.getName(); // The new template existed previously. See if it has changed and if so, in what way: // // IF the existingTemplate // has no attached defs AND // is not pinned // THEN we can update it with impunity // ELSE IF the directories have not changed // THEN we can update the base info fields only // Note that in the latter case we update the template but we will not push the // changes down to attached defs. This is a little odd because the template and defs can // get out of sync, but we don't want a plugin change to affect existing defs in case // the user has made manual changes, or wants it the way it is. if (newName.equals(existingName)) { stillDefined = true; DriftDefinition newDef = newTemplate.getTemplateDefinition(); boolean noDirChanges = (0 == dirComp.compare(existingDef, newDef)); if ((noAttachedDefs && notPinned) || noDirChanges) { existingTemplate.setTemplateDefinition(newDef); } else { // can't update directories for an existing template if pinned and/or having attached defs log.error("Failed to update drift definition [" + newName + "] on type [" + resourceType.getName() + "]. It is not allowed to update directories on an existing template that is pinned " + "or has attached definitions. It would invalidate pinned snapshots as the fileset " + "would no longer map from template to definition."); } break; } } // If the template is no longer defined then what we do depends on whether it has attached // definitions. If not it can be deleted, otherwise we keep it around so the user doesn't lose // anything, but set it to user-defined, in essence removing it from the plugin. if (!stillDefined) { if (noAttachedDefs) { entityManager.remove(existingTemplate); i.remove(); } else { existingTemplate.setUserDefined(true); log.warn("Plugin no longer defines drift template [" + existingTemplate.getName() + "] on type [" + resourceType.getName() + "]. This template has attached definitions. To preserve the existing definitions the " + " template will not be removed but is instead being set as user-defined. The user will " + " be responsible for further maintenance of this template."); } } } // Now add new templates, not previously defined for (DriftDefinitionTemplate newTemplate : newPluginDriftTemplates) { String newName = newTemplate.getName(); if (existingNames.contains(newName)) { continue; } newTemplate.setResourceType(existingType); entityManager.persist(newTemplate); existingDriftTemplates.add(newTemplate); } }
From source file:org.rhq.enterprise.server.content.ContentManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public ContentServiceRequest createDeployRequest(int resourceId, String username, Set<ResourcePackageDetails> packages, String notes) { Resource resource = entityManager.find(Resource.class, resourceId); ContentServiceRequest persistedRequest = new ContentServiceRequest(resource, username, ContentRequestType.DEPLOY);/* w w w . ja v a 2 s . com*/ persistedRequest.setStatus(ContentRequestStatus.IN_PROGRESS); persistedRequest.setNotes(notes); long timestamp = System.currentTimeMillis(); for (ResourcePackageDetails packageDetails : packages) { // Load the package version for the relationship PackageDetailsKey key = packageDetails.getKey(); Query packageVersionQuery = entityManager .createNamedQuery(PackageVersion.QUERY_FIND_BY_PACKAGE_DETAILS_KEY_WITH_NON_NULL_RESOURCE_TYPE); packageVersionQuery.setParameter("packageName", key.getName()); packageVersionQuery.setParameter("packageTypeName", key.getPackageTypeName()); packageVersionQuery.setParameter("architectureName", key.getArchitectureName()); packageVersionQuery.setParameter("version", key.getVersion()); packageVersionQuery.setParameter("resourceTypeId", resource.getResourceType().getId()); PackageVersion packageVersion = (PackageVersion) packageVersionQuery.getSingleResult(); // Create the history entity InstalledPackageHistory history = new InstalledPackageHistory(); history.setContentServiceRequest(persistedRequest); history.setDeploymentConfigurationValues(packageDetails.getDeploymentTimeConfiguration()); history.setPackageVersion(packageVersion); history.setResource(resource); history.setStatus(InstalledPackageHistoryStatus.BEING_INSTALLED); history.setTimestamp(timestamp); persistedRequest.addInstalledPackageHistory(history); } entityManager.persist(persistedRequest); return persistedRequest; }
From source file:com.flexive.ejb.beans.configuration.DivisionConfigurationEngineBean.java
/** * {@inheritDoc}/*ww w .j av a 2 s . co m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void removeFlatStorage(String name) throws FxApplicationException { try { try { FxFlatStorageManager.getInstance().removeFlatStorage(name); } catch (FxApplicationException e) { EJBUtils.rollback(ctx); throw e; } } catch (SQLException e) { throw new FxDbException(e, "ex.db.sqlError", e.getMessage()); } }
From source file:org.rhq.enterprise.server.plugin.ServerPluginManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void purgeServerPlugin(int pluginId) { // get the reference to attach to em and use the em.remove. this cascade deletes too. ServerPlugin doomed = this.entityManager.find(ServerPlugin.class, pluginId); doomed.getServersAcknowledgedDelete().clear(); this.entityManager.remove(doomed); log.info("Server plugin [" + doomed + "] has been purged from the db"); return;//from ww w .j av a2 s . c o m }
From source file:org.rhq.enterprise.server.resource.group.definition.GroupDefinitionManagerBean.java
@RequiredPermission(Permission.MANAGE_INVENTORY) @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void removeGroupDefinition(Subject subject, Integer groupDefinitionId) throws GroupDefinitionNotFoundException, GroupDefinitionDeleteException { Collection<Integer> managedGroupIds = getManagedResourceGroupIdsForGroupDefinition(groupDefinitionId); Subject overlord = subjectManager.getOverlord(); for (Integer managedGroupId : managedGroupIds) { removeManagedResource_helper(overlord, groupDefinitionId, managedGroupId); }/*w w w .j av a 2s .c om*/ GroupDefinition groupDefinition = getById(groupDefinitionId); try { entityManager.remove(groupDefinition); } catch (Exception e) { throw new GroupDefinitionDeleteException( "Error deleting groupDefinition '" + groupDefinition.getName() + "': ", e); } }
From source file:io.hops.hopsworks.common.project.ProjectController.java
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) private void verifyProject(Project project, DistributedFileSystemOps dfso, String sessionId) throws ProjectException, GenericException { //proceed to all the verifications and set up local variable // verify that the project folder does not exist // verify that users and groups corresponding to this project name does not already exist in HDFS // verify that Quota for this project name does not already exist in YARN // verify that There is no logs folders corresponding to this project name // verify that There is no certificates corresponding to this project name in the certificate generator final String severity = "Possible inconsistency, Please contact the administrator."; try {/*from w ww . j ava2s.c om*/ if (existingProjectFolder(project)) { throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_FOLDER_EXISTS, Level.INFO, severity, project.getName()); } else if (!noExistingUser(project.getName())) { throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_USER_EXISTS, Level.INFO, severity, project.getName()); } else if (!noExistingGroup(project.getName())) { throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_GROUP_EXISTS, Level.INFO, severity, project.getName()); } else if (!noExistingCertificates(project.getName())) { throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_CERTIFICATES_EXISTS, Level.INFO, severity, project.getName()); } else if (!verifyQuota(project.getName())) { cleanup(project, sessionId, true); throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_QUOTA_EXISTS, Level.INFO, project.getName()); } else if (!verifyLogs(dfso, project.getName())) { cleanup(project, sessionId, true); throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_LOGS_EXIST, Level.INFO, severity, project.getName()); } } catch (IOException | EJBException ex) { LOGGER.log(Level.SEVERE, RESTCodes.ProjectErrorCode.PROJECT_VERIFICATIONS_FAILED.toString(), ex); cleanup(project, sessionId, true); throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_VERIFICATIONS_FAILED, Level.SEVERE); } }
From source file:com.flexive.ejb.beans.configuration.DivisionConfigurationEngineBean.java
/** * {@inheritDoc}/* w ww . java2s . c om*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void exportDivision(String localFileName) throws FxApplicationException { if (!FxContext.getUserTicket().isGlobalSupervisor()) throw new FxNoAccessException("ex.export.noAccess"); if (StringUtils.isEmpty(localFileName)) throw new FxInvalidParameterException("localFileName", "ex.export.noFileProvided"); File zip = new File(localFileName); boolean createError = false; try { if (zip.exists() || !zip.createNewFile()) createError = true; } catch (IOException e) { LOG.info(e); createError = true; } if (createError) throw new FxInvalidParameterException("localFileName", "ex.export.fileCreateError", localFileName); FileOutputStream fos = null; Connection con = null; try { con = Database.getDbConnection(); fos = new FileOutputStream(zip); StorageManager.getStorageImpl().exportDivision(con, fos); } catch (Exception e) { throw new FxApplicationException(e, "ex.export.failed", localFileName, e.getMessage()); } finally { Database.closeObjects(DivisionConfigurationEngine.class, con, null); try { if (fos != null) fos.close(); } catch (IOException e) { LOG.error(e); } } }
From source file:ch.puzzle.itc.mobiliar.business.deploy.boundary.DeploymentService.java
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public Integer createDeploymentReturnTrackingId(Integer appServerGroupId, Integer releaseId, Date deploymentDate, Date stateToDeploy, List<Integer> contextIds, List<ApplicationWithVersion> applicationWithVersion, List<DeploymentParameter> deployParams, boolean sendEmail, boolean requestOnly, boolean doSimulate, boolean isExecuteShakedownTest, boolean isNeighbourhoodTest) { Integer trackingId = sequencesService.getNextValueAndUpdate(DeploymentEntity.SEQ_NAME); Date now = new Date(); if (deploymentDate == null || deploymentDate.before(now)) { deploymentDate = now;/*from w w w. ja v a 2 s . c o m*/ } createDeploymentForAppserver(appServerGroupId, releaseId, deploymentDate, stateToDeploy, contextIds, applicationWithVersion, deployParams, sendEmail, requestOnly, doSimulate, isExecuteShakedownTest, isNeighbourhoodTest, trackingId); if (deploymentDate == now && !requestOnly) { deploymentEvent.fire(new DeploymentEvent(DeploymentEventType.NEW, DeploymentState.scheduled)); } return trackingId; }
From source file:org.rhq.enterprise.server.resource.group.definition.GroupDefinitionManagerBean.java
@RequiredPermission(Permission.MANAGE_INVENTORY) @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void removeManagedResource_helper(Subject overlord, int groupDefinitionId, Integer doomedGroupId) throws GroupDefinitionDeleteException, GroupDefinitionNotFoundException { GroupDefinition groupDefinition = getById(groupDefinitionId); ResourceGroup doomedGroup = entityManager.getReference(ResourceGroup.class, doomedGroupId); groupDefinition.removeResourceGroup(doomedGroup); try {/* w w w. j av a2 s . co m*/ /* * using the group manager's delete method ensures that auditing data, * such as completed operations, is correctly removed */ resourceGroupManager.deleteResourceGroup(subjectManager.getOverlord(), doomedGroupId); } catch (Exception e) { throw new GroupDefinitionDeleteException("Error removing managedGroup '" + doomedGroup.getName() + "' " + "from groupDefinition '" + groupDefinition.getName() + "': ", e); } }
From source file:org.meveo.service.billing.impl.InvoiceService.java
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void producePdf(Map<String, Object> parameters, User currentUser) throws Exception { String meveoDir = paramBean.getProperty("providers.rootDir", "/tmp/meveo/") + File.separator + currentUser.getProvider().getCode() + File.separator; Invoice invoice = (Invoice) parameters.get(PdfGeneratorConstants.INVOICE); File billingRundir = new File(getBillingRunPath(invoice.getBillingRun(), invoice.getAuditable().getCreated(), currentUser.getProvider().getCode())); String thePrefix = ""; if (invoice.getInvoiceType().getCode().equals(invoiceTypeService.getAdjustementCode())) { thePrefix = paramBean.getProperty("invoicing.invoiceAdjustment.prefix", "_IA_"); }// ww w.j a v a 2s .c om String invoiceXmlFileName = billingRundir + File.separator + thePrefix + (!StringUtils.isBlank(invoice.getInvoiceNumber()) ? invoice.getInvoiceNumber() : invoice.getTemporaryInvoiceNumber()) + ".xml"; producePdf(parameters, currentUser, invoiceXmlFileName, meveoDir, invoice.getInvoiceType().getCode().equals(invoiceTypeService.getAdjustementCode())); }