Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entity-desc-pre: prep #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import tech.ydb.yoj.databind.expression.OrderExpression;
import tech.ydb.yoj.repository.db.Entity;
import tech.ydb.yoj.repository.db.Entity.Id;
import tech.ydb.yoj.repository.db.EntityDescription;
import tech.ydb.yoj.repository.db.EntityIdSchema;
import tech.ydb.yoj.repository.db.EntitySchema;
import tech.ydb.yoj.repository.db.Range;
Expand Down Expand Up @@ -57,6 +58,7 @@ public class YdbTable<T extends Entity<T>> implements Table<T> {
private final QueryExecutor executor;
@Getter
private final Class<T> type;
private final EntityDescription<T> desc;

public YdbTable(Class<T> type, QueryExecutor executor) {
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package tech.ydb.yoj.repository.db;

public record EntityDescription<E extends Entity<E>>(
Class<E> entityCls,
String tableName
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ default void checkSchemaCompatibility() {

<T extends Entity<T>> SchemaOperations<T> schema(Class<T> c);

<T extends Entity<T>> SchemaOperations<T> schema(EntityDescription<T> c);

/**
* @deprecated For testing purposes only. Will only <em>reliably</em> work for tables that were created or inspected
* using calls to {@link #schema(Class)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
public interface RepositoryTransaction {
<T extends Entity<T>> Table<T> table(Class<T> c);

<T extends Entity<T>> Table<T> table(EntityDescription<T> c);

/**
* Commits the transaction or throws exception. Note that this method is not expected to be called, if the last
* transaction statement has thrown an exception, because it means that transaction didn't 'execute normally'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.Maps;
import lombok.NonNull;
import tech.ydb.yoj.repository.db.Entity;
import tech.ydb.yoj.repository.db.EntityDescription;

import java.util.Collections;
import java.util.ConcurrentModificationException;
Expand All @@ -16,29 +17,33 @@


public interface FirstLevelCache {
<E extends Entity<E>> E get(@NonNull Entity.Id<E> id, @NonNull Function<Entity.Id<E>, E> loader);
<E extends Entity<E>> E get(
@NonNull EntityDescription<E> desc,
@NonNull Entity.Id<E> id,
@NonNull Function<Entity.Id<E>, E> loader
);

<E extends Entity<E>> Optional<E> peek(@NonNull Entity.Id<E> id);
<E extends Entity<E>> Optional<E> peek(@NonNull EntityDescription<E> desc, @NonNull Entity.Id<E> id);

/**
* Returns a immutable copy of the entities of {@code entityType} type that are in the
* transaction L1 cache.
*/
<E extends Entity<E>> List<E> snapshot(@NonNull Class<E> entityType);
<E extends Entity<E>> List<E> snapshot(@NonNull EntityDescription<E> desc);

/**
* Returns a unmodifiable map containing the entities of {@code entityType} type that are in the
* transaction L1 cache. The returned map is a unmodifiable live view of transaction L1 cache;
* changes to second affect the first. To avoid an {@link ConcurrentModificationException} exception
* when iterating and simultaneous modification of the transaction L1 cache, you may need to make a copy.
*/
<E extends Entity<E>> Map<Entity.Id<E>, E> entities(@NonNull Class<E> entityType);
<E extends Entity<E>> Map<Entity.Id<E>, E> entities(@NonNull EntityDescription<E> desc);

<E extends Entity<E>> void put(@NonNull E e);
<E extends Entity<E>> void put(@NonNull EntityDescription<E> desc, @NonNull E e);

<E extends Entity<E>> void putEmpty(@NonNull Entity.Id<E> id);
<E extends Entity<E>> void putEmpty(@NonNull EntityDescription<E> desc, @NonNull Entity.Id<E> id);

<E extends Entity<E>> boolean containsKey(@NonNull Entity.Id<E> id);
<E extends Entity<E>> boolean containsKey(@NonNull EntityDescription<E> desc, @NonNull Entity.Id<E> id);

static FirstLevelCache empty() {
return new FirstLevelCache() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@


import tech.ydb.yoj.repository.db.Entity;
import tech.ydb.yoj.repository.db.EntityDescription;
import tech.ydb.yoj.repository.db.RepositoryTransaction;

public interface ProjectionCache {
void load(Entity<?> entity);
<E extends Entity<E>> void load(EntityDescription<E> desc, Entity<?> entity);

void save(Entity<?> entity);
<E extends Entity<E>> void save(EntityDescription<E> desc, Entity<?> entity);

void delete(Entity.Id<?> id);
<E extends Entity<E>> void delete(EntityDescription<E> desc, Entity.Id<?> id);

void applyProjectionChanges(RepositoryTransaction transaction);
}
Loading