diff --git a/.gitignore b/.gitignore index 615baf86..55a578ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Compiled class file *.class +src/main/resources/* # Log file *.log diff --git a/src/main/java/com/fauna/query/builder/QueryArr.java b/src/main/java/com/fauna/query/builder/QueryArr.java index 6ccc3e89..bf666d64 100644 --- a/src/main/java/com/fauna/query/builder/QueryArr.java +++ b/src/main/java/com/fauna/query/builder/QueryArr.java @@ -1,10 +1,5 @@ package com.fauna.query.builder; -import com.fauna.codec.Codec; -import com.fauna.codec.CodecProvider; -import com.fauna.codec.UTF8FaunaGenerator; - -import java.io.IOException; import java.util.List; import java.util.Objects; @@ -12,19 +7,19 @@ * Represents a value fragment of a Fauna query. * This class encapsulates a value that can be a variable in the query. */ -public class QueryArr extends QueryFragment { - public static QueryArr of(T val) { - return new QueryArr<>(val); +public class QueryArr extends QueryFragment> { + public static QueryArr of(List val) { + return new QueryArr(val); } - private final T value; + private final List value; /** * Constructs a ValueFragment with the specified value. * - * @param value the value to encapsulate, which can be any object. + * @param value the value to encapsulate. */ - public QueryArr(T value) { + public QueryArr(List value) { this.value = value; } @@ -34,7 +29,7 @@ public QueryArr(T value) { * @return the encapsulated object. */ @Override - public T get() { + public List get() { return value; } @@ -43,7 +38,7 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - QueryArr that = (QueryArr) o; + QueryArr that = (QueryArr) o; return Objects.equals(value, that.value); } diff --git a/src/main/java/com/fauna/query/builder/QueryObj.java b/src/main/java/com/fauna/query/builder/QueryObj.java index fd8677b7..11de7c2b 100644 --- a/src/main/java/com/fauna/query/builder/QueryObj.java +++ b/src/main/java/com/fauna/query/builder/QueryObj.java @@ -1,30 +1,26 @@ package com.fauna.query.builder; -import com.fauna.codec.Codec; -import com.fauna.codec.CodecProvider; -import com.fauna.codec.UTF8FaunaGenerator; - -import java.io.IOException; +import java.util.Map; import java.util.Objects; /** * Represents an object fragment of a Fauna query. Object fragments allow for the evaluation of FQL statements * stored on the object. This class encapsulates an object that can be a variable in the query. */ -public class QueryObj extends QueryFragment { +public class QueryObj extends QueryFragment> { - public static QueryObj of(T val) { - return new QueryObj<>(val); + public static QueryObj of(Map val) { + return new QueryObj(val); } - private final T value; + private final Map value; /** * Constructs a QueryObj with the specified value. * - * @param value the value to encapsulate, which can be any object. + * @param value the value to encapsulate. */ - public QueryObj(T value) { + public QueryObj(Map value) { this.value = value; } @@ -34,7 +30,7 @@ public QueryObj(T value) { * @return the encapsulated object. */ @Override - public T get() { + public Map get() { return value; } @@ -43,7 +39,7 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - QueryObj that = (QueryObj) o; + QueryObj that = (QueryObj) o; return Objects.equals(value, that.value); } diff --git a/src/test/java/com/fauna/beans/ClassWithNestedQuery.java b/src/test/java/com/fauna/beans/ClassWithNestedQuery.java deleted file mode 100644 index 8a01a1d7..00000000 --- a/src/test/java/com/fauna/beans/ClassWithNestedQuery.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.fauna.beans; - -import com.fauna.annotation.FaunaField; -import com.fauna.query.builder.Query; - - -public class ClassWithNestedQuery { - - @FaunaField(name = "result") - private Query query; - - public ClassWithNestedQuery(Query q) { - query = q; - } - - public Query getQuery() { - return query; - } -} diff --git a/src/test/java/com/fauna/e2e/E2EQueryObjTest.java b/src/test/java/com/fauna/e2e/E2EQueryObjTest.java index 3ee1ad35..30e20cac 100644 --- a/src/test/java/com/fauna/e2e/E2EQueryObjTest.java +++ b/src/test/java/com/fauna/e2e/E2EQueryObjTest.java @@ -1,10 +1,11 @@ package com.fauna.e2e; -import com.fauna.beans.ClassWithNestedQuery; import com.fauna.client.Fauna; import com.fauna.client.FaunaClient; import com.fauna.query.builder.Query; +import com.fauna.query.builder.QueryFragment; import com.fauna.query.builder.QueryObj; +import com.fauna.query.builder.QueryVal; import com.fauna.response.QuerySuccess; import org.junit.jupiter.api.Test; @@ -20,7 +21,7 @@ public class E2EQueryObjTest { @Test public void query_mapWithEmbeddedQuery() { Query subq = fql("4 + 2"); - Map obj = Map.of("k", subq); + Map obj = Map.of("k", subq); Query q = fql("${obj}", Map.of("obj", QueryObj.of(obj))); QuerySuccess> res = c.query(q, mapOf(Integer.class)); @@ -29,14 +30,14 @@ public void query_mapWithEmbeddedQuery() { } @Test - public void query_classWithEmbeddedQuery() { + public void query_mapMixedWithEmbeddedQuery() { Query subq = fql("4 + 2"); - var obj = new ClassWithNestedQuery(subq); + Map obj = Map.of("k", subq, "k2", new QueryVal<>(42)); Query q = fql("${obj}", Map.of("obj", QueryObj.of(obj))); QuerySuccess> res = c.query(q, mapOf(Integer.class)); - assertEquals(Map.of("result", 6), res.getData()); + assertEquals(Map.of("k", 6, "k2", 42), res.getData()); } @Test