Index: src/java/org/hibernate/tool/ant/QueryExporterTask.java
===================================================================
--- src/java/org/hibernate/tool/ant/QueryExporterTask.java (revision 20854)
+++ src/java/org/hibernate/tool/ant/QueryExporterTask.java (working copy)
@@ -14,6 +14,7 @@
private String query = "";
private String filename;
List queries = new ArrayList();
+ private boolean inOneTransaction = false;
public QueryExporterTask(HibernateToolTask parent) {
super( parent );
@@ -33,6 +34,7 @@
}
exporter.setQueries(queryStrings);
exporter.setFilename(filename);
+ exporter.setInOneTransaction(inOneTransaction);
super.configureExporter( exp );
return exporter;
}
@@ -83,7 +85,11 @@
public void setDestFile(String filename) {
this.filename = filename;
}
-
+
+ public void setInOneTransaction(boolean inOneTransaction) {
+ this.inOneTransaction = inOneTransaction;
+ }
+
public void execute() {
parent.log("Executing: [" + query + "]");
super.execute();
Index: src/java/org/hibernate/tool/hbm2x/QueryExporter.java
===================================================================
--- src/java/org/hibernate/tool/hbm2x/QueryExporter.java (revision 20854)
+++ src/java/org/hibernate/tool/hbm2x/QueryExporter.java (working copy)
@@ -20,6 +20,7 @@
private String filename;
private List queryStrings;
+ private boolean inOneTransaction = false;
public void doStart() {
Session session = null;
@@ -28,7 +29,9 @@
try {
sessionFactory = getConfiguration().buildSessionFactory();
session = sessionFactory.openSession();
- transaction = session.beginTransaction();
+ if (inOneTransaction) {
+ transaction = session.beginTransaction();
+ }
// TODO: this is not the most efficient loop (opening/closing file)
for (Iterator iter = queryStrings.iterator(); iter.hasNext();) {
String query = (String) iter.next();
@@ -59,7 +62,9 @@
}
}
}
- transaction.commit();
+ if (transaction != null) {
+ transaction.commit();
+ }
} catch(HibernateException he) {
if(transaction!=null) {
transaction.rollback();
@@ -72,12 +77,10 @@
if(sessionFactory!=null) {
sessionFactory.close();
}
-
-
}
}
- private String getFileName() {
+ public String getFileName() {
return filename;
}
@@ -89,4 +92,11 @@
this.queryStrings = queryStrings;
}
+ public boolean getInOneTransaction() {
+ return inOneTransaction;
+ }
+
+ public void setInOneTransaction(boolean inOneTransaction) {
+ this.inOneTransaction = inOneTransaction;
+ }
}
Index: src/test/org/hibernate/tool/ant/AntHibernateToolTest.java
===================================================================
--- src/test/org/hibernate/tool/ant/AntHibernateToolTest.java (revision 20854)
+++ src/test/org/hibernate/tool/ant/AntHibernateToolTest.java (working copy)
@@ -263,6 +263,8 @@
File baseDir = new File(project.getProperty("build.dir"), "querytest");
assertTrue(new File(baseDir, "queryresult.txt").exists());
+ assertTrue(new File(baseDir, "queryresult2.txt").exists());
+ assertTrue(new File(baseDir, "queryresult3.txt").exists());
}
Index: src/test/org/hibernate/tool/hbm2x/query/QueryExporterTest.java
===================================================================
--- src/test/org/hibernate/tool/hbm2x/query/QueryExporterTest.java (revision 20854)
+++ src/test/org/hibernate/tool/hbm2x/query/QueryExporterTest.java (working copy)
@@ -10,9 +10,12 @@
import org.hibernate.tool.NonReflectiveTestCase;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2x.QueryExporter;
+import org.hibernate.tool.test.TestHelper;
public class QueryExporterTest extends NonReflectiveTestCase {
+ SessionFactory factory = null;
+
public QueryExporterTest(String name) {
super( name );
}
@@ -30,7 +33,7 @@
protected void setUp() throws Exception {
super.setUp();
getCfg().setProperty( Environment.HBM2DDL_AUTO, "update" );
- SessionFactory factory = getCfg().buildSessionFactory();
+ factory = getCfg().buildSessionFactory();
Session s = factory.openSession();
@@ -41,35 +44,57 @@
s.persist( user );
s.flush();
-
s.close();
-
- QueryExporter exporter = new QueryExporter();
- exporter.setConfiguration( getCfg() );
- exporter.setOutputDirectory( getOutputDir() );
- exporter.setFilename( FILE );
- List queries = new ArrayList();
- queries.add("from java.lang.Object");
- exporter.setQueries( queries );
-
- exporter.start();
-
- factory.close();
}
protected void tearDown() throws Exception {
+ factory = null;
SchemaExport export = new SchemaExport(getCfg());
- export.drop( false, true );
-
+ export.drop(false, true);
super.tearDown();
}
-
-
- public void testQueryExporter() {
+
+ public void testRunQueriesSeparately() {
+ QueryExporter exporter = new QueryExporter();
+ exporter.setConfiguration(getCfg());
+ exporter.setOutputDirectory(getOutputDir());
+ exporter.setFilename(FILE);
+ List queries = new ArrayList();
+ queries.add("from java.lang.Object");
+ queries.add("from java.lang.Object");
+ exporter.setQueries(queries);
- assertFileAndExists( new File(getOutputDir(), FILE ));
+ exporter.start();
+ if (factory != null) {
+ factory.close();
+ factory = null;
+ }
+
+ final File outputFile = new File(getOutputDir(), FILE);
+ assertFileAndExists(outputFile);
+ TestHelper.deleteDir(outputFile);
+ }
+
+ public void testRunQueriesInOneTransaction() {
+ QueryExporter exporter = new QueryExporter();
+ exporter.setConfiguration(getCfg());
+ exporter.setOutputDirectory(getOutputDir());
+ exporter.setFilename(FILE);
+ exporter.setInOneTransaction(true);
+ List queries = new ArrayList();
+ queries.add("from java.lang.Object");
+ queries.add("from java.lang.Object");
+ exporter.setQueries(queries);
-
+ exporter.start();
+ if (factory != null) {
+ factory.close();
+ factory = null;
+ }
+
+ final File outputFile = new File(getOutputDir(), FILE);
+ assertFileAndExists(outputFile);
+ TestHelper.deleteDir(outputFile);
}
}
Index: src/testsupport/anttest-build.xml
===================================================================
--- src/testsupport/anttest-build.xml (revision 20854)
+++ src/testsupport/anttest-build.xml (working copy)
@@ -542,6 +542,8 @@
from java.io.Serializable
from java.io.Serializable
+ from java.io.Serializable
+ from java.lang.Object