Search in sources :

Example 1 with RID_FIELD

use of org.jnosql.diana.orientdb.document.OrientDBConverter.RID_FIELD in project jnosql-diana-driver by eclipse.

the class DefaultOrientDBDocumentCollectionManagerAsync method insert.

@Override
public void insert(DocumentEntity entity, Consumer<DocumentEntity> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
    requireNonNull(entity, "Entity is required");
    requireNonNull(callBack, "Callback is required");
    ODatabaseDocumentTx tx = pool.acquire();
    ODocument document = new ODocument(entity.getName());
    Map<String, Object> entityValues = entity.toMap();
    entityValues.keySet().stream().forEach(k -> document.field(k, entityValues.get(k)));
    ORecordCallback<Number> createCallBack = (rid, clusterPosition) -> {
        entity.add(Document.of(RID_FIELD, rid.toString()));
        callBack.accept(entity);
    };
    ORecordCallback<Integer> updateCallback = (rid, version) -> {
        entity.add(Document.of(RID_FIELD, rid.toString()));
        entity.add(Document.of(VERSION_FIELD, version));
        callBack.accept(entity);
    };
    tx.save(document, null, ASYNCHRONOUS, false, createCallBack, updateCallback);
}
Also used : ASYNCHRONOUS(com.orientechnologies.orient.core.db.ODatabase.OPERATION_MODE.ASYNCHRONOUS) VERSION_FIELD(org.jnosql.diana.orientdb.document.OrientDBConverter.VERSION_FIELD) Document(org.jnosql.diana.api.document.Document) ExecuteAsyncQueryException(org.jnosql.diana.api.ExecuteAsyncQueryException) ORecordCallback(com.orientechnologies.orient.core.storage.ORecordCallback) RID_FIELD(org.jnosql.diana.orientdb.document.OrientDBConverter.RID_FIELD) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Consumer(java.util.function.Consumer) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Duration(java.time.Duration) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) ORecordAbstract(com.orientechnologies.orient.core.record.ORecordAbstract) QueryOSQLFactory.toAsync(org.jnosql.diana.orientdb.document.QueryOSQLFactory.toAsync) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ASYNCHRONOUS (com.orientechnologies.orient.core.db.ODatabase.OPERATION_MODE.ASYNCHRONOUS)1 OPartitionedDatabasePool (com.orientechnologies.orient.core.db.OPartitionedDatabasePool)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 ORecordAbstract (com.orientechnologies.orient.core.record.ORecordAbstract)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 ORecordCallback (com.orientechnologies.orient.core.storage.ORecordCallback)1 Duration (java.time.Duration)1 List (java.util.List)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Consumer (java.util.function.Consumer)1 Collectors.toList (java.util.stream.Collectors.toList)1 ExecuteAsyncQueryException (org.jnosql.diana.api.ExecuteAsyncQueryException)1 Document (org.jnosql.diana.api.document.Document)1 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)1 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)1 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)1 RID_FIELD (org.jnosql.diana.orientdb.document.OrientDBConverter.RID_FIELD)1 VERSION_FIELD (org.jnosql.diana.orientdb.document.OrientDBConverter.VERSION_FIELD)1 QueryOSQLFactory.toAsync (org.jnosql.diana.orientdb.document.QueryOSQLFactory.toAsync)1