Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import static com.couchbase.client.java.kv.GetAndTouchOptions.getAndTouchOptions;
import static com.couchbase.client.java.transactions.internal.ConverterUtil.makeCollectionIdentifier;

import com.couchbase.client.core.msg.kv.DurabilityLevel;
import com.couchbase.client.java.kv.PersistTo;
import com.couchbase.client.java.kv.ReplicateTo;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -107,6 +110,7 @@ public Mono<T> one(final String id) {
pArgs.getScope(), pArgs.getCollection(), null, null));
}
} else {
rejectInvalidTransactionalOptions();
return ctxOpt.get().getCore().get(makeCollectionIdentifier(rc.async()), id)
.flatMap(result -> support.decodeEntity(id, new String(result.contentAsBytes(), StandardCharsets.UTF_8),
result.cas(), domainType, pArgs.getScope(), pArgs.getCollection(),
Expand All @@ -129,6 +133,18 @@ public Mono<T> one(final String id) {

}

private void rejectInvalidTransactionalOptions() {
if (this.expiry != null) {
throw new IllegalArgumentException("withExpiry is not supported in a transaction");
}
if (this.options != null) {
throw new IllegalArgumentException("withOptions is not supported in a transaction");
}
if (this.fields != null) {
throw new IllegalArgumentException("project is not supported in a transaction");
}
}

@Override
public Flux<? extends T> all(final Collection<String> ids) {
return Flux.fromIterable(ids).flatMap(this::one);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.function.Consumer;
import java.util.function.Function;

import com.couchbase.client.core.msg.kv.DurabilityLevel;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -43,6 +42,8 @@
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;

import com.couchbase.client.core.msg.kv.DurabilityLevel;
import com.couchbase.client.java.kv.GetOptions;
import com.couchbase.client.java.kv.InsertOptions;
import com.couchbase.client.java.kv.PersistTo;
import com.couchbase.client.java.kv.RemoveOptions;
Expand Down Expand Up @@ -177,6 +178,30 @@ public void removeWithOptions() {
});
}

@DisplayName("Using findById().withExpiry in a transaction is rejected at runtime")
@Test
public void findWithExpiry() {
test((ops) -> {
ops.replaceById(Person.class).withExpiry(Duration.ofSeconds(3)).one(WalterWhite);
});
}

@DisplayName("Using findById().project in a transaction is rejected at runtime")
@Test
public void findProject() {
test((ops) -> {
ops.findById(Person.class).project(new String[] { "someField" }).one(WalterWhite.id());
});
}

@DisplayName("Using findById().withOptions in a transaction is rejected at runtime")
@Test
public void findWithOptions() {
test((ops) -> {
ops.findById(Person.class).withOptions(GetOptions.getOptions()).one(WalterWhite.id());
});
}

@Service
@Component
@EnableTransactionManagement
Expand Down