tech.ydb.yoj.databind.expression.OrderBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yoj-databind Show documentation
Show all versions of yoj-databind Show documentation
Core data-binding logic used by YOJ (YDB ORM for Java) to convert
between Java objects and database rows (or anything representable by
a Java Map, really).
The newest version!
package tech.ydb.yoj.databind.expression;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import tech.ydb.yoj.databind.schema.Schema;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import static lombok.AccessLevel.PRIVATE;
@RequiredArgsConstructor(access = PRIVATE)
public final class OrderBuilder {
private final Schema schema;
private final List sortKeys = new ArrayList<>();
public static OrderBuilder forSchema(@NonNull Schema schema) {
return new OrderBuilder<>(schema);
}
public FieldOrderBuilder orderBy(@NonNull String fieldPath) {
return new FieldOrderBuilder(fieldPath);
}
public OrderBuilder orderBy(@NonNull OrderExpression.SortKey key) {
sortKeys.add(key);
return this;
}
public OrderBuilder orderBy(@Nullable OrderExpression orderExpression) {
if (orderExpression != null) {
sortKeys.addAll(orderExpression.getKeys());
}
return this;
}
public OrderExpression build() {
return new OrderExpression<>(schema, List.copyOf(sortKeys));
}
public final class FieldOrderBuilder {
private final Schema.JavaField field;
private FieldOrderBuilder(@NonNull String fieldPath) {
this.field = schema.getField(fieldPath);
}
public OrderBuilder ascending() {
return order(OrderExpression.SortOrder.ASCENDING);
}
public OrderBuilder descending() {
return order(OrderExpression.SortOrder.DESCENDING);
}
public OrderBuilder order(@NonNull OrderExpression.SortOrder order) {
return OrderBuilder.this.orderBy(new OrderExpression.SortKey(field, order));
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy