Example usage for org.hibernate.criterion Order ignoreCase

List of usage examples for org.hibernate.criterion Order ignoreCase

Introduction

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

Prototype

boolean ignoreCase

To view the source code for org.hibernate.criterion Order ignoreCase.

Click Source Link

Usage

From source file:br.com.tcc.service.persistence.CriteriaHelper.java

/**
 * Cria uma instancia de {@link Order} do Hibernate
 * baseado em um {@link OrderBy} do CelulaTronco.
 * @param orderBy instancia de {@link OrderBy}
 * @return instancia de {@link Order}/* www . j  a v a  2  s  . co m*/
 */
public static Order convertOrderByToOrder(final OrderBy orderBy) {
    Order order = null;
    if (orderBy.isAscending()) {
        order = Order.asc(orderBy.getName());
    } else {
        order = Order.desc(orderBy.getName());
    }
    if (!orderBy.isCaseSensitive()) {
        order = order.ignoreCase();
    }
    return order;
}

From source file:lucee.runtime.orm.hibernate.HibernateORMSession.java

License:Open Source License

private Object load(PageContext pc, String cfcName, Struct filter, Struct options, String order, boolean unique)
        throws PageException {
    Component cfc = data.getEngine().create(pc, this, cfcName, false);
    Key dsn = KeyImpl.init(ORMUtil.getDataSourceName(pc, cfc));
    Session sess = getSession(dsn);/*  w w w .  j a v a 2 s .c  o m*/

    String name = HibernateCaster.getEntityName(cfc);
    ClassMetadata metaData = null;

    Object rtn;
    try {
        //trans.begin();

        Criteria criteria = sess.createCriteria(name);

        // filter
        if (filter != null && !filter.isEmpty()) {
            metaData = sess.getSessionFactory().getClassMetadata(name);
            Object value;
            Entry<Key, Object> entry;
            Iterator<Entry<Key, Object>> it = filter.entryIterator();
            String colName;
            while (it.hasNext()) {
                entry = it.next();
                colName = HibernateUtil.validateColumnName(metaData, CommonUtil.toString(entry.getKey()));
                Type type = HibernateUtil.getPropertyType(metaData, colName, null);
                value = entry.getValue();
                if (!(value instanceof Component))
                    value = HibernateCaster.toSQL(type, value, null);

                if (value != null)
                    criteria.add(Restrictions.eq(colName, value));
                else
                    criteria.add(Restrictions.isNull(colName));
            }
        }

        // options
        boolean ignoreCase = false;
        if (options != null && !options.isEmpty()) {
            // ignorecase
            Boolean ignorecase = CommonUtil.toBoolean(options.get("ignorecase", null), null);
            if (ignorecase != null)
                ignoreCase = ignorecase.booleanValue();

            // offset
            int offset = CommonUtil.toIntValue(options.get("offset", null), 0);
            if (offset > 0)
                criteria.setFirstResult(offset);

            // maxResults
            int max = CommonUtil.toIntValue(options.get("maxresults", null), -1);
            if (max > -1)
                criteria.setMaxResults(max);

            // cacheable
            Boolean cacheable = CommonUtil.toBoolean(options.get("cacheable", null), null);
            if (cacheable != null)
                criteria.setCacheable(cacheable.booleanValue());

            // MUST cacheName ?

            // maxResults
            int timeout = CommonUtil.toIntValue(options.get("timeout", null), -1);
            if (timeout > -1)
                criteria.setTimeout(timeout);
        }

        // order 
        if (!Util.isEmpty(order)) {
            if (metaData == null)
                metaData = sess.getSessionFactory().getClassMetadata(name);

            String[] arr = CommonUtil.toStringArray(order, ',');
            CommonUtil.trimItems(arr);
            String[] parts;
            String col;
            boolean isDesc;
            Order _order;
            //ColumnInfo ci;
            for (int i = 0; i < arr.length; i++) {
                parts = CommonUtil.toStringArray(arr[i], " \t\n\b\r");
                CommonUtil.trimItems(parts);
                col = parts[0];

                col = HibernateUtil.validateColumnName(metaData, col);
                isDesc = false;
                if (parts.length > 1) {
                    if (parts[1].equalsIgnoreCase("desc"))
                        isDesc = true;
                    else if (!parts[1].equalsIgnoreCase("asc")) {
                        throw ExceptionUtil.createException((ORMSession) null, null,
                                "invalid order direction defintion [" + parts[1] + "]",
                                "valid values are [asc, desc]");
                    }

                }
                _order = isDesc ? Order.desc(col) : Order.asc(col);
                if (ignoreCase)
                    _order.ignoreCase();

                criteria.addOrder(_order);

            }
        }

        // execute
        if (!unique) {
            rtn = HibernateCaster.toCFML(criteria.list());
        } else {
            rtn = HibernateCaster.toCFML(criteria.uniqueResult());
        }

    } catch (Throwable t) {
        throw CommonUtil.toPageException(t);
    }

    return rtn;
}

From source file:net.databinder.models.hib.BaseCriteriaBuildAndSort.java

License:Open Source License

public void buildOrdered(final Criteria criteria) {
    buildUnordered(criteria);//  w ww .  j ava 2s .  co m

    String property = defaultSortProperty;
    if (property != null) {
        property = processProperty(criteria, property);
        Order order = sortAscending ? Order.asc(property) : Order.desc(property);
        order = sortCased ? order : order.ignoreCase();
        criteria.addOrder(order);
    }
}

From source file:net.databinder.models.hib.CriteriaBuildAndSort.java

License:Open Source License

@Override
public void buildOrdered(final Criteria criteria) {
    buildUnordered(criteria);/*from  w w  w  .ja  v a 2  s .c  o  m*/

    SortParam<S> sort = sortState.getSort();
    String property;
    if (sort != null && sort.getProperty() != null) {
        property = (String) sort.getProperty(); //FIXME
        sortAscending = sort.isAscending();
    } else {
        property = defaultSortProperty;
    }

    if (property != null) {
        property = processProperty(criteria, property);
        Order order = sortAscending ? Order.asc(property) : Order.desc(property);
        order = sortCased ? order : order.ignoreCase();
        criteria.addOrder(order);
    }
}

From source file:net.databinder.models.hib.CriteriaSorter.java

License:Open Source License

public void build(Criteria criteria) {
    SortParam sort = sortState.getSort();
    String property;//w  w w. ja va2 s  . c  om
    if (sort != null && sort.getProperty() != null) {
        property = sort.getProperty();
        asc = sort.isAscending();
    } else {
        property = defaultProperty;
    }
    if (property != null) {
        if (property.contains(".")) {
            // for 'dot' properties we need to add aliases
            // e.g. for the property 'orderbook.order.item.name' we need to add an aliases for 'order' and 'order.item'
            String path[] = property.split("\\.");
            for (int ii = 0; ii < path.length - 1; ii++) {
                StringBuffer sb = new StringBuffer();
                for (int jj = 0; jj <= ii; jj++) {
                    if (sb.length() > 0)
                        sb.append(".");
                    sb.append(path[jj]);
                }
                criteria.createAlias(sb.toString(), path[ii], CriteriaSpecification.LEFT_JOIN);
            }
            // when we have a 'dot' property we want to sort by the sub tables field
            // e.g. for the property 'orderbook.order.item.name' we need to sort by 'item.name'
            if (path.length > 1)
                property = String.format("%s.%s", path[path.length - 2], path[path.length - 1]);
            else
                property = path[path.length - 1];
        }
        Order order = asc ? Order.asc(property) : Order.desc(property);
        order = cased ? order : order.ignoreCase();
        criteria.addOrder(order);
    }
}

From source file:nl.b3p.viewer.admin.stripes.AttributeActionBean.java

License:Open Source License

public Resolution getGridData() throws JSONException {
    JSONArray jsonData = new JSONArray();

    List<SimpleFeatureType> featureTypes = new ArrayList();
    if (simpleFeatureTypeId != null && simpleFeatureTypeId != -1) {
        SimpleFeatureType sft = (SimpleFeatureType) Stripersist.getEntityManager().find(SimpleFeatureType.class,
                simpleFeatureTypeId);//from   w ww. j a  v a2 s.c  om
        if (sft != null) {
            featureTypes.add(sft);
        }
    } else if (featureSourceId != null && featureSourceId != -1) {
        FeatureSource fc = (FeatureSource) Stripersist.getEntityManager().find(FeatureSource.class,
                featureSourceId);
        featureTypes = fc.getFeatureTypes();
    }

    String filterAlias = "";
    String filterAttribuut = "";
    String filterType = "";
    /* 
     * FILTERING: filter is delivered by frontend as JSON array [{property, value}]
     * for demo purposes the value is now returned, ofcourse here should the DB
     * query be built to filter the right records
     */
    if (this.getFilter() != null) {
        for (int k = 0; k < this.getFilter().length(); k++) {
            JSONObject j = this.getFilter().getJSONObject(k);
            String property = j.getString("property");
            String value = j.getString("value");
            if (property.equals("alias")) {
                filterAlias = value;
            }
            if (property.equals("attribute")) {
                filterAttribuut = value;
            }
            if (property.equals("type")) {
                filterType = value;
            }
        }
    }

    Session sess = (Session) Stripersist.getEntityManager().getDelegate();
    Criteria c = sess.createCriteria(AttributeDescriptor.class);

    /* Sorting is delivered by the frontend
     * as two variables: sort which holds the column name and dir which
     * holds the direction (ASC, DESC).
     */
    if (sort != null && dir != null) {
        Order order = null;
        if (sort.equals("attribute")) {
            sort = "name";
        }
        if (dir.equals("ASC")) {
            order = Order.asc(sort);
        } else {
            order = Order.desc(sort);
        }
        order.ignoreCase();
        c.addOrder(order);
    }

    if (filterAlias != null && filterAlias.length() > 0) {
        Criterion aliasCrit = Restrictions.ilike("alias", filterAlias, MatchMode.ANYWHERE);
        c.add(aliasCrit);
    }
    if (filterAttribuut != null && filterAttribuut.length() > 0) {
        Criterion attribuutCrit = Restrictions.ilike("name", filterAttribuut, MatchMode.ANYWHERE);
        c.add(attribuutCrit);
    }
    if (filterType != null && filterType.length() > 0) {
        Criterion typeCrit = Restrictions.ilike("type", filterType, MatchMode.ANYWHERE);
        c.add(typeCrit);
    }

    if (featureTypes != null && featureTypes.size() > 0) {
        /* Criteria for the all attribute descriptor ids of the feature types 
         * in featureTypes
         */
        DetachedCriteria c2 = DetachedCriteria.forClass(SimpleFeatureType.class);
        Collection ftIds = new ArrayList<Long>();
        for (SimpleFeatureType sft : featureTypes) {
            ftIds.add(sft.getId());
        }
        c2.add(Restrictions.in("id", ftIds));
        c2.createAlias("attributes", "attr");
        c2.setProjection(Projections.property("attr.id"));

        c.add(org.hibernate.criterion.Property.forName("id").in(c2));
    }
    int rowCount = c.list().size();

    if (limit > 0) {
        c.setMaxResults(limit);
    }
    c.setFirstResult(start);

    List attributes = c.list();

    for (Iterator it = attributes.iterator(); it.hasNext();) {
        AttributeDescriptor attr = (AttributeDescriptor) it.next();

        JSONObject j = this.getGridRow(attr.getId().intValue(), attr.getAlias(), attr.getName(),
                attr.getType());
        jsonData.put(j);
    }

    final JSONObject grid = new JSONObject();
    grid.put("totalCount", rowCount);
    grid.put("gridrows", jsonData);

    return new StreamingResolution("application/json") {
        @Override
        public void stream(HttpServletResponse response) throws Exception {
            response.getWriter().print(grid.toString());
        }
    };
}

From source file:nl.b3p.viewer.admin.stripes.AttributeSourceActionBean.java

License:Open Source License

