You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by do...@apache.org on 2013/10/01 01:39:21 UTC

svn commit: r1527826 - in /buildr/trunk: lib/buildr/ide/idea.rb spec/ide/idea_spec.rb

Author: donaldp
Date: Mon Sep 30 23:39:21 2013
New Revision: 1527826

URL: http://svn.apache.org/r1527826
Log:
Support sql server data source types

Modified:
    buildr/trunk/lib/buildr/ide/idea.rb
    buildr/trunk/spec/ide/idea_spec.rb

Modified: buildr/trunk/lib/buildr/ide/idea.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/ide/idea.rb?rev=1527826&r1=1527825&r2=1527826&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/ide/idea.rb (original)
+++ buildr/trunk/lib/buildr/ide/idea.rb Mon Sep 30 23:39:21 2013
@@ -654,7 +654,6 @@ module Buildr #:nodoc:
       end
 
       def add_postgres_data_source(name, options = {})
-
         if options[:url].nil? && options[:database]
          default_url = "jdbc:postgresql://#{(options[:host] || "127.0.0.1")}:#{(options[:port] || "5432")}/#{options[:database]}"
         end
@@ -663,11 +662,27 @@ module Buildr #:nodoc:
           :driver => 'org.postgresql.Driver',
           :url => default_url,
           :username => ENV["USER"],
+          :dialect => 'PostgreSQL',
           :classpath => ["org.postgresql:postgresql:jar:9.2-1003-jdbc4"]
         }.merge(options)
         add_data_source(name, params)
       end
 
+      def add_sql_server_data_source(name, options = {})
+        if options[:url].nil? && options[:database]
+          default_url = "jdbc:jtds:sqlserver://#{(options[:host] || "127.0.0.1")}:#{(options[:port] || "1433")}/#{options[:database]}"
+        end
+
+        params = {
+          :driver => 'net.sourceforge.jtds.jdbc.Driver',
+          :url => default_url,
+          :username => ENV["USER"],
+          :dialect => 'TSQL',
+          :classpath => ['net.sourceforge.jtds:jtds:jar:1.2.7']
+        }.merge(options)
+        add_data_source(name, params)
+      end
+
       def add_data_source(name, options = {})
         add_to_composite_component(self.data_sources) do |xml|
           data_source_options = {
@@ -682,6 +697,8 @@ module Buildr #:nodoc:
             xml.tag!("jdbc-url", options[:url]) if options[:url]
             xml.tag!("user-name", options[:username]) if options[:username]
             xml.tag!("user-password", encrypt(options[:password])) if options[:password]
+            xml.tag!("default-dialect", options[:dialect]) if options[:dialect]
+
             xml.libraries do |xml|
               classpath.each do |classpath_element|
                 a = Buildr.artifact(classpath_element)

Modified: buildr/trunk/spec/ide/idea_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/ide/idea_spec.rb?rev=1527826&r1=1527825&r2=1527826&view=diff
==============================================================================
--- buildr/trunk/spec/ide/idea_spec.rb (original)
+++ buildr/trunk/spec/ide/idea_spec.rb Mon Sep 30 23:39:21 2013
@@ -738,6 +738,7 @@ describe Buildr::IntellijIdea do
                               :url => "jdbc:postgresql://127.0.0.1:5432/MyDb",
                               :username => "MyDBUser",
                               :password => "secreto",
+                              :dialect => "PostgreSQL",
                               :classpath => ["org.postgresql:postgresql:jar:9.not-a-version"])
         end
         invoke_generate_task
@@ -754,6 +755,7 @@ describe Buildr::IntellijIdea do
         doc.should have_xpath("#{ds_path}/jdbc-url/text() = 'jdbc:postgresql://127.0.0.1:5432/MyDb'")
         doc.should have_xpath("#{ds_path}/user-name/text() = 'MyDBUser'")
         doc.should have_xpath("#{ds_path}/user-password/text() = 'dfd9dfcfdfc9dfd8dfcfdfdedfc5'")
+        doc.should have_xpath("#{ds_path}/default-dialect/text() = 'PostgreSQL'")
         doc.should have_xpath("#{ds_path}/libraries/library/url/text() = '$MAVEN_REPOSITORY$/org/postgresql/postgresql/9.not-a-version/postgresql-9.not-a-version.jar'")
       end
     end
@@ -778,10 +780,37 @@ describe Buildr::IntellijIdea do
         doc.should have_xpath("#{ds_path}/jdbc-driver/text() = 'org.postgresql.Driver'")
         doc.should have_xpath("#{ds_path}/jdbc-url/text() = 'jdbc:postgresql://127.0.0.1:5432/MyDb'")
         doc.should have_xpath("#{ds_path}/user-name/text() = 'Bob'")
+        doc.should have_xpath("#{ds_path}/default-dialect/text() = 'PostgreSQL'")
         doc.should have_xpath("#{ds_path}/libraries/library/url/text() = '$MAVEN_REPOSITORY$/org/postgresql/postgresql/9.2-1003-jdbc4/postgresql-9.2-1003-jdbc4.jar'")
       end
     end
 
+    describe "with add_sql_server_data_source" do
+      before do
+        ENV["USER"] = "Bob"
+        artifact('net.sourceforge.jtds:jtds:jar:1.2.7') { |task| write task.name }
+        @foo = define "foo" do
+          ipr.add_sql_server_data_source("SqlServer", :database => 'MyDb')
+        end
+        invoke_generate_task
+      end
+
+      it "generates a data source manager with specified data source" do
+        doc = xml_document(@foo._("foo.ipr"))
+        prefix_xpath = "/project/component[@name='DataSourceManagerImpl', @format='xml', @hash='3208837817']/data-source"
+        doc.should have_nodes(prefix_xpath, 1)
+        ds_path = "#{prefix_xpath}[@source='LOCAL', @name='SqlServer']"
+        doc.should have_xpath(ds_path)
+
+        doc.should have_xpath("#{ds_path}/synchronize/text() = 'true'")
+        doc.should have_xpath("#{ds_path}/jdbc-driver/text() = 'net.sourceforge.jtds.jdbc.Driver'")
+        doc.should have_xpath("#{ds_path}/jdbc-url/text() = 'jdbc:jtds:sqlserver://127.0.0.1:1433/MyDb'")
+        doc.should have_xpath("#{ds_path}/user-name/text() = 'Bob'")
+        doc.should have_xpath("#{ds_path}/default-dialect/text() = 'TSQL'")
+        doc.should have_xpath("#{ds_path}/libraries/library/url/text() = '$MAVEN_REPOSITORY$/net/sourceforge/jtds/1.2.7/jtds-1.2.7.jar'")
+      end
+    end
+
     describe "with artifacts added to root project" do
       before do
         @foo = define "foo" do