Permalink
Browse files

Attempting a different way of importing the Model into the Adapter, and

about about to throw out the old way. Wanted a history, just in case it
doesn't work.
  • Loading branch information...
1 parent fb39793 commit fd33c760164cd3f86a5a0575c19454a016de056a @cpoirier committed Mar 24, 2012
@@ -136,6 +136,13 @@ def install( schema )
end
+ def synchronize()
+ @monitor.synchronize do
+ yield
+ end
+ end
+
+
protected
@@ -28,7 +28,7 @@ module Adapters
module GenericSQL
class Adapter < Adapters::Adapter
- attr_reader :type_manager
+ attr_reader :wrappers, :type_manager
def print_to( printer )
@@ -55,7 +55,11 @@ def install( schema )
transact do |connection|
installed_version = connection.retrieve_value("version", 0, @version_query, schema_name)
if installed_version == 0 then
- map(schema)
+ @schema_maps[schema] = schema_map = create_schema_map(schema, create_name())
+ schema_map.build()
+ @tables.each do |table|
+ Schemaform.debug.dump(table.render_sql_create())
+ end
fail_todo()
@@ -76,30 +80,16 @@ def install( schema )
#
- # Builds an appropriate Map::Node on the specified Model object. Override this if you customize
- # the base Map classes.
-
- def map( model )
- case model
- when Model::Schema
- Map::Schema.new(self, model)
- when Model::Entity
- Map::Entity.new(self, model)
- end
- end
-
-
- #
# Defines a new table and calls your block to fill it in.
def define_table( name, or_return_existing = false )
name_string = name.to_s
@monitor.synchronize do
if @tables.member?(name_string) then
- assert(or_return_existing, "cannot create duplicate table [#{name_s}]")
+ assert(or_return_existing, "cannot create duplicate table [#{name_string}]")
else
- build_table(name).use do |table|
+ create_table(name).use do |table|
yield(table)
@tables.register(table, name_string)
end
@@ -110,49 +100,106 @@ def define_table( name, or_return_existing = false )
end
+ #
+ # Defines a new table and gives it an identifier, optionally by linking it to a master table's
+ # identifier.
+
+ def define_linkable_table( name, base_table = nil )
+ define_table(name) do |table|
+ id_name = create_internal_name("id")
+
+ if base_table.exists? then
+ base_id = base_table.identifier
+ table.identifier = table.define_reference_field(id_name, base_table, table.create_primary_key_mark())
+ else
+ table.identifier = table.define_identifier_field(id_name, table.create_primary_key_mark())
+ end
+
+ yield(table)
+ end
+ end
+
+
+
# =======================================================================================
# Object Instantiation
# =======================================================================================
- def build_query( relation )
+ def create_query( relation )
Query.new(relation)
end
- def build_table( name )
+ def create_table( name )
Table.new(self, name)
end
- def build_name( *parts )
+ def create_name( *parts )
Name.new(parts, @separator)
end
- def build_internal_name( *parts )
+ def create_internal_name( *parts )
parts << sprintf(@internal_format, parts.pop)
- build_name(parts)
+ create_name(parts)
end
- def build_present_name( *parts )
+ def create_present_name( *parts )
parts << sprinf(@present_format, parts.pop)
- build_name(parts)
+ create_name(parts)
+ end
+
+ def create_schema_map( model, base_name )
+ SchemaMap.new(self, model, base_name)
+ end
+
+ def create_entity_map(schema_map, model, base_name)
+ EntityMap.new(schema_map, model, base_name)
+ end
+
+ def create_tuple_map(context_map, model, base_name)
+ TupleMap.new(context_map, model, base_name)
+ end
+
+ def create_attribute_map(tuple_map, model, base_name)
+ AttributeMap.new(tuple_map, model, base_name)
+ end
+
+ def create_relation_map(context_map, model, base_name)
+ RelationMap.new(context_map, model, base_name)
+ end
+
+ def create_enumeration_map(context_map, model, base_name)
+ EnumerationMap.new(context_map, model, base_name)
+ end
+
+ def create_set_map(context_map, model, base_name)
+ SetMap.new(context_map, model, base_name)
+ end
+
+ def create_list_map(context_map, model, base_name)
+ ListMap.new(context_map, model, base_name)
end
+ def create_scalar_map(context_map, type)
+ ScalarMap.new(context_map, type)
+ end
protected
def initialize( address, configuration = {} )
super(address)
+ @wrappers = {}
@type_manager = TypeManager.new(self)
@tables = TableRegistry.new() # name => Table
@schema_maps = {} # Schemaform::Model::Schema => SchemaMap
@entity_maps = {} # Schemaform::Model::Entity => EntityMap
@query_plans = {} # Language::Placeholder => QueryPlan
@schemas_table = define_table("schemas", true) do |table|
- table.define_field(:name , type_manager().text_type(60) , table.build_primary_key_mark())
+ table.define_field(:name , type_manager().text_type(60) , table.create_primary_key_mark())
table.define_field(:version, type_manager().integer_type())
end
@@ -199,7 +246,7 @@ def type_width()
end # Adapters
end # Schemaform
-["query_parts", "map"].each do |subdir|
+["query_parts"].each do |subdir|
Dir[Schemaform.locate("#{subdir}/*.rb")].each{|path| require path}
end
@@ -1,42 +0,0 @@
-#!/usr/bin/env ruby
-# =============================================================================================
-# Schemaform
-# A DSL giving the power of spreadsheets in a relational setting.
-#
-# [Website] http://schemaform.org
-# [Copyright] Copyright 2004-2012 Chris Poirier
-# [License] Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# =============================================================================================
-
-require Schemaform.locate("node.rb")
-
-
-#
-# Maps the Model::Entity into the adapter for processing.
-
-module Schemaform
-module Adapters
-module GenericSQL
-module Map
-class Entity < Node
-
- def initialize( adapter, model )
- super
- end
-
-
-end # Entity
-end # Map
-end # GenericSQL
-end # Adapters
-end # Schemaform
@@ -1,42 +0,0 @@
-#!/usr/bin/env ruby
-# =============================================================================================
-# Schemaform
-# A DSL giving the power of spreadsheets in a relational setting.
-#
-# [Website] http://schemaform.org
-# [Copyright] Copyright 2004-2012 Chris Poirier
-# [License] Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# =============================================================================================
-
-
-#
-# The base class for things that map Model elements into the adapter.
-
-module Schemaform
-module Adapters
-module GenericSQL
-module Map
-class Node
-
- def initialize( adapter, model )
- @adapter = adapter
- @model = model
- end
-
- attr_reader :adapter, :model
-
-end # Node
-end # Map
-end # GenericSQL
-end # Adapters
-end # Schemaform
@@ -0,0 +1,89 @@
+# #!/usr/bin/env ruby
+# # =============================================================================================
+# # Schemaform
+# # A DSL giving the power of spreadsheets in a relational setting.
+# #
+# # [Website] http://schemaform.org
+# # [Copyright] Copyright 2004-2012 Chris Poirier
+# # [License] Licensed under the Apache License, Version 2.0 (the "License");
+# # you may not use this file except in compliance with the License.
+# # You may obtain a copy of the License at
+# #
+# # http://www.apache.org/licenses/LICENSE-2.0
+# #
+# # Unless required by applicable law or agreed to in writing, software
+# # distributed under the License is distributed on an "AS IS" BASIS,
+# # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# # See the License for the specific language governing permissions and
+# # limitations under the License.
+# # =============================================================================================
+#
+# require Schemaform.locate("maps.rb")
+#
+#
+# module Schemaform
+# module Adapters
+# module GenericSQL
+#
+#
+# #
+# # The base class for things that map Model elements into the adapter.
+#
+# class Map
+# def build()
+# end
+# end
+#
+#
+# class SchemaMap < Map
+# end
+#
+#
+# class EntityMap < Map
+# end
+#
+#
+# class TupleMap < Map
+# end
+#
+#
+# class AttributeMap < Map
+# end
+#
+#
+#
+#
+# #
+# # The base class for maps of things that take up space.
+#
+# class StorageMap < Map
+# end
+#
+#
+# class ScalarMap < StorageMap
+# end
+#
+# class CollectionMap < ScalarMap
+# end
+#
+# class ListMap < CollectionMap
+# end
+#
+# class EnumerationMap < ListMap
+# end
+#
+# class SetMap < CollectionMap
+# end
+#
+# class RelationMap < SetMap
+# def build()
+# @heading_map.build()
+# end
+# end
+#
+#
+#
+#
+# end # GenericSQL
+# end # Adapters
+# end # Schemaform
Oops, something went wrong.

0 comments on commit fd33c76

Please sign in to comment.