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.ResourceFactoryManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public CreateResourceHistory persistCreateHistory(Subject user, int parentResourceId, int resourceTypeId, String createResourceName, Configuration configuration) { // Load relationships Resource parentResource = entityManager.getReference(Resource.class, parentResourceId); ResourceType resourceType = entityManager.getReference(ResourceType.class, resourceTypeId); // CreateResourceHistory.configuration is one-to-one, so make sure to clone the config, zeroing out all id's. Configuration configurationClone = (configuration != null) ? configuration.deepCopy(false) : null; // Persist and establish relationships CreateResourceHistory history = new CreateResourceHistory(parentResource, resourceType, user.getName(), configurationClone);//from w ww . j av a 2 s . c om history.setCreatedResourceName(createResourceName); history.setStatus(CreateResourceStatus.IN_PROGRESS); entityManager.persist(history); parentResource.addCreateChildResourceHistory(history); // Caller will need this parentResource.getAgent(); return history; }
From source file:org.rhq.enterprise.server.measurement.MeasurementBaselineManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) //@TransactionTimeout( 60 * 60 ) public int _calculateAutoBaselinesDELETE(long olderThanTime) throws Exception { Query query = entityManager.createNamedQuery(MeasurementBaseline.QUERY_DELETE_BY_COMPUTE_TIME); query.setParameter("timestamp", olderThanTime); int rowsAffected = query.executeUpdate(); return rowsAffected; }
From source file:org.rhq.enterprise.server.configuration.ConfigurationManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public Configuration getPluginConfiguration(int resourceId) { // Ensure that we return a non-proxied Configuration object that can survive after the // Hibernate session goes away. Query query = entityManager.createNamedQuery(Configuration.QUERY_GET_PLUGIN_CONFIG_BY_RESOURCE_ID); query.setParameter("resourceId", resourceId); Configuration pluginConfiguration = (Configuration) query.getSingleResult(); // Mask the configuration before returning it. Resource resource = resourceManager.getResourceById(subjectManager.getOverlord(), resourceId); ConfigurationDefinition pluginConfigurationDefinition = getPluginConfigurationDefinitionForResourceType( subjectManager.getOverlord(), resource.getResourceType().getId()); // We do not want the masked configurations persisted, so detach all entities before masking the configurations. pluginConfiguration.getMap().size(); entityManager.clear();//from w w w .j ava2s . c o m ConfigurationMaskingUtility.maskConfiguration(pluginConfiguration, pluginConfigurationDefinition); return pluginConfiguration; }
From source file:org.rhq.enterprise.server.bundle.BundleManagerBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) @RequiredPermission(Permission.MANAGE_BUNDLE) public BundleDeployment createBundleDeploymentInNewTrans(Subject subject, int bundleVersionId, int bundleDestinationId, String name, String description, Configuration configuration) throws Exception { BundleVersion bundleVersion = entityManager.find(BundleVersion.class, bundleVersionId); if (null == bundleVersion) { throw new IllegalArgumentException("Invalid bundleVersionId: " + bundleVersionId); }//w w w .jav a 2 s . co m BundleDestination bundleDestination = entityManager.find(BundleDestination.class, bundleDestinationId); if (null == bundleDestination) { throw new IllegalArgumentException("Invalid bundleDestinationId: " + bundleVersionId); } return createBundleDeploymentImpl(subject, bundleVersion, bundleDestination, name, description, configuration); }
From source file:org.rhq.enterprise.server.measurement.MeasurementBaselineManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) //@TransactionTimeout( 60 * 60 ) public int _calculateAutoBaselinesINSERT(long amountOfData) throws Exception { long now = System.currentTimeMillis(); long computeTime = now; long endTime = now; long startTime = endTime - amountOfData; Connection conn = null;/*from w w w. j av a2s .c o m*/ PreparedStatement insertQuery = null; try { // calculate the baselines for schedules that have no baseline yet (or were just deleted) // do everything via JDBC - our perf testing shows that we hit entity cache locking timeouts // when the entity manager performs native queries under heavy load conn = dataSource.getConnection(); DatabaseType dbType = DatabaseTypeFactory.getDatabaseType(conn); if (dbType instanceof PostgresqlDatabaseType || dbType instanceof H2DatabaseType) { insertQuery = conn .prepareStatement(MeasurementBaseline.NATIVE_QUERY_CALC_FIRST_AUTOBASELINE_POSTGRES); insertQuery.setLong(1, computeTime); insertQuery.setLong(2, startTime); insertQuery.setLong(3, endTime); insertQuery.setLong(4, startTime); } else if (dbType instanceof OracleDatabaseType) { insertQuery = conn .prepareStatement(MeasurementBaseline.NATIVE_QUERY_CALC_FIRST_AUTOBASELINE_ORACLE); insertQuery.setLong(1, computeTime); insertQuery.setLong(2, startTime); insertQuery.setLong(3, endTime); insertQuery.setLong(4, startTime); } else if (dbType instanceof SQLServerDatabaseType) { insertQuery = conn .prepareStatement(MeasurementBaseline.NATIVE_QUERY_CALC_FIRST_AUTOBASELINE_SQLSERVER); insertQuery.setLong(1, computeTime); insertQuery.setLong(2, startTime); insertQuery.setLong(3, endTime); insertQuery.setLong(4, startTime); } else { throw new IllegalArgumentException("Unknown database type, can't continue: " + dbType); } int inserted = insertQuery.executeUpdate(); return inserted; } finally { if (insertQuery != null) { try { insertQuery.close(); } catch (Exception e) { } } if (conn != null) { try { conn.close(); } catch (Exception e) { } } } }
From source file:org.rhq.enterprise.server.measurement.CallTimeDataManagerBean.java
/** * Deletes call-time data older than the specified time. * * @param deleteUpToTime call-time data older than this time will be deleted *//* w w w . j a va 2 s . c o m*/ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) @TransactionTimeout(6 * 60 * 60) public int purgeCallTimeData(Date deleteUpToTime) throws SQLException { // NOTE: Apparently, Hibernate does not support DML JPQL queries, so we're stuck using JDBC. Connection conn = null; PreparedStatement stmt = null; try { conn = rhqDs.getConnection(); // Purge old rows from RHQ_CALLTIME_DATA_VALUE. stmt = conn.prepareStatement(CALLTIME_VALUE_PURGE_STATEMENT); stmt.setLong(1, deleteUpToTime.getTime()); long startTime = System.currentTimeMillis(); int deletedRowCount = stmt.executeUpdate(); MeasurementMonitor.getMBean().incrementPurgeTime(System.currentTimeMillis() - startTime); MeasurementMonitor.getMBean().setPurgedCallTimeData(deletedRowCount); return deletedRowCount; // NOTE: We do not purge unreferenced rows from RHQ_CALLTIME_DATA_KEY, because this can cause issues // (see http://jira.jboss.com/jira/browse/JBNADM-1606). Once we limit the number of keys per // resource at insertion time (see http://jira.jboss.com/jira/browse/JBNADM-2618), the key // table will not require truncation. } finally { JDBCUtil.safeClose(conn, stmt, null); } }
From source file:io.hops.hopsworks.common.security.CertificatesMgmService.java
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void issueServiceKeyRotationCommand() { List<Hosts> allHosts = hostsFacade.find(); for (Hosts host : allHosts) { SystemCommand rotateCommand = new SystemCommand(host, SystemCommandFacade.OP.SERVICE_KEY_ROTATION); systemCommandFacade.persist(rotateCommand); }//from w ww . j a v a 2s . c o m }
From source file:nl.knaw.dans.dataverse.DeletedStudyServiceBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void setIndexTime(Long studyId, Date indexTime) { DeletedStudy deletedStudy = em.find(DeletedStudy.class, studyId); deletedStudy.setLastIndexTime(indexTime); em.merge(deletedStudy);/*from www . j a v a 2s. c o m*/ }
From source file:org.rhq.enterprise.server.cloud.StorageNodeManagerBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public StorageNode createStorageNode(Resource resource, StorageClusterSettings clusterSettings) { Configuration pluginConfig = resource.getPluginConfiguration(); StorageNode storageNode = new StorageNode(); storageNode.setAddress(pluginConfig.getSimpleValue(RHQ_STORAGE_ADDRESS_PROPERTY)); storageNode.setCqlPort(clusterSettings.getCqlPort()); storageNode.setResource(resource);/*from w ww. j a v a 2 s. co m*/ storageNode.setOperationMode(OperationMode.INSTALLED); entityManager.persist(storageNode); return storageNode; }