[hibernate-commits] Hibernate SVN: r11361 - in trunk/Hibernate3/test/org/hibernate/test: legacy and 1 other directory.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Thu Mar 29 08:48:35 EDT 2007
Author: steve.ebersole at jboss.com
Date: 2007-03-29 08:48:35 -0400 (Thu, 29 Mar 2007)
New Revision: 11361
Modified:
trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java
trunk/Hibernate3/test/org/hibernate/test/legacy/LegacyTestCase.java
Log:
test suite fixes : postgresql (boolean handling)
Modified: trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java 2007-03-29 12:47:49 UTC (rev 11360)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java 2007-03-29 12:48:35 UTC (rev 11361)
@@ -11,7 +11,6 @@
import antlr.RecognitionException;
import junit.framework.Test;
-import junit.framework.TestSuite;
import org.hibernate.Hibernate;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -516,8 +515,7 @@
}
public void testSubstitutions() throws Exception {
- HashMap replacements = new HashMap();
- replacements.put("true", "1");
+ Map replacements = buildTrueFalseReplacementMapForDialect();
replacements.put("yes", "'Y'");
assertTranslation( "from Human h where h.pregnant = true", replacements );
assertTranslation( "from Human h where h.pregnant = yes", replacements );
@@ -663,27 +661,35 @@
public void testPolymorphism() throws Exception {
- HashMap replacements = new HashMap();
- replacements.put( "false", "0" );
- replacements.put( "true", "1" );
+ Map replacements = buildTrueFalseReplacementMapForDialect();
assertTranslation( "from Mammal" );
assertTranslation( "from Dog" );
assertTranslation( "from Mammal m where m.pregnant = false and m.bodyWeight > 10", replacements );
assertTranslation( "from Dog d where d.pregnant = false and d.bodyWeight > 10", replacements );
}
- public void testTokenReplacement() throws Exception {
+ private Map buildTrueFalseReplacementMapForDialect() {
HashMap replacements = new HashMap();
- replacements.put( "false", "0" );
- replacements.put( "true", "1" );
- assertTranslation( "from Mammal m where m.pregnant = false and m.bodyWeight > 10",
- replacements );
+ try {
+ String dialectTrueRepresentation = getDialect().toBooleanValueString( true );
+ // if this call succeeds, then the dialect is saying to represent true/false as int values...
+ Integer.parseInt( dialectTrueRepresentation );
+ replacements.put( "true", "1" );
+ replacements.put( "false", "0" );
+ }
+ catch( NumberFormatException nfe ) {
+ // the Integer#parseInt call failed...
+ }
+ return replacements;
}
+ public void testTokenReplacement() throws Exception {
+ Map replacements = buildTrueFalseReplacementMapForDialect();
+ assertTranslation( "from Mammal m where m.pregnant = false and m.bodyWeight > 10", replacements );
+ }
+
public void testProduct() throws Exception {
- HashMap replacements = new HashMap();
- replacements.put( "false", "0" );
- replacements.put( "true", "1" );
+ Map replacements = buildTrueFalseReplacementMapForDialect();
assertTranslation( "from Animal, Animal" );
assertTranslation( "from Animal x, Animal y where x.bodyWeight = y.bodyWeight" );
assertTranslation( "from Animal x, Mammal y where x.bodyWeight = y.bodyWeight and not y.pregnant = true", replacements );
@@ -747,9 +753,7 @@
}
public void testExplicitJoins() throws Exception {
- HashMap replacements = new HashMap();
- replacements.put( "false", "0" );
- replacements.put( "true", "1" );
+ Map replacements = buildTrueFalseReplacementMapForDialect();
assertTranslation( "from Zoo zoo join zoo.mammals mam where mam.pregnant = true and mam.description like '%white%'", replacements );
assertTranslation( "from Zoo zoo join zoo.animals an where an.description like '%white%'" );
}
Modified: trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java 2007-03-29 12:47:49 UTC (rev 11360)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java 2007-03-29 12:48:35 UTC (rev 11361)
@@ -106,7 +106,7 @@
assertTranslation( hql, null, scalar, null );
}
- protected void assertTranslation(String hql, HashMap replacements) {
+ protected void assertTranslation(String hql, Map replacements) {
ComparisonFailure cf = null;
try {
assertTranslation( hql, replacements, false, null );
@@ -141,7 +141,7 @@
System.out.println( "OLD SQL: " + oldsql );
}
- protected void assertTranslation(String hql, HashMap replacements, boolean scalar, String sql) {
+ protected void assertTranslation(String hql, Map replacements, boolean scalar, String sql) {
SessionFactoryImplementor factory = getSessionFactoryImplementor();
// Create an empty replacements map if we don't have one.
@@ -198,12 +198,12 @@
}
- protected QueryTranslatorImpl createNewQueryTranslator(String hql, HashMap replacements, boolean scalar) {
+ protected QueryTranslatorImpl createNewQueryTranslator(String hql, Map replacements, boolean scalar) {
SessionFactoryImplementor factory = getSessionFactoryImplementor();
return createNewQueryTranslator( hql, replacements, scalar, factory );
}
- private QueryTranslatorImpl createNewQueryTranslator(String hql, HashMap replacements, boolean scalar, SessionFactoryImplementor factory) {
+ private QueryTranslatorImpl createNewQueryTranslator(String hql, Map replacements, boolean scalar, SessionFactoryImplementor factory) {
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
QueryTranslatorImpl newQueryTranslator = ( QueryTranslatorImpl ) ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, factory );
newQueryTranslator.compile( replacements, scalar );
Modified: trunk/Hibernate3/test/org/hibernate/test/legacy/LegacyTestCase.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/legacy/LegacyTestCase.java 2007-03-29 12:47:49 UTC (rev 11360)
+++ trunk/Hibernate3/test/org/hibernate/test/legacy/LegacyTestCase.java 2007-03-29 12:48:35 UTC (rev 11361)
@@ -5,6 +5,7 @@
import org.hibernate.hql.classic.ClassicQueryTranslatorFactory;
import org.hibernate.util.StringHelper;
import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.dialect.Dialect;
/**
* @author Steve Ebersole
@@ -32,14 +33,25 @@
super.configure( cfg );
if ( !useAntlrParser ) {
cfg.setProperty( Environment.QUERY_TRANSLATOR, ClassicQueryTranslatorFactory.class.getName() );
- String subs = cfg.getProperties().getProperty( Environment.QUERY_SUBSTITUTIONS );
- if ( StringHelper.isEmpty( subs ) ) {
- subs = "true=1, false=0";
+ try {
+ String dialectTrueRepresentation = Dialect.getDialect().toBooleanValueString( true );
+ // if this call succeeds, then the dialect is saying to represent true/false as int values...
+ Integer.parseInt( dialectTrueRepresentation );
+ String subs = cfg.getProperties().getProperty( Environment.QUERY_SUBSTITUTIONS );
+ if ( subs == null ) {
+ subs = "";
+ }
+ if ( StringHelper.isEmpty( subs ) ) {
+ subs = "true=1, false=0";
+ }
+ else {
+ subs += ", true=1, false=0";
+ }
+ cfg.getProperties().setProperty( Environment.QUERY_SUBSTITUTIONS, subs );
}
- else {
- subs += ", true=1, false=0";
+ catch( NumberFormatException nfe ) {
+ // the Integer#parseInt call failed...
}
- cfg.getProperties().setProperty( Environment.QUERY_SUBSTITUTIONS, subs );
}
}
}
More information about the hibernate-commits
mailing list