public Resolution getGridData() throws JSONException {
    JSONArray jsonData = new JSONArray();

    String filterName = "";
    String filterUrl = "";
    String filterType = "";
    /*//from w w  w. ja va 2  s . c  o m
     * FILTERING: filter is delivered by frontend as JSON array [{property,
     * value}] for demo purposes the value is now returned, ofcourse here
     * should the DB query be built to filter the right records
     */
    if (this.getFilter() != null) {
        for (int k = 0; k < this.getFilter().length(); k++) {
            JSONObject j = this.getFilter().getJSONObject(k);
            String property = j.getString("property");
            String value = j.getString("value");
            if (property.equals("name")) {
                filterName = value;
            }
            if (property.equals("url")) {
                filterUrl = value;
            }
            if (property.equals("protocol")) {
                filterType = value;
            }
        }
    }

    Session sess = (Session) Stripersist.getEntityManager().getDelegate();
    Criteria c = sess.createCriteria(FeatureSource.class);

    /*
     * Sorting is delivered by the frontend as two variables: sort which
     * holds the column name and dir which holds the direction (ASC, DESC).
     */
    if (sort != null && dir != null) {
        /*
         * Sorteren op status nog niet mogelijk
         */
        if (!sort.equals("status") && !sort.equals("protocol")) {
            Order order = null;
            if (dir.equals("ASC")) {
                order = Order.asc(sort);
            } else {
                order = Order.desc(sort);
            }
            order.ignoreCase();
            c.addOrder(order);
        } else {
            if (sort.equals("protocol")) {
                Order order = null;
                if (dir.equals("ASC")) {
                    order = Order.asc("class");
                } else {
                    order = Order.desc("class");
                }
                order.ignoreCase();
                c.addOrder(order);
            }
        }
    }

    if (filterName != null && filterName.length() > 0) {
        Criterion nameCrit = Restrictions.ilike("name", filterName, MatchMode.ANYWHERE);
        c.add(nameCrit);
    }
    if (filterUrl != null && filterUrl.length() > 0) {
        Criterion urlCrit = Restrictions.ilike("url", filterUrl, MatchMode.ANYWHERE);
        c.add(urlCrit);
    }
    if (filterType != null && filterType.length() > 0) {
        Criterion protocolCrit = Restrictions.ilike("class", filterType, MatchMode.ANYWHERE);
        c.add(protocolCrit);
    }

    int rowCount = c.list().size();

    c.setMaxResults(limit);
    c.setFirstResult(start);

    List sources = c.list();

    for (Iterator it = sources.iterator(); it.hasNext();) {
        FeatureSource source = (FeatureSource) it.next();
        String protocolType = "";
        if (source instanceof WFSFeatureSource) {
            protocolType = "WFS";
        } else if (source instanceof JDBCFeatureSource) {
            protocolType = "JDBC";
        } else if (source instanceof ArcGISFeatureSource) {
            protocolType = "ArcGIS";
        } else if (source instanceof ArcXMLFeatureSource) {
            protocolType = "ArcXML";
        }
        JSONObject j = this.getGridRow(source.getId().intValue(), source.getName(), source.getUrl(),
                protocolType);
        jsonData.put(j);
    }

    final JSONObject grid = new JSONObject();
    grid.put("totalCount", rowCount);
    grid.put("gridrows", jsonData);

    return new StreamingResolution("application/json") {

        @Override
        public void stream(HttpServletResponse response) throws Exception {
            response.getWriter().print(grid.toString());
        }
    };
}

From source file:nl.b3p.viewer.admin.stripes.BookmarkActionBean.java

License:Open Source License

