Skip to content

Commit 3db00da

Browse files
committed
Makes orientdb async interface
1 parent 2b18df2 commit 3db00da

File tree

1 file changed

+12
-98
lines changed

1 file changed

+12
-98
lines changed

orientdb-driver/src/main/java/org/jnosql/diana/orientdb/document/OrientDBDocumentCollectionManagerAsync.java

Lines changed: 12 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -44,102 +44,16 @@
4444
* Also has supports to query:
4545
* <p>{@link OrientDBDocumentCollectionManagerAsync#find(String, Consumer, Object...)}</p>
4646
*/
47-
public class OrientDBDocumentCollectionManagerAsync implements DocumentCollectionManagerAsync {
48-
49-
private static final Consumer<DocumentEntity> NOOPS = d -> {
50-
};
51-
52-
53-
private final OPartitionedDatabasePool pool;
54-
55-
OrientDBDocumentCollectionManagerAsync(OPartitionedDatabasePool pool) {
56-
this.pool = pool;
57-
}
58-
59-
@Override
60-
public void insert(DocumentEntity entity, Duration ttl) throws ExecuteAsyncQueryException, UnsupportedOperationException {
61-
throw new UnsupportedOperationException("There is support to ttl on OrientDB");
62-
}
63-
64-
@Override
65-
public void insert(DocumentEntity entity) throws ExecuteAsyncQueryException, UnsupportedOperationException {
66-
insert(entity, NOOPS);
67-
}
68-
69-
@Override
70-
public void insert(DocumentEntity entity, Consumer<DocumentEntity> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
71-
Objects.toString(entity, "Entity is required");
72-
ODatabaseDocumentTx tx = pool.acquire();
73-
ODocument document = new ODocument(entity.getName());
74-
Map<String, Object> entityValues = entity.toMap();
75-
entityValues.keySet().stream().forEach(k -> document.field(k, entityValues.get(k)));
76-
ORecordCallback<Number> createCallBack = (a, b) -> {
77-
entity.add(Document.of(RID_FIELD, a.toString()));
78-
callBack.accept(entity);
79-
};
80-
ORecordCallback<Integer> updateCallback = (a, b) -> {
81-
entity.add(Document.of(RID_FIELD, a.toString()));
82-
callBack.accept(entity);
83-
};
84-
tx.save(document, null, ASYNCHRONOUS, false, createCallBack, updateCallback);
85-
}
86-
87-
@Override
88-
public void insert(DocumentEntity entity, Duration ttl, Consumer<DocumentEntity> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
89-
throw new UnsupportedOperationException("There is support to ttl on OrientDB");
90-
}
91-
92-
@Override
93-
public void update(DocumentEntity entity) throws ExecuteAsyncQueryException, UnsupportedOperationException {
94-
insert(entity);
95-
}
96-
97-
@Override
98-
public void update(DocumentEntity entity, Consumer<DocumentEntity> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
99-
insert(entity, callBack);
100-
}
101-
102-
@Override
103-
public void delete(DocumentDeleteQuery query) throws ExecuteAsyncQueryException, UnsupportedOperationException {
104-
delete(query, v -> {
105-
});
106-
}
107-
108-
@Override
109-
public void delete(DocumentDeleteQuery query, Consumer<Void> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
110-
ODatabaseDocumentTx tx = pool.acquire();
111-
OSQLQueryFactory.QueryResult orientQuery = toAsync(DocumentQuery.of(query.getCollection())
112-
.and(query.getCondition().orElseThrow(() -> new IllegalArgumentException("Condition is required"))), l -> {
113-
l.forEach(d -> d.delete());
114-
callBack.accept(null);
115-
});
116-
tx.command(orientQuery.getQuery()).execute(orientQuery.getParams());
117-
}
118-
119-
@Override
120-
public void select(DocumentQuery query, Consumer<List<DocumentEntity>> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
121-
ODatabaseDocumentTx tx = pool.acquire();
122-
OSQLQueryFactory.QueryResult orientQuery = toAsync(query, l -> {
123-
callBack.accept(l.stream()
124-
.map(OrientDBConverter::convert)
125-
.collect(toList()));
126-
});
127-
tx.command(orientQuery.getQuery()).execute(orientQuery.getParams());
128-
}
129-
130-
public void find(String query, Consumer<List<DocumentEntity>> callBack, Object... params) {
131-
ODatabaseDocumentTx tx = pool.acquire();
132-
OSQLQueryFactory.QueryResult orientQuery = toAsync(query, l -> {
133-
callBack.accept(l.stream()
134-
.map(OrientDBConverter::convert)
135-
.collect(toList()));
136-
}, params);
137-
tx.command(orientQuery.getQuery()).execute(orientQuery.getParams());
138-
}
139-
140-
141-
@Override
142-
public void close() {
143-
pool.close();
144-
}
47+
public interface OrientDBDocumentCollectionManagerAsync extends DocumentCollectionManagerAsync {
48+
49+
50+
/**
51+
* Find async from Query
52+
*
53+
* @param query the query
54+
* @param callBack the callback
55+
* @param params the params
56+
* @throws NullPointerException when there any parameter null
57+
*/
58+
void find(String query, Consumer<List<DocumentEntity>> callBack, Object... params) throws NullPointerException;
14559
}

0 commit comments

Comments
 (0)