Example usage for org.hibernate.criterion CriteriaQuery findColumns

List of usage examples for org.hibernate.criterion CriteriaQuery findColumns

Introduction

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

Prototype

public String[] findColumns(String propertyPath, Criteria criteria) throws HibernateException;

Source Link

Document

Get the names of the columns mapped by a property path; if the property path is not found in criteria, try the "outer" query.

Usage

From source file:org.eulerframework.web.core.extend.hibernate5.InExpressionX.java

License:Apache License

@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
    final String[] columns = criteriaQuery.findColumns(propertyName, criteria);
    String cols = StringHelper.join(" = ? and ", columns) + "= ?";
    cols = values.length > 0 ? StringHelper.repeat(cols + " or ", values.length - 1) + cols : "";
    cols = " (" + cols + ") ";
    return cols;//w w w . j ava  2  s.  co  m
}

From source file:org.eulerframework.web.core.extend.hibernate5.LikeExpressionX.java

License:Apache License

@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
    final Dialect dialect = criteriaQuery.getFactory().getDialect();
    final String[] columns = criteriaQuery.findColumns(propertyName, criteria);
    if (columns.length != 1) {
        throw new HibernateException("Like may only be used with single-column properties");
    }/*from   www .j  a  v a  2s  . c  o m*/

    final String escape = escapeChar == null ? "" : " escape \'" + escapeChar + "\'";
    final String column = columns[0];
    if (ignoreCase) {
        if (dialect.supportsCaseInsensitiveLike()) {
            return column + " " + dialect.getCaseInsensitiveLike() + " ?" + escape;
        } else {
            return dialect.getLowercaseFunction() + '(' + column + ')' + " like ?" + escape;
        }
    } else {
        return column + " like ?" + escape;
    }
}

From source file:org.molasdin.wbase.hibernate.criterion.FilterCriterion.java

License:Apache License

@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    //        Dialect dialect = criteriaQuery.getFactory().getDialect();
    String[] columns = criteriaQuery.findColumns(property, criteria);
    if (columns.length != 1) {
        throw new HibernateException("Filter may only be used with single-column properties");
    }/*from w w  w  .j a  v a  2 s .com*/

    String propFormatted = String.format(matchFormat, value.toString());
    return String.format(FILTER_PART2, columns[0], FILTER_MAX_CHARS, propFormatted);
}

From source file:py.una.pol.karaku.dao.where.NumberLike.java

License:Open Source License

@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {

    String[] columns = criteriaQuery.findColumns(getPropiedad(), criteria);
    if (columns.length != 1) {
        throw new HibernateException("NumberLike may only be used with single-column properties");
    }/*from   ww  w.java2s.com*/
    SessionFactoryImplementor factory = criteriaQuery.getFactory();

    if (factory.getDialect() instanceof H2Dialect) {
        return "cast(cast(" + columns[0] + " as int) as VARCHAR) " + "like ?";
    } else {
        // XXX ver consistencia entre bases de datos
        return columns[0] + "::text like ?";
    }
}

From source file:py.una.pol.karaku.dao.where.Regex.java

License:Open Source License

@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {

    String[] columns = criteriaQuery.findColumns(getPath(), criteria);
    if (columns.length != 1) {
        throw new HibernateException("Regex may only be used with single-column properties");
    }//w ww .j  a  v  a 2s.com
    SessionFactoryImplementor factory = criteriaQuery.getFactory();

    if (factory.getDialect() instanceof H2Dialect) {
        return columns[0] + " regexp ?";
    } else {
        // XXX ver consistencia entre bases de datos
        return columns[0] + " ~ ?";
    }
}