tech.ydb.yoj.repository.db.EntityExpressions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yoj-repository Show documentation
Show all versions of yoj-repository Show documentation
Core YOJ (YDB ORM for Java) abstractions and APIs for domain entities, repositories, transactions etc.
The 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();
}
}