public Resolution getGridData() throws JSONException {
    final JSONObject result = new JSONObject();
    JSONArray gridrows = new JSONArray();

    Session sess = (Session) Stripersist.getEntityManager().getDelegate();
    Criteria c = sess.createCriteria(Bookmark.class, "bookmark");
    c.createAlias("bookmark.application", "application");

    String applicationName = "";
    /*//from w  w w  .j a va  2 s  . c o m
     * FILTERING: filter is delivered by frontend as JSON array [{property,
     * value}] for demo purposes the value is now returned, ofcourse here
     * should the DB query be built to filter the right records
     */
    if (this.getFilter() != null) {
        for (int k = 0; k < this.getFilter().length(); k++) {
            JSONObject j = this.getFilter().getJSONObject(k);
            String property = j.getString("property");
            String value = j.getString("value");
            if (property.equals("application.name")) {
                applicationName = value;
            }
        }
    }

    /*
    * Sorting is delivered by the frontend as two variables: sort which
    * holds the column name and dir which holds the direction (ASC, DESC).
    */
    if (sort != null && dir != null) {
        Order order = null;
        if (sort.equals("published")) {
            sort = "version";
        }
        if (dir.equals("ASC")) {
            order = Order.asc(sort);
        } else {
            order = Order.desc(sort);
        }
        order.ignoreCase();
        c.addOrder(order);
    }

    if (applicationName != null && applicationName.length() > 0) {
        Criterion nameCrit = Restrictions.ilike("application.name", applicationName, MatchMode.ANYWHERE);
        c.add(nameCrit);
    }

    int rowCount = c.list().size();

    c.setMaxResults(limit);
    c.setFirstResult(start);

    List<Bookmark> bookmarks = c.list();
    for (Bookmark bm : bookmarks) {
        Application app = bm.getApplication();
        String appName = null;
        if (app != null) {
            appName = app.getName();
            if (app.getVersion() != null) {
                appName += " v" + app.getVersion();
            }
        }

        Date dateCreated = bm.getCreatedAt();

        JSONObject j = getGridRow(bm.getId(), appName, bm.getCode(), dateCreated);
        gridrows.put(j);
    }

    result.put("totalCount", rowCount);
    result.put("gridrows", gridrows);

    return new StreamingResolution("application/json") {

        @Override
        public void stream(HttpServletResponse response) throws Exception {
            response.getWriter().print(result.toString());
        }
    };
}

From source file:nl.b3p.viewer.admin.stripes.ChooseApplicationActionBean.java

License:Open Source License

public Resolution getGridData() throws JSONException {
    JSONArray jsonData = new JSONArray();

    String filterName = "";
    String filterPublished = "";
    String filterOwner = "";
    /*//from  w w w  . j a  va2s.c o  m
     * FILTERING: filter is delivered by frontend as JSON array [{property,
     * value}] for demo purposes the value is now returned, ofcourse here
     * should the DB query be built to filter the right records
     */
    if (this.getFilter() != null) {
        for (int k = 0; k < this.getFilter().length(); k++) {
            JSONObject j = this.getFilter().getJSONObject(k);
            String property = j.getString("property");
            String value = j.getString("value");
            if (property.equals("name")) {
                filterName = value;
            }
            if (property.equals("published")) {
                filterPublished = value;
            }
            if (property.equals("owner")) {
                filterOwner = value;
            }
        }
    }

    Session sess = (Session) Stripersist.getEntityManager().getDelegate();
    Criteria c = sess.createCriteria(Application.class);

    /*
     * Sorting is delivered by the frontend as two variables: sort which
     * holds the column name and dir which holds the direction (ASC, DESC).
     */
    if (sort != null && dir != null) {
        Order order = null;
        if (sort.equals("published")) {
            sort = "version";
        }
        if (dir.equals("ASC")) {
            order = Order.asc(sort);
        } else {
            order = Order.desc(sort);
        }
        order.ignoreCase();
        c.addOrder(order);
    }

    if (filterName != null && filterName.length() > 0) {
        Criterion nameCrit = Restrictions.ilike("name", filterName, MatchMode.ANYWHERE);
        c.add(nameCrit);
    }
    if (filterPublished != null && filterPublished.length() > 0) {
        if (filterPublished.equalsIgnoreCase("nee")) {
            Criterion publishedCrit = Restrictions.isNotNull("version");
            c.add(publishedCrit);
        } else if (filterPublished.equalsIgnoreCase("ja")) {
            Criterion publishedCrit = Restrictions.isNull("version");
            c.add(publishedCrit);
        }
    }
    if (filterOwner != null && filterOwner.length() > 0) {
        Criterion ownerCrit = Restrictions.ilike("owner.username", filterOwner, MatchMode.ANYWHERE);
        c.add(ownerCrit);
    }

    int rowCount = c.list().size();

    c.setMaxResults(limit);
    c.setFirstResult(start);

    List applications = c.list();

    for (Iterator it = applications.iterator(); it.hasNext();) {
        Application app = (Application) it.next();
        String appName = app.getName();
        if (app.getVersion() != null) {
            appName += " v" + app.getVersion();
        }
        String ownername = "";
        if (app.getOwner() != null) {
            ownername = app.getOwner().getUsername();
        }
        String published = "Nee";
        if (app.getVersion() == null) {
            published = "Ja";
        }
        JSONObject j = this.getGridRow(app.getId().intValue(), appName, published, ownername);
        jsonData.put(j);
    }

    final JSONObject grid = new JSONObject();
    grid.put("totalCount", rowCount);
    grid.put("gridrows", jsonData);

    return new StreamingResolution("application/json") {

        @Override
        public void stream(HttpServletResponse response) throws Exception {
            response.getWriter().print(grid.toString());
        }
    };
}

