HHH-5200 - Prepare to use H2 as the default testing datbase
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19412 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
cb51ef1a64
commit
413666f293
|
@ -2015,4 +2015,23 @@ public abstract class Dialect {
|
|||
public boolean supportsBindAsCallableArgument() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this dialect support `count(a,b)`?
|
||||
*
|
||||
* @return True if the database supports counting tuples; false otherwise.
|
||||
*/
|
||||
public boolean supportsTupleCounts() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this dialect support `count(distinct a,b)`?
|
||||
*
|
||||
* @return True if the database supports counting disintct tuples; false otherwise.
|
||||
*/
|
||||
public boolean supportsTupleDistinctCounts() {
|
||||
// oddly most database in fact seem to, so true is the default.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -305,4 +305,9 @@ public class H2Dialect extends Dialect {
|
|||
public boolean supportsLobValueChangePropogation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsTupleDistinctCounts() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -331,4 +331,9 @@ public class HSQLDialect extends Dialect {
|
|||
public boolean supportsLobValueChangePropogation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsTupleDistinctCounts() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -598,7 +598,7 @@
|
|||
<properties>
|
||||
<db.dialect>org.hibernate.dialect.H2Dialect</db.dialect>
|
||||
<jdbc.driver>org.h2.Driver</jdbc.driver>
|
||||
<jdbc.url>jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1</jdbc.url>
|
||||
<jdbc.url>jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE</jdbc.url>
|
||||
<jdbc.user>sa</jdbc.user>
|
||||
<jdbc.pass />
|
||||
<jdbc.isolation />
|
||||
|
|
|
@ -90,6 +90,7 @@ public class CompositeElementTest extends FunctionalTestCase {
|
|||
public void testCustomColumnReadAndWrite() {
|
||||
final double HEIGHT_INCHES = 49;
|
||||
final double HEIGHT_CENTIMETERS = HEIGHT_INCHES * 2.54d;
|
||||
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Child c = new Child( "Child One" );
|
||||
|
@ -99,8 +100,8 @@ public class CompositeElementTest extends FunctionalTestCase {
|
|||
c.setParent( p );
|
||||
s.save( p );
|
||||
s.flush();
|
||||
|
||||
// Test value conversion during insert
|
||||
|
||||
// Test value conversion during insert
|
||||
Double heightViaSql = (Double)s.createSQLQuery("select height_centimeters from parentchild c where c.name='Child One'")
|
||||
.uniqueResult();
|
||||
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
||||
|
|
|
@ -985,10 +985,18 @@ public class CriteriaQueryTest extends FunctionalTestCase {
|
|||
result = s.createCriteria( Student.class )
|
||||
.setProjection( Projections.count( "cityState" ) )
|
||||
.uniqueResult();
|
||||
fail( "expected SQLGrammarException" );
|
||||
if ( ! getDialect().supportsTupleCounts() ) {
|
||||
fail( "expected SQLGrammarException" );
|
||||
}
|
||||
assertEquals( 1, ( ( Long ) result ).longValue() );
|
||||
}
|
||||
catch ( SQLGrammarException ex ) {
|
||||
// expected
|
||||
if ( ! getDialect().supportsTupleCounts() ) {
|
||||
// expected
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
t.rollback();
|
||||
|
@ -999,13 +1007,18 @@ public class CriteriaQueryTest extends FunctionalTestCase {
|
|||
t = s.beginTransaction();
|
||||
try {
|
||||
result = s.createCriteria( Student.class )
|
||||
.setProjection( Projections.countDistinct( "cityState" ) )
|
||||
.uniqueResult();
|
||||
.setProjection( Projections.countDistinct( "cityState" ) )
|
||||
.uniqueResult();
|
||||
if ( ! getDialect().supportsTupleDistinctCounts() ) {
|
||||
fail( "expected SQLGrammarException" );
|
||||
}
|
||||
assertEquals( 1, ( ( Long ) result ).longValue() );
|
||||
}
|
||||
catch ( SQLGrammarException ex ) {
|
||||
// HSQLDB's cannot handle more than 1 argument in SELECT COUNT( DISTINCT ... ) )
|
||||
if ( ! ( getDialect() instanceof HSQLDialect ) ) {
|
||||
if ( ! getDialect().supportsTupleDistinctCounts() ) {
|
||||
// expected
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
@ -1276,11 +1289,16 @@ public class CriteriaQueryTest extends FunctionalTestCase {
|
|||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
try {
|
||||
Object result = s.createCriteria( CourseMeeting.class).setProjection( Projections.countDistinct( "id" ) ).list();
|
||||
s.createCriteria( CourseMeeting.class).setProjection( Projections.countDistinct( "id" ) ).list();
|
||||
if ( ! getDialect().supportsTupleDistinctCounts() ) {
|
||||
fail( "expected SQLGrammarException" );
|
||||
}
|
||||
}
|
||||
catch ( SQLGrammarException ex ) {
|
||||
// HSQLDB's cannot handle more than 1 argument in SELECT COUNT( DISTINCT ... ) )
|
||||
if ( ! ( getDialect() instanceof HSQLDialect ) ) {
|
||||
if ( ! getDialect().supportsTupleDistinctCounts() ) {
|
||||
// expected
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -230,11 +230,16 @@ public class CriteriaHQLAlignmentTest extends QueryTranslatorTestCase {
|
|||
t = s.beginTransaction();
|
||||
try {
|
||||
count = ( Long ) s.createQuery( "select count( distinct name ) from Human" ).uniqueResult();
|
||||
if ( ! getDialect().supportsTupleDistinctCounts() ) {
|
||||
fail( "expected SQLGrammarException" );
|
||||
}
|
||||
assertEquals( 2, count.longValue() );
|
||||
}
|
||||
catch ( SQLGrammarException ex ) {
|
||||
// HSQLDB's cannot handle more than 1 argument in SELECT COUNT( DISTINCT ... ) )
|
||||
if ( ! ( getDialect() instanceof HSQLDialect ) ) {
|
||||
if ( ! getDialect().supportsTupleDistinctCounts() ) {
|
||||
// expected
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
@ -247,13 +252,18 @@ public class CriteriaHQLAlignmentTest extends QueryTranslatorTestCase {
|
|||
t = s.beginTransaction();
|
||||
try {
|
||||
count = ( Long ) s.createCriteria( Human.class )
|
||||
.setProjection( Projections.count( "name" ).setDistinct() )
|
||||
.uniqueResult();
|
||||
.setProjection( Projections.count( "name" ).setDistinct() )
|
||||
.uniqueResult();
|
||||
if ( ! getDialect().supportsTupleDistinctCounts() ) {
|
||||
fail( "expected SQLGrammarException" );
|
||||
}
|
||||
assertEquals( 2, count.longValue() );
|
||||
}
|
||||
catch ( SQLGrammarException ex ) {
|
||||
// HSQLDB's cannot handle more than 1 argument in SELECT COUNT( DISTINCT ... ) )
|
||||
if ( ! ( getDialect() instanceof HSQLDialect ) ) {
|
||||
if ( ! getDialect().supportsTupleDistinctCounts() ) {
|
||||
// expected
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
@ -278,10 +288,18 @@ public class CriteriaHQLAlignmentTest extends QueryTranslatorTestCase {
|
|||
t = s.beginTransaction();
|
||||
try {
|
||||
count = ( Long ) s.createQuery( "select count( name ) from Human" ).uniqueResult();
|
||||
fail( "should have failed due to SQLGrammarException" );
|
||||
if ( ! getDialect().supportsTupleCounts() ) {
|
||||
fail( "expected SQLGrammarException" );
|
||||
}
|
||||
assertEquals( 1, count.longValue() );
|
||||
}
|
||||
catch ( SQLGrammarException ex ) {
|
||||
// expected
|
||||
if ( ! getDialect().supportsTupleCounts() ) {
|
||||
// expected
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
t.rollback();
|
||||
|
@ -292,12 +310,20 @@ public class CriteriaHQLAlignmentTest extends QueryTranslatorTestCase {
|
|||
t = s.beginTransaction();
|
||||
try {
|
||||
count = ( Long ) s.createCriteria( Human.class )
|
||||
.setProjection( Projections.count( "name" ) )
|
||||
.uniqueResult();
|
||||
fail( "should have failed due to SQLGrammarException" );
|
||||
.setProjection( Projections.count( "name" ) )
|
||||
.uniqueResult();
|
||||
if ( ! getDialect().supportsTupleCounts() ) {
|
||||
fail( "expected SQLGrammarException" );
|
||||
}
|
||||
assertEquals( 1, count.longValue() );
|
||||
}
|
||||
catch ( SQLGrammarException ex ) {
|
||||
// expected
|
||||
if ( ! getDialect().supportsTupleCounts() ) {
|
||||
// expected
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
t.rollback();
|
||||
|
|
|
@ -14,6 +14,7 @@ import junit.framework.Test;
|
|||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.dialect.DB2Dialect;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.dialect.HSQLDialect;
|
||||
import org.hibernate.dialect.IngresDialect;
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
|
@ -726,9 +727,12 @@ public class HQLTest extends QueryTranslatorTestCase {
|
|||
public void testGroupByFunction() {
|
||||
if ( getDialect() instanceof Oracle8iDialect ) return; // the new hiearchy...
|
||||
if ( getDialect() instanceof PostgreSQLDialect ) return;
|
||||
assertTranslation( "select count(*) from Human h group by year(h.birthdate)" );
|
||||
if ( ! H2Dialect.class.isInstance( getDialect() ) ) {
|
||||
// H2 has no year function
|
||||
assertTranslation( "select count(*) from Human h group by year(h.birthdate)" );
|
||||
assertTranslation( "select count(*) from Human h group by year(sysdate)" );
|
||||
}
|
||||
assertTranslation( "select count(*) from Human h group by trunc( sqrt(h.bodyWeight*4)/2 )" );
|
||||
assertTranslation( "select count(*) from Human h group by year(sysdate)" );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -53,16 +53,14 @@ public class ScrollableCollectionFetchingTest extends FunctionalTestCase {
|
|||
Session s = openSession();
|
||||
Transaction txn = s.beginTransaction();
|
||||
|
||||
assertTrue(s
|
||||
.createQuery( "from Animal a left join fetch a.offspring where a.description like :desc order by a.id" )
|
||||
.setString( "desc", "root%" )
|
||||
.list()
|
||||
.isEmpty() );
|
||||
final String query = "from Animal a left join fetch a.offspring where a.description like :desc order by a.id";
|
||||
|
||||
ScrollableResults results = s
|
||||
.createQuery( "from Animal a left join fetch a.offspring where a.description like :desc order by a.id" )
|
||||
.setString( "desc", "root%" )
|
||||
.scroll();
|
||||
// first, as a control, make sure there are no results
|
||||
int size = s.createQuery( query ).setString( "desc", "root%" ).list().size();
|
||||
assertEquals( 0, size );
|
||||
|
||||
// now get the scrollable results
|
||||
ScrollableResults results = s.createQuery( query ).setString( "desc", "root%" ).scroll();
|
||||
|
||||
assertFalse( results.isFirst() );
|
||||
assertFalse( results.isLast() );
|
||||
|
|
Loading…
Reference in New Issue