Skip to content

Commit 31045db

Browse files
authored
Merge pull request #145 from eclipse/NOSQL-20
Support for iterables
2 parents 732d271 + 122cf1c commit 31045db

File tree

76 files changed

+538
-548
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+538
-548
lines changed

arangodb-driver/src/main/java/org/jnosql/diana/arangodb/document/ArangoDBDocumentCollectionManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import jakarta.nosql.document.DocumentCollectionManager;
1818
import jakarta.nosql.document.DocumentEntity;
1919

20-
import java.util.List;
2120
import java.util.Map;
21+
import java.util.stream.Stream;
2222

2323
/**
2424
* The ArangoDB implementation of {@link DocumentCollectionManager} it does not support to TTL methods:
@@ -35,7 +35,7 @@ public interface ArangoDBDocumentCollectionManager extends DocumentCollectionMan
3535
* @return the query result
3636
* @throws NullPointerException when either query or values are null
3737
*/
38-
List<DocumentEntity> aql(String query, Map<String, Object> values);
38+
Stream<DocumentEntity> aql(String query, Map<String, Object> values);
3939

4040
/**
4141
* Executes ArangoDB query language, AQL.
@@ -48,7 +48,7 @@ public interface ArangoDBDocumentCollectionManager extends DocumentCollectionMan
4848
* @return the query result
4949
* @throws NullPointerException when either query or values are null
5050
*/
51-
<T> List<T> aql(String query, Map<String, Object> values, Class<T> typeClass);
51+
<T> Stream<T> aql(String query, Map<String, Object> values, Class<T> typeClass);
5252

5353
/**
5454
* Executes ArangoDB query language, AQL.
@@ -60,5 +60,5 @@ public interface ArangoDBDocumentCollectionManager extends DocumentCollectionMan
6060
* @return the query result
6161
* @throws NullPointerException when either query or values are null
6262
*/
63-
<T> List<T> aql(String query, Class<T> typeClass);
63+
<T> Stream<T> aql(String query, Class<T> typeClass);
6464
}

arangodb-driver/src/main/java/org/jnosql/diana/arangodb/document/ArangoDBDocumentCollectionManagerAsync.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import jakarta.nosql.document.DocumentCollectionManagerAsync;
2020
import jakarta.nosql.document.DocumentEntity;
2121

22-
import java.util.List;
2322
import java.util.Map;
2423
import java.util.function.Consumer;
24+
import java.util.stream.Stream;
2525

2626
/**
2727
* The ArandoDB implementation of {@link DocumentCollectionManagerAsync}. It does not support to TTL methods:
@@ -42,7 +42,7 @@ public interface ArangoDBDocumentCollectionManagerAsync extends DocumentCollecti
4242
* @throws UnsupportedOperationException when the database does not support this feature
4343
* @throws NullPointerException when either select or callback are null
4444
*/
45-
void aql(String query, Map<String, Object> values, Consumer<List<DocumentEntity>> callBack) throws
45+
void aql(String query, Map<String, Object> values, Consumer<Stream<DocumentEntity>> callBack) throws
4646
ExecuteAsyncQueryException, UnsupportedOperationException, NullPointerException;
4747

4848

arangodb-driver/src/main/java/org/jnosql/diana/arangodb/document/DefaultArangoDBDocumentCollectionManager.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@
2828
import org.jnosql.diana.writer.ValueWriterDecorator;
2929

3030
import java.time.Duration;
31-
import java.util.List;
3231
import java.util.Map;
3332
import java.util.Objects;
3433
import java.util.Optional;
3534
import java.util.stream.Collectors;
35+
import java.util.stream.Stream;
3636
import java.util.stream.StreamSupport;
3737

3838
import static java.util.Collections.emptyMap;
3939
import static java.util.Objects.requireNonNull;
40-
import static java.util.stream.Collectors.toList;
4140
import static org.jnosql.diana.arangodb.document.ArangoDBUtil.getBaseDocument;
4241

