[
https://hibernate.onjira.com/browse/HHH-7284?page=com.atlassian.jira.plug...
]
Uday Kari commented on HHH-7284:
--------------------------------
Happy to. How about I just refer Hibernate - without any qualifiers - like Search, ORM
etc? Already done.
Soon as Tapestry 5.4.x is released, I can update the libraries from 3.4.2 Final to 4.1.2
(if I am understanding correctly, your resquest).
https://issues.apache.org/jira/browse/TAP5-1922
Bottom line, the same fix is needed in 4.1.2 as well.
ExcludeFalse Capability Query by Example Example
------------------------------------------------
Key: HHH-7284
URL:
https://hibernate.onjira.com/browse/HHH-7284
Project: Hibernate ORM
Issue Type: Improvement
Components: query-criteria
Environment: all
Reporter: Uday Kari
Assignee: Steve Ebersole
Priority: Minor
Labels: search
In web form development, checkboxes are mapped to booleans properties. When using a form
to conduct Query By Example, the results should exclude un-checked or false properties. I
have already fixed this for my application, here is the code...you are welcome to use it.
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.criterion;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hibernate.Criteria;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.engine.TypedValue;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
import org.hibernate.util.StringHelper;
/**
* Support for query by example.
* <pre>
* List results = session.createCriteria(Parent.class)
* .add( Example.create(parent).ignoreCase() )
* .createCriteria("child")
* .add( Example.create( parent.getChild() ) )
* .list();
* </pre>
* "Examples" may be mixed and matched with "Expressions" in the same
<tt>Criteria</tt>.
* @see org.hibernate.Criteria
* @author Gavin King
*/
public class Example implements Criterion {
private final Object entity;
private final Set excludedProperties = new HashSet();
private PropertySelector selector;
private boolean isLikeEnabled;
private Character escapeCharacter;
private boolean isIgnoreCaseEnabled;
private MatchMode matchMode;
/**
* A strategy for choosing property values for inclusion in the query
* criteria
*/
public static interface PropertySelector extends Serializable {
public boolean include(Object propertyValue, String propertyName, Type type);
}
private static final PropertySelector NOT_NULL = new NotNullPropertySelector();
private static final PropertySelector ALL = new AllPropertySelector();
private static final PropertySelector NOT_NULL_OR_ZERO = new
NotNullOrZeroPropertySelector();
////////////////////////////////////////////////////////////
// Uday Edits
//
private static final PropertySelector NOT_FALSE = new NotFalsePropertySelector();
static final class NotFalsePropertySelector implements PropertySelector
{
public boolean include(Object object, String propertyName, Type type)
{
if (object == null)
{
return false;
}
else if (object instanceof Boolean)
{
return ((Boolean) object).booleanValue();
}
else
{
return true;
}
}
}
/**
* Exclude false-valued properties
*/
public Example excludeFalse() {
setPropertySelector(NOT_FALSE);
return this;
}
//
// End
/////////////////////////////////////////
[...]
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira