Skip to content

Commit 9ef0f47

Browse files
committed
Add fields option to ProxySpace
Closes #236
1 parent 7cc906e commit 9ef0f47

34 files changed

+626
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

5+
- Added `fields` option to ProxySpace ([#236](https://github.com/tarantool/cartridge-java/pull/236))
56
- Move metadata parsing to separate converters ([#325](https://github.com/tarantool/cartridge-java/pull/325))
67
- Parse metadata from crud response ([#272](https://github.com/tarantool/cartridge-java/pull/272))
78
- Use netty part dependencies instead of netty-all ([#295](https://github.com/tarantool/cartridge-java/issues/295))

src/main/java/io/tarantool/driver/api/space/options/DeleteOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
* @author Alexey Kuzin
88
*/
99
public interface DeleteOptions<T extends DeleteOptions<T>>
10-
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T> {
10+
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
1111
}

src/main/java/io/tarantool/driver/api/space/options/InsertManyOptions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
*
88
* @author Alexey Kuzin
99
*/
10-
public interface InsertManyOptions<T extends InsertManyOptions<T>> extends OperationWithTimeoutOptions<T> {
10+
public interface InsertManyOptions<T extends InsertManyOptions<T>>
11+
extends OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
1112
/**
1213
* Return whether all changes should not be saved if any tuple insertion
1314
* was unsuccesful.

src/main/java/io/tarantool/driver/api/space/options/InsertOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
* @author Alexey Kuzin
88
*/
99
public interface InsertOptions<T extends InsertOptions<T>>
10-
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T> {
10+
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
1111
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.tarantool.driver.api.space.options;
2+
3+
import java.util.List;
4+
import java.util.Optional;
5+
6+
/**
7+
* Base interface for all operation options that may have a configurable return.
8+
*
9+
* @author Artyom Dubinin
10+
*/
11+
public interface OperationWithFieldsOptions<T extends OperationWithFieldsOptions<T>>
12+
extends Options, Self<T> {
13+
14+
String FIELDS = "fields";
15+
16+
/**
17+
* Specifies list of fields names for getting only a subset of fields.
18+
* By default, all fields are returned.
19+
*
20+
* @param fields list of string field names
21+
* @return this options instance
22+
*/
23+
default T withFields(List<String> fields) {
24+
addOption(FIELDS, fields);
25+
return self();
26+
}
27+
28+
/**
29+
* Return list of fields names for getting only a subset of fields.
30+
*
31+
* @return list of fields string names
32+
*/
33+
default Optional<List> getFields() {
34+
return getOption(FIELDS, List.class);
35+
}
36+
}

src/main/java/io/tarantool/driver/api/space/options/ReplaceManyOptions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
*
88
* @author Alexey Kuzin
99
*/
10-
public interface ReplaceManyOptions<T extends ReplaceManyOptions<T>> extends OperationWithTimeoutOptions<T> {
10+
public interface ReplaceManyOptions<T extends ReplaceManyOptions<T>>
11+
extends OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
1112
/**
1213
* Return whether all changes should not be saved if any tuple replace
1314
* was unsuccesful.

src/main/java/io/tarantool/driver/api/space/options/ReplaceOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
* @author Alexey Kuzin
88
*/
99
public interface ReplaceOptions<T extends ReplaceOptions<T>>
10-
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T> {
10+
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
1111
}

src/main/java/io/tarantool/driver/api/space/options/SelectOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @author Alexey Kuzin
1010
*/
1111
public interface SelectOptions<T extends SelectOptions<T>>
12-
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T> {
12+
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
1313
/**
1414
* Return the internal size of batch for transferring data between
1515
* storage and router nodes.

src/main/java/io/tarantool/driver/api/space/options/UpdateOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
* @author Alexey Kuzin
88
*/
99
public interface UpdateOptions<T extends UpdateOptions<T>>
10-
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T> {
10+
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
1111
}

src/main/java/io/tarantool/driver/api/space/options/UpsertOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
* @author Alexey Kuzin
88
*/
99
public interface UpsertOptions<T extends UpsertOptions<T>>
10-
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T> {
10+
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
1111
}

src/main/java/io/tarantool/driver/core/proxy/CRUDBaseOptions.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ class CRUDBaseOptions extends CRUDAbstractOperationOptions {
2424
*
2525
* @see CRUDAbstractOperationOptions.AbstractBuilder
2626
*/
27-
protected abstract static
28-
class AbstractBuilder<O extends CRUDBaseOptions, T extends AbstractBuilder<O, T>>
29-
extends CRUDAbstractOperationOptions.AbstractBuilder<O, T> {
27+
protected abstract static class AbstractBuilder<O extends CRUDBaseOptions, B extends AbstractBuilder<O, B>>
28+
extends CRUDAbstractOperationOptions.AbstractBuilder<O, B> {
3029
protected Optional<Integer> timeout = Optional.empty();
3130

32-
public T withTimeout(Optional<Integer> timeout) {
31+
public B withTimeout(Optional<Integer> timeout) {
3332
this.timeout = timeout;
3433
return self();
3534
}

src/main/java/io/tarantool/driver/core/proxy/CRUDBatchOptions.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,35 @@
99
*
1010
* @author Alexey Kuzin
1111
*/
12-
public final class CRUDBatchOptions extends CRUDBaseOptions {
12+
final class CRUDBatchOptions extends CRUDReturnOptions {
1313

1414
public static final String BATCH_STOP_ON_ERROR = "stop_on_error";
1515
public static final String BATCH_ROLLBACK_ON_ERROR = "rollback_on_error";
1616

1717
private <T extends AbstractBuilder<T>>
1818
CRUDBatchOptions(AbstractBuilder<T> builder) {
1919
super(builder);
20-
2120
addOption(BATCH_STOP_ON_ERROR, builder.stopOnError);
2221
addOption(BATCH_ROLLBACK_ON_ERROR, builder.rollbackOnError);
2322
}
2423

25-
protected abstract static
26-
class AbstractBuilder<T extends AbstractBuilder<T>>
27-
extends CRUDBaseOptions.AbstractBuilder<CRUDBatchOptions, T> {
24+
protected abstract static class AbstractBuilder<B extends AbstractBuilder<B>>
25+
extends CRUDReturnOptions.AbstractBuilder<CRUDBatchOptions, B> {
2826
private Optional<Boolean> stopOnError = Optional.empty();
2927
private Optional<Boolean> rollbackOnError = Optional.empty();
3028

31-
public T withStopOnError(Optional<Boolean> stopOnError) {
29+
public B withStopOnError(Optional<Boolean> stopOnError) {
3230
this.stopOnError = stopOnError;
3331
return self();
3432
}
3533

36-
public T withRollbackOnError(Optional<Boolean> rollbackOnError) {
34+
public B withRollbackOnError(Optional<Boolean> rollbackOnError) {
3735
this.rollbackOnError = rollbackOnError;
3836
return self();
3937
}
4038
}
4139

4240
protected static final class Builder extends AbstractBuilder<Builder> {
43-
4441
@Override
4542
Builder self() {
4643
return this;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package io.tarantool.driver.core.proxy;
2+
3+
import java.util.List;
4+
import java.util.Optional;
5+
6+
/**
7+
* This class is not part of the public API.
8+
* <p>
9+
* Represent options for cluster delete operation.
10+
*
11+
* @author Alexey Kuzin
12+
* @author Artyom Dubinin
13+
*/
14+
class CRUDDeleteOptions extends CRUDBucketIdOptions {
15+
16+
public static final String FIELDS = "fields";
17+
18+
protected <O extends CRUDDeleteOptions, B extends AbstractBuilder<O, B>>
19+
CRUDDeleteOptions(CRUDDeleteOptions.AbstractBuilder<O, B> builder) {
20+
super(builder);
21+
addOption(FIELDS, builder.fields);
22+
}
23+
24+
protected abstract static
25+
class AbstractBuilder<O extends CRUDDeleteOptions, B extends AbstractBuilder<O, B>>
26+
extends CRUDBucketIdOptions.AbstractBuilder<O, B> {
27+
private Optional<List> fields = Optional.empty();
28+
29+
public B withFields(Optional<List> fields) {
30+
this.fields = fields;
31+
return self();
32+
}
33+
}
34+
35+
protected static final class Builder extends AbstractBuilder<CRUDDeleteOptions, Builder> {
36+
37+
@Override
38+
CRUDDeleteOptions.Builder self() {
39+
return this;
40+
}
41+
42+
@Override
43+
public CRUDDeleteOptions build() {
44+
return new CRUDDeleteOptions(this);
45+
}
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package io.tarantool.driver.core.proxy;
2+
3+
import java.util.List;
4+
import java.util.Optional;
5+
6+
/**
7+
* This class is not part of the public API.
8+
* <p>
9+
* Represent options for cluster insert operation.
10+
*
11+
* @author Alexey Kuzin
12+
* @author Artyom Dubinin
13+
*/
14+
class CRUDInsertOptions extends CRUDBucketIdOptions {
15+
16+
public static final String FIELDS = "fields";
17+
18+
protected <O extends CRUDInsertOptions, B extends AbstractBuilder<O, B>>
19+
CRUDInsertOptions(CRUDInsertOptions.AbstractBuilder<O, B> builder) {
20+
super(builder);
21+
addOption(FIELDS, builder.fields);
22+
}
23+
24+
protected abstract static
25+
class AbstractBuilder<O extends CRUDInsertOptions, B extends AbstractBuilder<O, B>>
26+
extends CRUDBucketIdOptions.AbstractBuilder<O, B> {
27+
private Optional<List> fields = Optional.empty();
28+
29+
public B withFields(Optional<List> fields) {
30+
this.fields = fields;
31+
return self();
32+
}
33+
}
34+
35+
protected static final class Builder extends AbstractBuilder<CRUDInsertOptions, Builder> {
36+
37+
@Override
38+
CRUDInsertOptions.Builder self() {
39+
return this;
40+
}
41+
42+
@Override
43+
public CRUDInsertOptions build() {
44+
return new CRUDInsertOptions(this);
45+
}
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package io.tarantool.driver.core.proxy;
2+
3+
import java.util.List;
4+
import java.util.Optional;
5+
6+
/**
7+
* This class is not part of the public API.
8+
* <p>
9+
* Represent options for cluster replace operation.
10+
*
11+
* @author Alexey Kuzin
12+
* @author Artyom Dubinin
13+
*/
14+
class CRUDReplaceOptions extends CRUDBucketIdOptions {
15+
16+
public static final String FIELDS = "fields";
17+
18+
protected <O extends CRUDReplaceOptions, B extends AbstractBuilder<O, B>>
19+
CRUDReplaceOptions(CRUDReplaceOptions.AbstractBuilder<O, B> builder) {
20+
super(builder);
21+
addOption(FIELDS, builder.fields);
22+
}
23+
24+
protected abstract static
25+
class AbstractBuilder<O extends CRUDReplaceOptions, B extends AbstractBuilder<O, B>>
26+
extends CRUDBucketIdOptions.AbstractBuilder<O, B> {
27+
private Optional<List> fields = Optional.empty();
28+
29+
public B withFields(Optional<List> fields) {
30+
this.fields = fields;
31+
return self();
32+
}
33+
}
34+
35+
protected static final class Builder extends AbstractBuilder<CRUDReplaceOptions, Builder> {
36+
37+
@Override
38+
CRUDReplaceOptions.Builder self() {
39+
return this;
40+
}
41+
42+
@Override
43+
public CRUDReplaceOptions build() {
44+
return new CRUDReplaceOptions(this);
45+
}
46+
}
47+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.tarantool.driver.core.proxy;
2+
3+
import java.util.List;
4+
import java.util.Optional;
5+
6+
/**
7+
* This class is not part of the public API.
8+
* <p>
9+
* Represent returned options for cluster proxy operations.
10+
* The return set of fields of the tuples can be specified.
11+
*
12+
* @author Alexey Kuzin
13+
* @author Artyom Dubinin
14+
*/
15+
class CRUDReturnOptions extends CRUDBaseOptions {
16+
17+
public static final String FIELDS = "fields";
18+
19+
protected <O extends CRUDReturnOptions, B extends AbstractBuilder<O, B>>
20+
CRUDReturnOptions(CRUDReturnOptions.AbstractBuilder<O, B> builder) {
21+
super(builder);
22+
addOption(FIELDS, builder.fields);
23+
}
24+
25+
protected abstract static
26+
class AbstractBuilder<O extends CRUDReturnOptions, B extends AbstractBuilder<O, B>>
27+
extends CRUDBaseOptions.AbstractBuilder<O, B> {
28+
private Optional<List> fields = Optional.empty();
29+
30+
public B withFields(Optional<List> fields) {
31+
this.fields = fields;
32+
return self();
33+
}
34+
}
35+
36+
protected static final class Builder extends AbstractBuilder<CRUDReturnOptions, Builder> {
37+
38+
@Override
39+
CRUDReturnOptions.Builder self() {
40+
return this;
41+
}
42+
43+
@Override
44+
public CRUDReturnOptions build() {
45+
return new CRUDReturnOptions(this);
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)