-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from fauna/release-0.1.0-M4
Release 0.1.0-M4.
- Loading branch information
Showing
39 changed files
with
900 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
version=0.1.0-M3 | ||
version=0.1.0-M4 | ||
junitVersion=5.10.0 | ||
mockitoVersion=5.6.0 | ||
jacksonVersion=2.15.3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package com.fauna.client; | ||
|
||
|
||
import com.fauna.exception.FaunaException; | ||
import com.fauna.query.QueryOptions; | ||
import com.fauna.query.builder.Query; | ||
import com.fauna.response.QuerySuccess; | ||
import com.fauna.serialization.generic.PageOf; | ||
import com.fauna.types.Page; | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.NoSuchElementException; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionException; | ||
|
||
import static com.fauna.query.builder.Query.fql; | ||
|
||
/** | ||
* PageIterator iterates over paged responses from Fauna, the default page size is 16. | ||
* @param <E> | ||
*/ | ||
public class PageIterator<E> implements Iterator<Page<E>> { | ||
private static final String PAGINATE_QUERY = "Set.paginate(${after})"; | ||
private final FaunaClient client; | ||
private final QueryOptions options; | ||
private final PageOf<E> pageClass; | ||
private CompletableFuture<QuerySuccess<Page<E>>> queryFuture; | ||
private Page<E> latestResult; | ||
|
||
/** | ||
* Construct a new PageIterator. | ||
* @param client A client that makes requests to Fauna. | ||
* @param fql The FQL query. | ||
* @param resultClass The class of the elements returned from Fauna (i.e. the rows). | ||
* @param options (optionally) pass in QueryOptions. | ||
*/ | ||
public PageIterator(FaunaClient client, Query fql, Class<E> resultClass, QueryOptions options) { | ||
this.client = client; | ||
this.pageClass = new PageOf<>(resultClass); | ||
this.options = options; | ||
// Initial query; | ||
this.queryFuture = client.asyncQuery(fql, this.pageClass, options); | ||
this.latestResult = null; | ||
} | ||
|
||
public PageIterator(FaunaClient client, Page<E> page, Class<E> resultClass, QueryOptions options) { | ||
this.client = client; | ||
this.pageClass = new PageOf<>(resultClass); | ||
this.options = options; | ||
this.queryFuture = null; | ||
this.latestResult = page; | ||
} | ||
|
||
private void completeFuture() { | ||
if (this.queryFuture != null && this.latestResult == null) { | ||
try { | ||
this.latestResult = queryFuture.join().getData(); | ||
} catch (CompletionException e) { | ||
if (e.getCause() != null && e.getCause() instanceof FaunaException) { | ||
throw (FaunaException) e.getCause(); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
this.queryFuture = null; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
completeFuture(); | ||
return this.latestResult != null; | ||
} | ||
|
||
|
||
|
||
/** | ||
* Get the next Page. | ||
* @return The next Page of elements E. | ||
*/ | ||
@Override | ||
public Page<E> next() { | ||
completeFuture(); | ||
if (this.latestResult != null) { | ||
Page<E> page = this.latestResult; | ||
this.latestResult = null; | ||
if (page.after() != null) { | ||
Map<String, Object> args = Map.of("after", page.after()); | ||
this.queryFuture = client.asyncQuery(fql(PAGINATE_QUERY, args), pageClass, options); | ||
} | ||
return page; | ||
} else { | ||
throw new NoSuchElementException(); | ||
} | ||
} | ||
|
||
/** | ||
* Return an iterator that iterates directly over the items that make up the page contents. | ||
* @return An iterator of E. | ||
*/ | ||
public Iterator<E> flatten() { | ||
return new Iterator<>() { | ||
private final PageIterator<E> pageIterator = PageIterator.this; | ||
private Iterator<E> thisPage = pageIterator.hasNext() ? pageIterator.next().data().iterator() : null; | ||
@Override | ||
public boolean hasNext() { | ||
return thisPage != null && (thisPage.hasNext() || pageIterator.hasNext()); | ||
} | ||
|
||
@Override | ||
public E next() { | ||
if (thisPage == null) { | ||
throw new NoSuchElementException(); | ||
} | ||
try { | ||
return thisPage.next(); | ||
} catch (NoSuchElementException e) { | ||
if (pageIterator.hasNext()) { | ||
this.thisPage = pageIterator.next().data().iterator(); | ||
return thisPage.next(); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.fauna.codec; | ||
|
||
import com.fauna.mapping.MappingContext; | ||
import com.fauna.mapping.MappingInfo; | ||
import com.fauna.serialization.UTF8FaunaGenerator; | ||
import com.fauna.serialization.UTF8FaunaParser; | ||
|
||
import java.io.IOException; | ||
|
||
public class ClassCodec<T> implements Codec<T> { | ||
|
||
private final MappingInfo info; | ||
|
||
public ClassCodec(MappingInfo info) { | ||
this.info = info; | ||
} | ||
|
||
@Override | ||
public T decode(UTF8FaunaParser parser) throws IOException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void encode(UTF8FaunaGenerator writer, T obj, MappingContext context) throws IOException { | ||
|
||
} | ||
|
||
@Override | ||
public Class<T> getCodecClass() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.fauna.codec; | ||
|
||
import com.fauna.mapping.MappingContext; | ||
import com.fauna.serialization.UTF8FaunaGenerator; | ||
import com.fauna.serialization.UTF8FaunaParser; | ||
|
||
import java.io.IOException; | ||
|
||
|
||
public interface Codec<T> { | ||
|
||
T decode(UTF8FaunaParser parser) throws IOException; | ||
|
||
void encode(UTF8FaunaGenerator gen, T obj, MappingContext context) throws IOException; | ||
|
||
Class<T> getCodecClass(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.fauna.codec; | ||
|
||
public interface CodecProvider { | ||
<T> Codec<T> get(CodecRegistry registry, Class<T> clazz); | ||
<T,K> Codec<T> get(CodecRegistry registry, Class<T> clazz, Class<K> subClazz); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.fauna.codec; | ||
|
||
public interface CodecRegistry { | ||
|
||
<T> Codec<T> get(CodecRegistryKey key); | ||
<T> void add(CodecRegistryKey key, Codec<T> codec); | ||
boolean contains(CodecRegistryKey key); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.fauna.codec; | ||
|
||
public class CodecRegistryKey { | ||
private final Class<?> base; | ||
private final Class<?> subtype; | ||
public <T> CodecRegistryKey(Class<?> clazz, Class<?> subtype) { | ||
base = clazz; | ||
this.subtype = subtype; | ||
} | ||
|
||
public static <T> CodecRegistryKey from(Class<?> clazz, Class<?> subtype) { | ||
return new CodecRegistryKey(clazz, subtype); | ||
} | ||
|
||
// TODO: Override equals/hash | ||
} |
Oops, something went wrong.