Java 类org.springframework.transaction.support.TransactionOperations 实例源码

项目:db-queue    文件:QueueRunnerFactoryTest.java   
@Test
public void should_return_external_executor_runner() throws Exception {
    QueueConsumer queueConsumer = mock(QueueConsumer.class);
    QueueSettings settings = QueueSettings.builder().withBetweenTaskTimeout(Duration.ZERO).withNoTaskTimeout(Duration.ZERO)
            .withProcessingMode(ProcessingMode.USE_EXTERNAL_EXECUTOR).build();
    QueueLocation location = QueueLocation.builder().withTableName("testTable")
            .withQueueId(new QueueId("testQueue")).build();
    when(queueConsumer.getQueueConfig()).thenReturn(new QueueConfig(location, settings));

    QueueRunner queueRunner = QueueRunner.Factory.createQueueRunner(queueConsumer,
            new QueueDao(new QueueShardId("s1"), mock(JdbcOperations.class), mock(TransactionOperations.class)),
            mock(TaskLifecycleListener.class),
            mock(Executor.class));

    assertThat(queueRunner, CoreMatchers.instanceOf(QueueRunnerInExternalExecutor.class));

}
项目:db-queue    文件:QueueRunnerFactoryTest.java   
@Test
public void should_return_separate_transactions_runner() throws Exception {
    QueueConsumer queueConsumer = mock(QueueConsumer.class);
    QueueSettings settings = QueueSettings.builder().withBetweenTaskTimeout(Duration.ZERO).withNoTaskTimeout(Duration.ZERO)
            .withProcessingMode(ProcessingMode.SEPARATE_TRANSACTIONS).build();
    QueueLocation location = QueueLocation.builder().withTableName("testTable")
            .withQueueId(new QueueId("testQueue")).build();
    when(queueConsumer.getQueueConfig()).thenReturn(new QueueConfig(location, settings));

    QueueRunner queueRunner = QueueRunner.Factory.createQueueRunner(queueConsumer,
            new QueueDao(new QueueShardId("s1"), mock(JdbcOperations.class), mock(TransactionOperations.class)),
            mock(TaskLifecycleListener.class),
            null);

    assertThat(queueRunner, CoreMatchers.instanceOf(QueueRunnerInSeparateTransactions.class));
}
项目:db-queue    文件:QueueRunnerFactoryTest.java   
@Test
public void should_return_wrap_in_transaction_runner() throws Exception {
    QueueConsumer queueConsumer = mock(QueueConsumer.class);
    QueueSettings settings = QueueSettings.builder().withBetweenTaskTimeout(Duration.ZERO).withNoTaskTimeout(Duration.ZERO)
            .withProcessingMode(ProcessingMode.WRAP_IN_TRANSACTION).build();
    QueueLocation location = QueueLocation.builder().withTableName("testTable")
            .withQueueId(new QueueId("testQueue")).build();
    when(queueConsumer.getQueueConfig()).thenReturn(new QueueConfig(location, settings));

    QueueRunner queueRunner = QueueRunner.Factory.createQueueRunner(queueConsumer,
            new QueueDao(new QueueShardId("s1"), mock(JdbcOperations.class), mock(TransactionOperations.class)),
            mock(TaskLifecycleListener.class),
            null);

    assertThat(queueRunner, CoreMatchers.instanceOf(QueueRunnerInTransaction.class));
}
项目:sqlapp    文件:ExecQueryServiceImpl.java   
@Override
public PageSet query(String databaseName, final String sql, final Map<String, ?> paramMap, final Consumer consumer) {

    final DataSource dataSource = dataSourceDef.getDataSource(databaseName);
    PlatformTransactionManager txMgr = new DataSourceTransactionManager(dataSource);
    DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
    txDef.setReadOnly(true);

    TransactionOperations txOp = new TransactionTemplate(txMgr, txDef);
    return txOp.execute(new TransactionCallback<PageSet>() {
        @Override
        public PageSet doInTransaction(TransactionStatus status) {
            try {

                long numOfItems = extractor.extract(dataSource, sql, paramMap, consumer, new NoneLimiter());
                PageSet pageSet = paginator.paginate(0L, numOfItems, (numOfItems <= 0L ? 1L : numOfItems));

                return pageSet;
            } catch (IOException ex) {
                throw new IllegalStateException(ex);
            }
        }
    });
}
项目:sqlapp    文件:ExecLoadFileProcessHandler.java   
@Override
public FileProcessResult handleFile(final File file, String name, String originalFilename, String contentType,
        long size, long asyncId, String... args) throws IOException {
    final DataSource dataSource = dataSourceDef.getDataSource(args[0]);
    final String sql = args[1];
    TransactionOperations txOp = new TransactionTemplate(new DataSourceTransactionManager(dataSource));
    return txOp.execute(new TransactionCallback<FileProcessResult>() {
        @Override
        public FileProcessResult doInTransaction(TransactionStatus status) {
            try (InputStream in = new FileInputStream(file); Reader reader = new InputStreamReader(in, charset)) {

                LoadResult r = loader.load(dataSource, sql, new CsvProvider(reader, true), new NoneLimiter());

                FileProcessResult result = new FileProcessResult();
                result.setTotalCount(r.getTotalCount());
                result.setOkCount(r.getSuccessCount());
                result.setNgCount(r.getFailedCount());
                return result;

            } catch (IOException ex) {
                throw new IllegalStateException(ex);
            }
        }
    });
}
项目:springapp    文件:UsermanImportFileProcessHandler.java   
@Override
public FileProcessResult handleFile(final File file, String name, String originalFilename, String contentType,
        long size, long asyncId, String... args) throws IOException {
    TransactionOperations txOp = new TransactionTemplate(new DataSourceTransactionManager(dataSource));
    return txOp.execute(new TransactionCallback<FileProcessResult>() {
        @Override
        public FileProcessResult doInTransaction(TransactionStatus status) {
            try (InputStream in = new FileInputStream(file); Reader reader = new InputStreamReader(in, charset)) {

                LoadResult r = loader.load(dataSource, usermanImportSql, new CsvProvider(reader, true),
                        new NoneLimiter());

                FileProcessResult result = new FileProcessResult();
                result.setTotalCount(r.getTotalCount());
                result.setOkCount(r.getSuccessCount());
                result.setNgCount(r.getFailedCount());
                return result;

            } catch (IOException ex) {
                throw new IllegalStateException(ex);
            }
        }
    });
}
项目:springapp    文件:ExecQueryServiceImpl.java   
@Override
public PageSet query(String databaseName, final String sql, final Map<String, ?> paramMap, final Consumer consumer) {

    final DataSource dataSource = dataSourceDef.getDataSource(databaseName);
    PlatformTransactionManager txMgr = new DataSourceTransactionManager(dataSource);
    DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
    txDef.setReadOnly(true);

    TransactionOperations txOp = new TransactionTemplate(txMgr, txDef);
    return txOp.execute(new TransactionCallback<PageSet>() {
        @Override
        public PageSet doInTransaction(TransactionStatus status) {
            try {

                long numOfItems = extractor.extract(dataSource, sql, paramMap, consumer, new NoneLimiter());
                PageSet pageSet = paginator.paginate(0L, numOfItems, (numOfItems <= 0L ? 1L : numOfItems));

                return pageSet;
            } catch (IOException ex) {
                throw new IllegalStateException(ex);
            }
        }
    });
}
项目:springapp    文件:SqlLoadSupport.java   
public FileProcessResult handleFile(final MultipartFile file, String dataSourceName, final String sql) {
    final DataSource dataSource = dataSourceDef.getDataSource(dataSourceName);
    TransactionOperations txOp = new TransactionTemplate(new DataSourceTransactionManager(dataSource));
    return txOp.execute(new TransactionCallback<FileProcessResult>() {
        @Override
        public FileProcessResult doInTransaction(TransactionStatus status) {
            try (InputStream in = file.getInputStream();
                    Reader reader = new InputStreamReader(in, config.getImportCharset())) {

                LoadResult r = loader.load(dataSource, sql, new CsvProvider(reader, true), new NoneLimiter());

                FileProcessResult result = new FileProcessResult();
                result.setTotalCount(r.getTotalCount());
                result.setOkCount(r.getSuccessCount());
                result.setNgCount(r.getFailedCount());
                return result;

            } catch (IOException ex) {
                throw new IllegalStateException(ex);
            }
        }
    });
}
项目:bandwidth-on-demand    文件:NsiConnectionProviderSoapClient.java   
public NsiConnectionProviderSoapClient(
    NsiHelper nsiHelper,
    AsyncSoapClient soapClient,
    Function<String, Optional<NsiProvider>> provider,
    NsiConnectionRequesterService requesterService,
    NsiV2MessageRepo messageRepo,
    TransactionOperations transactionTemplate,
    ReservationRepo reservationRepo,
    Function<String, Collection<AccessToken>> findUserAccessTokens) {
  this.nsiHelper = nsiHelper;
  this.soapClient = soapClient;
  this.findUserAccessTokens = findUserAccessTokens;
  this.findProvider = nsa -> provider.apply(nsa).orElseThrow(() -> new IllegalStateException("cannot send request to unknown provider '" + nsa + "'"));
  this.requesterService = requesterService;
  this.messageRepo = messageRepo;
  this.transactionTemplate = transactionTemplate;
  this.reservationRepo = reservationRepo;
}
项目:owsi-core-parent    文件:SimpleHibernateBatchExecutor.java   
@Override
public TransactionOperations getExecuteTransactionOperations() {
    return new TransactionOperations() {
        @Override
        public <T2> T2 execute(TransactionCallback<T2> action) throws TransactionException {
            return action.doInTransaction(new SimpleTransactionStatus());
        }
    };
}
项目:sqlapp    文件:ExecQueryServiceImpl.java   
@Override
public PageSet query(String databaseName, final QueryBuilder queryBuilder, final Map<String, ?> paramMap,
        final long pageNo, final long pageSz, final Consumer consumer) {

    final DataSource dataSource = dataSourceDef.getDataSource(databaseName);
    PlatformTransactionManager txMgr = new DataSourceTransactionManager(dataSource);
    DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
    txDef.setReadOnly(true);

    TransactionOperations txOp = new TransactionTemplate(txMgr, txDef);
    return txOp.execute(new TransactionCallback<PageSet>() {
        @Override
        public PageSet doInTransaction(TransactionStatus status) {
            try {

                long count = count(dataSource, queryBuilder.buildCount(), paramMap);
                PageSet pageSet = paginator.paginate(pageNo, count, pageSz);

                long numOfItems = extractor.extract(dataSource,
                        queryBuilder.build(pageSz, pageSet.getCurrent().getFrom()), paramMap, consumer,
                        new NoneLimiter());
                if (numOfItems != pageSet.getCurrent().getCount()) {
                    throw new IllegalStateException();
                }

                return pageSet;
            } catch (IOException ex) {
                throw new IllegalStateException(ex);
            }
        }
    });
}
项目:springapp    文件:ExecQueryServiceImpl.java   
@Override
public PageSet query(String databaseName, final QueryBuilder queryBuilder, final Map<String, ?> paramMap,
        final long pageNo, final long pageSz, final Consumer consumer) {

    final DataSource dataSource = dataSourceDef.getDataSource(databaseName);
    PlatformTransactionManager txMgr = new DataSourceTransactionManager(dataSource);
    DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
    txDef.setReadOnly(true);

    TransactionOperations txOp = new TransactionTemplate(txMgr, txDef);
    return txOp.execute(new TransactionCallback<PageSet>() {
        @Override
        public PageSet doInTransaction(TransactionStatus status) {
            try {

                long count = count(dataSource, queryBuilder.buildCount(), paramMap);
                PageSet pageSet = paginator.paginate(pageNo, count, pageSz);

                long numOfItems = extractor.extract(dataSource,
                        queryBuilder.build(pageSz, pageSet.getCurrent().getFrom()), paramMap, consumer,
                        new NoneLimiter());
                if (numOfItems != pageSet.getCurrent().getCount()) {
                    throw new IllegalStateException();
                }

                return pageSet;
            } catch (IOException ex) {
                throw new IllegalStateException(ex);
            }
        }
    });
}
项目:molgenis    文件:TransactionalJob.java   
public TransactionalJob(Progress progress, TransactionOperations transactionOperations,
        Authentication authentication)
{
    this.progress = requireNonNull(progress);
    this.transactionOperations = requireNonNull(transactionOperations);
    this.authentication = requireNonNull(authentication);
}
项目:molgenis    文件:JobExecutionTemplate.java   
private <T> T tryCallInTransaction(Job<T> job, Progress progress, TransactionOperations transactionOperations)
{
    try
    {
        return transactionOperations.execute((status) -> tryCall(job, progress));
    }
    catch (TransactionException te)
    {
        LOG.error("Transaction error while running job", te);
        progress.failed(te);
        throw te;
    }
}
项目:db-queue    文件:SpringQueueCollectorTest.java   
@DependsOn("testShardRouter2")
@Bean
QueueDao queueDao1() {
    return new QueueDao(new QueueShardId("1"), mock(JdbcOperations.class),
            mock(TransactionOperations.class));
}
项目:db-queue    文件:SpringQueueCollectorTest.java   
@DependsOn("queueDao1")
@Bean
QueueDao queueDao2() {
    return new QueueDao(new QueueShardId("2"), mock(JdbcOperations.class),
            mock(TransactionOperations.class));
}
项目:db-queue    文件:SpringQueueCollectorTest.java   
@DependsOn("testShardRouter2")
@Bean
QueueDao queueDao1() {
    return new QueueDao(new QueueShardId("1"), mock(JdbcOperations.class),
            mock(TransactionOperations.class));
}
项目:db-queue    文件:SpringQueueCollectorTest.java   
@DependsOn("queueDao1")
@Bean
QueueDao queueDao2() {
    return new QueueDao(new QueueShardId("1"), mock(JdbcOperations.class),
            mock(TransactionOperations.class));
}
项目:owsi-core-parent    文件:ThreadedProcessor.java   
public <T> void runWithTransaction(final String loggerContext, Collection<? extends Runnable> runnables,
        TransactionOperations TransactionOperations, Integer totalItems) throws ExecutionException {
    callWithTransaction(loggerContext, Collections2.transform(runnables, RUNNABLE_TO_CALLABLE),
            TransactionOperations, totalItems);
}
项目:owsi-core-parent    文件:TransactionWrapperCallable.java   
public TransactionWrapperCallable(TransactionOperations transactionTemplate, Callable<T> callable) {
    super();
    this.transactionTemplate = transactionTemplate;
    this.callable = callable;
}
项目:owsi-core-parent    文件:SimpleHibernateBatchExecutor.java   
@Override
public TransactionOperations getExecuteTransactionOperations() {
    return executor.newTransactionTemplate(
            runnable.getWriteability(), TransactionDefinition.PROPAGATION_REQUIRED
    );
}
项目:opennmszh    文件:MapWidgetComponent.java   
public void setTransactionOperation(final TransactionOperations tx) {
    m_transactionOperations = tx;
}
项目:opennmszh    文件:NodeMapsApplication.java   
public void setTransactionOperations(final TransactionOperations tx) {
    m_transaction = tx;
}
项目:opennmszh    文件:NodeMapsApplicationFactory.java   
public void setTransactionOperations(final TransactionOperations tx) {
    m_transaction = tx;
}
项目:bandwidth-on-demand    文件:DefaultOrganizationService.java   
@VisibleForTesting
void setTransactionOperations(TransactionOperations transactionOperations) {
  this.transactionOperations = transactionOperations;
}
项目:bandwidth-on-demand    文件:NocService.java   
@VisibleForTesting
void setTransactionOperations(TransactionOperations transactionOperations) {
  this.transactionOperations = transactionOperations;
}
项目:db-queue    文件:PickTaskDao.java   
/**
 * Конструктор
 *
 * @param shardId             идентификатор шарда на котором будет происходить выборка задач
 * @param jdbcTemplate        spring jdbc template
 * @param transactionTemplate spring transaction template
 */
PickTaskDao(@Nonnull QueueShardId shardId, @Nonnull JdbcOperations jdbcTemplate,
            @Nonnull TransactionOperations transactionTemplate) {
    this.shardId = requireNonNull(shardId);
    this.jdbcTemplate = new NamedParameterJdbcTemplate(requireNonNull(jdbcTemplate));
    this.transactionTemplate = requireNonNull(transactionTemplate);
}
项目:molgenis    文件:JobExecutionTemplate.java   
/**
 * Executes a job in the calling thread within a transaction.
 *
 * @param job                   the {@link Job} to execute.
 * @param progress              {@link Progress} to report progress to
 * @param authentication        {@link Authentication} to run the job with
 * @param transactionOperations TransactionOperations to use for a transactional call
 * @param <T>                   Job result type
 * @return the result of the job execution
 * @throws JobExecutionException if job execution throws an exception
 * @deprecated Create a service bean with a @Transactional annotation instead
 */
@Deprecated
<T> T call(Job<T> job, Progress progress, Authentication authentication,
        TransactionOperations transactionOperations)
{
    return runWithAuthentication(authentication, () -> tryCallInTransaction(job, progress, transactionOperations));
}
项目:db-queue    文件:QueueDao.java   
/**
 * Конструктор.
 * <p>
 * Клиентский код обязан обеспечить уникальную привязку пары (jdbcTemplate, transactionTemplate) к shardId
 *
 * @param shardId             идентификатор шарда
 * @param jdbcTemplate        spring jdbc template
 * @param transactionTemplate spring transaction template
 */
