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 Dec 22, 2022
1 parent 7cc906e commit 87f9179
Show file tree
Hide file tree
Showing 34 changed files with 626 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Added `fields` option to ProxySpace ([#236](https://github.com/tarantool/cartridge-java/pull/236))
- Move metadata parsing to separate converters ([#325](https://github.com/tarantool/cartridge-java/pull/325))
- Parse metadata from crud response ([#272](https://github.com/tarantool/cartridge-java/pull/272))
- Use netty part dependencies instead of netty-all ([#295](https://github.com/tarantool/cartridge-java/issues/295))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
* @author Alexey Kuzin
*/
public interface DeleteOptions<T extends DeleteOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T> {
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*
* @author Alexey Kuzin
*/
public interface InsertManyOptions<T extends InsertManyOptions<T>> extends OperationWithTimeoutOptions<T> {
public interface InsertManyOptions<T extends InsertManyOptions<T>>
extends OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
/**
* 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 @@ -7,5 +7,5 @@
* @author Alexey Kuzin
*/
public interface InsertOptions<T extends InsertOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T> {
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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<T extends OperationWithFieldsOptions<T>>
extends Options, Self<T> {

String FIELDS = "fields";

/**
* Specifies list of fields names for getting only a subset of fields.
* By default, all fields are returned.
*
* @param fields list of string field names
* @return this options instance
*/
default T withFields(List<String> fields) {
addOption(FIELDS, fields);
return self();
}

/**
* Return list of fields names for getting only a subset of fields.
*
* @return list of fields string names
*/
default Optional<List> getFields() {
return getOption(FIELDS, List.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*
* @author Alexey Kuzin
*/
public interface ReplaceManyOptions<T extends ReplaceManyOptions<T>> extends OperationWithTimeoutOptions<T> {
public interface ReplaceManyOptions<T extends ReplaceManyOptions<T>>
extends OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
/**
* 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 @@ -7,5 +7,5 @@
* @author Alexey Kuzin
*/
public interface ReplaceOptions<T extends ReplaceOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T> {
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Alexey Kuzin
*/
public interface SelectOptions<T extends SelectOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T> {
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
/**
* 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 @@ -7,5 +7,5 @@
* @author Alexey Kuzin
*/
public interface UpdateOptions<T extends UpdateOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T> {
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
* @author Alexey Kuzin
*/
public interface UpsertOptions<T extends UpsertOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T> {
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,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> {
protected abstract static 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,35 @@
*
* @author Alexey Kuzin
*/
public final class CRUDBatchOptions extends CRUDBaseOptions {
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);
}

protected abstract static
class AbstractBuilder<T extends AbstractBuilder<T>>
extends CRUDBaseOptions.AbstractBuilder<CRUDBatchOptions, T> {
protected abstract static class AbstractBuilder<B extends AbstractBuilder<B>>
extends CRUDReturnOptions.AbstractBuilder<CRUDBatchOptions, 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> {

@Override
Builder self() {
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 delete operation.
*
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
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);
}

protected abstract static
class AbstractBuilder<O extends CRUDDeleteOptions, B extends AbstractBuilder<O, B>>
extends CRUDBucketIdOptions.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<CRUDDeleteOptions, Builder> {

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

@Override
public CRUDDeleteOptions build() {
return new CRUDDeleteOptions(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 insert operation.
*
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
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);
}

protected abstract static
class AbstractBuilder<O extends CRUDInsertOptions, B extends AbstractBuilder<O, B>>
extends CRUDBucketIdOptions.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<CRUDInsertOptions, Builder> {

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

@Override
public CRUDInsertOptions build() {
return new CRUDInsertOptions(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 replace operation.
*
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
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);
}

protected abstract static
class AbstractBuilder<O extends CRUDReplaceOptions, B extends AbstractBuilder<O, B>>
extends CRUDBucketIdOptions.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<CRUDReplaceOptions, Builder> {

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

@Override
public CRUDReplaceOptions build() {
return new CRUDReplaceOptions(this);
}
}
}
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 returned options for cluster proxy operations.
* The return set of fields of the tuples can be specified.
*
* @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);
}
}
}
Loading

0 comments on commit 87f9179

Please sign in to comment.