use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeExecuteDmlEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplate method executePartitionedDmlStatement.
@Override
public long executePartitionedDmlStatement(Statement statement) {
Assert.notNull(statement, "A non-null statement is required.");
maybeEmitEvent(new BeforeExecuteDmlEvent(statement));
long rowsAffected = doWithOrWithoutTransactionContext(x -> {
throw new SpannerDataException("Cannot execute partitioned DML in a transaction.");
}, () -> this.databaseClientProvider.get().executePartitionedUpdate(statement));
maybeEmitEvent(new AfterExecuteDmlEvent(statement, rowsAffected));
return rowsAffected;
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeExecuteDmlEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method executeDmlTest.
@Test
public void executeDmlTest() {
TransactionContext context = mock(TransactionContext.class);
TransactionRunner transactionRunner = mock(TransactionRunner.class);
when(this.databaseClient.readWriteTransaction()).thenReturn(transactionRunner);
when(transactionRunner.run(any())).thenAnswer((invocation) -> {
TransactionCallable transactionCallable = invocation.getArgument(0);
return transactionCallable.run(context);
});
when(context.executeUpdate(eq(DML))).thenReturn(333L);
verifyBeforeAndAfterEvents(new BeforeExecuteDmlEvent(DML), new AfterExecuteDmlEvent(DML, 333L), () -> this.spannerTemplate.executeDmlStatement(DML), x -> {
});
verify(context, times(1)).executeUpdate(eq(DML));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeExecuteDmlEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method executePartitionedDmlTest.
@Test
public void executePartitionedDmlTest() {
when(this.databaseClient.executePartitionedUpdate(eq(DML))).thenReturn(333L);
verifyBeforeAndAfterEvents(new BeforeExecuteDmlEvent(DML), new AfterExecuteDmlEvent(DML, 333L), () -> this.spannerTemplate.executePartitionedDmlStatement(DML), x -> x.verify(this.databaseClient, times(1)).executePartitionedUpdate(eq(DML)));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeExecuteDmlEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplate method executeDmlStatement.
@Override
public long executeDmlStatement(Statement statement) {
Assert.notNull(statement, "A non-null statement is required.");
maybeEmitEvent(new BeforeExecuteDmlEvent(statement));
long rowsAffected = doWithOrWithoutTransactionContext((x) -> x.executeUpdate(statement), () -> this.databaseClientProvider.get().readWriteTransaction().run(transactionContext -> transactionContext.executeUpdate(statement)));
maybeEmitEvent(new AfterExecuteDmlEvent(statement, rowsAffected));
return rowsAffected;
}
Aggregations