Example usage for org.hibernate.criterion Criterion Criterion

List of usage examples for org.hibernate.criterion Criterion Criterion

Introduction

In this page you can find the example usage for org.hibernate.criterion Criterion Criterion.

Prototype

Criterion

Source Link

Usage

From source file:com.court.controller.HomeFXMLController.java

private Criterion filterByMonthCriterion(final String propertyName) {

    return new Criterion() {

        final int month = new Date().getMonth() + 1;

        @Override//from  w ww.  j a va 2s. co m
        public String toSqlString(Criteria crtr, CriteriaQuery cq) throws HibernateException {
            String[] columns = cq.getColumns(propertyName, crtr);
            if (columns.length != 1) {
                throw new HibernateException("monthEq may only be used with single-column properties");
            }
            return "month(" + columns[0] + ") = ?";
        }

        @Override
        public TypedValue[] getTypedValues(Criteria crtr, CriteriaQuery cq) throws HibernateException {
            return new TypedValue[] { new TypedValue(IntegerType.INSTANCE, month, EntityMode.POJO) };
        }

        @Override
        public String toString() {
            return "month(" + propertyName + ") = " + month;
        }

    };
}