[hibernate-commits] Hibernate SVN: r19787 - in core/branches/gradle2/hibernate-core/src/test: perf and 11 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Wed Jun 23 02:15:02 EDT 2010
Author: steve.ebersole at jboss.com
Date: 2010-06-23 02:15:02 -0400 (Wed, 23 Jun 2010)
New Revision: 19787
Added:
core/branches/gradle2/hibernate-core/src/test/README
core/branches/gradle2/hibernate-core/src/test/perf/
core/branches/gradle2/hibernate-core/src/test/perf/org/
core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/
core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/
core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/
core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/ConfigurationPerformanceTest.java
core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/NewPerformanceTest.java
core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/NewerPerformanceTest.java
core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/PerformanceTest.java
core/branches/gradle2/hibernate-core/src/test/unmaintained/
core/branches/gradle2/hibernate-core/src/test/unmaintained/org/
core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/
core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/
core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/hql/
core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/hql/ASTQueryTranslatorTest.java
core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/tool/
core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/tool/Team.hbm.xml
core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/tool/Team.java
core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/tool/TestSchemaTools.java
Modified:
core/branches/gradle2/hibernate-core/src/test/resources/log4j.properties
Log:
converted hibernate-core and hibernate-annotations to use intgTest stuff
Added: core/branches/gradle2/hibernate-core/src/test/README
===================================================================
--- core/branches/gradle2/hibernate-core/src/test/README (rev 0)
+++ core/branches/gradle2/hibernate-core/src/test/README 2010-06-23 06:15:02 UTC (rev 19787)
@@ -0,0 +1,4 @@
+Currently we have folded (1) unit tests, (2) integration tests and (3) test infrastructure code into this one directory.
+
+Eventually would like to have at least 2 'sourceSets' (one for unit tests and one for integration tests + test
+infrastructure code).
\ No newline at end of file
Added: core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/ConfigurationPerformanceTest.java
===================================================================
--- core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/ConfigurationPerformanceTest.java (rev 0)
+++ core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/ConfigurationPerformanceTest.java 2010-06-23 06:15:02 UTC (rev 19787)
@@ -0,0 +1,248 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, 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.perf;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.classic.Session;
+import org.hibernate.testing.junit.UnitTestCase;
+
+/**
+ * Test of configuration, specifically "cacheable files".
+ *
+ * @author Max Andersen
+ * @author Steve Ebersole
+ */
+public class ConfigurationPerformanceTest extends UnitTestCase {
+
+ private final String workPackageName = "org.hibernate.test.cfg.work";
+ private File compilationBaseDir;
+ private File workPackageDir;
+
+ protected void setUp() throws Exception {
+ compilationBaseDir = getTestComplileDirectory();
+ workPackageDir = new File( compilationBaseDir, workPackageName.replace( '.', '/' ) );
+ if ( workPackageDir.exists() ) {
+ //noinspection ResultOfMethodCallIgnored
+ workPackageDir.delete();
+ }
+ boolean created = workPackageDir.mkdirs();
+ if ( !created ) {
+ System.err.println( "Unable to create workPackageDir during setup" );
+ }
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public ConfigurationPerformanceTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new TestSuite( ConfigurationPerformanceTest.class );
+ }
+
+ public static void main(String[] args) throws Exception {
+ TestRunner.run( suite() );
+ }
+
+ public void testSessionFactoryCreationTime() throws Throwable {
+ generateTestFiles();
+ if ( !workPackageDir.exists() ) {
+ System.err.println( workPackageDir.getAbsoluteFile() + " not found" );
+ return;
+ }
+
+ long start = System.currentTimeMillis();
+ Configuration configuration = buildConfigurationFromCacheableFiles(
+ workPackageDir,
+ workPackageDir.list(
+ new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.endsWith( ".hbm.xml" );
+ }
+ }
+ )
+ );
+ SessionFactory factory = configuration.buildSessionFactory();
+ long initial = System.currentTimeMillis() - start;
+ factory.close();
+
+ start = System.currentTimeMillis();
+ configuration = buildConfigurationFromCacheableFiles(
+ workPackageDir,
+ workPackageDir.list(
+ new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.endsWith( ".hbm.xml" );
+ }
+ }
+ )
+ );
+ factory = configuration.buildSessionFactory();
+ long subsequent = System.currentTimeMillis() - start;
+
+ // Let's make sure the mappings were read in correctly (in termas of they are operational).
+ Session session = factory.openSession();
+ session.beginTransaction();
+ session.createQuery( "from Test1" ).list();
+ session.getTransaction().commit();
+ session.close();
+ factory.close();
+
+ System.err.println( "Initial SessionFactory load time : " + initial );
+ System.err.println( "Subsequent SessionFactory load time : " + subsequent );
+ }
+
+ private Configuration buildConfigurationFromCacheableFiles(File mappingFileBase, String[] files) {
+ long start = System.currentTimeMillis();
+ Configuration cfg = new Configuration();
+ cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
+ System.err.println(
+ "Created configuration: " + ( System.currentTimeMillis() - start ) / 1000.0 + " sec."
+ );
+
+ start = System.currentTimeMillis();
+ //noinspection ForLoopReplaceableByForEach
+ for ( int i = 0; i < files.length; i++ ) {
+ cfg.addCacheableFile( new File( mappingFileBase, files[i] ) );
+ }
+ System.err.println(
+ "Added " + ( files.length ) + " resources: " +
+ ( System.currentTimeMillis() - start ) / 1000.0 + " sec."
+ );
+ return cfg;
+ }
+
+ public void generateTestFiles() throws Throwable {
+ String filesToCompile = "";
+ for ( int count = 0; count < 100; count++ ) {
+ String name = "Test" + count;
+ File javaFile = new File( workPackageDir, name + ".java" );
+ File hbmFile = new File( workPackageDir, name + ".hbm.xml" );
+ filesToCompile += ( javaFile.getAbsolutePath() + " " );
+
+ System.out.println( "Generating " + javaFile.getAbsolutePath() );
+ PrintWriter javaWriter = null;
+ PrintWriter hbmWriter = null;
+ try {
+ javaWriter = new PrintWriter( new FileWriter( javaFile ) );
+ hbmWriter = new PrintWriter( new FileWriter( hbmFile ) );
+
+ javaWriter.println( "package " + workPackageName + ";" );
+ hbmWriter.println(
+ "<?xml version=\"1.0\"?>\r\n" +
+ "<!DOCTYPE hibernate-mapping PUBLIC \r\n" +
+ " \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\r\n" +
+ " \"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd\">\r\n"
+ );
+
+ hbmWriter.println( "<hibernate-mapping package=\"" + workPackageName + "\">" );
+
+ javaWriter.println( "public class " + name + " {" );
+ javaWriter.println( " static { System.out.println(\"" + name + " initialized!\"); }" );
+ hbmWriter.println( "<class name=\"" + name + "\">" );
+
+ hbmWriter.println( "<id type=\"long\"><generator class=\"assigned\"/></id>" );
+ for ( int propCount = 0; propCount < 100; propCount++ ) {
+ String propName = "Prop" + propCount;
+
+ writeJavaProperty( javaWriter, propName );
+
+ hbmWriter.println( "<property name=\"" + propName + "\" type=\"string\"/>" );
+
+ }
+ hbmWriter.println( "</class>" );
+ javaWriter.println( "}" );
+ hbmWriter.println( "</hibernate-mapping>" );
+ }
+ finally {
+ if ( javaWriter != null ) {
+ javaWriter.flush();
+ javaWriter.close();
+ }
+ if ( hbmWriter != null ) {
+ hbmWriter.flush();
+ hbmWriter.close();
+ }
+ }
+ }
+
+ String javac = "javac -version -d " + compilationBaseDir + " " + filesToCompile;
+ System.err.println( "JAVAC : " + javac );
+ Process process = Runtime.getRuntime().exec( javac );
+ process.waitFor();
+ System.err.println( "********************* JAVAC OUTPUT **********************" );
+ pullStream( process.getInputStream() );
+ System.err.println( "---------------------------------------------------------" );
+ pullStream( process.getErrorStream() );
+ System.err.println( "*********************************************************" );
+ }
+
+ private void pullStream(InputStream stream) throws IOException {
+ if ( stream == null || stream.available() <= 0 ) {
+ return;
+ }
+ byte[] buffer = new byte[256];
+ while ( true ) {
+ int read = stream.read( buffer );
+ if ( read == -1 ) {
+ break;
+ }
+ System.err.write( buffer, 0, read );
+ }
+// System.err.println( "" );
+ }
+
+ private void writeJavaProperty(PrintWriter javaWriter, String propName) {
+ javaWriter.println( " String " + propName + ";" );
+ javaWriter.println( " String get" + propName + "() { return " + propName + "; }" );
+ javaWriter.println( " void set" + propName + "(String newVal) { " + propName + "=newVal; }" );
+ }
+
+ private File getTestComplileDirectory() {
+ String resourceName = "org/hibernate/test/legacy/ABC.hbm.xml";
+ String prefix = getClass().getClassLoader().getResource( resourceName ).getFile();
+ prefix = prefix.substring( 0, prefix.lastIndexOf( '/' ) ); // ABC.hbm.xml
+ prefix = prefix.substring( 0, prefix.lastIndexOf( '/' ) ); // legacy/
+ prefix = prefix.substring( 0, prefix.lastIndexOf( '/' ) ); // test/
+ prefix = prefix.substring( 0, prefix.lastIndexOf( '/' ) ); // hibernate/
+ prefix = prefix.substring( 0, prefix.lastIndexOf( '/' ) ); // org/
+ return new File( prefix + '/' );
+ }
+}
Added: core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/NewPerformanceTest.java
===================================================================
--- core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/NewPerformanceTest.java (rev 0)
+++ core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/NewPerformanceTest.java 2010-06-23 06:15:02 UTC (rev 19787)
@@ -0,0 +1,93 @@
+package org.hibernate.test.perf;
+
+import java.io.Serializable;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.textui.TestRunner;
+
+import org.hibernate.classic.Session;
+import org.hibernate.testing.junit.functional.FunctionalTestCase;
+import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.legacy.Simple;
+
+public class NewPerformanceTest extends FunctionalTestCase {
+
+ public NewPerformanceTest(String arg0) {
+ super(arg0);
+ }
+
+ public String[] getMappings() {
+ return new String[] { "legacy/Simple.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( NewPerformanceTest.class );
+ }
+
+ public static void main(String[] args) throws Exception {
+ TestRunner.run( suite() );
+ }
+
+ public void testPerformance() throws Exception {
+
+ for ( int n=2; n<4000; n*=2 ) {
+
+ Simple[] simples = new Simple[n];
+ Serializable[] ids = new Serializable[n];
+ for ( int i=0; i<n; i++ ) {
+ simples[i] = new Simple();
+ simples[i].init();
+ simples[i].setCount(i);
+ ids[i] = new Long(i);
+ }
+
+ Session s = openSession();
+ prepare(s, simples, ids, n);
+ s.close();
+
+ long find = 0;
+ long flush = 0;
+
+ for ( int i=0; i<100; i++ ) {
+
+ s = openSession();
+ long time = System.currentTimeMillis();
+ List list = s.createQuery("from Simple s where not s.name='osama bin laden' and s.other is null").list();
+ find += System.currentTimeMillis() - time;
+ assertTrue( list.size()==n );
+ time = System.currentTimeMillis();
+ s.flush();
+ flush += System.currentTimeMillis() - time;
+ time = System.currentTimeMillis();
+ s.connection().commit();
+ find += System.currentTimeMillis() - time;
+ s.close();
+
+ }
+
+ System.out.println( "Objects: " + n + " - find(): " + find + "ms / flush(): " + flush + "ms / Ratio: " + ( (float) flush )/find );
+ System.out.println( "Objects: " + n + " flush time per object: " + flush / 100.0 / n );
+ System.out.println( "Objects: " + n + " load time per object: " + find / 100.0 / n );
+ s = openSession();
+ delete(s);
+ s.close();
+
+ }
+ }
+
+ private void prepare(Session s, Simple[] simples, Serializable[] ids, int N) throws Exception {
+ for ( int i=0; i<N; i++ ) {
+ s.save( simples[i], ids[i] );
+ }
+ s.flush();
+ s.connection().commit();
+ }
+
+ private void delete(Session s) throws Exception {
+ s.delete("from Simple s");
+ s.flush();
+ s.connection().commit();
+ }
+
+}
Added: core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/NewerPerformanceTest.java
===================================================================
--- core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/NewerPerformanceTest.java (rev 0)
+++ core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/NewerPerformanceTest.java 2010-06-23 06:15:02 UTC (rev 19787)
@@ -0,0 +1,396 @@
+package org.hibernate.test.perf;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.textui.TestRunner;
+
+import org.hibernate.cfg.Environment;
+import org.hibernate.classic.Session;
+import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.connection.ConnectionProviderFactory;
+import org.hibernate.testing.junit.functional.FunctionalTestCase;
+import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.legacy.Simple;
+
+public class NewerPerformanceTest extends FunctionalTestCase {
+
+ public NewerPerformanceTest(String name) {
+ super( name );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "legacy/Simple.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( NewerPerformanceTest.class );
+ }
+
+ public static void main(String[] args) throws Exception {
+ TestRunner.run( suite() );
+ }
+
+ public void testMany() throws Exception {
+
+ ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider( Environment.getProperties() );
+
+ long hiber=0;
+ long jdbc=0;
+
+ for ( int n=0; n<20; n++ ) {
+
+ Session s = openSession();
+ s.delete("from Simple");
+ s.flush();
+ Simple[] simples = new Simple[n];
+ Serializable[] ids = new Serializable[n];
+ for ( int i=0; i<n; i++ ) {
+ simples[i] = new Simple();
+ simples[i].init();
+ simples[i].setCount(i);
+ ids[i] = new Long(i);
+ s.save(simples[i], ids[i]);
+ }
+ s.flush();
+ s.connection().commit();
+ s.close();
+
+ //allow cache to settle
+
+ s = openSession();
+ hibernate(s, simples, ids, n, "h0");
+ s.close();
+
+ Connection c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j0" );
+ cp.closeConnection(c);
+
+ s = openSession();
+ hibernate(s, simples, ids, n, "h0");
+ s.close();
+
+ c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j0" );
+ cp.closeConnection(c);
+
+ //Now do timings
+
+ int N=30;
+
+ long time = System.currentTimeMillis();
+ for (int i=0; i<N; i++) {
+ s = openSession();
+ hibernate(s, simples, ids, n, "h1");
+ s.close();
+ }
+ hiber += System.currentTimeMillis() - time;
+
+ time = System.currentTimeMillis();
+ for (int i=0; i<N; i++) {
+ c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j1" );
+ cp.closeConnection(c);
+ }
+ jdbc += System.currentTimeMillis() - time;
+
+ time = System.currentTimeMillis();
+ for (int i=0; i<N; i++) {
+ s = openSession();
+ hibernate(s, simples, ids, n, "h2");
+ s.close();
+ }
+ hiber += System.currentTimeMillis() - time;
+
+ time = System.currentTimeMillis();
+ for (int i=0; i<N; i++) {
+ c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j2" );
+ cp.closeConnection(c);
+ }
+ jdbc += System.currentTimeMillis() - time;
+
+ time = System.currentTimeMillis();
+ for (int i=0; i<N; i++) {
+ s = openSession();
+ hibernate(s, simples, ids, n, "h1");
+ s.close();
+ }
+ hiber += System.currentTimeMillis() - time;
+
+ time = System.currentTimeMillis();
+ for (int i=0; i<N; i++) {
+ c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j1" );
+ cp.closeConnection(c);
+ }
+ jdbc += System.currentTimeMillis() - time;
+
+ }
+
+ System.out.println( "Hibernate: " + hiber + "ms / Direct JDBC: " + jdbc + "ms = Ratio: " + ( (float) hiber )/jdbc );
+
+ cp.close();
+ System.gc();
+ }
+
+ public void testSimultaneous() throws Exception {
+
+ ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider( Environment.getProperties() );
+
+ for ( int n=2; n<4000; n*=2 ) {
+
+ Session s = openSession();
+ s.delete("from Simple");
+ s.flush();
+ Simple[] simples = new Simple[n];
+ Serializable[] ids = new Serializable[n];
+ for ( int i=0; i<n; i++ ) {
+ simples[i] = new Simple();
+ simples[i].init();
+ simples[i].setCount(i);
+ ids[i] = new Long(i);
+ s.save(simples[i], ids[i]);
+ }
+ s.flush();
+ s.connection().commit();
+ s.close();
+
+ //allow cache to settle
+
+ s = openSession();
+ hibernate(s, simples, ids, n, "h0");
+ s.close();
+
+ Connection c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j0" );
+ cp.closeConnection(c);
+
+ s = openSession();
+ hibernate(s, simples, ids, n, "h0");
+ s.close();
+
+ c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j0" );
+ cp.closeConnection(c);
+
+ //Now do timings
+
+ s = openSession();
+ long time = System.currentTimeMillis();
+ hibernate(s, simples, ids, n, "h1");
+ long hiber = System.currentTimeMillis() - time;
+ s.close();
+
+ c = cp.getConnection();
+ time = System.currentTimeMillis();
+ directJDBC( c, simples, ids, n, "j1" );
+ long jdbc = System.currentTimeMillis() - time;
+ cp.closeConnection(c);
+
+ s = openSession();
+ time = System.currentTimeMillis();
+ hibernate(s, simples, ids, n, "h2");
+ hiber += System.currentTimeMillis() - time;
+ s.close();
+
+ c = cp.getConnection();
+ time = System.currentTimeMillis();
+ directJDBC( c, simples, ids, n, "j2" );
+ jdbc += System.currentTimeMillis() - time;
+ cp.closeConnection(c);
+
+ s = openSession();
+ time = System.currentTimeMillis();
+ hibernate(s, simples, ids, n, "h2");
+ hiber += System.currentTimeMillis() - time;
+ s.close();
+
+ c = cp.getConnection();
+ time = System.currentTimeMillis();
+ directJDBC( c, simples, ids, n, "j2" );
+ jdbc += System.currentTimeMillis() - time;
+ cp.closeConnection(c);
+
+ System.out.println( "Objects: " + n + " - Hibernate: " + hiber + "ms / Direct JDBC: " + jdbc + "ms = Ratio: " + ( (float) hiber )/jdbc );
+
+ }
+
+ cp.close();
+ System.gc();
+ }
+
+ public void testHibernateOnly() throws Exception {
+
+ for ( int n=2; n<4000; n*=2 ) {
+
+ Session s = openSession();
+ Simple[] simples = new Simple[n];
+ s.delete("from Simple");
+ s.flush();
+ Serializable[] ids = new Serializable[n];
+ for ( int i=0; i<n; i++ ) {
+ simples[i] = new Simple();
+ simples[i].init();
+ simples[i].setCount(i);
+ ids[i] = new Long(i);
+ s.save(simples[i], ids[i]);
+ }
+ s.flush();
+ s.connection().commit();
+ s.close();
+
+ //Now do timings
+
+ s = openSession();
+ long time = System.currentTimeMillis();
+ hibernate(s, simples, ids, n, "h1");
+ long hiber = System.currentTimeMillis() - time;
+ s.close();
+
+ s = openSession();
+ time = System.currentTimeMillis();
+ hibernate(s, simples, ids, n, "h2");
+ hiber += System.currentTimeMillis() - time;
+ s.close();
+
+ s = openSession();
+ time = System.currentTimeMillis();
+ hibernate(s, simples, ids, n, "h2");
+ hiber += System.currentTimeMillis() - time;
+ s.close();
+
+ System.out.println( "Objects: " + n + " - Hibernate: " + hiber );
+
+ }
+
+ System.gc();
+ }
+
+ public void testJdbcOnly() throws Exception {
+
+ ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider( Environment.getProperties() );
+
+ for ( int n=2; n<4000; n*=2 ) {
+
+ Session s = openSession();
+ Simple[] simples = new Simple[n];
+ s.delete("from Simple");
+ s.flush();
+ Serializable[] ids = new Serializable[n];
+ for ( int i=0; i<n; i++ ) {
+ simples[i] = new Simple();
+ simples[i].init();
+ simples[i].setCount(i);
+ ids[i] = new Long(i);
+ s.save(simples[i], ids[i]);
+ }
+ s.flush();
+ s.connection().commit();
+ s.close();
+
+
+ //Now do timings
+
+ Connection c = cp.getConnection();
+ long time = System.currentTimeMillis();
+ directJDBC( c, simples, ids, n, "j1" );
+ long jdbc = System.currentTimeMillis() - time;
+ cp.closeConnection(c);
+
+ c = cp.getConnection();
+ time = System.currentTimeMillis();
+ directJDBC( c, simples, ids, n, "j2" );
+ jdbc += System.currentTimeMillis() - time;
+ cp.closeConnection(c);
+
+ c = cp.getConnection();
+ time = System.currentTimeMillis();
+ directJDBC( c, simples, ids, n, "j2" );
+ jdbc += System.currentTimeMillis() - time;
+ cp.closeConnection(c);
+
+ System.out.println( "Objects: " + n + " Direct JDBC: " + jdbc );
+
+ }
+
+ cp.close();
+ System.gc();
+ }
+
+ /*private void hibernate(Session s, Simple[] simples, Serializable[] ids, int N, String runname) throws Exception {
+ for ( int i=0; i<N; i++ ) {
+ s.get( Simple.class, ids[i] );
+ //s.find("from Simple s where s.id = ?", ids[i], Hibernate.LONG);
+ }
+ //s.flush();
+ s.connection().commit();
+ }
+
+ private void directJDBC(Connection c, Simple[] simples, Serializable[] ids, int N, String runname) throws SQLException {
+
+ for ( int i=0; i<N; i++ ) {
+ PreparedStatement select = c.prepareStatement("SELECT s.id_, s.name, s.address, s.count_, s.date_, s.pay, s.other FROM Simple s where s.id_=?");
+ select.setLong( 1, ( (Long) ids[i] ).longValue() );
+ ResultSet rs = select.executeQuery();
+ rs.next();
+ /*new Long( rs.getLong(1) );
+ rs.getString(2);
+ rs.getString(3);
+ rs.getInt(4);
+ rs.getDate(5);
+ rs.getFloat(6);
+ rs.getLong(7);*/
+ /*Simple s = new Simple();
+ new Long( rs.getLong("id_") ); rs.wasNull();
+ s.setName( rs.getString("name") ); rs.wasNull();
+ s.setAddress( rs.getString("address") ); rs.wasNull();
+ s.setCount( rs.getInt("count_") ); rs.wasNull();
+ s.setDate( rs.getTimestamp("date_") ); rs.wasNull();
+ s.setPay( new Float( rs.getFloat("pay") ) ); rs.wasNull();
+ rs.getLong("other"); rs.wasNull(); s.setOther(null);
+ rs.close();
+ select.close();
+ }
+ c.commit();
+ }*/
+
+ private void hibernate(Session s, Simple[] simples, Serializable[] ids, int N, String runname) throws Exception {
+ s.createQuery("from Simple s").list();
+ s.connection().commit();
+ }
+
+ private void directJDBC(Connection c, Simple[] simples, Serializable[] ids, int N, String runname) throws SQLException {
+ List result=new ArrayList();
+ PreparedStatement select = c.prepareStatement("SELECT s.id_ as id_, s.name as name, s.address as address, s.count_ as count_, s.date_ as date_, s.pay as pay, s.other as other FROM Simple s");
+ ResultSet rs = select.executeQuery();
+ while ( rs.next() ) {
+ /*new Long( rs.getLong(1) );
+ rs.getString(2);
+ rs.getString(3);
+ rs.getInt(4);
+ rs.getDate(5);
+ rs.getFloat(6);
+ rs.getLong(7);*/
+ Simple s = new Simple();
+ new Long( rs.getLong("id_") ); rs.wasNull();
+ s.setName( rs.getString("name") ); rs.wasNull();
+ s.setAddress( rs.getString("address") ); rs.wasNull();
+ s.setCount( rs.getInt("count_") ); rs.wasNull();
+ s.setDate( rs.getTimestamp("date_") ); rs.wasNull();
+ s.setPay( new Float( rs.getFloat("pay") ) ); rs.wasNull();
+ rs.getLong("other"); rs.wasNull(); s.setOther(null);
+ result.add(s);
+ }
+ rs.close();
+ select.close();
+ c.commit();
+ }
+
+}
Added: core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/PerformanceTest.java
===================================================================
--- core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/PerformanceTest.java (rev 0)
+++ core/branches/gradle2/hibernate-core/src/test/perf/org/hibernate/test/perf/PerformanceTest.java 2010-06-23 06:15:02 UTC (rev 19787)
@@ -0,0 +1,357 @@
+package org.hibernate.test.perf;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.hibernate.cfg.Environment;
+import org.hibernate.classic.Session;
+import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.connection.ConnectionProviderFactory;
+import org.hibernate.testing.junit.functional.FunctionalTestCase;
+import org.hibernate.test.legacy.Simple;
+
+public class PerformanceTest extends FunctionalTestCase {
+
+ public PerformanceTest(String arg0) {
+ super(arg0);
+ }
+
+ public String[] getMappings() {
+ return new String[] { "legacy/Simple.hbm.xml" };
+ }
+
+ public static Test suite() throws Exception {
+ return new TestSuite(PerformanceTest.class);
+ }
+
+ public static void main(String[] args) throws Exception {
+ TestRunner.run( suite() );
+ }
+
+ public void testMany() throws Exception {
+
+ ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider( Environment.getProperties() );
+
+ long hiber=0;
+ long jdbc=0;
+
+ for ( int n=0; n<20; n++ ) {
+
+ Simple[] simples = new Simple[n];
+ Serializable[] ids = new Serializable[n];
+ for ( int i=0; i<n; i++ ) {
+ simples[i] = new Simple();
+ simples[i].init();
+ simples[i].setCount(i);
+ ids[i] = new Long(i);
+ }
+
+ //allow cache to settle
+
+ Session s = openSession();
+ hibernate(s, simples, ids, n, "h0");
+ s.close();
+
+ Connection c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j0" );
+ cp.closeConnection(c);
+
+ s = openSession();
+ hibernate(s, simples, ids, n, "h0");
+ s.close();
+
+ c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j0" );
+ cp.closeConnection(c);
+
+ //Now do timings
+
+ int N=30;
+
+ long time = System.currentTimeMillis();
+ for (int i=0; i<N; i++) {
+ s = openSession();
+ hibernate(s, simples, ids, n, "h1");
+ s.close();
+ }
+ hiber += System.currentTimeMillis() - time;
+
+ time = System.currentTimeMillis();
+ for (int i=0; i<N; i++) {
+ c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j1" );
+ cp.closeConnection(c);
+ }
+ jdbc += System.currentTimeMillis() - time;
+
+ time = System.currentTimeMillis();
+ for (int i=0; i<N; i++) {
+ s = openSession();
+ hibernate(s, simples, ids, n, "h2");
+ s.close();
+ }
+ hiber += System.currentTimeMillis() - time;
+
+ time = System.currentTimeMillis();
+ for (int i=0; i<N; i++) {
+ c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j2" );
+ cp.closeConnection(c);
+ }
+ jdbc += System.currentTimeMillis() - time;
+
+ time = System.currentTimeMillis();
+ for (int i=0; i<N; i++) {
+ s = openSession();
+ hibernate(s, simples, ids, n, "h1");
+ s.close();
+ }
+ hiber += System.currentTimeMillis() - time;
+
+ time = System.currentTimeMillis();
+ for (int i=0; i<N; i++) {
+ c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j1" );
+ cp.closeConnection(c);
+ }
+ jdbc += System.currentTimeMillis() - time;
+
+ }
+
+ System.out.println( "Hibernate: " + hiber + "ms / Direct JDBC: " + jdbc + "ms = Ratio: " + ( (float) hiber )/jdbc );
+
+ cp.close();
+ System.gc();
+ }
+
+ public void testSimultaneous() throws Exception {
+
+ ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider( Environment.getProperties() );
+
+ for ( int n=2; n<4000; n*=2 ) {
+
+ Simple[] simples = new Simple[n];
+ Serializable[] ids = new Serializable[n];
+ for ( int i=0; i<n; i++ ) {
+ simples[i] = new Simple();
+ simples[i].init();
+ simples[i].setCount(i);
+ ids[i] = new Long(i);
+ }
+
+ //allow cache to settle
+
+ Session s = openSession();
+ hibernate(s, simples, ids, n, "h0");
+ s.close();
+
+ Connection c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j0" );
+ cp.closeConnection(c);
+
+ s = openSession();
+ hibernate(s, simples, ids, n, "h0");
+ s.close();
+
+ c = cp.getConnection();
+ directJDBC( c, simples, ids, n, "j0" );
+ cp.closeConnection(c);
+
+ //Now do timings
+
+ s = openSession();
+ long time = System.currentTimeMillis();
+ hibernate(s, simples, ids, n, "h1");
+ long hiber = System.currentTimeMillis() - time;
+ s.close();
+
+ c = cp.getConnection();
+ time = System.currentTimeMillis();
+ directJDBC( c, simples, ids, n, "j1" );
+ long jdbc = System.currentTimeMillis() - time;
+ cp.closeConnection(c);
+
+ s = openSession();
+ time = System.currentTimeMillis();
+ hibernate(s, simples, ids, n, "h2");
+ hiber += System.currentTimeMillis() - time;
+ s.close();
+
+ c = cp.getConnection();
+ time = System.currentTimeMillis();
+ directJDBC( c, simples, ids, n, "j2" );
+ jdbc += System.currentTimeMillis() - time;
+ cp.closeConnection(c);
+
+ s = openSession();
+ time = System.currentTimeMillis();
+ hibernate(s, simples, ids, n, "h2");
+ hiber += System.currentTimeMillis() - time;
+ s.close();
+
+ c = cp.getConnection();
+ time = System.currentTimeMillis();
+ directJDBC( c, simples, ids, n, "j2" );
+ jdbc += System.currentTimeMillis() - time;
+ cp.closeConnection(c);
+
+ System.out.println( "Objects: " + n + " - Hibernate: " + hiber + "ms / Direct JDBC: " + jdbc + "ms = Ratio: " + ( (float) hiber )/jdbc );
+
+ }
+
+ cp.close();
+ System.gc();
+ }
+
+ public void testHibernateOnly() throws Exception {
+
+ for ( int n=2; n<4000; n*=2 ) {
+
+ Simple[] simples = new Simple[n];
+ Serializable[] ids = new Serializable[n];
+ for ( int i=0; i<n; i++ ) {
+ simples[i] = new Simple();
+ simples[i].init();
+ simples[i].setCount(i);
+ ids[i] = new Long(i);
+ }
+
+ //Now do timings
+
+ Session s = openSession();
+ long time = System.currentTimeMillis();
+ hibernate(s, simples, ids, n, "h1");
+ long hiber = System.currentTimeMillis() - time;
+ s.close();
+
+ s = openSession();
+ time = System.currentTimeMillis();
+ hibernate(s, simples, ids, n, "h2");
+ hiber += System.currentTimeMillis() - time;
+ s.close();
+
+ s = openSession();
+ time = System.currentTimeMillis();
+ hibernate(s, simples, ids, n, "h2");
+ hiber += System.currentTimeMillis() - time;
+ s.close();
+
+ System.out.println( "Objects: " + n + " - Hibernate: " + hiber );
+
+ }
+
+ System.gc();
+ }
+
+ public void testJdbcOnly() throws Exception {
+
+ ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider( Environment.getProperties() );
+
+ for ( int n=2; n<4000; n*=2 ) {
+
+ Simple[] simples = new Simple[n];
+ Serializable[] ids = new Serializable[n];
+ for ( int i=0; i<n; i++ ) {
+ simples[i] = new Simple();
+ simples[i].init();
+ simples[i].setCount(i);
+ ids[i] = new Long(i);
+ }
+
+ //Now do timings
+
+ Connection c = cp.getConnection();
+ long time = System.currentTimeMillis();
+ directJDBC( c, simples, ids, n, "j1" );
+ long jdbc = System.currentTimeMillis() - time;
+ cp.closeConnection(c);
+
+ c = cp.getConnection();
+ time = System.currentTimeMillis();
+ directJDBC( c, simples, ids, n, "j2" );
+ jdbc += System.currentTimeMillis() - time;
+ cp.closeConnection(c);
+
+ c = cp.getConnection();
+ time = System.currentTimeMillis();
+ directJDBC( c, simples, ids, n, "j2" );
+ jdbc += System.currentTimeMillis() - time;
+ cp.closeConnection(c);
+
+ System.out.println( "Objects: " + n + " Direct JDBC: " + jdbc );
+
+ }
+
+ cp.close();
+ System.gc();
+ }
+
+ private void hibernate(Session s, Simple[] simples, Serializable[] ids, int N, String runname) throws Exception {
+ for ( int i=0; i<N; i++ ) {
+ s.save( simples[i], ids[i] );
+ }
+ for ( int i=0; i<N; i++ ) {
+ simples[0].setName("A Different Name!" + i + N + runname);
+ }
+ //s.flush();
+ // the results of this test are highly dependent upon
+ // how many times we flush!
+ assertTrue( "assertion", s.delete("from Simple s")==N );
+ s.flush();
+ s.connection().commit();
+ }
+
+ private void directJDBC(Connection c, Simple[] simples, Serializable[] ids, int N, String runname) throws SQLException {
+
+ PreparedStatement insert = c.prepareStatement("insert into Simple ( name, address, count_, date_, other, id_ ) values ( ?, ?, ?, ?, ?, ? )");
+ PreparedStatement delete = c.prepareStatement("delete from Simple where id_ = ?");
+ PreparedStatement select = c.prepareStatement("SELECT s.id_, s.name, s.address, s.count_, s.date_, s.other FROM Simple s");
+ PreparedStatement update = c.prepareStatement("update Simple set name = ?, address = ?, count_ = ?, date_ = ?, other = ? where id_ = ?");
+ for ( int i=0; i<N; i++ ) {
+ insert.setString(1, simples[i].getName() );
+ insert.setString(2, simples[i].getAddress() );
+ insert.setInt(3, simples[i].getCount() );
+ insert.setDate( 4, (java.sql.Date) simples[i].getDate() );
+ insert.setNull(5, Types.BIGINT);
+ insert.setLong( 6, ( (Long) ids[i] ).longValue() );
+ insert.executeUpdate();
+ }
+ insert.close();
+ for ( int i=0; i<N; i++ ) {
+ update.setString(1, "A Different Name!" + i + N + runname );
+ update.setString(2, simples[i].getAddress() );
+ update.setInt(3, simples[i].getCount() );
+ update.setDate( 4, (java.sql.Date) simples[i].getDate() );
+ update.setNull(5, Types.BIGINT);
+ update.setLong( 6, ( (Long) ids[i] ).longValue() );
+ update.executeUpdate();
+ }
+ update.close();
+ java.sql.ResultSet rs = select.executeQuery();
+ Long[] keys = new Long[N];
+ int j=0;
+ while ( rs.next() ) {
+ keys[j++] = new Long( rs.getLong(1) );
+ rs.getString(2);
+ rs.getString(3);
+ rs.getInt(4);
+ rs.getDate(5);
+ rs.getLong(6);
+ }
+ rs.close();
+ select.close();
+ for ( int i=0; i<N; i++ ) {
+ delete.setLong(1, keys[i].longValue() );
+ delete.executeUpdate();
+ }
+ delete.close();
+ c.commit();
+ }
+}
Modified: core/branches/gradle2/hibernate-core/src/test/resources/log4j.properties
===================================================================
--- core/branches/gradle2/hibernate-core/src/test/resources/log4j.properties 2010-06-23 05:56:05 UTC (rev 19786)
+++ core/branches/gradle2/hibernate-core/src/test/resources/log4j.properties 2010-06-23 06:15:02 UTC (rev 19787)
@@ -27,7 +27,3 @@
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=info, stdout
-
-log4j.logger.org.hibernate.test=info
-log4j.logger.org.hibernate.tool.hbm2ddl=debug
-log4j.logger.org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator=trace
\ No newline at end of file
Added: core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/hql/ASTQueryTranslatorTest.java
===================================================================
--- core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/hql/ASTQueryTranslatorTest.java (rev 0)
+++ core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/hql/ASTQueryTranslatorTest.java 2010-06-23 06:15:02 UTC (rev 19787)
@@ -0,0 +1,176 @@
+// $Id: ASTQueryTranslatorTest.java 8889 2005-12-20 17:35:54Z steveebersole $
+package org.hibernate.test.hql;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Tests cases where the AST based QueryTranslator does not generate identical SQL.
+ *
+ * @author josh Dec 6, 2004 9:07:58 AM
+ */
+public class ASTQueryTranslatorTest extends QueryTranslatorTestCase {
+
+ public ASTQueryTranslatorTest(String x) {
+ super( x );
+ }
+
+ public static Test suite() {
+ return new TestSuite( ASTQueryTranslatorTest.class );
+ }
+
+ protected boolean dropAfterFailure() {
+ return false;
+ }
+
+ // ##### TESTS THAT DON'T PASS BECAUSE THEY GENERATE DIFFERENT, POSSIBLY VALID SQL #####
+
+ public void testSelectManyToOne() {
+ assertTranslation("select distinct a.zoo from Animal a where a.zoo is not null");
+ assertTranslation("select a.zoo from Animal a");
+ }
+
+ public void testSelectExpression() {
+ //old qt cant handle select-clause expressions
+ assertTranslation("select a.bodyWeight + m.bodyWeight from Animal a join a.mother m");
+ }
+
+ public void testFetchProperties() {
+ //not implemented in old qt
+ assertTranslation("from Animal a fetch all properties join a.offspring o fetch all properties");
+ }
+
+ public void testOldSyntax() {
+ //generates ANSI join instead of theta join
+ assertTranslation("from a in class Animal, o in elements(a.offspring), h in class Human");
+ }
+
+ public void testImplicitJoinInsideOutsideSubselect() {
+ // new qt re-uses the joins defined by 's.other.count' path when referenced in the subquery,
+ // whereas the old qt reuses only the "root table" (not the already defined join to 'other'):
+ // OLD SQL :
+ // select simple0_.id_ as col_0_0_
+ // from Simple simple0_,
+ // Simple simple1_
+ // where (simple1_.count_>0
+ // and simple0_.other=simple1_.id_)
+ // and (simple0_.id_=some(
+ // select simple2_.id_
+ // from Simple simple2_,
+ // Simple simple3_,
+ // Simple simple4_
+ // where (simple3_.count_=simple4_.count_
+ // and simple2_.other=simple3_.id_
+ // and simple0_.other=simple4_.id_)
+ // ))
+ // NEW SQL :
+ // select simple0_.id_ as col_0_0_
+ // from Simple simple0_,
+ // Simple simple1_
+ // where (simple1_.count_>0
+ // and simple0_.id_=some(
+ // select simple2_.id_
+ // from Simple simple2_,
+ // Simple simple3_
+ // where (simple3_.count_=simple1_.count_
+ // and simple2_.other=simple3_.id_)
+ // )
+ // and simple0_.other=simple1_.id_)
+ assertTranslation( "from Simple s where s = some( from Simple sim where sim.other.count=s.other.count ) and s.other.count > 0" );
+ assertTranslation( "from Simple s where s.other.count > 0 and s = some( from Simple sim where sim.other.count=s.other.count )" );
+ }
+
+ public void testNakedPropertyRef() {
+ // this is needed for ejb3 selects and bulk statements
+ // Note: these all fail because the old parser did not have this
+ // feature, it just "passes the tokens through" to the SQL.
+ assertTranslation( "from Animal where bodyWeight = bodyWeight" );
+ assertTranslation( "select bodyWeight from Animal" );
+ assertTranslation( "select max(bodyWeight) from Animal" );
+ }
+
+ public void testNakedComponentPropertyRef() {
+ // this is needed for ejb3 selects and bulk statements
+ // Note: these all fail because the old parser did not have this
+ // feature, it just "passes the tokens through" to the SQL.
+ assertTranslation( "from Human where name.first = 'Gavin'" );
+ assertTranslation( "select name from Human" );
+ assertTranslation( "select upper(h.name.first) from Human as h" );
+ assertTranslation( "select upper(name.first) from Human" );
+ }
+
+ public void testNakedMapIndex() throws Exception {
+ assertTranslation( "from Zoo where mammals['dog'].description like '%black%'" );
+ }
+
+ public void testNakedImplicitJoins() {
+ assertTranslation( "from Animal where mother.father = ?" );
+ }
+
+ public void testDuplicateImplicitJoinInWhere() {
+ //new qt has more organized joins
+ assertTranslation("from Human h where h.mother.bodyWeight>10 and h.mother.bodyWeight<10");
+ }
+
+ public void testWhereExpressions() {
+ assertTranslation("from User u where u.userName='gavin' and u.human.name.first='Gavin'");
+ //new qt has more organized joins
+ assertTranslation("from User u where u.human.name.last='King' and u.human.name.first='Gavin'");
+ assertTranslation("from Bar bar where bar.baz.name='josh'");
+ assertTranslation("from Bar bar where bar.baz.name='josh' and not bar.baz.name='gavin'");
+ }
+
+ public void testImplicitJoinInSelect() {
+ //slightly diff select clause, both correct
+ assertTranslation("select foo.long, foo.foo from Foo foo");
+ }
+
+ public void testSelectStandardFunctions() throws Exception {
+ //old parser throws an exception
+ assertTranslation( "select current_date(), current_time(), current_timestamp() from Animal" );
+ }
+
+ public void testSelectClauseImplicitJoin() throws Exception {
+ //the old query translator has a bug which results in the wrong return type!
+ assertTranslation( "select d.owner.mother from Dog d" );
+ }
+
+ public void testComplexWhereExpression() throws Exception {
+ // classic QT generates lots of extra parens and some extra theta joins.
+ assertTranslation( "select distinct s from Simple s\n" +
+ "where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2" );
+ }
+
+ public void testDuplicateImplicitJoin() throws Exception {
+ // old qt generates an extra theta join
+ assertTranslation( "from Animal an where an.mother.bodyWeight > 10 and an.mother.bodyWeight < 20" );
+ }
+
+ public void testKeywordClassNameAndAlias() throws Exception {
+ // The old QT throws an exception, the new one doesn't, which is better
+ assertTranslation( "from Order order" );
+ }
+
+ public void testComponent3() throws Exception {
+ // The old translator generates duplicate inner joins *and* duplicate theta join clauses in the where statement in this case.
+ assertTranslation( "from Dog dog where dog.owner.name.first = 'Gavin' and dog.owner.name.last='King' and dog.owner.bodyWeight<70" );
+ }
+
+ public void testUncorrelatedSubselectWithJoin() throws Exception {
+ // The old translator generates unnecessary inner joins for the Animal subclass of zoo.mammals
+ // The new one is working fine now!
+ assertTranslation( "from Animal a where a in (select mam from Zoo zoo join zoo.mammals mam)" );
+ }
+
+ public void testFetch() throws Exception {
+ //SQL is correct, new qt is not throwing an exception when it should be (minor issue)
+ assertTranslation("from Customer cust left join fetch cust.billingAddress where cust.customerId='abc123'");
+ }
+
+ public void testImplicitJoin() throws Exception {
+ //old qt generates an exception, the new one doesnt
+ //this is actually invalid HQL, an implicit join on a many-valued association
+ assertTranslation( "from Animal an where an.offspring.mother.bodyWeight > 10" );
+ }
+
+}
Added: core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/tool/Team.hbm.xml
===================================================================
--- core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/tool/Team.hbm.xml (rev 0)
+++ core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/tool/Team.hbm.xml 2010-06-23 06:15:02 UTC (rev 19787)
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping SYSTEM
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.tool">
+ <class name="Team" table="`Team`">
+ <id name="id" column="`iD`">
+ <generator class="native">
+ <param name="sequence">TEAM_SEQ</param>
+ </generator>
+ </id>
+ <property name="name"/>
+ </class>
+
+ <class entity-name="OtherTeam" name="Team" table="TEAM">
+ <id name="id" column="id">
+ <generator class="native">
+ <param name="sequence">TEAM_SEQ</param>
+ </generator>
+ </id>
+ <property name="name" column="xname"/>
+ </class>
+
+</hibernate-mapping>
Added: core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/tool/Team.java
===================================================================
--- core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/tool/Team.java (rev 0)
+++ core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/tool/Team.java 2010-06-23 06:15:02 UTC (rev 19787)
@@ -0,0 +1,20 @@
+package org.hibernate.test.tool;
+
+
+public class Team {
+ private Long id;
+ private String name;
+ public Long getId() {
+ return id;
+ }
+ public void setId(Long id) {
+ this.id = id;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
Added: core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/tool/TestSchemaTools.java
===================================================================
--- core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/tool/TestSchemaTools.java (rev 0)
+++ core/branches/gradle2/hibernate-core/src/test/unmaintained/org/hibernate/test/tool/TestSchemaTools.java 2010-06-23 06:15:02 UTC (rev 19787)
@@ -0,0 +1,226 @@
+package org.hibernate.test.tool;
+
+import java.sql.Connection;
+import java.sql.Statement;
+import java.sql.SQLException;
+
+import junit.framework.Test;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.HSQLDialect;
+import org.hibernate.testing.junit.functional.DatabaseSpecificFunctionalTestCase;
+import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.tool.hbm2ddl.SchemaUpdate;
+import org.hibernate.tool.hbm2ddl.SchemaValidator;
+
+/**
+ * @author Anthony
+ *
+ * Basic smoke test for schemaupdate/validator.
+ * Dependent on schemas, and probably also HQLDB - Not possible to have in the global test suite at the moment.
+ *
+ * WARNING, if you want this test to work, you need to define a default schema = SB
+ * in hibernate global configuration.
+ * This schema should not be the same at the default db user schema and should come after the users schema alphabetically.
+ *
+ */
+public class TestSchemaTools extends DatabaseSpecificFunctionalTestCase {
+
+ public TestSchemaTools(String name) {
+ super( name );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "tool/Team.hbm.xml" };
+ }
+
+ public boolean createSchema() {
+ return false;
+ }
+
+ public void afterSessionFactoryBuilt(SessionFactoryImplementor sfi) {
+ super.afterSessionFactoryBuilt( sfi );
+ Session session = null;
+ try {
+ session = sfi.openSession();
+ Statement stat = session.connection().createStatement();
+ stat.execute("CREATE SCHEMA sb AUTHORIZATION DBA ");
+ stat.execute(" CREATE SCHEMA sa AUTHORIZATION DBA ");
+ stat.execute(" CREATE TABLE \"SA\".\"Team\" (test INTEGER) ");
+ stat.close();
+ }
+ catch ( SQLException e ) {
+ throw new RuntimeException( "could not prepare additional schemas" );
+ }
+ finally {
+ if ( session != null ) {
+ try {
+ session.close();
+ }
+ catch( Throwable ignore ) {
+ }
+ }
+ }
+ }
+
+ protected void prepareTest() throws Exception {
+ super.prepareTest();
+ }
+
+
+ public boolean appliesTo(Dialect dialect) {
+ return dialect instanceof HSQLDialect;
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( TestSchemaTools.class );
+ }
+
+ public void testSchemaTools() throws Exception{
+ // database schema have been created thanks to the setUp method
+ // we have 2 schemas SA et SB, SB must be set as the default schema
+ // used by hibernate hibernate.default_schema SB
+ SchemaExport se = new SchemaExport(getCfg());
+ se.create(true,true);
+
+ // here we modify the generated table in order to test SchemaUpdate
+ Session session = openSession();
+ Connection conn = session.connection();
+ Statement stat = conn.createStatement();
+ stat.execute("ALTER TABLE \"SB\".\"Team\" DROP COLUMN name ");
+
+ // update schema
+ SchemaUpdate su = new SchemaUpdate(getCfg());
+ su.execute(true,true);
+
+ // we can run schema validation. Note that in the setUp method a *wrong* table
+ // has been created with different column names
+ // if schema validator chooses the bad db schema, then the testcase will fail (exception)
+ SchemaValidator sv = new SchemaValidator(getCfg());
+ sv.validate();
+
+ // it's time to clean our database
+ se.drop(true,true);
+
+ // then the schemas and false table.
+
+ stat.execute("DROP TABLE \"SA\".\"Team\" ");
+ stat.execute(" DROP SCHEMA sa ");
+ stat.execute("DROP SCHEMA sb ");
+ stat.close();
+ session.close();
+ }
+
+ public void testSchemaToolsNonQuote() throws Exception{
+ // database schema have been created thanks to the setUp method
+ // we have 2 schemas SA et SB, SB must be set as the default schema
+ // used by hibernate hibernate.default_schema SB
+ SchemaExport se = new SchemaExport(getCfg());
+ se.create(true,true);
+
+ // here we modify the generated table in order to test SchemaUpdate
+ Session session = openSession();
+ Connection conn = session.connection();
+ Statement stat = conn.createStatement();
+ stat.execute("ALTER TABLE \"SB\".\"TEAM\" DROP COLUMN xname ");
+
+ // update schema
+ SchemaUpdate su = new SchemaUpdate(getCfg());
+ su.execute(true,true);
+
+ // we can run schema validation. Note that in the setUp method a *wrong* table
+ // has been created with different column names
+ // if schema validator chooses the bad db schema, then the testcase will fail (exception)
+ SchemaValidator sv = new SchemaValidator(getCfg());
+ sv.validate();
+
+ // it's time to clean our database
+ se.drop(true,true);
+
+ // then the schemas and false table.
+
+ stat.execute("DROP TABLE \"SA\".\"Team\" ");
+ stat.execute(" DROP SCHEMA sa ");
+ stat.execute("DROP SCHEMA sb ");
+ stat.close();
+ session.close();
+ }
+ public void testFailingQuoteValidation() throws Exception{
+ // database schema have been created thanks to the setUp method
+ // we have 2 schemas SA et SB, SB must be set as the default schema
+ // used by hibernate hibernate.default_schema SB
+ SchemaExport se = new SchemaExport(getCfg());
+ se.create(true,true);
+
+ // here we modify the generated table in order to test SchemaUpdate
+ Session session = openSession();
+ Connection conn = session.connection();
+ Statement stat = conn.createStatement();
+ stat.execute("ALTER TABLE \"SB\".\"Team\" DROP COLUMN name ");
+
+ // update schema
+ //SchemaUpdate su = new SchemaUpdate(getCfg());
+ //su.execute(true,true);
+
+ try {
+ SchemaValidator sv = new SchemaValidator(getCfg());
+ sv.validate();
+ fail("should fail since we mutated the current schema.");
+ } catch(HibernateException he) {
+
+ }
+
+ // it's time to clean our database
+ se.drop(true,true);
+
+ // then the schemas and false table.
+
+ stat.execute("DROP TABLE \"SA\".\"Team\" ");
+ stat.execute(" DROP SCHEMA sa ");
+ stat.execute("DROP SCHEMA sb ");
+ stat.close();
+ session.close();
+ }
+
+ public void testFailingNonQuoteValidation() throws Exception{
+ // database schema have been created thanks to the setUp method
+ // we have 2 schemas SA et SB, SB must be set as the default schema
+ // used by hibernate hibernate.default_schema SB
+ SchemaExport se = new SchemaExport(getCfg());
+ se.create(true,true);
+
+ // here we modify the generated table in order to test SchemaUpdate
+ Session session = openSession();
+ Connection conn = session.connection();
+ Statement stat = conn.createStatement();
+ stat.execute("ALTER TABLE \"SB\".\"TEAM\" DROP COLUMN xname ");
+
+ // update schema
+ //SchemaUpdate su = new SchemaUpdate(getCfg());
+ //su.execute(true,true);
+
+ try {
+ SchemaValidator sv = new SchemaValidator(getCfg());
+ sv.validate();
+ fail("should fail since we mutated the current schema.");
+ } catch(HibernateException he) {
+
+ }
+
+ // it's time to clean our database
+ se.drop(true,true);
+
+ // then the schemas and false table.
+
+ stat.execute("DROP TABLE \"SA\".\"Team\" ");
+ stat.execute(" DROP SCHEMA sa ");
+ stat.execute("DROP SCHEMA sb ");
+ stat.close();
+ session.close();
+ }
+
+}
More information about the hibernate-commits
mailing list