From d1c452b8577eb6ffab6a6b437e9ba511b65d42a7 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 07:51:00 +0000 Subject: [PATCH 01/17] refactor: update record Signed-off-by: Otavio Santana --- .../column/DefaultColumnDeleteQuery.java | 41 ++----------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQuery.java b/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQuery.java index 7467130df..fc97c3d8f 100644 --- a/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQuery.java +++ b/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQuery.java @@ -28,19 +28,9 @@ /** * The default implementation of {@link ColumnDeleteQuery} */ -class DefaultColumnDeleteQuery implements ColumnDeleteQuery { +record DefaultColumnDeleteQuery(String columnFamily, ColumnCondition columnCondition, List columns) + implements ColumnDeleteQuery { - private final String columnFamily; - - private final ColumnCondition condition; - - private final List columns; - - DefaultColumnDeleteQuery(String columnFamily, ColumnCondition condition, List columns) { - this.columnFamily = columnFamily; - this.condition = ofNullable(condition).map(ColumnCondition::readOnly).orElse(null); - this.columns = columns; - } @Override public String name() { @@ -49,7 +39,7 @@ public String name() { @Override public Optional condition() { - return ofNullable(condition); + return ofNullable(columnCondition); } @Override @@ -57,29 +47,4 @@ public List columns() { return unmodifiableList(columns); } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof ColumnDeleteQuery that)) { - return false; - } - return Objects.equals(columnFamily, that.name()) && - Objects.equals(condition, that.condition().orElse(null)) && - Objects.equals(columns, that.columns()); - } - - @Override - public int hashCode() { - return Objects.hash(columnFamily, condition, columns); - } - - @Override - public String toString() { - return "DefaultColumnDeleteQuery{" + "columnFamily='" + columnFamily + '\'' + - ", condition=" + condition + - ", columns=" + columns + - '}'; - } } From e635412f596c5620d4ade8babcac5895ca1681fe Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 07:54:49 +0000 Subject: [PATCH 02/17] refactor: update record to default column query Signed-off-by: Otavio Santana --- .../column/DefaultColumnQuery.java | 74 +------------------ 1 file changed, 4 insertions(+), 70 deletions(-) diff --git a/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnQuery.java b/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnQuery.java index 008a71cfd..7fc6dffd8 100644 --- a/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnQuery.java +++ b/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnQuery.java @@ -31,49 +31,14 @@ /** * The default implementation of column query. */ -class DefaultColumnQuery implements ColumnQuery { +record DefaultColumnQuery(long limit, long skip, String name, + List columns, List sorts, ColumnCondition columnCondition) + implements ColumnQuery { - private final long maxResults; - - private final long firstResult; - - private final String columnFamily; - - private final List columns; - - private final List sorts; - - private final ColumnCondition condition; - - - DefaultColumnQuery(long maxResults, long firstResult, String columnFamily, - List columns, List sorts, ColumnCondition condition) { - this.maxResults = maxResults; - this.firstResult = firstResult; - this.columnFamily = columnFamily; - this.columns = columns; - this.sorts = sorts; - this.condition = ofNullable(condition).map(ColumnCondition::readOnly).orElse(null); - } - - @Override - public long limit() { - return maxResults; - } - - @Override - public long skip() { - return firstResult; - } - - @Override - public String name() { - return columnFamily; - } @Override public Optional condition() { - return ofNullable(condition); + return ofNullable(columnCondition).map(ColumnCondition::readOnly); } @Override @@ -86,37 +51,6 @@ public List sorts() { return unmodifiableList(sorts); } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof ColumnQuery that)) { - return false; - } - return maxResults == that.limit() && - firstResult == that.skip() && - Objects.equals(columnFamily, that.name()) && - Objects.equals(columns, that.columns()) && - Objects.equals(sorts, that.sorts()) && - Objects.equals(condition, that.condition().orElse(null)); - } - - @Override - public int hashCode() { - return Objects.hash(maxResults, firstResult, columnFamily, columns, sorts, condition); - } - - @Override - public String toString() { - return "ColumnQuery{" + "maxResults=" + maxResults + - ", firstResult=" + firstResult + - ", columnFamily='" + columnFamily + '\'' + - ", columns=" + columns + - ", sorts=" + sorts + - ", condition=" + condition + - '}'; - } static ColumnQuery countBy(ColumnQuery query) { return new DefaultColumnQuery(0, 0, query.name(), query.columns(), Collections.emptyList(), query.condition().orElse(null)); From 7bb3b10cd1a53206fffc60a7b3d12f2bc0629553 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 07:58:06 +0000 Subject: [PATCH 03/17] refactor: update to record Signed-off-by: Otavio Santana --- .../column/DefaultColumnDeleteQuery.java | 1 - .../column/DefaultColumnQuery.java | 1 - .../document/DefaultDocumentDeleteQuery.java | 48 ++----------------- 3 files changed, 3 insertions(+), 47 deletions(-) diff --git a/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQuery.java b/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQuery.java index fc97c3d8f..3c14b3fb1 100644 --- a/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQuery.java +++ b/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQuery.java @@ -19,7 +19,6 @@ import java.util.List; -import java.util.Objects; import java.util.Optional; import static java.util.Collections.unmodifiableList; diff --git a/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnQuery.java b/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnQuery.java index 7fc6dffd8..962957323 100644 --- a/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnQuery.java +++ b/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnQuery.java @@ -22,7 +22,6 @@ import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.Optional; import static java.util.Collections.unmodifiableList; diff --git a/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentDeleteQuery.java b/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentDeleteQuery.java index d1936c468..bf5981a4e 100644 --- a/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentDeleteQuery.java +++ b/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentDeleteQuery.java @@ -19,7 +19,6 @@ import java.util.List; -import java.util.Objects; import java.util.Optional; import static java.util.Collections.unmodifiableList; @@ -28,58 +27,17 @@ /** * The default implementation of {@link DocumentDeleteQuery} */ -final class DefaultDocumentDeleteQuery implements DocumentDeleteQuery { +record DefaultDocumentDeleteQuery (String name, - private final String documentCollection; - - private final DocumentCondition condition; - - private final List documents; - - DefaultDocumentDeleteQuery(String documentCollection, DocumentCondition condition, List documents) { - this.documentCollection = documentCollection; - this.condition = ofNullable(condition).map(DocumentCondition::readOnly).orElse(null); - this.documents = documents; - } - - @Override - public String name() { - return documentCollection; - } + DocumentCondition documentCondition, List documents) implements DocumentDeleteQuery { @Override public Optional condition() { - return ofNullable(condition); + return ofNullable(documentCondition).map(DocumentCondition::readOnly); } @Override public List documents() { return unmodifiableList(documents); } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof DocumentDeleteQuery that)) { - return false; - } - return Objects.equals(documentCollection, that.name()) && - Objects.equals(condition, that.condition().orElse(null)) && - Objects.equals(documents, that.documents()); - } - - @Override - public int hashCode() { - return Objects.hash(documentCollection, condition, documents); - } - - @Override - public String toString() { - return "DefaultDocumentDeleteQuery{" + "documentCollection='" + documentCollection + '\'' + - ", condition=" + condition + - ", documents=" + documents + - '}'; - } } From dc64486b2ba60c16f64601a354460fe77a12399e Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 07:59:58 +0000 Subject: [PATCH 04/17] refactor: update default document query to record Signed-off-by: Otavio Santana --- .../document/DefaultDocumentQuery.java | 74 +------------------ 1 file changed, 3 insertions(+), 71 deletions(-) diff --git a/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentQuery.java b/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentQuery.java index 64b776559..561f35c64 100644 --- a/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentQuery.java +++ b/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentQuery.java @@ -21,55 +21,19 @@ import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.Optional; import static java.util.Collections.unmodifiableList; import static java.util.Optional.ofNullable; -class DefaultDocumentQuery implements DocumentQuery { +record DefaultDocumentQuery(long limit, long skip, String name, + List documents, List sorts, DocumentCondition documentCondition) implements DocumentQuery { - private final long limit; - private final long skip; - - private final String documentCollection; - - private final DocumentCondition condition; - - private final List sorts; - - private final List documents; - - DefaultDocumentQuery(long limit, long skip, String documentCollection, - List documents, List sorts, DocumentCondition condition) { - - this.limit = limit; - this.skip = skip; - this.documentCollection = documentCollection; - this.condition = ofNullable(condition).map(DocumentCondition::readOnly).orElse(null); - this.sorts = sorts; - this.documents = documents; - } - - @Override - public long limit() { - return limit; - } - - @Override - public long skip() { - return skip; - } - - @Override - public String name() { - return documentCollection; - } @Override public Optional condition() { - return ofNullable(condition); + return ofNullable(documentCondition).map(DocumentCondition::readOnly); } @Override @@ -82,38 +46,6 @@ public List documents() { return unmodifiableList(documents); } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof DocumentQuery that)) { - return false; - } - return limit == that.limit() && - skip == that.skip() && - Objects.equals(documentCollection, that.name()) && - Objects.equals(condition, that.condition().orElse(null)) && - Objects.equals(sorts, that.sorts()) && - Objects.equals(documents, that.documents()); - } - - @Override - public int hashCode() { - return Objects.hash(limit, skip, documentCollection, condition, sorts, documents); - } - - @Override - public String toString() { - return "DocumentQuery{" + "maxResult=" + limit + - ", firstResult=" + skip + - ", documentCollection='" + documentCollection + '\'' + - ", condition=" + condition + - ", sorts=" + sorts + - ", documents=" + documents + - '}'; - } - static DocumentQuery countBy(DocumentQuery query) { return new DefaultDocumentQuery(0, 0, query.name(), query.documents(), Collections.emptyList(), query.condition().orElse(null)); From cd5177c9eb375f698fc831c7fc8dd392162fbce2 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 08:01:56 +0000 Subject: [PATCH 05/17] refactor using record Signed-off-by: Otavio Santana --- .../query/DefaultSelectQuery.java | 73 +------------------ 1 file changed, 3 insertions(+), 70 deletions(-) diff --git a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultSelectQuery.java b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultSelectQuery.java index 70e4a9072..eae07bbc7 100644 --- a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultSelectQuery.java +++ b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultSelectQuery.java @@ -23,60 +23,15 @@ /** * The default implementation of {@link SelectQuery} */ -final class DefaultSelectQuery implements SelectQuery { +record DefaultSelectQuery(String entity, List fields, List orderBy, long skip, + long limit, Where condition) implements SelectQuery { - private final String entity; - - private final List fields; - - private final List sorts; - - private final long skip; - - private final long limit; - - private final Where where; - - DefaultSelectQuery(String entity, List fields, List sorts, long skip, long limit, Where where) { - this.entity = entity; - this.fields = fields; - this.sorts = sorts; - this.skip = skip; - this.limit = limit; - this.where = where; - } - - @Override - public List fields() { - return fields; - } - - @Override - public String entity() { - return entity; - } @Override public Optional where() { - return Optional.ofNullable(where); - } - - @Override - public long skip() { - return skip; - } - - @Override - public long limit() { - return limit; + return Optional.ofNullable(condition); } - @Override - public List orderBy() { - return sorts; - } - - /** * Obtains an instance of {@link DefaultSelectQuery} from a text string. * @@ -88,26 +43,4 @@ static DefaultSelectQuery parse(String query) { Objects.requireNonNull(query, "query is required"); return new SelectQueryConverter().apply(query); } - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof DefaultSelectQuery that)) { - return false; - } - return skip == that.skip && - limit == that.limit && - Objects.equals(entity, that.entity) && - Objects.equals(fields, that.fields) && - Objects.equals(sorts, that.sorts) && - Objects.equals(where, that.where); - } - - @Override - public int hashCode() { - return Objects.hash(entity, fields, sorts, skip, limit, where); - } } From 740660bbb333fc81cd2830d821bdd855b536d1ee Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 08:03:37 +0000 Subject: [PATCH 06/17] refact: update default value to record Signed-off-by: Otavio Santana --- .../jnosql/communication/DefaultValue.java | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/jnosql-communication/jnosql-communication-core/src/main/java/org/eclipse/jnosql/communication/DefaultValue.java b/jnosql-communication/jnosql-communication-core/src/main/java/org/eclipse/jnosql/communication/DefaultValue.java index 454077481..8506298a4 100644 --- a/jnosql-communication/jnosql-communication-core/src/main/java/org/eclipse/jnosql/communication/DefaultValue.java +++ b/jnosql-communication/jnosql-communication-core/src/main/java/org/eclipse/jnosql/communication/DefaultValue.java @@ -22,18 +22,12 @@ /** * Defines the default implementation of {@link Value} */ -final class DefaultValue implements Value { +record DefaultValue(Object value) implements Value { private static final ValueReader SERVICE_PROVIDER = ValueReaderDecorator.getInstance(); private static final TypeReferenceReader REFERENCE_READER = TypeReferenceReaderDecorator.getInstance(); - private final Object value; - - DefaultValue(Object value) { - this.value = value; - } - @Override public Object get() { @@ -72,14 +66,4 @@ public boolean equals(Object o) { return Objects.equals(value, that.get()); } - @Override - public int hashCode() { - return Objects.hashCode(value); - } - - @Override - public String toString() { - return "DefaultValue{" + "value=" + value + - '}'; - } } From 82fc8b910f715d7d781f6b6ebf398312208bb566 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 08:05:44 +0000 Subject: [PATCH 07/17] refactor: update refactoring of method array value Signed-off-by: Otavio Santana --- .../query/method/MethodArrayValue.java | 32 +------------------ 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/method/MethodArrayValue.java b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/method/MethodArrayValue.java index 904dfb198..aa81f35a0 100644 --- a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/method/MethodArrayValue.java +++ b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/method/MethodArrayValue.java @@ -15,42 +15,12 @@ import org.eclipse.jnosql.communication.query.ArrayQueryValue; import org.eclipse.jnosql.communication.query.QueryValue; -import java.util.Arrays; - -final class MethodArrayValue implements ArrayQueryValue { - - private final QueryValue[] values; - - private MethodArrayValue(QueryValue[] values) { - this.values = values; - } +record MethodArrayValue(QueryValue[] values) implements ArrayQueryValue { @Override public QueryValue[] get() { return values; } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof MethodArrayValue that)) { - return false; - } - return Arrays.equals(values, that.values); - } - - @Override - public int hashCode() { - return Arrays.hashCode(values); - } - - @Override - public String toString() { - return Arrays.toString(values); - } - static ArrayQueryValue of(String name) { return new MethodArrayValue(new QueryValue[] {new MethodParamQueryValue(name), new MethodParamQueryValue(name)}); From 7a415070f4327a70c06a9348e5011c67d0bb9eb7 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 08:08:35 +0000 Subject: [PATCH 08/17] refact: update condition query value to record Signed-off-by: Otavio Santana --- .../query/ConditionQueryValue.java | 28 +------------------ 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/ConditionQueryValue.java b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/ConditionQueryValue.java index b0fad1f1a..2789f9072 100644 --- a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/ConditionQueryValue.java +++ b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/ConditionQueryValue.java @@ -22,40 +22,14 @@ * and ({@link org.eclipse.jnosql.communication.Condition#AND}), or ({@link org.eclipse.jnosql.communication.Condition#OR}) * and negation ({@link org.eclipse.jnosql.communication.Condition#NOT}). */ -public class ConditionQueryValue implements QueryValue> { +public record ConditionQueryValue(List conditions) implements QueryValue> { - private final List conditions; - - private ConditionQueryValue(List conditions) { - this.conditions = conditions; - } @Override public List get() { return unmodifiableList(conditions); } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof ConditionQueryValue that)) { - return false; - } - return Objects.equals(conditions, that.conditions); - } - - @Override - public int hashCode() { - return Objects.hashCode(conditions); - } - - @Override - public String toString() { - return conditions.toString(); - } - /** * Create Condition query value * @param conditions the conditions From f9190787a656bb4b75076b9b4c8e26e915387de5 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 08:09:41 +0000 Subject: [PATCH 09/17] refact: update record to use default array query value Signed-off-by: Otavio Santana --- .../query/DefaultArrayQueryValue.java | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultArrayQueryValue.java b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultArrayQueryValue.java index a40b938b3..ce91f4959 100644 --- a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultArrayQueryValue.java +++ b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultArrayQueryValue.java @@ -12,45 +12,18 @@ package org.eclipse.jnosql.communication.query; -import java.util.Arrays; /** * A sequence of elements that can be either {@link NumberQueryValue} or {@link StringQueryValue} */ -final class DefaultArrayQueryValue implements ArrayQueryValue { +record DefaultArrayQueryValue(QueryValue[] values) implements ArrayQueryValue { - private final QueryValue[] values; - - private DefaultArrayQueryValue(QueryValue[] values) { - this.values = values; - } @Override public QueryValue[] get() { return values; } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof DefaultArrayQueryValue that)) { - return false; - } - return Arrays.equals(values, that.values); - } - - @Override - public int hashCode() { - return Arrays.hashCode(values); - } - - @Override - public String toString() { - return Arrays.toString(values); - } - static DefaultArrayQueryValue of(QueryValue[] values) { return new DefaultArrayQueryValue(values); } From ca1338a0ee1fa855d8e81e41ac7e7ef2fb3d39bd Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 08:11:03 +0000 Subject: [PATCH 10/17] refactor: update record at function Signed-off-by: Otavio Santana --- .../communication/query/DefaultFunction.java | 45 +------------------ 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultFunction.java b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultFunction.java index 20b201aa6..755f0b84c 100644 --- a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultFunction.java +++ b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultFunction.java @@ -12,51 +12,8 @@ package org.eclipse.jnosql.communication.query; -import java.util.Arrays; -import java.util.Objects; -final class DefaultFunction implements Function { - - private final String name; - - private final Object[] args; - - private DefaultFunction(String name, Object[] args) { - this.name = name; - this.args = args; - } - - @Override - public String name() { - return name; - } - - @Override - public Object[] params() { - return args; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof DefaultFunction that)) { - return false; - } - return Objects.equals(name, that.name) && - Arrays.equals(args, that.args); - } - - @Override - public int hashCode() { - return 31 * Objects.hashCode(name) + Arrays.hashCode(args); - } - - @Override - public String toString() { - return name + "(" + Arrays.toString(args) + ")"; - } +record DefaultFunction(String name, Object[] params) implements Function { static Function of(String name, Object[] args) { return new DefaultFunction(name, args); From d5ed6390632a74b8eaffa4fdafcc4f2fcc41f4c9 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 08:12:33 +0000 Subject: [PATCH 11/17] refac: update defaultvquery value Signed-off-by: Otavio Santana --- .../query/DefaultQueryValue.java | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultQueryValue.java b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultQueryValue.java index 07f41acd5..768374f77 100644 --- a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultQueryValue.java +++ b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultQueryValue.java @@ -13,40 +13,17 @@ import org.eclipse.jnosql.query.grammar.QueryParser; -import java.util.Objects; /** * The default implementation of {@link ParamQueryValue} - */ -final class DefaultQueryValue implements ParamQueryValue { - - private final String value; + */ record DefaultQueryValue(String value) implements ParamQueryValue { - DefaultQueryValue(String value) { - this.value = value; - } @Override public String get() { return value; } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof DefaultQueryValue that)) { - return false; - } - return Objects.equals(value, that.value); - } - - @Override - public int hashCode() { - return Objects.hashCode(value); - } - @Override public String toString() { return "@" + value; From 0ddde3caa0a550b01c69598f2896a592496bc5ee Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 08:17:18 +0000 Subject: [PATCH 12/17] refac: update default value Signed-off-by: Otavio Santana --- .../java/org/eclipse/jnosql/communication/DefaultValue.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jnosql-communication/jnosql-communication-core/src/main/java/org/eclipse/jnosql/communication/DefaultValue.java b/jnosql-communication/jnosql-communication-core/src/main/java/org/eclipse/jnosql/communication/DefaultValue.java index 8506298a4..7f8886514 100644 --- a/jnosql-communication/jnosql-communication-core/src/main/java/org/eclipse/jnosql/communication/DefaultValue.java +++ b/jnosql-communication/jnosql-communication-core/src/main/java/org/eclipse/jnosql/communication/DefaultValue.java @@ -66,4 +66,8 @@ public boolean equals(Object o) { return Objects.equals(value, that.get()); } + @Override + public int hashCode() { + return Objects.hashCode(value); + } } From 35a32d185ff58fb7b15ca391f3d6c447289c2148 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 08:21:36 +0000 Subject: [PATCH 13/17] refactor: return oringl code at default funcion Signed-off-by: Otavio Santana --- .../communication/query/DefaultFunction.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultFunction.java b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultFunction.java index 755f0b84c..ef5e79940 100644 --- a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultFunction.java +++ b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultFunction.java @@ -12,9 +12,33 @@ package org.eclipse.jnosql.communication.query; +import java.util.Arrays; +import java.util.Objects; record DefaultFunction(String name, Object[] params) implements Function { + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof DefaultFunction that)) { + return false; + } + return Objects.equals(name, that.name) && + Arrays.equals(params, that.params); + } + + @Override + public int hashCode() { + return 31 * Objects.hashCode(name) + Arrays.hashCode(params); + } + + @Override + public String toString() { + return name + "(" + Arrays.toString(params) + ")"; + } + static Function of(String name, Object[] args) { return new DefaultFunction(name, args); } From 13ae97d2e4c68f10dfaa2fb582138b9ef16dcdc8 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 08:23:44 +0000 Subject: [PATCH 14/17] refact: default array query value Signed-off-by: Otavio Santana --- .../query/DefaultArrayQueryValue.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultArrayQueryValue.java b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultArrayQueryValue.java index ce91f4959..7a9f4284a 100644 --- a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultArrayQueryValue.java +++ b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/DefaultArrayQueryValue.java @@ -12,6 +12,7 @@ package org.eclipse.jnosql.communication.query; +import java.util.Arrays; /** * A sequence of elements that can be either {@link NumberQueryValue} or {@link StringQueryValue} @@ -19,11 +20,33 @@ record DefaultArrayQueryValue(QueryValue[] values) implements ArrayQueryValue { + @Override public QueryValue[] get() { return values; } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof DefaultArrayQueryValue that)) { + return false; + } + return Arrays.equals(values, that.values); + } + + @Override + public int hashCode() { + return Arrays.hashCode(values); + } + + @Override + public String toString() { + return Arrays.toString(values); + } + static DefaultArrayQueryValue of(QueryValue[] values) { return new DefaultArrayQueryValue(values); } From 5dc15459ce09c017c7597e82ec7cdaeceb8b72e0 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 08:38:19 +0000 Subject: [PATCH 15/17] refactor: update condition Signed-off-by: Otavio Santana --- .../column/DefaultColumnQuery.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnQuery.java b/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnQuery.java index 962957323..393fd0336 100644 --- a/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnQuery.java +++ b/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnQuery.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Optional; import static java.util.Collections.unmodifiableList; @@ -50,6 +51,28 @@ public List sorts() { return unmodifiableList(sorts); } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ColumnQuery that)) { + return false; + } + return limit == that.limit() && + skip == that.skip() && + Objects.equals(name, that.name()) && + Objects.equals(columns, that.columns()) && + Objects.equals(sorts, that.sorts()) && + Objects.equals(columnCondition, that.condition().orElse(null)); + } + + @Override + public int hashCode() { + return Objects.hash(limit, skip, name, columns, sorts, columnCondition); + } + + static ColumnQuery countBy(ColumnQuery query) { return new DefaultColumnQuery(0, 0, query.name(), query.columns(), Collections.emptyList(), query.condition().orElse(null)); From 6050942a585e3627a68e7202cac1b4f7c5a98e08 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 08:39:36 +0000 Subject: [PATCH 16/17] refactor: update document query Signed-off-by: Otavio Santana --- .../document/DefaultDocumentQuery.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentQuery.java b/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentQuery.java index 561f35c64..0aafdebf3 100644 --- a/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentQuery.java +++ b/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentQuery.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Optional; import static java.util.Collections.unmodifiableList; @@ -46,6 +47,28 @@ public List documents() { return unmodifiableList(documents); } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof DocumentQuery that)) { + return false; + } + return limit == that.limit() && + skip == that.skip() && + Objects.equals(name, that.name()) && + Objects.equals(documentCondition, that.condition().orElse(null)) && + Objects.equals(sorts, that.sorts()) && + Objects.equals(documents, that.documents()); + } + + @Override + public int hashCode() { + return Objects.hash(limit, skip, name, documentCondition, sorts, documents); + } + + static DocumentQuery countBy(DocumentQuery query) { return new DefaultDocumentQuery(0, 0, query.name(), query.documents(), Collections.emptyList(), query.condition().orElse(null)); From 73b7098ddebc45ba6025b54fec08e8bdbe53243e Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 11 Nov 2023 09:28:33 +0000 Subject: [PATCH 17/17] refactor: return equals and hascode from delete query Signed-off-by: Otavio Santana --- .../column/DefaultColumnDeleteQuery.java | 27 ++++++++++++++----- .../document/DefaultDocumentDeleteQuery.java | 20 ++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQuery.java b/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQuery.java index 3c14b3fb1..b27d17549 100644 --- a/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQuery.java +++ b/jnosql-communication/jnosql-communication-column/src/main/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQuery.java @@ -19,6 +19,7 @@ import java.util.List; +import java.util.Objects; import java.util.Optional; import static java.util.Collections.unmodifiableList; @@ -27,15 +28,10 @@ /** * The default implementation of {@link ColumnDeleteQuery} */ -record DefaultColumnDeleteQuery(String columnFamily, ColumnCondition columnCondition, List columns) +record DefaultColumnDeleteQuery(String name, ColumnCondition columnCondition, List columns) implements ColumnDeleteQuery { - @Override - public String name() { - return columnFamily; - } - @Override public Optional condition() { return ofNullable(columnCondition); @@ -46,4 +42,23 @@ public List columns() { return unmodifiableList(columns); } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ColumnDeleteQuery that)) { + return false; + } + return Objects.equals(name, that.name()) && + Objects.equals(columnCondition, that.condition().orElse(null)) && + Objects.equals(columns, that.columns()); + } + + @Override + public int hashCode() { + return Objects.hash(name, columnCondition, columns); + } + + } diff --git a/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentDeleteQuery.java b/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentDeleteQuery.java index bf5981a4e..d5ec7bf80 100644 --- a/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentDeleteQuery.java +++ b/jnosql-communication/jnosql-communication-document/src/main/java/org/eclipse/jnosql/communication/document/DefaultDocumentDeleteQuery.java @@ -19,6 +19,7 @@ import java.util.List; +import java.util.Objects; import java.util.Optional; import static java.util.Collections.unmodifiableList; @@ -40,4 +41,23 @@ public Optional condition() { public List documents() { return unmodifiableList(documents); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof DocumentDeleteQuery that)) { + return false; + } + return Objects.equals(name, that.name()) && + Objects.equals(documentCondition, that.condition().orElse(null)) && + Objects.equals(documents, that.documents()); + } + + @Override + public int hashCode() { + return Objects.hash(name, documentCondition, documents); + } + }