From source file:nl.b3p.viewer.admin.stripes.DocumentActionBean.java

License:Open Source License

@DontValidate
public Resolution getGridData() throws JSONException {
    JSONArray jsonData = new JSONArray();

    String filterName = "";
    String filterUrl = "";
    String filterCategory = "";
    /* /*from  w  w  w. j  av a  2  s . c  o m*/
     * FILTERING: filter is delivered by frontend as JSON array [{property, value}]
     * for demo purposes the value is now returned, ofcourse here should the DB
     * query be built to filter the right records
     */
    if (this.getFilter() != null) {
        for (int k = 0; k < this.getFilter().length(); k++) {
            JSONObject j = this.getFilter().getJSONObject(k);
            String property = j.getString("property");
            String value = j.getString("value");
            if (property.equals("name")) {
                filterName = value;
            }
            if (property.equals("url")) {
                filterUrl = value;
            }
            if (property.equals("category")) {
                filterCategory = value;
            }
        }
    }

    Session sess = (Session) Stripersist.getEntityManager().getDelegate();
    Criteria c = sess.createCriteria(Document.class);

    /* Sorting is delivered by the frontend
     * as two variables: sort which holds the column name and dir which
     * holds the direction (ASC, DESC).
     */
    if (sort != null && dir != null) {
        Order order = null;
        if (dir.equals("ASC")) {
            order = Order.asc(sort);
        } else {
            order = Order.desc(sort);
        }
        order.ignoreCase();
        c.addOrder(order);
    }

    if (filterName != null && filterName.length() > 0) {
        Criterion nameCrit = Restrictions.ilike("name", filterName, MatchMode.ANYWHERE);
        c.add(nameCrit);
    }
    if (filterUrl != null && filterUrl.length() > 0) {
        Criterion urlCrit = Restrictions.ilike("url", filterUrl, MatchMode.ANYWHERE);
        c.add(urlCrit);
    }
    if (filterCategory != null && filterCategory.length() > 0) {
        Criterion rubriekCrit = Restrictions.ilike("category", filterCategory, MatchMode.ANYWHERE);
        c.add(rubriekCrit);
    }

    int rowCount = c.list().size();

    c.setMaxResults(limit);
    c.setFirstResult(start);

    List documenten = c.list();
    for (Iterator it = documenten.iterator(); it.hasNext();) {
        Document doc = (Document) it.next();
        JSONObject j = this.getGridRow(doc.getId().intValue(), doc.getName(), doc.getUrl(), doc.getCategory());
        jsonData.put(j);
    }

    final JSONObject grid = new JSONObject();
    grid.put("totalCount", rowCount);
    grid.put("gridrows", jsonData);

    return new StreamingResolution("application/json") {
        @Override
        public void stream(HttpServletResponse response) throws Exception {
            response.getWriter().print(grid.toString());
        }
    };
}