JBPAPP-1679

Aligned hibernate.properties with hibernate.properties in testsuite module.

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@16421 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Hardy Ferentschik 2009-04-23 11:53:54 +00:00
parent 6c90c9cf5b
commit 339ec18771
6 changed files with 209 additions and 173 deletions

View File

@ -68,14 +68,14 @@ protected void buildSessionFactory( Class<?>[] classes, String[] packages, Strin
if ( recreateSchema() ) {
cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
}
for ( int i = 0; i < packages.length; i++ ) {
getCfg().addPackage(packages[i]);
for ( String aPackage : packages ) {
getCfg().addPackage( aPackage );
}
for ( int i = 0; i < classes.length; i++ ) {
getCfg().addAnnotatedClass(classes[i]);
for ( Class<?> aClass : classes ) {
getCfg().addAnnotatedClass( aClass );
}
for ( int i = 0; i < xmlFiles.length; i++ ) {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(xmlFiles[i]);
for ( String xmlFile : xmlFiles ) {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
getCfg().addInputStream( is );
}
setDialect(Dialect.getDialect());
@ -134,7 +134,7 @@ private void checkSkip( Method runMethod ) {
}
}
private void runTestMethod( Method runMethod ) throws Throwable, IllegalAccessException {
private void runTestMethod( Method runMethod ) throws Throwable {
try {
runMethod.invoke(this, new Class[0]);
} catch ( InvocationTargetException e ) {

View File

@ -3,15 +3,17 @@
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.stat.Statistics;
import org.hibernate.test.annotations.TestCase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Test case for NaturalId annotation. See ANN-750.
@ -28,9 +30,12 @@ public void testMappingProperties() {
log.warn( "Commented out test" );
ClassMetadata metaData = getSessions().getClassMetadata(
NaturalIdOnManyToOne.class);
assertTrue("Class should have a natural key", metaData
.hasNaturalIdentifier());
NaturalIdOnManyToOne.class
);
assertTrue(
"Class should have a natural key", metaData
.hasNaturalIdentifier()
);
int[] propertiesIndex = metaData.getNaturalIdentifierProperties();
assertTrue( "Wrong number of elements", propertiesIndex.length == 1 );
}
@ -65,23 +70,33 @@ public void testManyToOneNaturalIdCached() {
Statistics stats = getSessions().getStatistics();
stats.setStatisticsEnabled( true );
stats.clear();
assertEquals("Cache hits should be empty", 0, stats
.getQueryCacheHitCount());
assertEquals(
"Cache hits should be empty", 0, stats
.getQueryCacheHitCount()
);
// first query
List results = criteria.list();
assertEquals( 1, results.size() );
assertEquals("Cache hits should be empty", 0, stats
.getQueryCacheHitCount());
assertEquals("First query should be a miss", 1, stats
.getQueryCacheMissCount());
assertEquals("Query result should be added to cache", 1, stats
.getQueryCachePutCount());
assertEquals(
"Cache hits should be empty", 0, stats
.getQueryCacheHitCount()
);
assertEquals(
"First query should be a miss", 1, stats
.getQueryCacheMissCount()
);
assertEquals(
"Query result should be added to cache", 1, stats
.getQueryCachePutCount()
);
// query a second time - result should be cached
results = criteria.list();
assertEquals("Cache hits should be empty", 1, stats
.getQueryCacheHitCount());
criteria.list();
assertEquals(
"Cache hits should be empty", 1, stats
.getQueryCacheHitCount()
);
// cleanup
tx.rollback();
@ -89,7 +104,13 @@ public void testManyToOneNaturalIdCached() {
}
protected Class[] getMappings() {
return new Class[] { Citizen.class, State.class,
NaturalIdOnManyToOne.class };
return new Class[] {
Citizen.class, State.class,
NaturalIdOnManyToOne.class
};
}
protected void configure(Configuration cfg) {
cfg.setProperty( "hibernate.cache.use_query_cache", "true" );
}
}

View File

@ -6,6 +6,7 @@
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.stat.Statistics;
@ -22,9 +23,12 @@ public class NaturalIdTest extends TestCase {
public void testMappingProperties() {
ClassMetadata metaData = getSessions().getClassMetadata(
Citizen.class);
assertTrue("Class should have a natural key", metaData
.hasNaturalIdentifier());
Citizen.class
);
assertTrue(
"Class should have a natural key", metaData
.hasNaturalIdentifier()
);
int[] propertiesIndex = metaData.getNaturalIdentifierProperties();
assertTrue( "Wrong number of elements", propertiesIndex.length == 2 );
}
@ -34,32 +38,46 @@ public void testNaturalIdCached() {
Session s = openSession();
Transaction tx = s.beginTransaction();
State france = (State) s.load(State.class, new Integer(2));
State france = ( State ) s.load( State.class, 2 );
Criteria criteria = s.createCriteria( Citizen.class );
criteria.add(Restrictions.naturalId().set("ssn", "1234").set("state",
france));
criteria.add(
Restrictions.naturalId().set( "ssn", "1234" ).set(
"state",
france
)
);
criteria.setCacheable( true );
Statistics stats = getSessions().getStatistics();
stats.setStatisticsEnabled( true );
stats.clear();
assertEquals("Cache hits should be empty", 0, stats
.getQueryCacheHitCount());
assertEquals(
"Cache hits should be empty", 0, stats
.getQueryCacheHitCount()
);
// first query
List results = criteria.list();
assertEquals( 1, results.size() );
assertEquals("Cache hits should be empty", 0, stats
.getQueryCacheHitCount());
assertEquals("First query should be a miss", 1, stats
.getQueryCacheMissCount());
assertEquals("Query result should be added to cache", 1, stats
.getQueryCachePutCount());
assertEquals(
"Cache hits should be empty", 0, stats
.getQueryCacheHitCount()
);
assertEquals(
"First query should be a miss", 1, stats
.getQueryCacheMissCount()
);
assertEquals(
"Query result should be added to cache", 1, stats
.getQueryCachePutCount()
);
// query a second time - result should be cached
results = criteria.list();
assertEquals("Cache hits should be empty", 1, stats
.getQueryCacheHitCount());
criteria.list();
assertEquals(
"Cache hits should be empty", 1, stats
.getQueryCacheHitCount()
);
// cleanup
tx.rollback();
@ -72,30 +90,42 @@ public void testNaturalIdUncached() {
Session s = openSession();
Transaction tx = s.beginTransaction();
State france = (State) s.load(State.class, new Integer(2));
State france = ( State ) s.load( State.class, 2 );
Criteria criteria = s.createCriteria( Citizen.class );
criteria.add(Restrictions.naturalId().set("ssn", "1234").set("state",
france));
criteria.add(
Restrictions.naturalId().set( "ssn", "1234" ).set(
"state",
france
)
);
criteria.setCacheable( false );
Statistics stats = getSessions().getStatistics();
stats.setStatisticsEnabled( true );
stats.clear();
assertEquals("Cache hits should be empty", 0, stats
.getQueryCacheHitCount());
assertEquals(
"Cache hits should be empty", 0, stats
.getQueryCacheHitCount()
);
// first query
List results = criteria.list();
assertEquals( 1, results.size() );
assertEquals("Cache hits should be empty", 0, stats
.getQueryCacheHitCount());
assertEquals("Query result should be added to cache", 0, stats
.getQueryCachePutCount());
assertEquals(
"Cache hits should be empty", 0, stats
.getQueryCacheHitCount()
);
assertEquals(
"Query result should be added to cache", 0, stats
.getQueryCachePutCount()
);
// query a second time
results = criteria.list();
assertEquals("Cache hits should be empty", 0, stats
.getQueryCacheHitCount());
criteria.list();
assertEquals(
"Cache hits should be empty", 0, stats
.getQueryCacheHitCount()
);
// cleanup
tx.rollback();
@ -103,8 +133,10 @@ public void testNaturalIdUncached() {
}
protected Class[] getMappings() {
return new Class[] { Citizen.class, State.class,
NaturalIdOnManyToOne.class };
return new Class[] {
Citizen.class, State.class,
NaturalIdOnManyToOne.class
};
}
private void saveSomeCitizens() {
@ -134,4 +166,8 @@ private void saveSomeCitizens() {
tx.commit();
s.close();
}
protected void configure(Configuration cfg) {
cfg.setProperty( "hibernate.cache.use_query_cache", "true" );
}
}

View File

@ -9,6 +9,7 @@
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.stat.Statistics;
import org.hibernate.test.annotations.A320;
import org.hibernate.test.annotations.A320b;
@ -377,4 +378,8 @@ protected String[] getXmlFiles() {
"org/hibernate/test/annotations/query/orm.xml"
};
}
protected void configure(Configuration cfg) {
cfg.setProperty( "hibernate.cache.use_query_cache", "true" );
}
}

View File

@ -1,26 +1,18 @@
#
# 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
#
################################################################################
# Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved. #
# #
# 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, v. 2.1. This program is distributed in the #
# hope that it will be useful, but WITHOUT A 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, v.2.1 along with this #
# distribution; if not, write to the Free Software Foundation, Inc., #
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
# #
# Red Hat Author(s): Steve Ebersole #
################################################################################
hibernate.dialect ${db.dialect}
hibernate.connection.driver_class ${jdbc.driver}
hibernate.connection.url ${jdbc.url}
@ -37,7 +29,3 @@ hibernate.max_fetch_depth 5
hibernate.cache.region_prefix hibernate.test
hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider
hibernate.cache.use_query_cache true
# hibernate.jdbc.batch_size 0

View File

@ -1,26 +1,18 @@
#
# 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
#
################################################################################
# Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved. #
# #
# 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, v. 2.1. This program is distributed in the #
# hope that it will be useful, but WITHOUT A 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, v.2.1 along with this #
# distribution; if not, write to the Free Software Foundation, Inc., #
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
# #
# Red Hat Author(s): Steve Ebersole #
################################################################################
hibernate.dialect ${db.dialect}
hibernate.connection.driver_class ${jdbc.driver}
hibernate.connection.url ${jdbc.url}
@ -33,13 +25,7 @@ hibernate.connection.pool_size 5
hibernate.show_sql true
hibernate.format_sql true
hibernate.hbm2ddl.auto create-drop
hibernate.max_fetch_depth 5
hibernate.cache.region_prefix hibernate.test
hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider
hibernate.cache.use_query_cache true
# hibernate.jdbc.batch_size 0