4342
class DefaultArangoDBDocumentCollectionManager implements ArangoDBDocumentCollectionManager {
@@ -100,16 +99,15 @@ public void delete(DocumentDeleteQuery query) {
10099
}
101100

102101
@Override
103-
public List<DocumentEntity> select(DocumentQuery query) throws NullPointerException {
102+
public Stream<DocumentEntity> select(DocumentQuery query) throws NullPointerException {
104103
requireNonNull(query, "query is required");
105104

106105
AQLQueryResult result = QueryAQLConverter.select(query);
107106
ArangoCursor<BaseDocument> documents = arangoDB.db(database).query(result.getQuery(),
108107
result.getValues(), null, BaseDocument.class);
109108

110109
return StreamSupport.stream(documents.spliterator(), false)
111-
.map(ArangoDBUtil::toEntity)
112-
.collect(toList());
110+
.map(ArangoDBUtil::toEntity);
113111
}
114112

115113
@Override
@@ -122,31 +120,30 @@ public long count(String documentCollection) {
122120

123121

124122
@Override
125-
public List<DocumentEntity> aql(String query, Map<String, Object> values) throws NullPointerException {
123+
public Stream<DocumentEntity> aql(String query, Map<String, Object> values) throws NullPointerException {
126124
requireNonNull(query, "query is required");
127125
requireNonNull(values, "values is required");
128126
ArangoCursor<BaseDocument> result = arangoDB.db(database).query(query, values, null, BaseDocument.class);
129127
return StreamSupport.stream(result.spliterator(), false)
130-
.map(ArangoDBUtil::toEntity)
131-
.collect(toList());
128+
.map(ArangoDBUtil::toEntity);
132129

133130
}
134131

135132
@Override
136-
public <T> List<T> aql(String query, Map<String, Object> values, Class<T> typeClass) {
133+
public <T> Stream<T> aql(String query, Map<String, Object> values, Class<T> typeClass) {
137134
requireNonNull(query, "query is required");
138135
requireNonNull(values, "values is required");
139136
requireNonNull(typeClass, "typeClass is required");
140137
ArangoCursor<T> result = arangoDB.db(database).query(query, values, null, typeClass);
141-
return result.asListRemaining();
138+
return StreamSupport.stream(result.spliterator(), false);
142139
}
143140

144141
@Override
145-
public <T> List<T> aql(String query, Class<T> typeClass) {
142+
public <T> Stream<T> aql(String query, Class<T> typeClass) {
146143
requireNonNull(query, "query is required");
147144
requireNonNull(typeClass, "typeClass is required");
148145
ArangoCursor<T> result = arangoDB.db(database).query(query, emptyMap(), null, typeClass);
149-
return result.asListRemaining();
146+
return StreamSupport.stream(result.spliterator(), false);
150147
}
151148

152149

arangodb-driver/src/main/java/org/jnosql/diana/arangodb/document/DefaultArangoDBDocumentCollectionManagerAsync.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@
2828

2929
import java.time.Duration;
3030
import java.util.Collections;
31-
import java.util.List;
3231
import java.util.Map;
3332
import java.util.Objects;
3433
import java.util.concurrent.CompletableFuture;
3534
import java.util.function.Consumer;
35+
import java.util.stream.Stream;
3636
import java.util.stream.StreamSupport;
3737

3838
import static java.util.Objects.requireNonNull;
39-
import static java.util.stream.Collectors.toList;
4039
import static org.jnosql.diana.arangodb.document.ArangoDBUtil.ID;
4140
import static org.jnosql.diana.arangodb.document.ArangoDBUtil.KEY;
4241
import static org.jnosql.diana.arangodb.document.ArangoDBUtil.REV;
@@ -148,9 +147,8 @@ public void delete(DocumentDeleteQuery query, Consumer<Void> callBack)
148147
future.thenAccept(c -> callBack.accept(null));
149148
}
150149

151-
152150
@Override
153-
public void select(DocumentQuery query, Consumer<List<DocumentEntity>> callBack)
151+
public void select(DocumentQuery query, Consumer<Stream<DocumentEntity>> callBack)
154152
throws ExecuteAsyncQueryException, UnsupportedOperationException {
155153

156154
requireNonNull(query, "query is required");
@@ -176,7 +174,7 @@ public void count(String documentCollection, Consumer<Long> callback) {
176174
}
177175

178176
@Override
179-
public void aql(String query, Map<String, Object> values, Consumer<List<DocumentEntity>> callBack)
177+
public void aql(String query, Map<String, Object> values, Consumer<Stream<DocumentEntity>> callBack)
180178
throws ExecuteAsyncQueryException,
181179
UnsupportedOperationException, NullPointerException {
182180

@@ -188,12 +186,12 @@ public void aql(String query, Map<String, Object> values, Consumer<List<Document
188186

189187
}
190188

191-
private void runAql(String query, Map<String, Object> values, Consumer<List<DocumentEntity>> callBack) {
189+
private void runAql(String query, Map<String, Object> values, Consumer<Stream<DocumentEntity>> callBack) {
192190
CompletableFuture<ArangoCursorAsync<BaseDocument>> future = arangoDBAsync.db(database).query(query,
193191
values, null, BaseDocument.class);
194192

195193
future.thenAccept(b -> {
196-
List<DocumentEntity> entities = StreamSupport.stream(b.spliterator(), false).map(ArangoDBUtil::toEntity).collect(toList());
194+
Stream<DocumentEntity> entities = StreamSupport.stream(b.spliterator(), false).map(ArangoDBUtil::toEntity);
197195
callBack.accept(entities);
198196
});
199197
}

arangodb-driver/src/test/java/org/jnosql/diana/arangodb/document/ArangoDBDocumentCollectionManagerAsyncTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.util.concurrent.atomic.AtomicLong;
3232
import java.util.concurrent.atomic.AtomicReference;
3333
import java.util.function.Consumer;
34+
import java.util.stream.Collectors;
35+
import java.util.stream.Stream;
3436

3537
import static jakarta.nosql.document.DocumentDeleteQuery.delete;
3638
import static jakarta.nosql.document.DocumentQuery.select;
@@ -108,14 +110,14 @@ public void shouldSelect() {
108110
Document key = entity1.find("_key").get();
109111

110112
condition.set(false);
111-
AtomicReference<List<DocumentEntity>> references = new AtomicReference<>();
113+
AtomicReference<Stream<DocumentEntity>> references = new AtomicReference<>();
112114
entityManagerAsync.select(select().from(entity1.getName()).where("_key").eq(key.get()).build(), l -> {
113115
condition.set(true);
114116
references.set(l);
115117
});
116118
await().untilTrue(condition);
117119

118-
List<DocumentEntity> entities = references.get();
120+
List<DocumentEntity> entities = references.get().collect(Collectors.toList());
119121
assertFalse(entities.isEmpty());
120122
}
121123

@@ -137,14 +139,14 @@ public void shouldRunAQL() {
137139
Document key = entity1.find("_key").get();
138140

139141
condition.set(false);
140-
AtomicReference<List<DocumentEntity>> references = new AtomicReference<>();
142+
AtomicReference<Stream<DocumentEntity>> references = new AtomicReference<>();
141143
entityManagerAsync.aql("FOR p IN person FILTER p._key == @key RETURN p", Collections.singletonMap("key", key.get()), l -> {
142144
condition.set(true);
143145
references.set(l);
144146
});
145147

146148
await().untilTrue(condition);
147-
List<DocumentEntity> entities = references.get();
149+
List<DocumentEntity> entities = references.get().collect(Collectors.toList());
148150
assertFalse(entities.isEmpty());
149151
}
150152

arangodb-driver/src/test/java/org/jnosql/diana/arangodb/document/ArangoDBDocumentCollectionManagerTest.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
import java.util.List;
3333
import java.util.Map;
3434
import java.util.Random;
35+
import java.util.stream.Collectors;
3536

37+
import static jakarta.nosql.document.DocumentDeleteQuery.delete;
38+
import static jakarta.nosql.document.DocumentQuery.select;
3639
import static java.util.Arrays.asList;
3740
import static java.util.Collections.singletonMap;
3841
import static org.hamcrest.MatcherAssert.assertThat;
3942
import static org.hamcrest.Matchers.contains;
4043
import static org.hamcrest.Matchers.containsInAnyOrder;
41-
import static jakarta.nosql.document.DocumentDeleteQuery.delete;
42-
import static jakarta.nosql.document.DocumentQuery.select;
4344
import static org.jnosql.diana.arangodb.document.ArangoDBDocumentCollectionManagerFactorySupplier.INSTANCE;
4445
import static org.junit.jupiter.api.Assertions.assertEquals;
4546
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -91,7 +92,7 @@ public void shouldRemoveEntity() {
9192
DocumentQuery select = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
9293
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
9394
entityManager.delete(deleteQuery);
94-
assertTrue(entityManager.select(select).isEmpty());
95+
assertTrue(entityManager.select(select).collect(Collectors.toList()).isEmpty());
9596
}
9697

9798
@Test
@@ -101,7 +102,7 @@ public void shouldRemoveEntity2() {
101102
DocumentQuery select = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
102103
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
103104
entityManager.delete(deleteQuery);
104-
assertTrue(entityManager.select(select).isEmpty());
105+
assertTrue(entityManager.select(select).collect(Collectors.toList()).isEmpty());
105106
}
106107

107108

@@ -110,7 +111,7 @@ public void shouldFindDocument() {
110111
DocumentEntity entity = entityManager.insert(getEntity());
111112
Document id = entity.find(KEY_NAME).get();
112113
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
113-
List<DocumentEntity> entities = entityManager.select(query);
114+
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
114115
assertFalse(entities.isEmpty());
115116
DocumentEntity documentEntity = entities.get(0);
116117
assertEquals(entity.find(KEY_NAME).get().getValue().get(String.class), documentEntity.find(KEY_NAME).get()
@@ -127,7 +128,7 @@ public void shouldSaveSubDocument() {
127128
DocumentEntity entitySaved = entityManager.insert(entity);
128129
Document id = entitySaved.find(KEY_NAME).get();
129130
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
130-
DocumentEntity entityFound = entityManager.select(query).get(0);
131+
DocumentEntity entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
131132
Document subDocument = entityFound.find("phones").get();
132133
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
133134
});
@@ -141,7 +142,7 @@ public void shouldSaveSubDocument2() {
141142
DocumentEntity entitySaved = entityManager.insert(entity);
142143
Document id = entitySaved.find(KEY_NAME).get();
143144
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
144-
DocumentEntity entityFound = entityManager.select(query).get(0);
145+
DocumentEntity entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
145146
Document subDocument = entityFound.find("phones").get();
146147
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
147148
});
@@ -178,7 +179,7 @@ public void shouldRunAQL() {
178179

179180
String aql = "FOR a IN person FILTER a.name == @name RETURN a";
180181
List<DocumentEntity> entities = entityManager.aql(aql,
181-
singletonMap("name", "Poliana"));
182+
singletonMap("name", "Poliana")).collect(Collectors.toList());
182183
assertNotNull(entities);
183184
}
184185

@@ -197,7 +198,7 @@ public void shouldReadFromDifferentBaseDocumentUsingInstance() {
197198
ArangoDB arangoDB = DefaultArangoDBDocumentCollectionManager.class.cast(entityManager).getArangoDB();
198199
arangoDB.db(DATABASE).collection(COLLECTION_NAME).insertDocument(new Person());
199200
DocumentQuery select = select().from(COLLECTION_NAME).build();
200-
List<DocumentEntity> entities = entityManager.select(select);
201+
List<DocumentEntity> entities = entityManager.select(select).collect(Collectors.toList());
201202
assertFalse(entities.isEmpty());
202203
}
203204

@@ -210,7 +211,7 @@ public void shouldReadFromDifferentBaseDocumentUsingMap() {
210211
map.put("city", "Salvador");
211212
arangoDB.db(DATABASE).collection(COLLECTION_NAME).insertDocument(map);
212213
DocumentQuery select = select().from(COLLECTION_NAME).build();
213-
List<DocumentEntity> entities = entityManager.select(select);
214+
List<DocumentEntity> entities = entityManager.select(select).collect(Collectors.toList());
214215
assertFalse(entities.isEmpty());
215216
}
216217

@@ -219,7 +220,7 @@ public void shouldExecuteAQLWithTypeParams() {
219220
entityManager.insert(getEntity());
220221
String aql = "FOR a IN person FILTER a.name == @name RETURN a";
221222
List<String> entities = entityManager.aql(aql,
222-
singletonMap("name", "Poliana"), String.class);
223+
singletonMap("name", "Poliana"), String.class).collect(Collectors.toList());
223224

224225
assertFalse(entities.isEmpty());
225226
}
@@ -228,7 +229,7 @@ public void shouldExecuteAQLWithTypeParams() {
228229
public void shouldExecuteAQLWithType() {
229230
entityManager.insert(getEntity());
230231
String aql = "FOR a IN person RETURN a";
231-
List<String> entities = entityManager.aql(aql, String.class);
232+
List<String> entities = entityManager.aql(aql, String.class).collect(Collectors.toList());
232233
assertFalse(entities.isEmpty());
233234
}
234235

cassandra-driver/src/main/java/org/jnosql/diana/cassandra/column/CassandraColumnFamilyManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import jakarta.nosql.column.ColumnQuery;
2525

2626
import java.time.Duration;
27-
import java.util.List;
2827
import java.util.Map;
28+
import java.util.stream.Stream;
2929

3030
/**
3131
* The Cassandra implementation of {@link ColumnFamilyManager}, that supports all methods and also supports
@@ -99,7 +99,7 @@ public interface CassandraColumnFamilyManager extends ColumnFamilyManager {
9999
* @return the query using a consistency level
100100
* @throws NullPointerException when either query or level are null
101101
*/
102-
List<ColumnEntity> select(ColumnQuery query, ConsistencyLevel level) throws NullPointerException;
102+
Stream<ColumnEntity> select(ColumnQuery query, ConsistencyLevel level) throws NullPointerException;
103103

104104
/**
105105
* Executes CQL
@@ -108,7 +108,7 @@ public interface CassandraColumnFamilyManager extends ColumnFamilyManager {
108108
* @return the result of this query
109109
* @throws NullPointerException when query is null
110110
*/
111-
List<ColumnEntity> cql(String query) throws NullPointerException;
111+
Stream<ColumnEntity> cql(String query) throws NullPointerException;
112112

113113

114114
/**
@@ -120,7 +120,7 @@ public interface CassandraColumnFamilyManager extends ColumnFamilyManager {
120120
* @return the result of this query
121121
* @throws NullPointerException when either query or values are null
122122
*/
123-
List<ColumnEntity> cql(String query, Map<String, Object> values) throws NullPointerException;
123+
Stream<ColumnEntity> cql(String query, Map<String, Object> values) throws NullPointerException;
124124

125125
/**
126126
* Executes a statement
@@ -129,7 +129,7 @@ public interface CassandraColumnFamilyManager extends ColumnFamilyManager {
129129
* @return the result of this query
130130
* @throws NullPointerException when statement is null
131131
*/
132-
List<ColumnEntity> execute(Statement statement) throws NullPointerException;
132+
Stream<ColumnEntity> execute(Statement statement) throws NullPointerException;
133133

134134
/**
135135
* Executes an query and uses as {@link CassandraPrepareStatment}

0 commit comments

Comments
 (0)