Skip to content

Commit 5eb61ca

Browse files
committed
feat: update the update method with force sync
Signed-off-by: Otavio Santana <[email protected]>
1 parent df166ef commit 5eb61ca

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
import org.eclipse.jnosql.communication.document.DocumentDeleteQuery;
2828
import org.eclipse.jnosql.communication.document.DocumentEntity;
2929
import org.eclipse.jnosql.communication.document.DocumentQuery;
30-
import org.glassfish.jaxb.core.v2.model.core.ID;
3130

3231
import java.time.Duration;
3332
import java.util.ArrayList;
3433
import java.util.List;
3534
import java.util.Map;
3635
import java.util.Objects;
36+
import java.util.Optional;
3737
import java.util.stream.Stream;
3838
import java.util.stream.StreamSupport;
3939

@@ -105,7 +105,23 @@ public Iterable<DocumentEntity> insert(Iterable<DocumentEntity> entities, Durati
105105
@Override
106106
public DocumentEntity update(DocumentEntity entity) {
107107
requireNonNull(entity, "Entity is required");
108-
return insert(entity);
108+
109+
Optional<Document> rid = entity.find(RID_FIELD);
110+
Optional<Document> id = entity.find(ID_FIELD);
111+
ORecordId recordId = Stream.concat(rid.stream(), id.stream())
112+
.map(d -> d.get(String.class))
113+
.map(ORecordId::new)
114+
.findFirst()
115+
.orElseThrow(() -> new IllegalArgumentException("For updates at DocumentEntity"));
116+
try (ODatabaseSession tx = pool.acquire()) {
117+
ODocument record = tx.load(recordId);
118+
toMap(entity).forEach(record::field);
119+
tx.save(record);
120+
updateEntity(entity, record);
121+
return entity;
122+
}
123+
124+
109125
}
110126

111127
@Override

0 commit comments

Comments
 (0)