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

Make annotation @GlobalIndex not too much verbose #26

Open
g-sg-v opened this issue Feb 14, 2024 · 0 comments
Open

Make annotation @GlobalIndex not too much verbose #26

g-sg-v opened this issue Feb 14, 2024 · 0 comments
Labels

Comments

@g-sg-v
Copy link
Contributor

g-sg-v commented Feb 14, 2024

I propose to add new annotiation EntityIndex (for backward compatibility):

package tech.ydb.yoj.databind.schema;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface EntityIndex {
    /**
     * Class, records or interface that prescribes fields and their order for indexing
     *
     * @return index list
     */
    Class[] value();
}

Examples:

  1. Interface:
interface ValueIndexInterface<T> {
    String getValueId();
    String getValueId2();
}
@EntityIndex(ValueIndexInterface.class)
public class IndexedEntity implements Entity<IndexedEntity>, ValueIndexInterface<IndexedEntity> {

In this case data mapping for fields could be derived based on IndexedEntity mapping

  1. Class or record (more flexible, sometimes flattened fields could be a part of index):
@EntityIndex({IndexedEntity.Key.class, IndexedEntity.Key2.class})
@Table(name = "table_with_indexes")
public class IndexedEntity implements Entity<IndexedEntity> {
    @Value
    public static class Key {
        @Column(name = "value_id")
        String valueId;
        String valueId2;
    }

    public record Key2 (
            @Column(name = "value_id")
            String valueId,
            String valueId2
    ) {
    }
}

In both cases filed name can be overridden in index entity using @Colunm annotation.

@lavrukov lavrukov added feature New feature or request proposal and removed feature New feature or request labels Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants