Author: seanahn
Date: Mon Mar 16 21:53:17 2009
New Revision: 755015

URL: http://svn.apache.org/viewvc?rev=755015&view=rev
Log:
ODE-554, Add sqlserver and oracle unit testing capabilities

Modified:
    ode/branches/APACHE_ODE_1.X/settings.rb.example
    ode/branches/APACHE_ODE_1.X/tasks/nativedb.rake

Modified: ode/branches/APACHE_ODE_1.X/settings.rb.example
URL: 
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/settings.rb.example?rev=755015&r1=755014&r2=755015&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/settings.rb.example (original)
+++ ode/branches/APACHE_ODE_1.X/settings.rb.example Mon Mar 16 21:53:17 2009
@@ -1,8 +1,9 @@
 MYSQL               = "mysql:mysql-connector-java:jar:5.0.4",
 SYBASE              = "sybase:jconnect:jar:4.3",
 DB2                 = "db2:jcc:jar:9.5"
+SQLSERVER2008       = "microsoft:sqljdbc:jar:2008"
 
-REQUIRES = [MYSQL, SYBASE, DB2]
+REQUIRES = [MYSQL, SYBASE, DB2, SQLSERVER2008]
 
 def settings
   jpa_derby = {
@@ -59,6 +60,17 @@
     :dao=>"org.apache.ode.axis2.instancecleanup.HibDaoConnectionFactoryImpl"
   }
 
+  hib_sqlserver = {
+    :integr_branch=>"5.2.x",
+    :db=>"sqlserver",
+    :driver=>"com.microsoft.sqlserver.jdbc.SQLServerDriver",
+    :url=>"jdbc:sqlserver://<host>:1433;database=<instance>",
+    :userid=>"sa",
+    :password=>"sa",
+    :autocommit=>"on",
+    :dao=>"org.apache.ode.axis2.instancecleanup.HibDaoConnectionFactoryImpl"
+  }
+
   {
     "jpa-derby"=>jpa_derby,
     "hib-derby"=>hib_derby
@@ -67,4 +79,4 @@
 #    "hib-db2"=>pxetest_hib_db2_95,
 #    "hib-sybase"=>pxetest_hib_sybase_12
   }
-end
\ No newline at end of file
+end

Modified: ode/branches/APACHE_ODE_1.X/tasks/nativedb.rake
URL: 
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/tasks/nativedb.rake?rev=755015&r1=755014&r2=755015&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/tasks/nativedb.rake (original)
+++ ode/branches/APACHE_ODE_1.X/tasks/nativedb.rake Mon Mar 16 21:53:17 2009
@@ -48,9 +48,11 @@
           rm_rf task.name if File.exist?(task.name)
           Dir.mkdir(task.name)
           Buildr.ant(name) do |ant|
+            create_tables_sql = "#{task.name}/ode_tables.sql"
+            drop_tables_sql = "#{task.name}/drop_ode_tables.sql"
             ant.get 
:src=>"http://git.intalio.com/?p=integr.git;a=blob_plain;f=descriptors/package/#{dbprops[:db]}/ode_tables.sql;hb=#{dbprops[:integr_branch]}";,
-                    :dest=>"#{task.name}/ode_tables.sql"
-            sqls = ["#{task.name}/ode_tables.sql"]
+                    :dest=> create_tables_sql
+            sqls = prepare_sqls(ant, [], :hib, dbprops[:db], drop_tables_sql, 
create_tables_sql)
             
             # Apply the sql scripts to the database
             ant.sql :driver=>dbprops[:driver], :url=>dbprops[:url], 
:userid=>dbprops[:userid], :password=>dbprops[:password], 
:autocommit=>dbprops[:autocommit] do
@@ -71,28 +73,10 @@
           rm_rf task.name if File.exist?(task.name)
           Dir.mkdir(task.name)
           Buildr.ant(name) do |ant|
-            sqls = []
-            if dbprops[:db] == "mysql"
-              # create the drop table sql file from the create table sql
-              create_tables = ""
-              File.open("#{base}/target/#{dbprops[:db]}.sql", "r") do |f1|  
-                while line = f1.gets
-                  create_tables <<= line
-                end
-              end
-            
-              File.open("#{task.name}/drop-#{dbprops[:db]}.sql", "w") do |f2|
-                create_tables.gsub(/CREATE TABLE (.*?)[\s\(].*?;/m) { |match|
-                  f2.puts "DROP TABLE IF EXISTS " << $1 << ";\n"
-                }
-              end
-              
-              sqls |= ["#{task.name}/drop-#{dbprops[:db]}.sql"]
-            end
-            
-            ant.copy :file=>"#{base}/target/#{dbprops[:db]}.sql", 
:todir=>task.name
-            sqls |= ["#{task.name}/#{dbprops[:db]}.sql"]
-            
+            create_tables_sql = "#{base}/target/#{dbprops[:db]}.sql"
+            drop_tables_sql = "#{task.name}/drop-#{dbprops[:db]}.sql"
+            sqls = prepare_sqls(ant, [], :jpa, dbprops[:db], drop_tables_sql, 
create_tables_sql)
+                        
             # Apply the sql scripts to the database
             ant.sql :driver=>dbprops[:driver], :url=>dbprops[:url], 
:userid=>dbprops[:userid], :password=>dbprops[:password], 
:autocommit=>dbprops[:autocommit] do
               sqls.each { |sql| ant.transaction :src=>sql }
@@ -148,6 +132,47 @@
       end
     end
     
+    def prepare_sqls(ant, sql_files, orm, db, drop_tables_sql, 
create_tables_sql)
+      # read the create table sql into a string
+      create_tables = ""
+      File.open(create_tables_sql, "r") do |f1|  
+        while line = f1.gets
+          create_tables <<= line
+        end
+      end
+    
+      # create the drop table sql file from the create table sql
+      if orm == :hib and db == "sqlserver"
+        File.open(drop_tables_sql, "w") do |f2|
+          create_tables.gsub(/CREATE TABLE (.*?)[\s\(].*?;/mi) { |match|
+            f2.puts "IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE 
TABLE_TYPE='BASE TABLE' AND TABLE_NAME='" << $1 << "') DROP TABLE " << $1 << 
";\n"
+          }
+          # remove the 'go's in the sql
+          f2.puts create_tables.gsub(/\ngo[\n$]/mi, "\n")
+        end
+        # add in the drop table sql file
+        sql_files |= [drop_tables_sql]
+      elsif orm == :jpa and db == "mysql"
+        File.open(drop_tables_sql, "w") do |f2|
+          create_tables.gsub(/CREATE TABLE (.*?)[\s\(].*?;/m) { |match|
+            f2.puts "DROP TABLE IF EXISTS " << $1 << ";\n"
+          }
+        end
+        # add in the drop table sql file
+        sql_files |= [drop_tables_sql]
+      end
+      
+      # add in the create table sql file
+      if orm == :hib and db != "sqlserver"
+        sql_files |= [create_tables_sql]
+      elsif orm == :jpa
+        ant.copy :file=>create_tables_sql, :todir=>task.name
+        sql_files |= ["#{task.name}/#{db}.sql"]
+      end
+      
+      sql_files
+    end
+    
   protected
 
     # This will download all the required artifacts before returning a 
classpath, and we want to do this only once.


Reply via email to