Java Code Examples for org.springframework.transaction.support.DefaultTransactionDefinition#setName()
The following examples show how to use
org.springframework.transaction.support.DefaultTransactionDefinition#setName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringJdbcTransactionOperations.java From micronaut-data with Apache License 2.0 | 6 votes |
@Override public <R> R execute(@NonNull TransactionDefinition definition, @NonNull TransactionCallback<Connection, R> callback) { ArgumentUtils.requireNonNull("callback", callback); ArgumentUtils.requireNonNull("definition", definition); final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setReadOnly(definition.isReadOnly()); def.setIsolationLevel(definition.getIsolationLevel().getCode()); def.setPropagationBehavior(definition.getPropagationBehavior().ordinal()); def.setName(definition.getName()); final Duration timeout = definition.getTimeout(); if (!timeout.isNegative()) { def.setTimeout((int) timeout.getSeconds()); } TransactionTemplate template = new TransactionTemplate(transactionManager, def); return template.execute(status -> { try { return callback.call(new JdbcTransactionStatus(status)); } catch (RuntimeException | Error ex) { throw ex; } catch (Exception e) { throw new UndeclaredThrowableException(e, "TransactionCallback threw undeclared checked exception"); } } ); }
Example 2
Source File: SpringHibernateTransactionOperations.java From micronaut-data with Apache License 2.0 | 6 votes |
@Override public <R> R execute(@NonNull TransactionDefinition definition, @NonNull TransactionCallback<Connection, R> callback) { ArgumentUtils.requireNonNull("callback", callback); ArgumentUtils.requireNonNull("definition", definition); final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setReadOnly(definition.isReadOnly()); def.setIsolationLevel(definition.getIsolationLevel().getCode()); def.setPropagationBehavior(definition.getPropagationBehavior().ordinal()); def.setName(definition.getName()); final Duration timeout = definition.getTimeout(); if (!timeout.isNegative()) { def.setTimeout((int) timeout.getSeconds()); } TransactionTemplate template = new TransactionTemplate(transactionManager, def); return template.execute(status -> { try { return callback.call(new JpaTransactionStatus(status)); } catch (RuntimeException | Error ex) { throw ex; } catch (Exception e) { throw new UndeclaredThrowableException(e, "TransactionCallback threw undeclared checked exception"); } } ); }
Example 3
Source File: SpringHibernateDataStore.java From elide-spring-boot with Apache License 2.0 | 5 votes |
@Override public DataStoreTransaction beginTransaction() { // begin a spring transaction DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("elide transaction"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus txStatus = txManager.getTransaction(def); Session session = entityManager.unwrap(Session.class); Preconditions.checkNotNull(session); return transactionSupplier.get(session, txManager, txStatus, isScrollEnabled, scrollMode); }
Example 4
Source File: TransactionHandlerInterceptor.java From rice with Educational Community License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("request"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = txManager.getTransaction(def); context.set(status); return true; }
Example 5
Source File: UnitTestUtils.java From statefulj with Apache License 2.0 | 5 votes |
public static void startTransaction(JpaTransactionManager transactionManager) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("SomeTxName"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = transactionManager.getTransaction(def); tl.set(status); }
Example 6
Source File: DependencyServiceImpl.java From studio with GNU General Public License v3.0 | 5 votes |
@Override public Set<String> upsertDependencies(String site, String path) throws SiteNotFoundException, ContentNotFoundException, ServiceLayerException { Set<String> toRet = new HashSet<String>(); logger.debug("Resolving dependencies for content site: " + site + " path: " + path); Map<String, Set<String>> dependencies = dependencyResolver.resolve(site, path); List<DependencyEntity> dependencyEntities = new ArrayList<>(); if (dependencies != null) { logger.debug("Found " + dependencies.size() + " dependencies. Create entities to insert into database."); for (String type : dependencies.keySet()) { dependencyEntities.addAll(createDependencyEntities(site, path, dependencies.get(type), type, toRet)); } logger.debug("Preparing transaction for database updates."); DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition(); defaultTransactionDefinition.setName("upsertDependencies"); logger.debug("Starting transaction."); TransactionStatus txStatus = transactionManager.getTransaction(defaultTransactionDefinition); try { logger.debug("Delete all source dependencies for site: " + site + " path: " + path); deleteAllSourceDependencies(site, path); logger.debug("Insert all extracted dependencies entries for site: " + site + " path: " + path); insertDependenciesIntoDatabase(dependencyEntities); logger.debug("Committing transaction."); transactionManager.commit(txStatus); } catch (Exception e) { logger.debug("Rolling back transaction."); transactionManager.rollback(txStatus); throw new ServiceLayerException("Failed to upsert dependencies for site: " + site + " path: " + path, e); } } return toRet; }
Example 7
Source File: FixCoreferenceFeatures.java From webanno with Apache License 2.0 | 4 votes |
private void doMigration() { long start = System.currentTimeMillis(); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("migrationRoot"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = null; try { status = txManager.getTransaction(def); Query q = entityManager.createQuery( "UPDATE AnnotationFeature \n" + "SET type = :fixedType \n" + "WHERE type = :oldType \n" + "AND name in (:featureNames)"); // This condition cannot be applied: // "AND layer.type = :layerType" // q.setParameter("layerType", CHAIN_TYPE); // http://stackoverflow.com/questions/16506759/hql-is-generating-incomplete-cross-join-on-executeupdate // However, the risk that the migration upgrades the wrong featuers is still very low // even without this additional condition q.setParameter("featureNames", Arrays.asList(COREFERENCE_RELATION_FEATURE, COREFERENCE_TYPE_FEATURE)); q.setParameter("oldType", "de.tudarmstadt.ukp.dkpro.core.api.coref.type.Coreference"); q.setParameter("fixedType", CAS.TYPE_NAME_STRING); int changed = q.executeUpdate(); if (changed > 0) { log.info("DATABASE UPGRADE PERFORMED: [{}] coref chain features had their " + "type fixed.", changed); } txManager.commit(status); } finally { if (status != null && !status.isCompleted()) { txManager.rollback(status); } } log.info("Migration [" + getClass().getSimpleName() + "] took {}ms", System.currentTimeMillis() - start); }
Example 8
Source File: FixAttachFeature330.java From webanno with Apache License 2.0 | 4 votes |
private void doMigration() { long start = System.currentTimeMillis(); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("migrationRoot"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = null; try { status = txManager.getTransaction(def); for (Project project : projectService.listProjects()) { try { AnnotationLayer tokenLayer = annotationSchemaService.findLayer( project, Token.class.getName()); // Set attach-feature of Dependency layer to Token.pos if necessary fix(project, Dependency.class, RELATION_TYPE, tokenLayer, "pos"); // Set attach-feature of POS layer to Token.pos if necessary fix(project, POS.class, SPAN_TYPE, tokenLayer, "pos"); // Set attach-feature of Lemma layer to Token.lemma if necessary fix(project, Lemma.class, SPAN_TYPE, tokenLayer, "lemma"); // Set attach-feature of MorphologicalFeatures layer to Token.morph if necessary fix(project, MorphologicalFeatures.class, SPAN_TYPE, tokenLayer, "morph"); } catch (NoResultException e) { // This only happens if a project is not fully set up. Every project // should have a Token layer. However, it is not the responsibility of this // migration to enforce this, so we just ignore it. log.warn("Project {} does not seem to include a Token layer!", project); } } txManager.commit(status); } finally { if (status != null && !status.isCompleted()) { txManager.rollback(status); } } log.info("Migration [" + getClass().getSimpleName() + "] took {}ms", System.currentTimeMillis() - start); }
Example 9
Source File: MultiDataSourcesTransactionManager.java From uncode-dal-all with GNU General Public License v2.0 | 4 votes |
@Override public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException { MultiDataSourcesTransactionStatus transactionStatus = new MultiDataSourcesTransactionStatus(); log.debug("Operation '" + definition.getName() + "' starting transaction."); for (DataSource dataSource : dataSources) { DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition(definition); defaultTransactionDefinition.setName(definition.getName()); PlatformTransactionManager txManager = this.transactionManagers.get(dataSource); TransactionStatus status = txManager.getTransaction(defaultTransactionDefinition); TransactionSynchronizationManager.setCurrentTransactionName(defaultTransactionDefinition.getName()); transactionStatus.put(dataSource, status); } return transactionStatus; }
Example 10
Source File: DeploymentHelper.java From hawkbit with Eclipse Public License 1.0 | 3 votes |
/** * Executes the modifying action in new transaction * * @param txManager * transaction manager interface * @param transactionName * the name of the new transaction * @param isolationLevel * isolation level of the new transaction * @param action * the callback to execute in new tranaction * * @return the result of the action */ public static <T> T runInNewTransaction(@NotNull final PlatformTransactionManager txManager, final String transactionName, final int isolationLevel, @NotNull final TransactionCallback<T> action) { final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName(transactionName); def.setReadOnly(false); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); def.setIsolationLevel(isolationLevel); return new TransactionTemplate(txManager, def).execute(action); }