Skip to content

Commit 9c9bdc1

Browse files
committed
Makes couchbase async interface
1 parent a8a9222 commit 9c9bdc1

File tree

1 file changed

+8
-101
lines changed

1 file changed

+8
-101
lines changed

couchbase-driver/src/main/java/org/jnosql/diana/couchbase/document/CouchbaseDocumentCollectionManagerAsync.java

Lines changed: 8 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -19,90 +19,15 @@
1919
import com.couchbase.client.java.query.Statement;
2020
import org.jnosql.diana.api.ExecuteAsyncQueryException;
2121
import org.jnosql.diana.api.document.DocumentCollectionManagerAsync;
22-
import org.jnosql.diana.api.document.DocumentDeleteQuery;
2322
import org.jnosql.diana.api.document.DocumentEntity;
24-
import org.jnosql.diana.api.document.DocumentQuery;
25-
import rx.functions.Action1;
2623

27-
import java.time.Duration;
2824
import java.util.List;
2925
import java.util.function.Consumer;
3026

31-
import static java.util.Objects.requireNonNull;
32-
import static rx.Observable.just;
33-
34-
public class CouchbaseDocumentCollectionManagerAsync implements DocumentCollectionManagerAsync {
35-
36-
private static final Consumer<DocumentEntity> NOOP = d -> {
37-
};
38-
private static final Action1<Throwable> ERROR_SAVE = a -> new ExecuteAsyncQueryException("On error when try to execute couchbase save method");
39-
private static final Action1<Throwable> ERROR_FIND = a -> new ExecuteAsyncQueryException("On error when try to execute couchbase find method");
40-
private static final Action1<Throwable> ERROR_DELETE = a -> new ExecuteAsyncQueryException("On error when try to execute couchbase delete method");
41-
private static final Action1<Throwable> ERROR_N1QLQUERY = a -> new ExecuteAsyncQueryException("On error when try to execute couchbase n1qlQuery method");
42-
43-
private final CouchbaseDocumentCollectionManager manager;
44-
45-
CouchbaseDocumentCollectionManagerAsync(CouchbaseDocumentCollectionManager manager) {
46-
this.manager = manager;
47-
}
48-
49-
50-
@Override
51-
public void insert(DocumentEntity entity) throws ExecuteAsyncQueryException, UnsupportedOperationException {
52-
insert(entity, NOOP);
53-
}
54-
55-
@Override
56-
public void insert(DocumentEntity entity, Duration ttl) throws ExecuteAsyncQueryException, UnsupportedOperationException {
57-
insert(entity, ttl, NOOP);
58-
}
59-
60-
@Override
61-
public void insert(DocumentEntity entity, Consumer<DocumentEntity> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
62-
requireNonNull(callBack, "callBack is required");
63-
just(entity)
64-
.map(manager::insert)
65-
.subscribe(callBack::accept, ERROR_SAVE);
66-
}
67-
68-
@Override
69-
public void insert(DocumentEntity entity, Duration ttl, Consumer<DocumentEntity> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
70-
requireNonNull(callBack, "callBack is required");
71-
just(entity)
72-
.map(e -> manager.insert(e, ttl))
73-
.subscribe(callBack::accept, ERROR_SAVE);
74-
}
75-
76-
@Override
77-
public void update(DocumentEntity entity) throws ExecuteAsyncQueryException, UnsupportedOperationException {
78-
insert(entity);
79-
}
80-
81-
@Override
82-
public void update(DocumentEntity entity, Consumer<DocumentEntity> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
83-
insert(entity, callBack);
84-
}
85-
86-
@Override
87-
public void delete(DocumentDeleteQuery query) throws ExecuteAsyncQueryException, UnsupportedOperationException {
88-
delete(query, v -> {
89-
});
90-
}
91-
92-
@Override
93-
public void delete(DocumentDeleteQuery query, Consumer<Void> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
94-
requireNonNull(query, "query is required");
95-
requireNonNull(callBack, "callBack is required");
96-
just(query).map(q -> {
97-
manager.delete(q);
98-
return true;
99-
}).subscribe(a -> callBack.accept(null), ERROR_DELETE);
100-
}
101-
102-
@Override
103-
public void select(DocumentQuery query, Consumer<List<DocumentEntity>> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
104-
just(query).map(manager::select).subscribe(callBack::accept, ERROR_FIND);
105-
}
27+
/**
28+
* The Couchbase interface of {@link DocumentCollectionManagerAsync}
29+
*/
30+
public interface CouchbaseDocumentCollectionManagerAsync extends DocumentCollectionManagerAsync {
10631

10732

10833
/**
@@ -114,11 +39,7 @@ public void select(DocumentQuery query, Consumer<List<DocumentEntity>> callBack)
11439
* @throws NullPointerException when either n1qlQuery or params are null
11540
* @throws ExecuteAsyncQueryException an async error
11641
*/
117-
public void n1qlQuery(String n1qlQuery, JsonObject params, Consumer<List<DocumentEntity>> callback) throws NullPointerException, ExecuteAsyncQueryException {
118-
requireNonNull(callback, "callback is required");
119-
just(n1qlQuery).map(n -> manager.n1qlQuery(n, params))
120-
.subscribe(callback::accept, ERROR_N1QLQUERY);
121-
}
42+
void n1qlQuery(String n1qlQuery, JsonObject params, Consumer<List<DocumentEntity>> callback) throws NullPointerException, ExecuteAsyncQueryException;
12243

12344
/**
12445
* Executes the n1qlquery with params and then result que result
@@ -129,11 +50,7 @@ public void n1qlQuery(String n1qlQuery, JsonObject params, Consumer<List<Documen
12950
* @throws NullPointerException when either n1qlQuery or params are null
13051
* @throws ExecuteAsyncQueryException an async error
13152
*/
132-
public void n1qlQuery(Statement n1qlQuery, JsonObject params, Consumer<List<DocumentEntity>> callback) throws NullPointerException, ExecuteAsyncQueryException {
133-
requireNonNull(callback, "callback is required");
134-
just(n1qlQuery).map(n -> manager.n1qlQuery(n, params))
135-
.subscribe(callback::accept, ERROR_N1QLQUERY);
136-
}
53+
void n1qlQuery(Statement n1qlQuery, JsonObject params, Consumer<List<DocumentEntity>> callback) throws NullPointerException, ExecuteAsyncQueryException;
13754

13855
/**
13956
* Executes the n1qlquery plain query and then result que result
@@ -143,10 +60,7 @@ public void n1qlQuery(Statement n1qlQuery, JsonObject params, Consumer<List<Docu
14360
* @throws NullPointerException when either n1qlQuery or params are null
14461
* @throws ExecuteAsyncQueryException an async error
14562
*/
146-
public void n1qlQuery(String n1qlQuery, Consumer<List<DocumentEntity>> callback) throws NullPointerException, ExecuteAsyncQueryException {
147-
requireNonNull(callback, "callback is required");
148-
just(n1qlQuery).map(manager::n1qlQuery).subscribe(callback::accept, ERROR_N1QLQUERY);
149-
}
63+
void n1qlQuery(String n1qlQuery, Consumer<List<DocumentEntity>> callback) throws NullPointerException, ExecuteAsyncQueryException;
15064

15165
/**
15266
* Executes the n1qlquery plain query and then result que result
@@ -156,13 +70,6 @@ public void n1qlQuery(String n1qlQuery, Consumer<List<DocumentEntity>> callback)
15670
* @throws NullPointerException when either n1qlQuery or params are null
15771
* @throws ExecuteAsyncQueryException an async error
15872
*/
159-
public void n1qlQuery(Statement n1qlQuery, Consumer<List<DocumentEntity>> callback) throws NullPointerException, ExecuteAsyncQueryException {
160-
requireNonNull(callback, "callback is required");
161-
just(n1qlQuery).map(manager::n1qlQuery).subscribe(callback::accept, ERROR_N1QLQUERY);
162-
}
73+
void n1qlQuery(Statement n1qlQuery, Consumer<List<DocumentEntity>> callback) throws NullPointerException, ExecuteAsyncQueryException;
16374

164-
@Override
165-
public void close() {
166-
manager.close();
167-
}
16875
}

0 commit comments

Comments
 (0)