Title: [970] trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_cachedb.rb: Provided primary key support for cache db.
Revision
970
Author
kofno
Date
2008-04-23 09:47:12 -0400 (Wed, 23 Apr 2008)

Log Message

Provided primary key support for cache db. All but two of the ar-jdbc
tests pass.

 * LIMIT still isn't handled correctly
 * Still haven't run the rails test suite.

Added Paths

Diff

Added: trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_cachedb.rb (0 => 970)


--- trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_cachedb.rb	                        (rev 0)
+++ trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_cachedb.rb	2008-04-23 13:47:12 UTC (rev 970)
@@ -0,0 +1,49 @@
+module ::JdbcSpec
+  module ActiveRecordExtensions
+    def cachedb_connection( config )
+      config[:port] ||= 1972
+      config[:url] ||= "jdbc:Cache://#{config[:host]}:#{config[:port]}/#{ config[:database]}"
+      config[:driver] ||= "com.intersys.jdbc.CacheDriver"
+      jdbc_connection( config )
+    end
+  end
+
+  module CacheDB
+
+    def self.column_selector
+      [ /cache/i, lambda {  | cfg, col | col.extend( ::JdbcSpec::CacheDB::Column ) } ]
+    end
+
+    def self.adapter_selector
+      [ /cache/i, lambda {  | cfg, adapt | adapt.extend( ::JdbcSpec::CacheDB ) } ]
+    end
+
+    module Column
+    end
+
+    def modify_types(tp)
+      tp[:primary_key] = "int NOT NULL IDENTITY(1, 1) PRIMARY KEY"
+      tp
+    end
+
+    def type_to_sql(type, limit = nil, precision = nil, scale = nil)
+      return super unless type.to_s == 'integer'
+      
+      if limit.nil? || limit == 4
+        'INT'
+      elsif limit == 2
+        'SMALLINT'
+      elsif limit == 1
+        'TINYINT'
+      else
+        'BIGINT'
+      end
+    end
+
+    def create_table(name, options = { })
+      super(name, options)
+      primary_key = options[:primary_key] || "id"
+      execute "ALTER TABLE #{name} ADD CONSTRAINT #{name}_PK PRIMARY KEY(#{primary_key})" unless options[:id] == false
+    end
+  end
+end
Property changes on: trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_cachedb.rb
___________________________________________________________________
Name: svn:executable
   + *
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to