Skip to content

Commit

Permalink
Change inner API for CRUD options classes
Browse files Browse the repository at this point in the history
- Change inner API for CRUD options classes from working with ProxyOption enum class.
- Change CHANGELOG.md.

Closes for #420.
  • Loading branch information
nickkkccc committed Sep 13, 2023
1 parent 869b8f2 commit b743fe5
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 91 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
### API changes

- Add "mode" option for crud select operation ([#107](https://github.com/tarantool/cartridge-java/issues/107))
- Change using of proxy client parameters (mode, rollback_on_error, stop_on_error) with enum classes([#419](https://github.com/tarantool/cartridge-java/issues/419))
- Change using of proxy client parameters (mode, rollback_on_error, stop_on_error) with enum classes ([#419](https://github.com/tarantool/cartridge-java/issues/419))

### Bugfixes

- Fix Instant converter to parse 8 bytes datetime ([#408](https://github.com/tarantool/cartridge-java/issues/408))

### Internal changes

- Change using of option names with the String type in the internal API to using with the ProxyOption enum class ([#420](https://github.com/tarantool/cartridge-java/issues/420))

## [0.12.1] - 2023-08-04

### Bugfixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public enum ProxyOption {

BUCKET_ID("bucket_id"),

BATCH_SIZE("batch_size");
BATCH_SIZE("batch_size"),

AFTER("after"),

FIRST("first");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.tarantool.driver.core.proxy;

import io.tarantool.driver.api.space.options.enums.crud.ProxyOption;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand All @@ -16,6 +18,21 @@ abstract class CRUDAbstractOperationOptions {

private final Map<String, Object> resultMap = new HashMap<>();

protected void addOption(ProxyOption option, Optional<?> value) {
if (value.isPresent()) {
resultMap.put(option.toString(), value.get());
}
}

/**
* Return serializable options representation.
*
* @return a map
*/
public Map<String, Object> asMap() {
return resultMap;
}

/**
* Inheritable Builder for cluster proxy operation options.
* <p>
Expand All @@ -38,19 +55,4 @@ class AbstractBuilder<O extends CRUDAbstractOperationOptions, B extends Abstract

public abstract O build();
}

protected void addOption(String option, Optional<?> value) {
if (value.isPresent()) {
resultMap.put(option, value.get());
}
}

/**
* Return serializable options representation.
*
* @return a map
*/
public Map<String, Object> asMap() {
return resultMap;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.tarantool.driver.core.proxy;

import io.tarantool.driver.api.space.options.enums.crud.ProxyOption;

import java.util.Optional;

/**
Expand All @@ -12,11 +14,9 @@
*/
class CRUDBaseOptions extends CRUDAbstractOperationOptions {

public static final String TIMEOUT = "timeout";

protected <O extends CRUDBaseOptions, T extends AbstractBuilder<O, T>>
CRUDBaseOptions(AbstractBuilder<O, T> builder) {
addOption(TIMEOUT, builder.timeout);
addOption(ProxyOption.TIMEOUT, builder.timeout);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.tarantool.driver.core.proxy;

import io.tarantool.driver.api.space.options.enums.crud.ProxyOption;

import java.util.Optional;

/**
Expand All @@ -11,14 +13,11 @@
*/
final class CRUDBatchOptions extends CRUDReturnOptions {

public static final String BATCH_STOP_ON_ERROR = "stop_on_error";
public static final String BATCH_ROLLBACK_ON_ERROR = "rollback_on_error";

private <T extends AbstractBuilder<T>>
CRUDBatchOptions(AbstractBuilder<T> builder) {
super(builder);
addOption(BATCH_STOP_ON_ERROR, builder.stopOnError);
addOption(BATCH_ROLLBACK_ON_ERROR, builder.rollbackOnError);
addOption(ProxyOption.STOP_ON_ERROR, builder.stopOnError);
addOption(ProxyOption.ROLLBACK_ON_ERROR, builder.rollbackOnError);
}

protected abstract static class AbstractBuilder<B extends AbstractBuilder<B>>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.tarantool.driver.core.proxy;

import io.tarantool.driver.api.space.options.enums.crud.ProxyOption;

import java.util.Optional;

/**
Expand All @@ -13,12 +15,10 @@
*/
class CRUDBucketIdOptions extends CRUDBaseOptions {

public static final String BUCKET_ID = "bucket_id";

protected <O extends CRUDBucketIdOptions, B extends AbstractBuilder<O, B>>
CRUDBucketIdOptions(CRUDBucketIdOptions.AbstractBuilder<O, B> builder) {
super(builder);
addOption(BUCKET_ID, builder.bucketId);
addOption(ProxyOption.BUCKET_ID, builder.bucketId);
}

protected abstract static
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.tarantool.driver.core.proxy;

import io.tarantool.driver.api.space.options.enums.crud.ProxyOption;

import java.util.List;
import java.util.Optional;

Expand All @@ -13,12 +15,10 @@
*/
class CRUDDeleteOptions extends CRUDBucketIdOptions {

public static final String FIELDS = "fields";

protected <O extends CRUDDeleteOptions, B extends AbstractBuilder<O, B>>
CRUDDeleteOptions(CRUDDeleteOptions.AbstractBuilder<O, B> builder) {
super(builder);
addOption(FIELDS, builder.fields);
addOption(ProxyOption.FIELDS, builder.fields);
}

protected abstract static
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.tarantool.driver.core.proxy;

import io.tarantool.driver.api.space.options.enums.crud.ProxyOption;

import java.util.List;
import java.util.Optional;

Expand All @@ -13,12 +15,10 @@
*/
class CRUDInsertOptions extends CRUDBucketIdOptions {

public static final String FIELDS = "fields";

protected <O extends CRUDInsertOptions, B extends AbstractBuilder<O, B>>
CRUDInsertOptions(CRUDInsertOptions.AbstractBuilder<O, B> builder) {
super(builder);
addOption(FIELDS, builder.fields);
addOption(ProxyOption.FIELDS, builder.fields);
}

protected abstract static
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.tarantool.driver.core.proxy;

import io.tarantool.driver.api.space.options.enums.crud.ProxyOption;

import java.util.List;
import java.util.Optional;

Expand All @@ -13,12 +15,10 @@
*/
class CRUDReplaceOptions extends CRUDBucketIdOptions {

public static final String FIELDS = "fields";

protected <O extends CRUDReplaceOptions, B extends AbstractBuilder<O, B>>
CRUDReplaceOptions(CRUDReplaceOptions.AbstractBuilder<O, B> builder) {
super(builder);
addOption(FIELDS, builder.fields);
addOption(ProxyOption.FIELDS, builder.fields);
}

protected abstract static
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.tarantool.driver.core.proxy;

import io.tarantool.driver.api.space.options.enums.crud.ProxyOption;

import java.util.List;
import java.util.Optional;

Expand All @@ -14,12 +16,10 @@
*/
class CRUDReturnOptions extends CRUDBaseOptions {

public static final String FIELDS = "fields";

protected <O extends CRUDReturnOptions, B extends AbstractBuilder<O, B>>
CRUDReturnOptions(CRUDReturnOptions.AbstractBuilder<O, B> builder) {
super(builder);
addOption(FIELDS, builder.fields);
addOption(ProxyOption.FIELDS, builder.fields);
}

protected abstract static
Expand Down
33 changes: 14 additions & 19 deletions src/main/java/io/tarantool/driver/core/proxy/CRUDSelectOptions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.tarantool.driver.core.proxy;

import io.tarantool.driver.api.space.options.enums.crud.ProxyOption;
import io.tarantool.driver.protocol.Packable;

import java.util.List;
Expand All @@ -16,20 +17,14 @@
*/
final class CRUDSelectOptions extends CRUDBucketIdOptions {

public static final String SELECT_LIMIT = "first";
public static final String SELECT_AFTER = "after";
public static final String SELECT_BATCH_SIZE = "batch_size";
public static final String FIELDS = "fields";
public static final String MODE = "mode";

private <B extends AbstractBuilder<B>> CRUDSelectOptions(AbstractBuilder<B> builder) {
super(builder);

addOption(SELECT_LIMIT, builder.selectLimit);
addOption(SELECT_AFTER, builder.after);
addOption(SELECT_BATCH_SIZE, builder.selectBatchSize);
addOption(FIELDS, builder.fields);
addOption(MODE, builder.mode);
addOption(ProxyOption.FIRST, builder.first);
addOption(ProxyOption.AFTER, builder.after);
addOption(ProxyOption.BATCH_SIZE, builder.batchSize);
addOption(ProxyOption.FIELDS, builder.fields);
addOption(ProxyOption.MODE, builder.mode);
}

/**
Expand All @@ -39,24 +34,24 @@ private <B extends AbstractBuilder<B>> CRUDSelectOptions(AbstractBuilder<B> buil
*/
protected abstract static class AbstractBuilder<B extends AbstractBuilder<B>>
extends CRUDBucketIdOptions.AbstractBuilder<CRUDSelectOptions, B> {
private Optional<Long> selectLimit = Optional.empty();
private Optional<Long> first = Optional.empty();
private Optional<Packable> after = Optional.empty();
private Optional<Integer> selectBatchSize = Optional.empty();
private Optional<Integer> batchSize = Optional.empty();
private Optional<List> fields = Optional.empty();
private Optional<String> mode = Optional.empty();

public B withSelectLimit(Optional<Long> selectLimit) {
this.selectLimit = selectLimit;
public B withSelectLimit(Optional<Long> first) {
this.first = first;
return self();
}

public B withSelectBatchSize(Optional<Integer> selectBatchSize) {
this.selectBatchSize = selectBatchSize;
public B withSelectBatchSize(Optional<Integer> batchSize) {
this.batchSize = batchSize;
return self();
}

public B withSelectAfter(Optional<Packable> startTuple) {
this.after = startTuple;
public B withSelectAfter(Optional<Packable> after) {
this.after = after;
return self();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.tarantool.driver.core.proxy;

import io.tarantool.driver.api.space.options.enums.crud.ProxyOption;

import java.util.List;
import java.util.Optional;

Expand All @@ -13,12 +15,10 @@
*/
class CRUDUpdateOptions extends CRUDBucketIdOptions {

public static final String FIELDS = "fields";

protected <O extends CRUDUpdateOptions, B extends AbstractBuilder<O, B>>
CRUDUpdateOptions(CRUDUpdateOptions.AbstractBuilder<O, B> builder) {
super(builder);
addOption(FIELDS, builder.fields);
addOption(ProxyOption.FIELDS, builder.fields);
}

protected abstract static
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.tarantool.driver.core.proxy;

import io.tarantool.driver.api.space.options.enums.crud.ProxyOption;

import java.util.List;
import java.util.Optional;

Expand All @@ -13,12 +15,10 @@
*/
class CRUDUpsertOptions extends CRUDBucketIdOptions {

public static final String FIELDS = "fields";

protected <O extends CRUDUpsertOptions, B extends AbstractBuilder<O, B>>
CRUDUpsertOptions(CRUDUpsertOptions.AbstractBuilder<O, B> builder) {
super(builder);
addOption(FIELDS, builder.fields);
addOption(ProxyOption.FIELDS, builder.fields);
}

protected abstract static
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.tarantool.driver.core.proxy;

import io.tarantool.driver.api.space.options.enums.crud.ProxyOption;
import io.tarantool.driver.api.tuple.TarantoolTuple;
import io.tarantool.driver.core.tuple.TarantoolTupleImpl;
import io.tarantool.driver.mappers.MessagePackMapper;
Expand Down Expand Up @@ -39,10 +40,10 @@ public void selectOperationOptions_createNotEmptyTest() {

assertEquals(4, options.asMap().size());

assertEquals(1000, options.asMap().get(CRUDBaseOptions.TIMEOUT));
assertEquals(50L, options.asMap().get(CRUDSelectOptions.SELECT_LIMIT));
assertEquals(10, options.asMap().get(CRUDSelectOptions.SELECT_BATCH_SIZE));
assertEquals(tuple, options.asMap().get(CRUDSelectOptions.SELECT_AFTER));
assertEquals(1000, options.asMap().get(ProxyOption.TIMEOUT.toString()));
assertEquals(50L, options.asMap().get(ProxyOption.FIRST.toString()));
assertEquals(10, options.asMap().get(ProxyOption.BATCH_SIZE.toString()));
assertEquals(tuple, options.asMap().get(ProxyOption.AFTER.toString()));
}

@Test
Expand All @@ -52,7 +53,7 @@ public void baseOperationOptions_createNotEmptyTest() {
.build();

assertEquals(1, options.asMap().size());
assertEquals(1000, options.asMap().get(CRUDBaseOptions.TIMEOUT));
assertEquals(1000, options.asMap().get(ProxyOption.TIMEOUT.toString()));
}

@Test
Expand All @@ -63,7 +64,7 @@ public void batchOperationOptions_createNotEmptyTest() {
.build();

assertEquals(2, options.asMap().size());
assertEquals(false, options.asMap().get(CRUDBatchOptions.BATCH_STOP_ON_ERROR));
assertEquals(true, options.asMap().get(CRUDBatchOptions.BATCH_ROLLBACK_ON_ERROR));
assertEquals(false, options.asMap().get(ProxyOption.STOP_ON_ERROR.toString()));
assertEquals(true, options.asMap().get(ProxyOption.ROLLBACK_ON_ERROR.toString()));
}
}
Loading

0 comments on commit b743fe5

Please sign in to comment.