Skip to content

Commit 4fe9783

Browse files
committed
fix: fix delete method by integration test
Signed-off-by: Otavio Santana <[email protected]>
1 parent 2663112 commit 4fe9783

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

jnosql-orientdb/src/main/java/org/eclipse/jnosql/databases/orientdb/communication/DefaultOrientDBDocumentManager.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,18 @@ public void delete(DocumentDeleteQuery query) {
141141
DocumentQuery selectQuery = new OrientDBDocumentQuery(query);
142142
QueryOSQLFactory.QueryResult orientQuery = QueryOSQLFactory.to(selectQuery);
143143

144-
try (ODatabaseSession tx = pool.acquire();
145-
OResultSet resultSet = tx.command(orientQuery.getQuery(), orientQuery.getParams())) {
146-
while (resultSet.hasNext()) {
147-
OResult next = resultSet.next();
148-
tx.delete(next.toElement().getIdentity());
144+
try (ODatabaseSession tx = pool.acquire()) {
145+
146+
if (orientQuery.isRunQuery()) {
147+
try (OResultSet resultSet = tx.command(orientQuery.getQuery(), orientQuery.getParams())) {
148+
while (resultSet.hasNext()) {
149+
OResult result = resultSet.next();
150+
tx.delete(result.toElement().getIdentity());
151+
}
152+
}
153+
}
154+
if (orientQuery.isLoad()) {
155+
orientQuery.getIds().forEach(tx::delete);
149156
}
150157
}
151158

@@ -167,6 +174,7 @@ public Stream<DocumentEntity> select(DocumentQuery query) {
167174
if (orientQuery.isLoad()) {
168175
orientQuery.getIds().stream().map(tx::load)
169176
.map(o -> OrientDBConverter.convert((ODocument) o))
177+
.filter(Objects::nonNull)
170178
.forEach(entities::add);
171179
}
172180
return entities.stream();

jnosql-orientdb/src/main/java/org/eclipse/jnosql/databases/orientdb/communication/OrientDBConverter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,15 @@ static DocumentEntity convert(OResult row) {
7272
long clusterPosition = identity.getClusterPosition();
7373
entity.add(VERSION_FIELD, element.getVersion());
7474
entity.add(RID_FIELD, "#" + clusterId + ":" + clusterPosition);
75-
entity.add(ID_FIELD, "#" + clusterId + ":" + clusterPosition);
75+
entity.add(ID_FIELD, "#" + clusterId + ":" + clusterPosition);
7676
return entity;
7777
}
7878

7979

8080
static DocumentEntity convert(ODocument document) {
81+
if (document == null) {
82+
return null;
83+
}
8184
DocumentEntity entity = DocumentEntity.of(document.getClassName());
8285
Stream.of(document.fieldNames())
8386
.map(f -> Document.of(f, convert((Object) document.field(f))))

jnosql-orientdb/src/test/java/org/eclipse/jnosql/databases/orientdb/integration/OrientDBTemplateIntegrationTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public void shouldDelete() {
102102
assertThat(template.insert(book))
103103
.isNotNull()
104104
.isEqualTo(book);
105-
106105
template.delete(Book.class, book.id());
107106
assertThat(template.find(Book.class, book.id()))
108107
.isNotNull().isEmpty();

0 commit comments

Comments
 (0)