public QueueDao(QueueShardId shardId, JdbcOperations jdbcTemplate, TransactionOperations transactionTemplate) {
    this.shardId = shardId;
    this.jdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
    this.transactionTemplate = transactionTemplate;
}
项目:db-queue    文件:QueueDao.java   
/**
 * Получить transaction template данного шарда
 *
 * @return transaction template данного шарда
 */
public TransactionOperations getTransactionTemplate() {
    return transactionTemplate;
}
项目:db-queue    文件:QueueActorDao.java   
/**
 * Конструктор
 *
 * @param jdbcTemplate        spring jdbc template
 * @param transactionTemplate spring transaction template
 */
public QueueActorDao(JdbcOperations jdbcTemplate, TransactionOperations transactionTemplate) {
    this.jdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
    this.transactionTemplate = transactionTemplate;
}
项目:db-queue    文件:QueueActorDao.java   
/**
 * Получить transaction template
 *
 * @return spring transaction template
 */
public TransactionOperations getTransactionTemplate() {
    return transactionTemplate;
}
项目:db-queue    文件:QueueStatisticsDao.java   
/**
 * Конструктор
 *
 * @param jdbcTemplate        spring jdbc template
 * @param transactionTemplate spring transaction template
 */
public QueueStatisticsDao(JdbcOperations jdbcTemplate, TransactionOperations transactionTemplate) {
    this.jdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
    this.transactionTemplate = transactionTemplate;
}
项目:db-queue    文件:QueueStatisticsDao.java   
/**
 * Получить transaction template
 *
 * @return spring transaction template
 */
public TransactionOperations getTransactionTemplate() {
    return transactionTemplate;
}
项目:db-queue    文件:PickTaskDao.java   
/**
 * Получить transaction template данного шарда
 *
 * @return transaction template данного шарда
 */
TransactionOperations getTransactionTemplate() {
    return transactionTemplate;
}
项目:owsi-core-parent    文件:SimpleHibernateBatchExecutor.java   
public abstract TransactionOperations getExecuteTransactionOperations();