Skip to content

Make annotation @GlobalIndex less verbose #26

@g-sg-v

Description

@g-sg-v

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions