Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.ydb.yoj.repository.db.TableQueryBuilder;
import tech.ydb.yoj.repository.db.TableQueryImpl;
import tech.ydb.yoj.repository.db.ViewSchema;
import tech.ydb.yoj.repository.db.bulk.BulkParams;
import tech.ydb.yoj.repository.db.cache.FirstLevelCache;
import tech.ydb.yoj.repository.db.exception.IllegalTransactionIsolationLevelException;
import tech.ydb.yoj.repository.db.list.InMemoryQueries;
Expand Down Expand Up @@ -97,6 +98,11 @@ public void update(Entity.Id<T> id, Changeset changeset) {
transaction.getTransactionLocal().firstLevelCache(tableDescriptor).remove(id);
}

@Override
public void bulkUpsert(List<T> input, BulkParams params) {
input.forEach(this::save);
}

@Override
public List<T> find(
@Nullable String indexName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tech.ydb.yoj.repository.db.RepositoryTransaction;
import tech.ydb.yoj.repository.db.Table;
import tech.ydb.yoj.repository.db.TxOptions;
import tech.ydb.yoj.repository.db.bulk.BulkParams;
import tech.ydb.yoj.repository.db.common.CommonConverters;
import tech.ydb.yoj.repository.db.json.JacksonJsonConverter;
import tech.ydb.yoj.repository.test.sample.TestEntityOperations;
Expand Down Expand Up @@ -31,6 +32,7 @@
import tech.ydb.yoj.repository.test.sample.model.VersionedAliasedEntity;
import tech.ydb.yoj.repository.test.sample.model.VersionedEntity;

import java.util.List;
import java.util.Set;

public class TestInMemoryRepository extends InMemoryRepository {
Expand Down Expand Up @@ -153,6 +155,11 @@ private static class Supabubble2InMemoryTable extends AbstractDelegatingTable<Su
public Supabubble2InMemoryTable(Table<Supabubble2> target) {
super(target);
}

@Override
Comment thread
nvamelichev marked this conversation as resolved.
public void bulkUpsert(List<Supabubble2> input, BulkParams params) {
input.forEach(this::save);
}
}

private static class BubbleTableImpl extends AbstractDelegatingTable<Bubble> implements BubbleTable {
Expand All @@ -164,6 +171,11 @@ public BubbleTableImpl(Table<Bubble> target) {
public void updateSomeFields(Set<Bubble.Id> ids, String fieldA, String fieldB) {
throw new UnsupportedOperationException("not for in-memory");
}

@Override
public void bulkUpsert(List<Bubble> input, BulkParams params) {
input.forEach(this::save);
}
}

private static class IndexedTableImpl extends AbstractDelegatingTable<IndexedEntity> implements IndexedTable {
Expand All @@ -175,5 +187,10 @@ protected IndexedTableImpl(Table<IndexedEntity> target) {
public void updateSomeFields(Set<IndexedEntity.Id> ids, String value, String value2) {
throw new UnsupportedOperationException("not for in-memory");
}

@Override
public void bulkUpsert(List<IndexedEntity> input, BulkParams params) {
input.forEach(this::save);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import tech.ydb.yoj.repository.db.Tx;
import tech.ydb.yoj.repository.db.TxManager;
import tech.ydb.yoj.repository.db.TxOptions;
import tech.ydb.yoj.repository.db.bulk.BulkParams;
import tech.ydb.yoj.repository.db.common.CommonConverters;
import tech.ydb.yoj.repository.db.common.CommonConverters.EnumDeserializer;
import tech.ydb.yoj.repository.db.exception.ConversionException;
Expand Down Expand Up @@ -3360,6 +3361,26 @@ public void nullOrderingDesc() {
assertThat(results.subList(2, 4)).containsExactlyInAnyOrder(e2, e4);
}

@Test
public void bulkInserts() {
var id1 = new Bubble.Id("a", "b");
var id2 = new Bubble.Id("c", "d");

db.tx(() -> {
db.bubbles().bulkUpsert(
List.of(new Bubble(id1, "oldA", "oldB", "oldC"), new Bubble(id2, "oldA", "oldB", "oldC")),
BulkParams.DEFAULT
);
});

db.readOnly().run(() -> {
var first = this.db.bubbles().find(id1);
assertThat(first).isNotNull();
assertThat(first.getFieldA()).isEqualTo("oldA");
assertThat(this.db.bubbles().find(id2)).isNotNull();
});
}

@Test
public void loggingMdcContextEvenOnException() {
Logger log = LoggerFactory.getLogger("RepositoryTest");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import tech.ydb.yoj.repository.db.StdTxManager;
import tech.ydb.yoj.repository.db.TableDescriptor;
import tech.ydb.yoj.repository.db.Tx;
import tech.ydb.yoj.repository.db.bulk.BulkParams;
import tech.ydb.yoj.repository.db.common.CommonConverters;
import tech.ydb.yoj.repository.db.exception.ConversionException;
import tech.ydb.yoj.repository.db.exception.RetryableException;
Expand Down Expand Up @@ -804,26 +803,6 @@ public void complexInPredicate() {
});
}

@Test
public void bulkInserts() {
var id1 = new Bubble.Id("a", "b");
var id2 = new Bubble.Id("c", "d");

db.tx(() -> {
db.bubbles().bulkUpsert(
List.of(new Bubble(id1, "oldA", "oldB", "oldC"), new Bubble(id2, "oldA", "oldB", "oldC")),
BulkParams.DEFAULT
);
});

db.readOnly().run(() -> {
var first = this.db.bubbles().find(id1);
assertThat(first).isNotNull();
assertThat(first.getFieldA()).isEqualTo("oldA");
assertThat(this.db.bubbles().find(id2)).isNotNull();
});
}

@Test
public void testTransactionTakesTimeoutFromGrpcContext() {
int[] timeoutsMin = IntStream.range(3, 12).toArray();
Expand Down
Loading