Hibernate SVN: r19029 - in core/branches/Branch_3_2_4_SP1_CP: test/org/hibernate/test/criteria and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-03-18 18:10:28 -0400 (Thu, 18 Mar 2010)
New Revision: 19029
Added:
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/LikeTest.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/StringExpression.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/TestObject.hbm.xml
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/TestObject.java
Modified:
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/criterion/LikeExpression.java
Log:
JBPAPP-3946 HHH-2997 LikeExpression case sensitive not working properly
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/criterion/LikeExpression.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/criterion/LikeExpression.java 2010-03-18 21:58:11 UTC (rev 19028)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/criterion/LikeExpression.java 2010-03-18 22:10:28 UTC (rev 19029)
@@ -69,7 +69,7 @@
Criteria criteria,
CriteriaQuery criteriaQuery) throws HibernateException {
return new TypedValue[] {
- criteriaQuery.getTypedValue( criteria, propertyName, value.toString().toLowerCase() )
+ criteriaQuery.getTypedValue( criteria, propertyName, ignoreCase ? value.toString().toLowerCase() : value.toString() )
};
}
}
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/LikeTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/LikeTest.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/LikeTest.java 2010-03-18 22:10:28 UTC (rev 19029)
@@ -0,0 +1,116 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.criteria;
+
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+
+public class LikeTest extends FunctionalTestCase {
+
+ public LikeTest( String string ) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[]{"criteria/TestObject.hbm.xml"};
+ }
+ public void testLike(){
+ Session session=openSession();
+ String uniq = "uniq" + System.currentTimeMillis();
+
+ // insert object
+ try {
+ Transaction tx = session.beginTransaction();
+
+
+ TestObject obj = new TestObject();
+ obj.setText("XyZ " + uniq + " blablabla");
+
+ session.saveOrUpdate(obj);
+ session.flush();
+ tx.commit();
+ } finally {
+ session.close();
+
+ }
+ String pattern = "XyZ " + uniq + "%";
+
+ // retrieve object - case sensitive - works ok
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(Restrictions.like("text", pattern))
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+ // retrieve object - case insensitive - works ok
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(Restrictions.like("text", pattern).ignoreCase())
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+
+ // retrieve object - case insensitive via custom expression - works ok
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(StringExpression.stringExpression("text", pattern, true))
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+
+ // retrieve object - case sensitive via custom expression - not working
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(StringExpression.stringExpression("text", pattern, false))
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+ }
+}
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/StringExpression.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/StringExpression.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/StringExpression.java 2010-03-18 22:10:28 UTC (rev 19029)
@@ -0,0 +1,18 @@
+package org.hibernate.test.criteria;
+
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.LikeExpression;
+
+public class StringExpression extends LikeExpression {
+ private final static Character ESCAPE_CODE = new Character( '\\' );
+
+ protected StringExpression( String property, String value,
+ boolean ignoreCase ) {
+ super( property, value, ESCAPE_CODE, ignoreCase );
+ }
+
+ public static Criterion stringExpression( String propertyName,
+ String value, boolean ignoreCase ) {
+ return new StringExpression( propertyName, value, ignoreCase );
+ }
+}
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/TestObject.hbm.xml
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/TestObject.hbm.xml (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/TestObject.hbm.xml 2010-03-18 22:10:28 UTC (rev 19029)
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.criteria">
+ <class name="TestObject" table="test">
+ <id name="id">
+ <column name="ID" />
+ <generator class="sequence">
+ <param name="sequence">test_seq</param>
+ </generator>
+ </id>
+
+ <property name="text" />
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/TestObject.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/TestObject.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/criteria/TestObject.java 2010-03-18 22:10:28 UTC (rev 19029)
@@ -0,0 +1,22 @@
+package org.hibernate.test.criteria;
+
+public class TestObject {
+ private Integer id;
+ private String text;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId( Integer id ) {
+ this.id = id;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText( String text ) {
+ this.text = text;
+ }
+}
15 years, 6 months
Hibernate SVN: r19028 - in core/branches/Branch_3_3_2_GA_CP: testsuite/src/test/java/org/hibernate/test/criteria and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-03-18 17:58:11 -0400 (Thu, 18 Mar 2010)
New Revision: 19028
Added:
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/LikeTest.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/StringExpression.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.hbm.xml
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.java
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/criterion/LikeExpression.java
Log:
JBPAPP-3946 HHH-2997 LikeExpression case sensitive not working properly
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/criterion/LikeExpression.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/criterion/LikeExpression.java 2010-03-18 21:50:25 UTC (rev 19027)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/criterion/LikeExpression.java 2010-03-18 21:58:11 UTC (rev 19028)
@@ -93,7 +93,7 @@
Criteria criteria,
CriteriaQuery criteriaQuery) throws HibernateException {
return new TypedValue[] {
- criteriaQuery.getTypedValue( criteria, propertyName, value.toString().toLowerCase() )
+ criteriaQuery.getTypedValue( criteria, propertyName, ignoreCase ? value.toString().toLowerCase() : value.toString() )
};
}
}
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/LikeTest.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/LikeTest.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/LikeTest.java 2010-03-18 21:58:11 UTC (rev 19028)
@@ -0,0 +1,116 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.criteria;
+
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+
+public class LikeTest extends FunctionalTestCase {
+
+ public LikeTest( String string ) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[]{"criteria/TestObject.hbm.xml"};
+ }
+ public void testLike(){
+ Session session=openSession();
+ String uniq = "uniq" + System.currentTimeMillis();
+
+ // insert object
+ try {
+ Transaction tx = session.beginTransaction();
+
+
+ TestObject obj = new TestObject();
+ obj.setText("XyZ " + uniq + " blablabla");
+
+ session.saveOrUpdate(obj);
+ session.flush();
+ tx.commit();
+ } finally {
+ session.close();
+
+ }
+ String pattern = "XyZ " + uniq + "%";
+
+ // retrieve object - case sensitive - works ok
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(Restrictions.like("text", pattern))
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+ // retrieve object - case insensitive - works ok
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(Restrictions.like("text", pattern).ignoreCase())
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+
+ // retrieve object - case insensitive via custom expression - works ok
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(StringExpression.stringExpression("text", pattern, true))
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+
+ // retrieve object - case sensitive via custom expression - not working
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(StringExpression.stringExpression("text", pattern, false))
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+ }
+}
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/StringExpression.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/StringExpression.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/StringExpression.java 2010-03-18 21:58:11 UTC (rev 19028)
@@ -0,0 +1,18 @@
+package org.hibernate.test.criteria;
+
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.LikeExpression;
+
+public class StringExpression extends LikeExpression {
+ private final static Character ESCAPE_CODE = new Character( '\\' );
+
+ protected StringExpression( String property, String value,
+ boolean ignoreCase ) {
+ super( property, value, ESCAPE_CODE, ignoreCase );
+ }
+
+ public static Criterion stringExpression( String propertyName,
+ String value, boolean ignoreCase ) {
+ return new StringExpression( propertyName, value, ignoreCase );
+ }
+}
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.hbm.xml
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.hbm.xml (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.hbm.xml 2010-03-18 21:58:11 UTC (rev 19028)
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.criteria">
+ <class name="TestObject" table="test">
+ <id name="id">
+ <column name="ID" />
+ <generator class="sequence">
+ <param name="sequence">test_seq</param>
+ </generator>
+ </id>
+
+ <property name="text" />
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.java 2010-03-18 21:58:11 UTC (rev 19028)
@@ -0,0 +1,22 @@
+package org.hibernate.test.criteria;
+
+public class TestObject {
+ private Integer id;
+ private String text;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId( Integer id ) {
+ this.id = id;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText( String text ) {
+ this.text = text;
+ }
+}
15 years, 6 months
Hibernate SVN: r19027 - in core/branches/Branch_3_3: testsuite/src/test/java/org/hibernate/test/criteria and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-03-18 17:50:25 -0400 (Thu, 18 Mar 2010)
New Revision: 19027
Added:
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/LikeTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/StringExpression.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.hbm.xml
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.java
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/criterion/LikeExpression.java
Log:
HHH-2997 LikeExpression case sensitive not working properly
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/criterion/LikeExpression.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/criterion/LikeExpression.java 2010-03-18 21:49:48 UTC (rev 19026)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/criterion/LikeExpression.java 2010-03-18 21:50:25 UTC (rev 19027)
@@ -93,7 +93,7 @@
Criteria criteria,
CriteriaQuery criteriaQuery) throws HibernateException {
return new TypedValue[] {
- criteriaQuery.getTypedValue( criteria, propertyName, value.toString().toLowerCase() )
+ criteriaQuery.getTypedValue( criteria, propertyName, ignoreCase ? value.toString().toLowerCase() : value.toString() )
};
}
}
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/LikeTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/LikeTest.java (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/LikeTest.java 2010-03-18 21:50:25 UTC (rev 19027)
@@ -0,0 +1,116 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.criteria;
+
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+
+public class LikeTest extends FunctionalTestCase {
+
+ public LikeTest( String string ) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[]{"criteria/TestObject.hbm.xml"};
+ }
+ public void testLike(){
+ Session session=openSession();
+ String uniq = "uniq" + System.currentTimeMillis();
+
+ // insert object
+ try {
+ Transaction tx = session.beginTransaction();
+
+
+ TestObject obj = new TestObject();
+ obj.setText("XyZ " + uniq + " blablabla");
+
+ session.saveOrUpdate(obj);
+ session.flush();
+ tx.commit();
+ } finally {
+ session.close();
+
+ }
+ String pattern = "XyZ " + uniq + "%";
+
+ // retrieve object - case sensitive - works ok
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(Restrictions.like("text", pattern))
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+ // retrieve object - case insensitive - works ok
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(Restrictions.like("text", pattern).ignoreCase())
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+
+ // retrieve object - case insensitive via custom expression - works ok
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(StringExpression.stringExpression("text", pattern, true))
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+
+ // retrieve object - case sensitive via custom expression - not working
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(StringExpression.stringExpression("text", pattern, false))
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+ }
+}
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/StringExpression.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/StringExpression.java (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/StringExpression.java 2010-03-18 21:50:25 UTC (rev 19027)
@@ -0,0 +1,18 @@
+package org.hibernate.test.criteria;
+
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.LikeExpression;
+
+public class StringExpression extends LikeExpression {
+ private final static Character ESCAPE_CODE = new Character( '\\' );
+
+ protected StringExpression( String property, String value,
+ boolean ignoreCase ) {
+ super( property, value, ESCAPE_CODE, ignoreCase );
+ }
+
+ public static Criterion stringExpression( String propertyName,
+ String value, boolean ignoreCase ) {
+ return new StringExpression( propertyName, value, ignoreCase );
+ }
+}
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.hbm.xml
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.hbm.xml (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.hbm.xml 2010-03-18 21:50:25 UTC (rev 19027)
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.criteria">
+ <class name="TestObject" table="test">
+ <id name="id">
+ <column name="ID" />
+ <generator class="sequence">
+ <param name="sequence">test_seq</param>
+ </generator>
+ </id>
+
+ <property name="text" />
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.java (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.java 2010-03-18 21:50:25 UTC (rev 19027)
@@ -0,0 +1,22 @@
+package org.hibernate.test.criteria;
+
+public class TestObject {
+ private Integer id;
+ private String text;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId( Integer id ) {
+ this.id = id;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText( String text ) {
+ this.text = text;
+ }
+}
15 years, 6 months
Hibernate SVN: r19026 - core/trunk/core/src/main/java/org/hibernate/criterion.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-03-18 17:49:48 -0400 (Thu, 18 Mar 2010)
New Revision: 19026
Modified:
core/trunk/core/src/main/java/org/hibernate/criterion/LikeExpression.java
Log:
HHH-2997 LikeExpression case sensitive not working properly
Modified: core/trunk/core/src/main/java/org/hibernate/criterion/LikeExpression.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/criterion/LikeExpression.java 2010-03-18 21:47:54 UTC (rev 19025)
+++ core/trunk/core/src/main/java/org/hibernate/criterion/LikeExpression.java 2010-03-18 21:49:48 UTC (rev 19026)
@@ -93,7 +93,7 @@
Criteria criteria,
CriteriaQuery criteriaQuery) throws HibernateException {
return new TypedValue[] {
- criteriaQuery.getTypedValue( criteria, propertyName, value.toString().toLowerCase() )
+ criteriaQuery.getTypedValue( criteria, propertyName, ignoreCase ? value.toString().toLowerCase() : value.toString() )
};
}
}
15 years, 6 months
Hibernate SVN: r19025 - core/trunk/testsuite/src/test/java/org/hibernate/test/criteria.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-03-18 17:47:54 -0400 (Thu, 18 Mar 2010)
New Revision: 19025
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/LikeTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/StringExpression.java
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.java
Log:
HHH-2997 LikeExpression case sensitive not working properly
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/LikeTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/LikeTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/LikeTest.java 2010-03-18 21:47:54 UTC (rev 19025)
@@ -0,0 +1,116 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.criteria;
+
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+
+public class LikeTest extends FunctionalTestCase {
+
+ public LikeTest( String string ) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[]{"criteria/TestObject.hbm.xml"};
+ }
+ public void testLike(){
+ Session session=openSession();
+ String uniq = "uniq" + System.currentTimeMillis();
+
+ // insert object
+ try {
+ Transaction tx = session.beginTransaction();
+
+
+ TestObject obj = new TestObject();
+ obj.setText("XyZ " + uniq + " blablabla");
+
+ session.saveOrUpdate(obj);
+ session.flush();
+ tx.commit();
+ } finally {
+ session.close();
+
+ }
+ String pattern = "XyZ " + uniq + "%";
+
+ // retrieve object - case sensitive - works ok
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(Restrictions.like("text", pattern))
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+ // retrieve object - case insensitive - works ok
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(Restrictions.like("text", pattern).ignoreCase())
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+
+ // retrieve object - case insensitive via custom expression - works ok
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(StringExpression.stringExpression("text", pattern, true))
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+
+ // retrieve object - case sensitive via custom expression - not working
+ session = openSession();
+ try {
+ List objects = session.createCriteria(TestObject.class)
+ .add(StringExpression.stringExpression("text", pattern, false))
+ .list();
+
+ assertEquals(1, objects.size());
+ } finally {
+ session.close();
+ }
+
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/StringExpression.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/StringExpression.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/StringExpression.java 2010-03-18 21:47:54 UTC (rev 19025)
@@ -0,0 +1,18 @@
+package org.hibernate.test.criteria;
+
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.LikeExpression;
+
+public class StringExpression extends LikeExpression {
+ private final static Character ESCAPE_CODE = new Character( '\\' );
+
+ protected StringExpression( String property, String value,
+ boolean ignoreCase ) {
+ super( property, value, ESCAPE_CODE, ignoreCase );
+ }
+
+ public static Criterion stringExpression( String propertyName,
+ String value, boolean ignoreCase ) {
+ return new StringExpression( propertyName, value, ignoreCase );
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.hbm.xml 2010-03-18 21:47:54 UTC (rev 19025)
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.criteria">
+ <class name="TestObject" table="test">
+ <id name="id">
+ <column name="ID" />
+ <generator class="sequence">
+ <param name="sequence">test_seq</param>
+ </generator>
+ </id>
+
+ <property name="text" />
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/TestObject.java 2010-03-18 21:47:54 UTC (rev 19025)
@@ -0,0 +1,22 @@
+package org.hibernate.test.criteria;
+
+public class TestObject {
+ private Integer id;
+ private String text;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId( Integer id ) {
+ this.id = id;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText( String text ) {
+ this.text = text;
+ }
+}
15 years, 6 months
Hibernate SVN: r19024 - core/trunk/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-03-18 17:11:29 -0400 (Thu, 18 Mar 2010)
New Revision: 19024
Modified:
core/trunk/documentation/manual/src/main/docbook/en-US/content/persistent_classes.xml
core/trunk/documentation/manual/src/main/docbook/en-US/content/query_hql.xml
Log:
HHH-5022 Small documentation improvements
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/persistent_classes.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/persistent_classes.xml 2010-03-18 19:06:18 UTC (rev 19023)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/persistent_classes.xml 2010-03-18 21:11:29 UTC (rev 19024)
@@ -427,7 +427,6 @@
<programlisting role="JAVA"><![CDATA[Session s = openSession();
Transaction tx = s.beginTransaction();
-Session s = openSession();
// Create a customer
Map david = new HashMap();
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/query_hql.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/query_hql.xml 2010-03-18 19:06:18 UTC (rev 19023)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/query_hql.xml 2010-03-18 21:11:29 UTC (rev 19024)
@@ -1147,7 +1147,7 @@
</para>
<programlisting><![CDATA[select usr.id, usr.name
-from User usr.name
+from User usr
join usr.messages msg
group by usr.id, usr.name
having count(msg) >= 1]]></programlisting>
15 years, 6 months
Hibernate SVN: r19023 - search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-03-18 15:06:18 -0400 (Thu, 18 Mar 2010)
New Revision: 19023
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java
Log:
HSEARCH-414 add boolean query framework (needs test) and common query methods (boostedTo etc)
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java 2010-03-18 18:58:27 UTC (rev 19022)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java 2010-03-18 19:06:18 UTC (rev 19023)
@@ -127,11 +127,15 @@
assertEquals( 2, results.size() );
assertEquals( "February", results.get( 0 ).getName() );
+ //FIXME add other method tests besides boostedTo
+
transaction.commit();
cleanData( fts );
}
+ //FIXME add boolean tests
+
private void cleanData(FullTextSession fts) {
Transaction tx = fts.beginTransaction();
final List<Month> results = fts.createQuery( "from " + Month.class.getName() ).list();
15 years, 6 months
Hibernate SVN: r19022 - in search/trunk/hibernate-search/src: main/java/org/hibernate/search/query/dsl/v2/impl and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-03-18 14:58:27 -0400 (Thu, 18 Mar 2010)
New Revision: 19022
Added:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/BooleanJunction.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/MustJunction.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/QueryCustomization.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/BooleanQueryBuilder.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/QueryCustomizer.java
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/QueryBuilder.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/TermCustomization.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedQueryBuilder.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedTermContext.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/Month.java
Log:
HSEARCH-414 add boolean query framework (needs test) and common query methods (boostedTo etc)
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/BooleanJunction.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/BooleanJunction.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/BooleanJunction.java 2010-03-18 18:58:27 UTC (rev 19022)
@@ -0,0 +1,26 @@
+package org.hibernate.search.query.dsl.v2;
+
+import org.apache.lucene.search.Query;
+
+/**
+ * Represents a boolean query that can contains one or more elements to join
+ *
+ * @author Emmanuel Bernard
+ */
+public interface BooleanJunction<T extends BooleanJunction> extends QueryCustomization<T> {
+ /**
+ * The boolean query results should match the subquery
+ */
+ BooleanJunction should(Query query);
+
+ /**
+ * The boolean query results must (or must not) match the subquery
+ * Call the .not() method to ensure results of the boolean query do NOT match the subquery.
+ */
+ MustJunction must(Query query);
+
+ /**
+ * Return the lucene query representing the boolean operation
+ */
+ Query createQuery();
+}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/MustJunction.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/MustJunction.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/MustJunction.java 2010-03-18 18:58:27 UTC (rev 19022)
@@ -0,0 +1,14 @@
+package org.hibernate.search.query.dsl.v2;
+
+/**
+ * Represents the context in which a must clause is described.
+ *
+ * @author Emmanuel Bernard
+ */
+public interface MustJunction extends BooleanJunction<MustJunction> {
+ /**
+ * Negate the must clause.
+ * Results of the boolean query do NOT match the subquery.
+ */
+ BooleanJunction not();
+}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/QueryBuilder.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/QueryBuilder.java 2010-03-18 18:17:05 UTC (rev 19021)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/QueryBuilder.java 2010-03-18 18:58:27 UTC (rev 19022)
@@ -8,4 +8,10 @@
* build a term query
*/
TermContext term();
+
+
+ /**
+ * Boolean query
+ */
+ BooleanJunction<BooleanJunction> bool();
}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/QueryCustomization.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/QueryCustomization.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/QueryCustomization.java 2010-03-18 18:58:27 UTC (rev 19022)
@@ -0,0 +1,40 @@
+package org.hibernate.search.query.dsl.v2;
+
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.Query;
+
+/**
+ * Operations common to all types of queries
+ *
+ * @author Emmanuel Bernard
+ */
+public interface QueryCustomization<T> {
+
+ /**
+ * Boost the query to a given value
+ * Most of the time positive float:
+ * - lower than 1 to diminish the weight
+ * - higher than 1 to increase the weight
+ *
+ * Could be negative but not unless you understand what is going on (advanced)
+ */
+ T boostedTo(float boost);
+
+ /**
+ * All results matching the query have a constant score equals to the boost
+ * FIXME is that true?
+ */
+ T constantScore();
+
+ /**
+ * Filter the query results with the Filter instance
+ */
+ T filter(Filter filter);
+
+ //TODO filter(String) + parameters
+
+ /**
+ * Create a Lucene query
+ */
+ Query createQuery();
+}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/TermCustomization.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/TermCustomization.java 2010-03-18 18:17:05 UTC (rev 19021)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/TermCustomization.java 2010-03-18 18:58:27 UTC (rev 19022)
@@ -5,7 +5,7 @@
/**
* @author Emmanuel Bernard
*/
-public interface TermCustomization {
+public interface TermCustomization extends QueryCustomization<TermCustomization> {
/**
* Advanced
* Do not execute the analyzer on the text.
@@ -28,9 +28,4 @@
//TODO make it mutually exclusive with fuzzy use (but that's much more complex)
TermCustomization wildcard();
- /**
- * Create a Lucene query
- */
- Query createQuery();
-
}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/BooleanQueryBuilder.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/BooleanQueryBuilder.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/BooleanQueryBuilder.java 2010-03-18 18:58:27 UTC (rev 19022)
@@ -0,0 +1,87 @@
+package org.hibernate.search.query.dsl.v2.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.Query;
+
+import org.hibernate.annotations.common.AssertionFailure;
+import org.hibernate.search.query.dsl.v2.BooleanJunction;
+import org.hibernate.search.query.dsl.v2.MustJunction;
+
+/**
+ * @author Emmanuel Bernard
+ */
+class BooleanQueryBuilder implements MustJunction {
+ private final List<BooleanClause> clauses;
+ private final QueryCustomizer queryCustomizer;
+
+ BooleanQueryBuilder() {
+ clauses = new ArrayList<BooleanClause>(5);
+ queryCustomizer = new QueryCustomizer();
+ }
+
+ public BooleanJunction not() {
+ final int lastIndex = clauses.size() -1;
+ final BooleanClause last = clauses.get(lastIndex);
+ if ( ! last.getOccur().equals( BooleanClause.Occur.MUST ) ) {
+ throw new AssertionFailure( "Cannot negate class: " + last.getOccur() );
+ }
+ clauses.add( lastIndex, new BooleanClause( last.getQuery(), BooleanClause.Occur.MUST_NOT ) );
+ return this;
+ }
+
+ public BooleanJunction should(Query query) {
+ clauses.add( new BooleanClause( query, BooleanClause.Occur.SHOULD ) );
+ return this;
+ }
+
+ public MustJunction must(Query query) {
+ clauses.add( new BooleanClause( query, BooleanClause.Occur.SHOULD ) );
+ return this;
+ }
+
+ public MustJunction boostedTo(float boost) {
+ queryCustomizer.boostedTo( boost );
+ return this;
+ }
+
+ public MustJunction constantScore() {
+ queryCustomizer.constantScore();
+ return this;
+ }
+
+ public MustJunction filter(Filter filter) {
+ queryCustomizer.filter(filter);
+ return this;
+ }
+
+ public Query createQuery() {
+ final int nbrOfClauses = clauses.size();
+ if ( nbrOfClauses == 0) {
+ throw new AssertionFailure( "Cannot create an empty boolean query" );
+ }
+ else if ( nbrOfClauses == 1 ) {
+ final BooleanClause uniqueClause = clauses.get( 0 );
+ if ( uniqueClause.getOccur().equals( BooleanClause.Occur.MUST_NOT ) ) {
+ //FIXME We have two choices here, raise an exception or combine with an All query. #2 is done atm.
+ //TODO which normfield to use and how to pass it?
+ should( new MatchAllDocsQuery() );
+ }
+ else {
+ //optimize
+ return queryCustomizer.setWrappedQuery( uniqueClause.getQuery() ).createQuery();
+ }
+ }
+
+ BooleanQuery query = new BooleanQuery( );
+ for (BooleanClause clause : clauses) {
+ query.add( clause );
+ }
+ return queryCustomizer.setWrappedQuery( query ).createQuery();
+ }
+}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedQueryBuilder.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedQueryBuilder.java 2010-03-18 18:17:05 UTC (rev 19021)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedQueryBuilder.java 2010-03-18 18:58:27 UTC (rev 19022)
@@ -3,6 +3,7 @@
import org.apache.lucene.analysis.Analyzer;
import org.hibernate.search.SearchFactory;
+import org.hibernate.search.query.dsl.v2.BooleanJunction;
import org.hibernate.search.query.dsl.v2.QueryBuilder;
import org.hibernate.search.query.dsl.v2.TermContext;
@@ -23,4 +24,8 @@
public TermContext term() {
return new ConnectedTermContext( queryAnalyzer, factory);
}
+
+ public BooleanJunction bool() {
+ return new BooleanQueryBuilder();
+ }
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedTermContext.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedTermContext.java 2010-03-18 18:17:05 UTC (rev 19021)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedTermContext.java 2010-03-18 18:58:27 UTC (rev 19022)
@@ -12,6 +12,7 @@
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Filter;
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
@@ -28,7 +29,7 @@
/**
* @author Emmanuel Bernard
*/
-public class ConnectedTermContext implements TermContext {
+class ConnectedTermContext implements TermContext {
private final SearchFactory factory;
private final Analyzer queryAnalyzer;
@@ -62,6 +63,7 @@
private final String field;
private final String text;
private final Analyzer queryAnalyzer;
+ private final QueryCustomizer queryCustomizer;
private boolean ignoreAnalyzer;
private Approximation approximation = Approximation.EXACT;
@@ -73,6 +75,7 @@
this.field = field;
this.text = text;
this.queryAnalyzer = queryAnalyzer;
+ this.queryCustomizer = new QueryCustomizer();
}
public TermCustomization ignoreAnalyzer() {
@@ -96,9 +99,25 @@
return this;
}
+ public TermCustomization boostedTo(float boost) {
+ queryCustomizer.boostedTo( boost );
+ return this;
+ }
+
+ public TermCustomization constantScore() {
+ queryCustomizer.constantScore();
+ return this;
+ }
+
+ public TermCustomization filter(Filter filter) {
+ queryCustomizer.filter( filter );
+ return this;
+ }
+
public Query createQuery() {
+ final Query result;
if ( ignoreAnalyzer ) {
- return createTermQuery( text );
+ result = createTermQuery( text );
}
else {
List<String> terms;
@@ -112,18 +131,19 @@
throw new SearchException("try to search with an empty string: " + field);
}
else if (terms.size() == 1 ) {
- return createTermQuery( terms.get( 0 ) );
+ result = createTermQuery( terms.get( 0 ) );
}
else {
- BooleanQuery finalQuery = new BooleanQuery();
+ BooleanQuery booleanQuery = new BooleanQuery();
for (String term : terms) {
Query termQuery = createTermQuery(term);
//termQuery.setBoost( boost );
- finalQuery.add( termQuery, BooleanClause.Occur.SHOULD );
+ booleanQuery.add( termQuery, BooleanClause.Occur.SHOULD );
}
- return finalQuery;
+ result = booleanQuery;
}
}
+ return queryCustomizer.setWrappedQuery( result ).createQuery();
}
private Query createTermQuery(String term) {
@@ -146,19 +166,26 @@
}
private List<String> getAllTermsFromText(String fieldName, String text, Analyzer analyzer) throws IOException {
- Reader reader = new StringReader(text);
- TokenStream stream = analyzer.reusableTokenStream( fieldName, reader);
- TermAttribute attribute = (TermAttribute) stream.addAttribute( TermAttribute.class );
- stream.reset();
+ //it's better not to apply the analyzer with windcards as * and ? can be mistakenly removed
List<String> terms = new ArrayList<String>();
- while ( stream.incrementToken() ) {
- if ( attribute.termLength() > 0 ) {
- String term = attribute.term();
- terms.add( term );
+ if ( approximation == Approximation.WILDCARD ) {
+ terms.add( text );
+ }
+ else {
+ Reader reader = new StringReader(text);
+ TokenStream stream = analyzer.reusableTokenStream( fieldName, reader);
+ TermAttribute attribute = (TermAttribute) stream.addAttribute( TermAttribute.class );
+ stream.reset();
+
+ while ( stream.incrementToken() ) {
+ if ( attribute.termLength() > 0 ) {
+ String term = attribute.term();
+ terms.add( term );
+ }
}
+ stream.end();
+ stream.close();
}
- stream.end();
- stream.close();
return terms;
}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/QueryCustomizer.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/QueryCustomizer.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/QueryCustomizer.java 2010-03-18 18:58:27 UTC (rev 19022)
@@ -0,0 +1,56 @@
+package org.hibernate.search.query.dsl.v2.impl;
+
+import org.apache.lucene.search.ConstantScoreQuery;
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.FilteredQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.QueryFilter;
+import org.apache.lucene.search.QueryWrapperFilter;
+
+import org.hibernate.annotations.common.AssertionFailure;
+import org.hibernate.search.query.dsl.v2.QueryCustomization;
+
+/**
+ * @author Emmanuel Bernard
+ */
+class QueryCustomizer implements QueryCustomization<QueryCustomizer> {
+ private float boost = 1f;
+ private boolean constantScore;
+ private Query wrappedQuery;
+ private Filter filter;
+
+ public QueryCustomizer boostedTo(float boost) {
+ this.boost = boost;
+ return this;
+ }
+
+ public QueryCustomizer constantScore() {
+ constantScore = true;
+ return this;
+ }
+
+ public QueryCustomizer filter(Filter filter) {
+ this.filter = filter;
+ return this;
+ }
+
+ public QueryCustomizer setWrappedQuery(Query wrappedQuery) {
+ this.wrappedQuery = wrappedQuery;
+ return this;
+ }
+
+ public Query createQuery() {
+ Query finalQuery = wrappedQuery;
+ if (wrappedQuery == null) {
+ throw new AssertionFailure( "wrapped query not set" );
+ }
+ finalQuery.setBoost( boost );
+ if (filter != null) {
+ finalQuery = new FilteredQuery(finalQuery, filter);
+ }
+ if ( constantScore ) {
+ finalQuery = new ConstantScoreQuery( new QueryWrapperFilter( finalQuery ) );
+ }
+ return finalQuery;
+ }
+}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java 2010-03-18 18:17:05 UTC (rev 19021)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java 2010-03-18 18:58:27 UTC (rev 19022)
@@ -14,6 +14,7 @@
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.search.Environment;
+import org.hibernate.search.FullTextQuery;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.annotations.Factory;
@@ -27,16 +28,9 @@
public class DSLTest extends SearchTestCase {
public void testTermQueryOnAnalyzer() throws Exception {
- Session session = openSession();
- FullTextSession fts = Search.getFullTextSession( session );
+ FullTextSession fts = initData();
+
Transaction transaction = fts.beginTransaction();
- fts.persist( new Month("January", "Month of colder and whitening") );
- fts.persist( new Month("February", "Month of snowboarding") );
- transaction.commit();
-
- fts.clear();
-
- transaction = fts.beginTransaction();
final QueryBuilder monthQb = fts.getSearchFactory()
.buildQueryBuilder().forEntity( Month.class ).get();
Query
@@ -67,27 +61,15 @@
query = monthQb.term().on( "mythology" ).matches( "Month" ).createQuery();
- final List<Month> results = fts.createFullTextQuery( query, Month.class ).list();
- assertEquals( 2, results.size() );
+ transaction.commit();
- for (Month entity : results) {
- fts.delete( entity );
- }
- transaction.commit();
- fts.close();
+ cleanData( fts );
}
- public void tesFuzzyAndWildcardQuery() throws Exception {
- Session session = openSession();
- FullTextSession fts = Search.getFullTextSession( session );
+ public void testFuzzyAndWildcardQuery() throws Exception {
+ FullTextSession fts = initData();
+
Transaction transaction = fts.beginTransaction();
- fts.persist( new Month("January", "Month of colder and whitening") );
- fts.persist( new Month("February", "Month of snowboarding") );
- transaction.commit();
-
- fts.clear();
-
- transaction = fts.beginTransaction();
final QueryBuilder monthQb = fts.getSearchFactory()
.buildQueryBuilder().forEntity( Month.class ).get();
Query
@@ -106,19 +88,72 @@
.term().on( "mythology" ).matches( "mon*" )
.wildcard()
.createQuery();
-
+ System.out.println(query.toString( ));
assertEquals( 2, fts.createFullTextQuery( query, Month.class ).getResultSize() );
- final List<Month> results = fts.createFullTextQuery( query, Month.class ).list();
+ transaction.commit();
+
+ cleanData( fts );
+ }
+
+ public void testQueryCustomization() throws Exception {
+ FullTextSession fts = initData();
+
+ Transaction transaction = fts.beginTransaction();
+ final QueryBuilder monthQb = fts.getSearchFactory()
+ .buildQueryBuilder().forEntity( Month.class ).get();
+ Query
+
+ //combined query, January and february both contain whitening but February in a longer text
+ query = monthQb
+ .bool()
+ .should( monthQb.term().on( "mythology" ).matches( "whitening" ).createQuery() )
+ .should( monthQb.term().on( "history" ).matches( "whitening" ).createQuery() )
+ .createQuery();
+
+ List<Month> results = fts.createFullTextQuery( query, Month.class ).list();
assertEquals( 2, results.size() );
+ assertEquals( "January", results.get( 0 ).getName() );
+ //boosted query, January and february both contain whitening but February in a longer text
+ //since history is boosted, February should come first though
+ query = monthQb
+ .bool()
+ .should( monthQb.term().on( "mythology" ).matches( "whitening" ).createQuery() )
+ .should( monthQb.term().on( "history" ).matches( "whitening" ).boostedTo( 30 ).createQuery() )
+ .createQuery();
+
+ results = fts.createFullTextQuery( query, Month.class ).list();
+ assertEquals( 2, results.size() );
+ assertEquals( "February", results.get( 0 ).getName() );
+
+ transaction.commit();
+
+ cleanData( fts );
+ }
+
+ private void cleanData(FullTextSession fts) {
+ Transaction tx = fts.beginTransaction();
+ final List<Month> results = fts.createQuery( "from " + Month.class.getName() ).list();
+ assertEquals( 2, results.size() );
+
for (Month entity : results) {
fts.delete( entity );
}
- transaction.commit();
+ tx.commit();
fts.close();
}
+ private FullTextSession initData() {
+ Session session = openSession();
+ FullTextSession fts = Search.getFullTextSession( session );
+ Transaction tx = fts.beginTransaction();
+ fts.persist( new Month("January", "Month of colder and whitening", "Historically colder than any other month in the northern hemisphere") );
+ fts.persist( new Month("February", "Month of snowboarding", "Historically, the month where we make babies while watching the whitening landscape") );
+ tx.commit();
+ fts.clear();
+ return fts;
+ }
@Override
protected Class<?>[] getMappings() {
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/Month.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/Month.java 2010-03-18 18:17:05 UTC (rev 19021)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/Month.java 2010-03-18 18:58:27 UTC (rev 19022)
@@ -17,9 +17,10 @@
public class Month {
public Month() {}
- public Month(String name, String mythology) {
+ public Month(String name, String mythology, String history) {
this.name = name;
this.mythology = mythology;
+ this.history = history;
}
@Id @GeneratedValue
@@ -40,5 +41,11 @@
public String getMythology() { return mythology; }
public void setMythology(String mythology) { this.mythology = mythology; }
private String mythology;
+
+ @Field
+ public String getHistory() { return history; }
+ public void setHistory(String history) { this.history = history; }
+ private String history;
+
}
15 years, 6 months
Hibernate SVN: r19021 - in validator/trunk/hibernate-validator/src: test/java/org/hibernate/validator/engine and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-03-18 14:17:05 -0400 (Thu, 18 Mar 2010)
New Revision: 19021
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/CustomErrorMessageTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/DummyTestClass.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/IsValid.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/IsValidValidator.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintTree.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintViolationImpl.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/TestUtil.java
Log:
HV-297 Fixed ConstraintTree imlementation to allow the main ConstraintValidator to generate a custom error message
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintTree.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintTree.java 2010-03-18 16:36:48 UTC (rev 19020)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintTree.java 2010-03-18 18:17:05 UTC (rev 19021)
@@ -68,7 +68,7 @@
for ( ConstraintDescriptor<?> composingConstraint : descriptor.getComposingConstraints() ) {
composingConstraints.add( ( ConstraintDescriptorImpl<?> ) composingConstraint );
}
-
+
children = new ArrayList<ConstraintTree<?>>( composingConstraints.size() );
for ( ConstraintDescriptorImpl<?> composingDescriptor : composingConstraints ) {
@@ -90,7 +90,7 @@
}
public <T, U, V> void validateConstraints(Type type, GlobalExecutionContext<T> executionContext, LocalExecutionContext<U, V> localExecutionContext, List<ConstraintViolation<T>> constraintViolations) {
- // first validate composing constraints
+ // first validate composing constraints (recursively)
for ( ConstraintTree<?> tree : getChildren() ) {
List<ConstraintViolation<T>> tmpViolations = new ArrayList<ConstraintViolation<T>>();
tree.validateConstraints( type, executionContext, localExecutionContext, tmpViolations );
@@ -101,6 +101,20 @@
localExecutionContext.getPropertyPath(), descriptor
);
+ // check whether we have constraints violations, but we should only report the single message of the
+ // main constraint. We already have to generate the message here, since the composing constraints might
+ // not have its own ConstraintValidator.
+ // Also we want to leave it open to the final ConstraintValidator to generate a custom message.
+ if ( constraintViolations.size() > 0 && reportAsSingleViolation() ) {
+ constraintViolations.clear();
+ final String message = ( String ) getDescriptor().getAttributes().get( "message" );
+ MessageAndPath messageAndPath = new MessageAndPath( message, localExecutionContext.getPropertyPath() );
+ ConstraintViolation<T> violation = executionContext.createConstraintViolation(
+ localExecutionContext, messageAndPath, descriptor
+ );
+ constraintViolations.add( violation );
+ }
+
// we could have a composing constraint which does not need its own validator.
if ( !descriptor.getConstraintValidatorClasses().isEmpty() ) {
if ( log.isTraceEnabled() ) {
@@ -123,16 +137,6 @@
validator
);
}
-
- if ( reportAsSingleViolation() && constraintViolations.size() > 0 ) {
- constraintViolations.clear();
- final String message = ( String ) getDescriptor().getAttributes().get( "message" );
- MessageAndPath messageAndPath = new MessageAndPath( message, localExecutionContext.getPropertyPath() );
- ConstraintViolation<T> violation = executionContext.createConstraintViolation(
- localExecutionContext, messageAndPath, descriptor
- );
- constraintViolations.add( violation );
- }
}
private <T, U, V> void validateSingleConstraint(GlobalExecutionContext<T> executionContext, LocalExecutionContext<U, V> localExecutionContext, List<ConstraintViolation<T>> constraintViolations, ConstraintValidatorContextImpl constraintValidatorContext, ConstraintValidator<A, V> validator) {
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintViolationImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintViolationImpl.java 2010-03-18 16:36:48 UTC (rev 19020)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintViolationImpl.java 2010-03-18 18:17:05 UTC (rev 19021)
@@ -86,6 +86,7 @@
@Override
@SuppressWarnings("SimplifiableIfStatement")
+ // IMPORTANT - some behaviour of Validator depends on the correct implementation of this equals method!
public boolean equals(Object o) {
if ( this == o ) {
return true;
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/CustomErrorMessageTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/CustomErrorMessageTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/CustomErrorMessageTest.java 2010-03-18 18:17:05 UTC (rev 19021)
@@ -0,0 +1,47 @@
+/*
+ * $Id:$
+ *
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.engine.customerror;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.testng.annotations.Test;
+
+import static org.hibernate.validator.util.TestUtil.assertCorrectConstraintViolationMessages;
+import static org.hibernate.validator.util.TestUtil.getValidator;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class CustomErrorMessageTest {
+ /**
+ * HV-297
+ *
+ * @throws Exception in case the test fails.
+ */
+ @Test
+ public void testReportAsSingleViolationDoesNotInfluenceCustomError() throws Exception {
+ Validator validator = getValidator();
+ DummyTestClass dummyTestClass = new DummyTestClass();
+
+ Set<ConstraintViolation<DummyTestClass>> constraintViolations = validator.validate( dummyTestClass );
+ assertCorrectConstraintViolationMessages( constraintViolations, IsValidValidator.message );
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/CustomErrorMessageTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/DummyTestClass.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/DummyTestClass.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/DummyTestClass.java 2010-03-18 18:17:05 UTC (rev 19021)
@@ -0,0 +1,27 @@
+/*
+ * $Id:$
+ *
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.hibernate.validator.engine.customerror;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@IsValid
+public class DummyTestClass {
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/DummyTestClass.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/IsValid.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/IsValid.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/IsValid.java 2010-03-18 18:17:05 UTC (rev 19021)
@@ -0,0 +1,45 @@
+/*
+ * $Id:$
+ *
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.engine.customerror;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import javax.validation.ReportAsSingleViolation;
+import javax.validation.constraints.NotNull;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@NotNull
+@Target(TYPE)
+@Retention(RUNTIME)
+@Constraint(validatedBy = IsValidValidator.class)
+@ReportAsSingleViolation
+public @interface IsValid {
+ Class<?>[] groups() default { };
+
+ String message() default "Default error message";
+
+ Class<? extends Payload>[] payload() default { };
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/IsValid.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/IsValidValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/IsValidValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/IsValidValidator.java 2010-03-18 18:17:05 UTC (rev 19021)
@@ -0,0 +1,41 @@
+/*
+ * $Id:$
+ *
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.engine.customerror;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class IsValidValidator implements ConstraintValidator<IsValid, DummyTestClass> {
+
+ public static final String message = "Custom error message";
+
+
+ public void initialize(IsValid isValid) {
+ }
+
+ public boolean isValid(DummyTestClass dummyTestClass, ConstraintValidatorContext constraintValidatorContext) {
+ constraintValidatorContext.disableDefaultConstraintViolation();
+ constraintValidatorContext.buildConstraintViolationWithTemplate( message )
+ .addConstraintViolation();
+ return false;
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/IsValidValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/TestUtil.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/TestUtil.java 2010-03-18 16:36:48 UTC (rev 19020)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/TestUtil.java 2010-03-18 18:17:05 UTC (rev 19021)
@@ -118,7 +118,7 @@
actualMessages.add( violation.getMessage() );
}
- assertTrue( actualMessages.size() == messages.length, "Wrong number of error messages" );
+ assertEquals( actualMessages.size(), messages.length, "Wrong number of error messages" );
for ( String expectedMessage : messages ) {
assertTrue(
15 years, 6 months
Hibernate SVN: r19020 - validator/trunk/hibernate-validator/src/main/assembly.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-03-18 12:36:48 -0400 (Thu, 18 Mar 2010)
New Revision: 19020
Modified:
validator/trunk/hibernate-validator/src/main/assembly/dist.xml
Log:
Removed uneeded bundle format
Modified: validator/trunk/hibernate-validator/src/main/assembly/dist.xml
===================================================================
--- validator/trunk/hibernate-validator/src/main/assembly/dist.xml 2010-03-18 16:36:03 UTC (rev 19019)
+++ validator/trunk/hibernate-validator/src/main/assembly/dist.xml 2010-03-18 16:36:48 UTC (rev 19020)
@@ -22,7 +22,6 @@
<id>dist</id>
<formats>
<format>tar.gz</format>
- <format>tar.bz2</format>
<format>zip</format>
</formats>
15 years, 6 months