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

com.github.brunodutr.persistence.criteria.service.CriteriaProcessorStartOfDay Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package com.github.brunodutr.persistence.criteria.service;

import java.lang.reflect.Field;
import java.time.LocalDate;
import java.time.LocalDateTime;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

class CriteriaProcessorStartOfDay implements ICriteriaProcessor {

	@Override
	@SuppressWarnings("unchecked")
	public Predicate process(CriteriaBuilder criteriaBuilder, Root root, Object object, Field field) throws Exception {
		
		return processAnnotation(root, object, field, (path, value) -> {

			LocalDateTime dateTime;

			if (value instanceof LocalDate) {
				LocalDate date = (LocalDate) value;
				dateTime = date.atStartOfDay();
			} else {
				throw new UnsupportedOperationException(
						"CriteriaStartOfDay funciona apenas para o tipo java.time.LocalDate");
			}

			Path pathTime = (Path) path;

			return criteriaBuilder.greaterThan(pathTime, dateTime);
		});

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy