Commits

dep4b  committed 7f33599

Apply refactorings of DatabaseHelper. This mimics some changes done by Hani in OSWF.

git-svn-id: http://svn.opensymphony.com/svn/propertyset/trunk@108bf3cbcdd-1c1a-0410-9a68-d6f521e3fa7b

  • Participants
  • Parent commits 250258d

Comments (0)

Files changed (2)

File src/test/com/opensymphony/module/propertyset/DatabaseHelper.java

 
 import net.sf.hibernate.SessionFactory;
 import net.sf.hibernate.cfg.Configuration;
-import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
     //~ Static fields/initializers /////////////////////////////////////////////
 
     private static Log log = LogFactory.getLog(DatabaseHelper.class);
-    private static boolean databaseBuilt = false;
     private static SessionFactory sessionFactory;
     private static Configuration configuration;
 
         configuration.addFile(fileHibernatePropertySetItem);
 
 		// Use SchemaExport to see what Hibernate would have created!
-        createDatabase("src/etc/deployment/jdbc/mckoi-hibernate.sql");
+        createDatabase("src/etc/deployment/hibernate/mckoi.sql");
 
         //new SchemaExport(configuration).create(true, true);
         sessionFactory = configuration.buildSessionFactory();
         System.out.println("done");
     }
 
-    /**
-     * Build the database using a sql script
-     * @throws Exception
-     */
-    public static void exportSchemaForJDBC() throws Exception {
-        createDatabase("src/etc/deployment/jdbc/mckoi.sql");
-    }
-
     private static String getDatabaseCreationScript(String scriptFile) throws Exception {
         File file = new File(scriptFile);
         Assert.assertTrue(file.exists());
         return readTextStream(bis);
     }
 
-    private static void createDatabase(String scriptFile) {
+    public static void createDatabase(String scriptFile) {
         Connection connection;
         Statement statement = null;
         String sqlLine = null;
                 sqlLine = StringUtils.replace(sqlLine, "\n", "");
 
                 //String s = sqls[i];
-                if (sqlLine.length() > 0) {
+                if ((sqlLine.length() > 0) && (sqlLine.charAt(0) != '#')) {
                     try {
                         statement.executeQuery(sqlLine);
                     } catch (MSQLException msqlEx) {
             }
         }
 
-        databaseBuilt = true;
-
-        //  return connection;
     }
 
     private static String readTextStream(InputStream is) throws Exception {

File src/test/com/opensymphony/module/propertyset/database/JDBCPropertySetTest.java

 
     public void setUp() throws Exception {
         //ok so this code usually goes in the setUp but...
-        DatabaseHelper.exportSchemaForJDBC();
+        DatabaseHelper.createDatabase("src/etc/deployment/jdbc/mckoi.sql");
         args.put("globalKey", "test");
         super.setUp();
     }