Index: topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java diff -u topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.47 topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.48 --- topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.47 Mon Jan 15 13:38:51 2007 +++ topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java Thu Jan 18 21:58:47 2007 @@ -23,9 +23,9 @@ * * @author poussin * - * @version $Revision: 1.47 $ + * @version $Revision: 1.48 $ * - * Last update: $Date: 2007/01/15 13:38:51 $ by : $Author: bpoussin $ + * Last update: $Date: 2007/01/18 21:58:47 $ by : $Author: bpoussin $ */ package org.codelutin.topia.framework; @@ -90,6 +90,7 @@ import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.ReplicationMode; +import org.hibernate.SQLQuery; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; @@ -923,30 +924,38 @@ // Il y a un ArrayOutBoundException -> org.h2.command.dml.Script.add:203 // pour certaines lignes. C dommage, car on est obligé de rammener // tout en texte, ce qui peut-etre gros pour la memoire :( - Query query = getHibernate().createSQLQuery("SCRIPT");// TO '" + file.getAbsolutePath() + "'"); - List lines = query.list(); - - // en fait on est un peu obligé d'exporter toute la base - // (creation du schema compris) car sinon lors de la restauration - // si le schema a ete creer avant il contient aussi les - // contrainte et du coup les inserts se passent mal :( - // Si on ne voulait que les inserts, lors de la resauration il - // faudrait desactiver les contraintes et les reactiver ensuite - - OutputStream os = new BufferedOutputStream ( - new FileOutputStream(file)); - PrintStream out; + String options = ""; if (compress) { - out = new PrintStream(new GZIPOutputStream(os)); - } else { - out = new PrintStream(os); - } - - for (String line : lines) { - out.println(line + ";"); + options += " COMPRESSION GZIP"; } - out.close(); + + SQLQuery query = getHibernate().createSQLQuery("SCRIPT TO '" + file.getAbsolutePath() + "'" + options); + query.list(); + +// List lines = query.list(); + +// // en fait on est un peu obligé d'exporter toute la base +// // (creation du schema compris) car sinon lors de la restauration +// // si le schema a ete creer avant il contient aussi les +// // contrainte et du coup les inserts se passent mal :( +// // Si on ne voulait que les inserts, lors de la resauration il +// // faudrait desactiver les contraintes et les reactiver ensuite +// +// OutputStream os = new BufferedOutputStream ( +// new FileOutputStream(file)); +// +// PrintStream out; +// if (compress) { +// out = new PrintStream(new GZIPOutputStream(os)); +// } else { +// out = new PrintStream(os); +// } +// +// for (String line : lines) { +// out.println(line + ";"); +// } +// out.close(); } catch (Exception eee) { throw new TopiaException("Can't backup", eee); } @@ -972,26 +981,33 @@ int magic = ((int)in.read() << 8) | b; in.reset(); + String options = ""; + if (magic == GZIPInputStream.GZIP_MAGIC) { - in = new GZIPInputStream(in); +// in = new GZIPInputStream(in); + options += " COMPRESSION GZIP"; } + in.close(); - BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - Connection conn = getHibernate().connection(); - conn.setAutoCommit(false); - Statement stat = conn.createStatement(); - - while((sql = reader.readLine()) != null) { - // FIXME remove next line when h2 will do the bug correction (normaly in october 2006) - // this permit database restauration - if (sql.startsWith("ALTER TABLE")) { - sql = sql.replaceAll("INDEX CONSTRAINT_INDEX_\\d*", ""); - } - stat.execute(sql); - } - stat.close(); - conn.commit(); - conn.close(); + SQLQuery query = getHibernate().createSQLQuery("RUNSCRIPT FROM '" + file.getAbsolutePath() + "'" + options); + query.executeUpdate(); + +// BufferedReader reader = new BufferedReader(new InputStreamReader(in)); +// Connection conn = getHibernate().connection(); +// conn.setAutoCommit(false); +// Statement stat = conn.createStatement(); +// +// while((sql = reader.readLine()) != null) { +// // FIXME remove next line when h2 will do the bug correction (normaly in october 2006) +// // this permit database restauration +//// if (sql.startsWith("ALTER TABLE")) { +//// sql = sql.replaceAll("INDEX CONSTRAINT_INDEX_\\d*", ""); +//// } +// stat.execute(sql); +// } +// stat.close(); +// conn.commit(); +// conn.close(); // // by default we supposed that file is not compressed // File tmp = file; @@ -1042,6 +1058,7 @@ } Query query = tx.getHibernate().createSQLQuery(sql); query.executeUpdate(); + tx.closeContext(); root.finalize(); } catch (Throwable eee) { throw new TopiaException("Can't clear topia context", eee);