Skip to content

Commit

Permalink
Query multiple tables using one entity (review comments)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei Galiamichev committed Nov 23, 2024
1 parent c4a68fe commit 4e127c8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion databind/src/main/java/tech/ydb/yoj/ExperimentalApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
Expand All @@ -14,7 +15,7 @@
* Annotates <em>experimental features</em>. These features are not part of the stable YOJ API: they can change incompatibly,
* or even disappear entirely <em>in any release</em>.
*/
@Target({TYPE, FIELD, METHOD, PARAMETER, ANNOTATION_TYPE})
@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, ANNOTATION_TYPE})
@Retention(SOURCE)
public @interface ExperimentalApi {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public <T extends Entity<T>> Table<T> table(Class<T> c) {
* versions
*/
@Override
@ExperimentalApi(issue="https://github.com/ydb-platform/yoj-project/issues/32")
public <T extends Entity<T>> Table<T> table(@NonNull Class<T> clazz, @NonNull String tableName) {
return new YdbTable<>(new EntityDescriptor<>(clazz, tableName), this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
public class YdbTable<T extends Entity<T>> implements Table<T> {
private static final AtomicBoolean useOldStatementFactory = new AtomicBoolean(Boolean.getBoolean("yoj.use.type.statement.factory"));

/**
* @deprecated This method will be removed in YOJ 3.0.0. There is no alternative, just stop calling it.
*/
@Deprecated(forRemoval = true)
public static void setUseOldStatementFactory(boolean value) {
DeprecationWarnings.warnOnce("YdbTable.setUseOldStatementFactory(boolean)",
Expand Down
2 changes: 2 additions & 0 deletions repository/src/main/java/tech/ydb/yoj/repository/BaseDb.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.ydb.yoj.repository;

import tech.ydb.yoj.ExperimentalApi;
import tech.ydb.yoj.repository.db.Entity;
import tech.ydb.yoj.repository.db.Table;
import tech.ydb.yoj.repository.db.Tx;
Expand All @@ -12,6 +13,7 @@ static <T> T current(Class<T> type) {

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

@ExperimentalApi(issue="https://github.com/ydb-platform/yoj-project/issues/32")
default <T extends Entity<T>> Table<T> table(Class<T> c, String name) {
return table(c);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.google.common.reflect.TypeToken;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NonNull;
import tech.ydb.yoj.ExperimentalApi;
import tech.ydb.yoj.databind.expression.FilterExpression;
import tech.ydb.yoj.databind.expression.OrderExpression;
import tech.ydb.yoj.repository.BaseDb;
Expand All @@ -26,7 +28,8 @@ protected AbstractDelegatingTable() {
this.target = BaseDb.current(BaseDb.class).table(resolveEntityType());
}

protected AbstractDelegatingTable(String tableName) {
@ExperimentalApi(issue = "https://github.com/ydb-platform/yoj-project/issues/32")
protected AbstractDelegatingTable(@NonNull String tableName) {
this.target = BaseDb.current(BaseDb.class).table(resolveEntityType(), tableName);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package tech.ydb.yoj.repository.db;

import tech.ydb.yoj.databind.schema.Schema;
import lombok.NonNull;
import tech.ydb.yoj.ExperimentalApi;

import javax.annotation.Nullable;

@ExperimentalApi(issue="https://github.com/ydb-platform/yoj-project/issues/32")
public record EntityDescriptor<E extends Entity<E>>(Class<E> clazz, @Nullable String tableName) {
public String getTableName(Schema<?> schema) {
public String getTableName(@NonNull EntitySchema<?> schema) {
return tableName != null ? tableName : schema.getName();
}

public static <E extends Entity<E>> EntityDescriptor<E> of(Class<E> clazz) {
public static <E extends Entity<E>> EntityDescriptor<E> of(@NonNull Class<E> clazz) {
return new EntityDescriptor<>(clazz, null);
}
}

0 comments on commit 4e127c8

Please sign in to comment.