All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.ydb.yoj.repository.db.EntityExpressions Maven / Gradle / Ivy

Go to download

Core YOJ (YDB ORM for Java) abstractions and APIs for domain entities, repositories, transactions etc.

There is a newer version: 2.6.1
Show newest version
package tech.ydb.yoj.repository.db;

import lombok.NonNull;
import tech.ydb.yoj.databind.expression.FilterBuilder;
import tech.ydb.yoj.databind.expression.OrderBuilder;
import tech.ydb.yoj.databind.expression.OrderExpression;

import static tech.ydb.yoj.databind.expression.OrderExpression.SortOrder.ASCENDING;

public final class EntityExpressions {
    private EntityExpressions() {
    }

    public static > FilterBuilder newFilterBuilder(@NonNull Class entityType) {
        return FilterBuilder.forSchema(schema(entityType));
    }

    public static > OrderBuilder newOrderBuilder(@NonNull Class entityType) {
        return OrderBuilder.forSchema(schema(entityType));
    }

    private static > EntitySchema schema(@NonNull Class entityType) {
        return EntitySchema.of(entityType);
    }

    public static > OrderExpression defaultOrder(@NonNull Class entityType) {
        return orderById(entityType, ASCENDING);
    }

    public static > OrderExpression orderById(Class entityType, OrderExpression.SortOrder sortOrder) {
        return newOrderBuilder(entityType)
                .orderBy(new OrderExpression.SortKey(schema(entityType).getField(EntityIdSchema.ID_FIELD_NAME), sortOrder))
                .build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy