Skip to content

Commit

Permalink
Add fields option to ProxySpace
Browse files Browse the repository at this point in the history
Closes #236
  • Loading branch information
ArtDu committed Sep 20, 2022
1 parent 57af227 commit 1618cfe
Show file tree
Hide file tree
Showing 36 changed files with 338 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features
- Added options parameter to Tarantool Space API ([#266](https://github.com/tarantool/cartridge-java/pull/266))
- Added support for insert_many and replace_many CRUD operations ([#259](https://github.com/tarantool/cartridge-java/issues/259))
- Added `fields` option to ProxySpace ([#236](https://github.com/tarantool/cartridge-java/pull/236))

## [0.8.2] - 2022-09-16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* @author Artyom Dubinin
* @author Alexey Kuzin
*/
public interface DeleteOptions extends OperationWithTimeoutOptions {
public interface DeleteOptions extends OperationWithFieldsOptions {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @author Alexey Kuzin
*/
public interface InsertManyOptions extends OperationWithTimeoutOptions {
public interface InsertManyOptions extends OperationWithFieldsOptions {
/**
* Return whether all changes should not be saved if any tuple insertion
* was unsuccesful.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* @author Artyom Dubinin
* @author Alexey Kuzin
*/
public interface InsertOptions extends OperationWithTimeoutOptions {
public interface InsertOptions extends OperationWithFieldsOptions {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.tarantool.driver.api.space.options;

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

/**
* Base interface for all operation options that may have a configurable return.
*
* @author Artyom Dubinin
*/
public interface OperationWithFieldsOptions extends OperationWithTimeoutOptions {
/**
* Return list of fields.
*
* @return timeout, in milliseconds.
*/
Optional<List> getFields();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @author Alexey Kuzin
*/
public interface ReplaceManyOptions extends OperationWithTimeoutOptions {
public interface ReplaceManyOptions extends OperationWithFieldsOptions {
/**
* Return whether all changes should not be saved if any tuple replace
* was unsuccesful.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* @author Artyom Dubinin
* @author Alexey Kuzin
*/
public interface ReplaceOptions extends OperationWithTimeoutOptions {
public interface ReplaceOptions extends OperationWithFieldsOptions {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @author Artyom Dubinin
* @author Alexey Kuzin
*/
public interface SelectOptions extends OperationWithTimeoutOptions {
public interface SelectOptions extends OperationWithFieldsOptions {
/**
* Return the internal size of batch for transferring data between
* storage and router nodes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* @author Artyom Dubinin
* @author Alexey Kuzin
*/
public interface UpdateOptions extends OperationWithTimeoutOptions {
public interface UpdateOptions extends OperationWithFieldsOptions {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* @author Artyom Dubinin
* @author Alexey Kuzin
*/
public interface UpsertOptions extends OperationWithTimeoutOptions {
public interface UpsertOptions extends OperationWithFieldsOptions {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
public final class ProxyDeleteOptions extends ProxyBaseOptions<ProxyDeleteOptions> implements DeleteOptions {
public final class ProxyDeleteOptions extends ProxyReturnOptions<ProxyDeleteOptions> implements DeleteOptions {

private ProxyDeleteOptions() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @author Alexey Kuzin
*/
public final class ProxyInsertManyOptions extends ProxyBaseOptions<ProxyInsertManyOptions>
public final class ProxyInsertManyOptions extends ProxyReturnOptions<ProxyInsertManyOptions>
implements InsertManyOptions {

public static final String ROLLBACK_ON_ERROR = "rollback_on_error";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
public final class ProxyInsertOptions extends ProxyBaseOptions<ProxyInsertOptions> implements InsertOptions {
public final class ProxyInsertOptions extends ProxyReturnOptions<ProxyInsertOptions> implements InsertOptions {

private ProxyInsertOptions() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @author Alexey Kuzin
*/
public final class ProxyReplaceManyOptions extends ProxyBaseOptions<ProxyReplaceManyOptions>
public final class ProxyReplaceManyOptions extends ProxyReturnOptions<ProxyReplaceManyOptions>
implements ReplaceManyOptions {

public static final String ROLLBACK_ON_ERROR = "rollback_on_error";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
public final class ProxyReplaceOptions extends ProxyBaseOptions<ProxyReplaceOptions> implements ReplaceOptions {
public final class ProxyReplaceOptions extends ProxyReturnOptions<ProxyReplaceOptions> implements ReplaceOptions {

private ProxyReplaceOptions() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.tarantool.driver.api.space.options.proxy;

import io.tarantool.driver.api.space.options.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.OperationWithTimeoutOptions;

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

/**
* Represent options for functions which return values
*
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
abstract class ProxyReturnOptions<B extends ProxyReturnOptions<B>> extends ProxyBaseOptions<B>
implements OperationWithFieldsOptions {

public static final String FIELDS = "fields";

/** TODO:
* Specifies timeout for waiting for a server response for the operation.
* Configured request timeout for that client will be used by default.
*
* @param fields request timeout, in milliseconds
* @return this options instance
*/
public B withFields(List<String> fields) {
addOption(FIELDS, fields);
return self();
}

@Override
public Optional<List> getFields() {
return getOption(FIELDS, List.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
public final class ProxySelectOptions extends ProxyBaseOptions<ProxySelectOptions> implements SelectOptions {
public final class ProxySelectOptions extends ProxyReturnOptions<ProxySelectOptions> implements SelectOptions {

public static final String BATCH_SIZE = "batch_size";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
public final class ProxyUpdateOptions extends ProxyBaseOptions<ProxyUpdateOptions> implements UpdateOptions {
public final class ProxyUpdateOptions extends ProxyReturnOptions<ProxyUpdateOptions> implements UpdateOptions {

private ProxyUpdateOptions() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
public final class ProxyUpsertOptions extends ProxyBaseOptions<ProxyUpsertOptions> implements UpsertOptions {
public final class ProxyUpsertOptions extends ProxyReturnOptions<ProxyUpsertOptions> implements UpsertOptions {

private ProxyUpsertOptions() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class CRUDBaseOptions extends CRUDAbstractOperationOptions {
public static final String TIMEOUT = "timeout";

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

Expand All @@ -26,11 +26,11 @@ class CRUDBaseOptions extends CRUDAbstractOperationOptions {
* @see CRUDAbstractOperationOptions.AbstractBuilder
*/
protected abstract static
class AbstractBuilder<O extends CRUDBaseOptions, T extends AbstractBuilder<O, T>>
extends CRUDAbstractOperationOptions.AbstractBuilder<O, T> {
class AbstractBuilder<O extends CRUDBaseOptions, B extends AbstractBuilder<O, B>>
extends CRUDAbstractOperationOptions.AbstractBuilder<O, B> {
protected Optional<Integer> timeout = Optional.empty();

public T withTimeout(Optional<Integer> timeout) {
public B withTimeout(Optional<Integer> timeout) {
this.timeout = timeout;
return self();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,38 @@
*
* @author Alexey Kuzin
*/
public final class CRUDBatchOptions extends CRUDBaseOptions {
public 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";

protected
<T extends AbstractBuilder<T>>
CRUDBatchOptions(AbstractBuilder<T> builder) {
<O extends CRUDBatchOptions, B extends AbstractBuilder<O, B>>
CRUDBatchOptions(AbstractBuilder<O, B> builder) {
super(builder);

addOption(BATCH_STOP_ON_ERROR, builder.stopOnError);
addOption(BATCH_ROLLBACK_ON_ERROR, builder.rollbackOnError);
}

protected abstract static
class AbstractBuilder<T extends AbstractBuilder<T>>
extends CRUDBaseOptions.AbstractBuilder<CRUDBatchOptions, T> {
class AbstractBuilder<O extends CRUDBatchOptions, B extends AbstractBuilder<O, B>>
extends CRUDReturnOptions.AbstractBuilder<O, B> {
private Optional<Boolean> stopOnError = Optional.empty();
private Optional<Boolean> rollbackOnError = Optional.empty();

public T withStopOnError(Optional<Boolean> stopOnError) {
public B withStopOnError(Optional<Boolean> stopOnError) {
this.stopOnError = stopOnError;
return self();
}

public T withRollbackOnError(Optional<Boolean> rollbackOnError) {
public B withRollbackOnError(Optional<Boolean> rollbackOnError) {
this.rollbackOnError = rollbackOnError;
return self();
}
}

protected static final class Builder extends AbstractBuilder<Builder> {
protected static final class Builder extends AbstractBuilder<CRUDBatchOptions, Builder> {

@Override
Builder self() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.tarantool.driver.core.proxy;

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

/**
* This class is not part of the public API.
* <p>
* Represent options for cluster proxy operations which returns fields
*
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
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);
}

protected abstract static
class AbstractBuilder<O extends CRUDReturnOptions, B extends AbstractBuilder<O, B>>
extends CRUDBaseOptions.AbstractBuilder<O, B> {
private Optional<List> fields = Optional.empty();

public B withFields(Optional<List> fields) {
this.fields = fields;
return self();
}
}

protected static final class Builder extends AbstractBuilder<CRUDReturnOptions, Builder> {

@Override
CRUDReturnOptions.Builder self() {
return this;
}

@Override
public CRUDReturnOptions build() {
return new CRUDReturnOptions(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
final class CRUDSelectOptions extends CRUDBaseOptions {
final class CRUDSelectOptions extends CRUDReturnOptions {

public static final String SELECT_LIMIT = "first";
public static final String SELECT_AFTER = "after";
public static final String SELECT_BATCH_SIZE = "batch_size";

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

addOption(SELECT_LIMIT, builder.selectLimit);
Expand All @@ -34,23 +34,23 @@ final class CRUDSelectOptions extends CRUDBaseOptions {
* @see CRUDAbstractOperationOptions.AbstractBuilder
*/
protected abstract static
class AbstractBuilder<T extends AbstractBuilder<T>>
extends CRUDBaseOptions.AbstractBuilder<CRUDSelectOptions, T> {
class AbstractBuilder<O extends CRUDSelectOptions, B extends AbstractBuilder<O, B>>
extends CRUDReturnOptions.AbstractBuilder<O, B> {
private Optional<Long> selectLimit = Optional.empty();
private Optional<Packable> after = Optional.empty();
private Optional<Integer> selectBatchSize = Optional.empty();

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

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

public T withSelectAfter(Optional<Packable> startTuple) {
public B withSelectAfter(Optional<Packable> startTuple) {
this.after = startTuple;
return self();
}
Expand All @@ -59,7 +59,7 @@ public T withSelectAfter(Optional<Packable> startTuple) {
/**
* Concrete Builder implementation for select cluster proxy operation options.
*/
protected static final class Builder extends AbstractBuilder<Builder> {
protected static final class Builder extends AbstractBuilder<CRUDSelectOptions, Builder> {

@Override
Builder self() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ public Builder<T> withIndexQuery(TarantoolIndexQuery indexQuery) {
}

public DeleteProxyOperation<T> build() {
CRUDBaseOptions requestOptions = new CRUDBaseOptions.Builder()
CRUDReturnOptions requestOptions = new CRUDReturnOptions.Builder()
.withTimeout(options.getTimeout())
.withFields(options.getFields())
.build();

List<?> arguments = Arrays.asList(spaceName, indexQuery.getKeyValues(), requestOptions.asMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public InsertManyProxyOperation<T, R> build() {
.withTimeout(options.getTimeout())
.withStopOnError(options.getStopOnError())
.withRollbackOnError(options.getRollbackOnError())
.withFields(options.getFields())
.build();

List<?> arguments = Arrays.asList(spaceName, tuples, requestOptions.asMap());
Expand Down
Loading

0 comments on commit 1618cfe

Please sign in to comment.