Search in sources :

Example 1 with D2RTranslationBatchFunction

use of com.torodb.torod.pipeline.D2RTranslationBatchFunction in project torodb by torodb.

the class SameThreadInsertPipeline method insert.

@Override
public void insert(Stream<KvDocument> docs) throws RollbackException, UserException {
    D2RTranslationBatchFunction d2rFun = new D2RTranslationBatchFunction(translatorFactory, metaDb, mutableMetaCollection);
    DefaultToBackendFunction r2BackendFun = new DefaultToBackendFunction(jobFactory, metaDb, mutableMetaCollection);
    try {
        Iterators.partition(docs.iterator(), docBatchSize).forEachRemaining(list -> {
            CollectionData collData = d2rFun.apply(list);
            Iterable<BackendTransactionJob> jobs = r2BackendFun.apply(collData);
            jobs.forEach(Unchecked.consumer(job -> job.execute(backendConnection)));
        });
    } catch (UncheckedException ex) {
        Throwable cause = ex.getCause();
        if (cause != null && cause instanceof UserException) {
            throw (UserException) cause;
        }
        throw ex;
    }
}
Also used : CollectionData(com.torodb.core.d2r.CollectionData) Unchecked(org.jooq.lambda.Unchecked) KvDocument(com.torodb.kvdocument.values.KvDocument) UserException(com.torodb.core.exceptions.user.UserException) BackendTransactionJobFactory(com.torodb.core.dsl.backend.BackendTransactionJobFactory) Iterators(com.google.common.collect.Iterators) BackendTransactionJob(com.torodb.core.dsl.backend.BackendTransactionJob) RollbackException(com.torodb.core.transaction.RollbackException) D2RTranslatorFactory(com.torodb.core.d2r.D2RTranslatorFactory) Assisted(com.google.inject.assistedinject.Assisted) Inject(javax.inject.Inject) MutableMetaCollection(com.torodb.core.transaction.metainf.MutableMetaCollection) UncheckedException(org.jooq.lambda.UncheckedException) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) Stream(java.util.stream.Stream) DefaultToBackendFunction(com.torodb.torod.pipeline.DefaultToBackendFunction) WriteBackendTransaction(com.torodb.core.backend.WriteBackendTransaction) Preconditions(com.google.common.base.Preconditions) CollectionData(com.torodb.core.d2r.CollectionData) D2RTranslationBatchFunction(com.torodb.torod.pipeline.D2RTranslationBatchFunction) InsertPipeline(com.torodb.torod.pipeline.InsertPipeline) UncheckedException(org.jooq.lambda.UncheckedException) D2RTranslationBatchFunction(com.torodb.torod.pipeline.D2RTranslationBatchFunction) BackendTransactionJob(com.torodb.core.dsl.backend.BackendTransactionJob) UserException(com.torodb.core.exceptions.user.UserException) DefaultToBackendFunction(com.torodb.torod.pipeline.DefaultToBackendFunction)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Iterators (com.google.common.collect.Iterators)1 Assisted (com.google.inject.assistedinject.Assisted)1 WriteBackendTransaction (com.torodb.core.backend.WriteBackendTransaction)1 CollectionData (com.torodb.core.d2r.CollectionData)1 D2RTranslatorFactory (com.torodb.core.d2r.D2RTranslatorFactory)1 BackendTransactionJob (com.torodb.core.dsl.backend.BackendTransactionJob)1 BackendTransactionJobFactory (com.torodb.core.dsl.backend.BackendTransactionJobFactory)1 UserException (com.torodb.core.exceptions.user.UserException)1 RollbackException (com.torodb.core.transaction.RollbackException)1 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)1 MutableMetaCollection (com.torodb.core.transaction.metainf.MutableMetaCollection)1 KvDocument (com.torodb.kvdocument.values.KvDocument)1 D2RTranslationBatchFunction (com.torodb.torod.pipeline.D2RTranslationBatchFunction)1 DefaultToBackendFunction (com.torodb.torod.pipeline.DefaultToBackendFunction)1 InsertPipeline (com.torodb.torod.pipeline.InsertPipeline)1 Stream (java.util.stream.Stream)1 Inject (javax.inject.Inject)1 Unchecked (org.jooq.lambda.Unchecked)1 UncheckedException (org.jooq.lambda.UncheckedException)1