Class TimeValueProvider

java.lang.Object
org.cxbox.core.util.filter.provider.impl.AbstractClassifyDataProvider
org.cxbox.core.util.filter.provider.impl.TimeValueProvider
All Implemented Interfaces:
ClassifyDataProvider

@Component public class TimeValueProvider extends AbstractClassifyDataProvider implements ClassifyDataProvider
  • Constructor Details

    • TimeValueProvider

      public TimeValueProvider()
  • Method Details

    • getProviderParameterValues

      protected List<ClassifyDataParameter> getProviderParameterValues(Field dtoField, ClassifyDataParameter dataParameter, FilterParameter filterParam, SearchParameter searchParam, List<ClassifyDataProvider> providers)
      Specified by:
      getProviderParameterValues in class AbstractClassifyDataProvider
    • getSortExpression

      public jakarta.persistence.criteria.Expression<?> getSortExpression(@NonNull @NonNull SearchParameter searchParameter, @NonNull @NonNull jakarta.persistence.criteria.CriteriaBuilder builder, @NonNull @NonNull jakarta.persistence.criteria.CriteriaQuery query, @NonNull @NonNull jakarta.persistence.criteria.Root<?> root, @NonNull @NonNull Class dtoClazz, @NonNull @NonNull jakarta.persistence.criteria.Path fieldPath, @NonNull @NonNull DialectName dialect)
      Sorts entity column by time fraction (LocalDateTime and LocalTime)
      dialect (Oracle/PostgreSQL) - entityManager.getEntityManagerFactory().getProperties().get("hibernate.dialect").toString();
      dialect = PostgreSQL
      Column in DB: TIMESTAMP/TIME
      Actual SQL:
      Query:["select a1_0.id,a1_0.commend,a1_0.created_date from apple a1_0 order by cast(a1_0.created_date as time) asc"] so always add functional index CREATE INDEX idx_apple ON my_entity (cast(field as time(6)));
      dialect = Oracle
      Column in DB: TIMESTAMP
      Actual SQL: Query:["select a1_0.id,a1_0.commend,a1_0.created_date from apple a1_0 order by to_char(a1_0.created_date,'HH24:MI:SS') asc"]
      Specified by:
      getSortExpression in interface ClassifyDataProvider
    • getFilterPredicate

      public jakarta.persistence.criteria.Predicate getFilterPredicate(@NonNull @NonNull SearchOperation operator, @NonNull @NonNull jakarta.persistence.criteria.Root<?> root, @NonNull @NonNull jakarta.persistence.criteria.CriteriaBuilder cb, @NonNull @NonNull ClassifyDataParameter criteria, @NonNull @NonNull jakarta.persistence.criteria.Path field, @NonNull @NonNull Object value, @NonNull @NonNull DialectName dialect)
      Description copied from interface: ClassifyDataProvider
      Retrieves a filter predicate based on the provided search operation and criteria.

      Override this method in implementing classes to provide custom filtering logic. Default implementation returns null (no filtering).

      Example for LocalTime filtering:

      
       if (value instanceof LocalTime) {
           Expression<?> timeExpr = getExpressionByTimePart(field, cb, dialect);
           Comparable<?> comparableValue = MetadataUtils.requireComparable(value);
      
           switch (operator) {
               case EQUALS: return cb.equal(timeExpr, comparableValue);
               case GREATER_OR_EQUAL_THAN: return cb.greaterThanOrEqualTo(timeExpr, comparableValue);
               case LESS_OR_EQUAL_THAN: return cb.lessThanOrEqualTo(timeExpr, comparableValue);
               default: return null;
           }
       }
       return null;
       

      This method is intended to be overridden in the implementing class (Provider) if custom sorting logic is required. If this method is not implemented, the default sorting mechanism will be used.

      Specified by:
      getFilterPredicate in interface ClassifyDataProvider