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,15 +68,15 @@ 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]);
getCfg().addInputStream(is);
for ( String xmlFile : xmlFiles ) {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
getCfg().addInputStream( is );
}
setDialect(Dialect.getDialect());
setSessions(getCfg().buildSessionFactory( /* new TestInterceptor() */));
@ -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,85 +3,100 @@
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.
*
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
@SuppressWarnings("unchecked")
public class NaturalIdOnSingleManyToOneTest extends TestCase {
private Logger log = LoggerFactory.getLogger(NaturalIdOnManyToOne.class);
private Logger log = LoggerFactory.getLogger( NaturalIdOnManyToOne.class );
public void testMappingProperties() {
log.warn("Commented out test");
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);
assertTrue( "Wrong number of elements", propertiesIndex.length == 1 );
}
public void testManyToOneNaturalIdCached() {
NaturalIdOnManyToOne singleManyToOne = new NaturalIdOnManyToOne();
Citizen c1 = new Citizen();
c1.setFirstname("Emmanuel");
c1.setLastname("Bernard");
c1.setSsn("1234");
c1.setFirstname( "Emmanuel" );
c1.setLastname( "Bernard" );
c1.setSsn( "1234" );
State france = new State();
france.setName("Ile de France");
c1.setState(france);
france.setName( "Ile de France" );
c1.setState( france );
singleManyToOne.setCitizen(c1);
singleManyToOne.setCitizen( c1 );
Session s = openSession();
Transaction tx = s.beginTransaction();
s.persist(france);
s.persist(c1);
s.persist(singleManyToOne);
s.persist( france );
s.persist( c1 );
s.persist( singleManyToOne );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
Criteria criteria = s.createCriteria(NaturalIdOnManyToOne.class);
criteria.add(Restrictions.naturalId().set("citizen", c1));
criteria.setCacheable(true);
Criteria criteria = s.createCriteria( NaturalIdOnManyToOne.class );
criteria.add( Restrictions.naturalId().set( "citizen", c1 ) );
criteria.setCacheable( true );
Statistics stats = getSessions().getStatistics();
stats.setStatisticsEnabled(true);
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( 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()
);
// 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;
@ -13,7 +14,7 @@
/**
* Test case for NaturalId annotation
*
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
@ -22,11 +23,14 @@ 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);
assertTrue( "Wrong number of elements", propertiesIndex.length == 2 );
}
public void testNaturalIdCached() {
@ -34,32 +38,46 @@ public void testNaturalIdCached() {
Session s = openSession();
Transaction tx = s.beginTransaction();
State france = (State) s.load(State.class, new Integer(2));
Criteria criteria = s.createCriteria(Citizen.class);
criteria.add(Restrictions.naturalId().set("ssn", "1234").set("state",
france));
criteria.setCacheable(true);
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.setCacheable( true );
Statistics stats = getSessions().getStatistics();
stats.setStatisticsEnabled(true);
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( 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()
);
// 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));
Criteria criteria = s.createCriteria(Citizen.class);
criteria.add(Restrictions.naturalId().set("ssn", "1234").set("state",
france));
criteria.setCacheable(false);
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.setCacheable( false );
Statistics stats = getSessions().getStatistics();
stats.setStatisticsEnabled(true);
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( 1, results.size() );
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,35 +133,41 @@ 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() {
Citizen c1 = new Citizen();
c1.setFirstname("Emmanuel");
c1.setLastname("Bernard");
c1.setSsn("1234");
c1.setFirstname( "Emmanuel" );
c1.setLastname( "Bernard" );
c1.setSsn( "1234" );
State france = new State();
france.setName("Ile de France");
c1.setState(france);
france.setName( "Ile de France" );
c1.setState( france );
Citizen c2 = new Citizen();
c2.setFirstname("Gavin");
c2.setLastname("King");
c2.setSsn("000");
c2.setFirstname( "Gavin" );
c2.setLastname( "King" );
c2.setSsn( "000" );
State australia = new State();
australia.setName("Australia");
c2.setState(australia);
australia.setName( "Australia" );
c2.setState( australia );
Session s = openSession();
Transaction tx = s.beginTransaction();
s.persist(australia);
s.persist(france);
s.persist(c1);
s.persist(c2);
s.persist( australia );
s.persist( france );
s.persist( c1 );
s.persist( c2 );
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;
@ -100,11 +101,11 @@ public void testSQLQuery() {
q.setParameter( 0, 9990 );
List result = q.list();
assertEquals( 1, result.size() );
Night n2 = (Night) result.get( 0 );
Night n2 = ( Night ) result.get( 0 );
assertEquals( n2.getDuration(), n.getDuration() );
List areas = s.getNamedQuery( "getAreaByNative" ).list();
assertTrue( 1 == areas.size() );
assertEquals( area.getName(), ( (Area) areas.get( 0 ) ).getName() );
assertEquals( area.getName(), ( ( Area ) areas.get( 0 ) ).getName() );
tx.commit();
s.close();
}
@ -139,7 +140,7 @@ public void testSQLQueryWithManyToOne() {
assertEquals( 1, stats.getQueryCachePutCount() );
q.list();
assertEquals( 1, stats.getQueryCacheHitCount() );
Night n2 = (Night) ( (Object[]) result.get( 0 ) )[0];
Night n2 = ( Night ) ( ( Object[] ) result.get( 0 ) )[0];
assertEquals( n2.getDuration(), n.getDuration() );
tx.commit();
s.close();
@ -162,7 +163,7 @@ public void testImplicitNativeQuery() throws Exception {
Query q = s.getNamedQuery( "implicitSample" );
List result = q.list();
assertEquals( 1, result.size() );
assertEquals( ship.getModel(), ( (SpaceShip) result.get( 0 ) ).getModel() );
assertEquals( ship.getModel(), ( ( SpaceShip ) result.get( 0 ) ).getModel() );
s.delete( result.get( 0 ) );
tx.commit();
s.close();
@ -192,8 +193,8 @@ public void testNativeQueryAndCompositePKAndComponents() throws Exception {
Query q = s.getNamedQuery( "compositekey" );
List result = q.list();
assertEquals( 1, result.size() );
Object[] row = (Object[]) result.get( 0 );
SpaceShip spaceShip = (SpaceShip) row[0];
Object[] row = ( Object[] ) result.get( 0 );
SpaceShip spaceShip = ( SpaceShip ) row[0];
assertEquals( ship.getModel(), spaceShip.getModel() );
assertNotNull( spaceShip.getDimensions() );
assertEquals( ship.getDimensions().getWidth(), spaceShip.getDimensions().getWidth() );
@ -270,9 +271,9 @@ public void testCache() throws Exception {
s = openSession();
tx = s.beginTransaction();
Query query = s.getNamedQuery( "plane.byId" ).setParameter( "id", plane.getId() );
plane = (Plane) query.uniqueResult();
plane = ( Plane ) query.uniqueResult();
assertEquals( 1, getSessions().getStatistics().getQueryCachePutCount() );
plane = (Plane) s.getNamedQuery( "plane.byId" ).setParameter( "id", plane.getId() ).uniqueResult();
plane = ( Plane ) s.getNamedQuery( "plane.byId" ).setParameter( "id", plane.getId() ).uniqueResult();
assertEquals( 1, getSessions().getStatistics().getQueryCacheHitCount() );
tx.commit();
s.close();
@ -304,7 +305,7 @@ public void testEntitySQLOverriding() {
s.clear();
s.getSessionFactory().evict( Chaos.class );
Chaos resultChaos = (Chaos) s.load( Chaos.class, chaos.getId() );
Chaos resultChaos = ( Chaos ) s.load( Chaos.class, chaos.getId() );
assertEquals( upperName, resultChaos.getName() );
assertEquals( "nickname", resultChaos.getNickname() );
@ -326,23 +327,23 @@ public void testCollectionSQLOverriding() {
CasimirParticle p = new CasimirParticle();
p.setId( 1l );
s.persist( p );
chaos.getParticles().add(p);
chaos.getParticles().add( p );
p = new CasimirParticle();
p.setId( 2l );
s.persist( p );
chaos.getParticles().add(p);
chaos.getParticles().add( p );
s.flush();
s.clear();
s.getSessionFactory().evict( Chaos.class );
Chaos resultChaos = (Chaos) s.load( Chaos.class, chaos.getId() );
Chaos resultChaos = ( Chaos ) s.load( Chaos.class, chaos.getId() );
assertEquals( 2, resultChaos.getParticles().size() );
resultChaos.getParticles().remove( resultChaos.getParticles().iterator().next() );
resultChaos.getParticles().remove( resultChaos.getParticles().iterator().next() );
s.flush();
s.clear();
resultChaos = (Chaos) s.load( Chaos.class, chaos.getId() );
resultChaos = ( Chaos ) s.load( Chaos.class, chaos.getId() );
assertEquals( 0, resultChaos.getParticles().size() );
tx.rollback();
@ -350,7 +351,7 @@ public void testCollectionSQLOverriding() {
}
protected Class[] getMappings() {
return new Class[]{
return new Class[] {
Plane.class,
A320.class,
A320b.class,
@ -366,15 +367,19 @@ protected Class[] getMappings() {
}
protected String[] getAnnotatedPackages() {
return new String[]{
return new String[] {
"org.hibernate.test.annotations.query"
};
}
@Override
protected String[] getXmlFiles() {
return new String[]{
return new String[] {
"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