tech.ydb.yoj.repository.test.sample.TestEntityOperations Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yoj-repository-test Show documentation
Show all versions of yoj-repository-test Show documentation
Basic tests which all YOJ Repository implementations must pass.
The newest version!
package tech.ydb.yoj.repository.test.sample;
import tech.ydb.yoj.repository.BaseDb;
import tech.ydb.yoj.repository.db.AbstractDelegatingTable;
import tech.ydb.yoj.repository.db.Entity;
import tech.ydb.yoj.repository.db.Table;
import tech.ydb.yoj.repository.db.TableQueryBuilder;
import tech.ydb.yoj.repository.db.bulk.BulkParams;
import tech.ydb.yoj.repository.test.sample.model.Bubble;
import tech.ydb.yoj.repository.test.sample.model.BytePkEntity;
import tech.ydb.yoj.repository.test.sample.model.Complex;
import tech.ydb.yoj.repository.test.sample.model.DetachedEntity;
import tech.ydb.yoj.repository.test.sample.model.EntityWithValidation;
import tech.ydb.yoj.repository.test.sample.model.IndexedEntity;
import tech.ydb.yoj.repository.test.sample.model.LogEntry;
import tech.ydb.yoj.repository.test.sample.model.MultiWrappedEntity;
import tech.ydb.yoj.repository.test.sample.model.NetworkAppliance;
import tech.ydb.yoj.repository.test.sample.model.Primitive;
import tech.ydb.yoj.repository.test.sample.model.Project;
import tech.ydb.yoj.repository.test.sample.model.Referring;
import tech.ydb.yoj.repository.test.sample.model.Supabubble;
import tech.ydb.yoj.repository.test.sample.model.Supabubble2;
import tech.ydb.yoj.repository.test.sample.model.Team;
import tech.ydb.yoj.repository.test.sample.model.TypeFreak;
import tech.ydb.yoj.repository.test.sample.model.UpdateFeedEntry;
import tech.ydb.yoj.repository.test.sample.model.VersionedAliasedEntity;
import tech.ydb.yoj.repository.test.sample.model.VersionedEntity;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
public interface TestEntityOperations extends BaseDb {
ProjectTable projects();
BubbleTable bubbles();
ComplexTable complexes();
default Table bytePkEntities() {
return table(BytePkEntity.class);
}
TypeFreakTable typeFreaks();
Table primitives();
Table referrings();
Table logEntries();
Table teams();
Table entitiesWithValidation();
IndexedTable indexedTable();
SupabubbleTable supabubbles();
Supabubble2Table supabubbles2();
Table updateFeedEntries();
Table networkAppliances();
Table versionedEntities();
Table versionedAliasedEntities();
Table detachedEntities();
Table multiWrappedIdEntities();
class ProjectTable extends AbstractDelegatingTable {
public ProjectTable(Table target) {
super(target);
}
public List findNamed() {
return query()
.where("name").isNotNull()
.find();
}
public List findTopNamed(int n) {
return query()
.where("name").isNotNull()
.limit(n)
.find();
}
public void updateName(Project.Id id, String newName) {
modifyIfPresent(id, t -> t.withName(newName));
}
public List findByPredicateWithManyIds(Collection ids) {
return query().where("id").in(ids).find();
}
public List findByPredicateWithManyIdValues(Collection ids) {
return query().where("id").in(ids).find();
}
@Override
public void bulkUpsert(List input, BulkParams params) {
getTarget().bulkUpsert(input, params);
}
}
class TypeFreakTable extends AbstractDelegatingTable {
public TypeFreakTable(Table target) {
super(target);
}
public List findWithEmbeddedAIn(String possibleA, String... otherPossibleAs) {
List lst = new ArrayList<>(1 + otherPossibleAs.length);
lst.add(possibleA);
lst.addAll(asList(otherPossibleAs));
return findWithEmbeddedAIn(unmodifiableList(lst));
}
public List findWithEmbeddedAIn(Collection possibleA) {
return query().where("embedded.a.a").in(possibleA).find();
}
public List findWithEmbeddedANotIn(Collection possibleA) {
return query().where("embedded.a.a").notIn(possibleA).find();
}
public List findWithEmbeddedBNotEqualTo(String prohibitedB) {
return query().where("embedded.b.b").neq(prohibitedB).find();
}
public TypeFreak findByPredicateWithComplexId(TypeFreak.Id id) {
return find(id);
}
public List findViewWithEmbeddedAIn(Collection possibleA) {
return query()
.where("embedded.a.a").in(possibleA)
.find(TypeFreak.View.class);
}
public void updateEmbedded(TypeFreak.Id id, TypeFreak.Embedded newEmbedded) {
modifyIfPresent(id, t -> t.withEmbedded(newEmbedded));
}
}
interface TableWithQueryBuilder> extends Table {
@Override
TableQueryBuilder query();
}
interface ComplexTable extends TableWithQueryBuilder {
}
interface BubbleTable extends Table {
void updateSomeFields(Set ids, String fieldA, String fieldB);
}
interface IndexedTable extends TableWithQueryBuilder {
void updateSomeFields(Set ids, String value, String value2);
}
class SupabubbleTable extends AbstractDelegatingTable {
public SupabubbleTable(Table target) {
super(target);
}
@Override
public TableQueryBuilder query() {
return super.query();
}
}
interface Supabubble2Table extends Table {
default List findLessThan(Supabubble2.Id id) {
throw new UnsupportedOperationException();
}
}
}