rtm-activerecord 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rtm-activerecord.rb +4 -0
- data/lib/rtm/activerecord.rb +58 -74
- data/lib/rtm/activerecord/002_rtm01to02.rb +17 -0
- data/lib/rtm/activerecord/association_and_role.rb +1 -1
- data/lib/rtm/activerecord/base.rb +8 -29
- data/lib/rtm/activerecord/io/from_xtm2.rb +3 -3
- data/lib/rtm/activerecord/merging.rb +5 -5
- data/lib/rtm/activerecord/quaaxtm2rtm.rb +10 -10
- data/lib/rtm/activerecord/quaaxtm2rtmviews.rb +6 -6
- data/lib/rtm/activerecord/rdbms_config.rb +43 -0
- data/lib/rtm/activerecord/tm_delegator.rb +5 -5
- data/lib/rtm/activerecord/tm_set_delegator.rb +11 -11
- data/lib/rtm/activerecord/tmdm.rb +1 -0
- data/lib/rtm/activerecord/topic.rb +3 -3
- data/lib/rtm/activerecord/topic_map_system.rb +42 -0
- metadata +42 -20
- data/lib/rtm/activerecord/connect.rb +0 -102
data/lib/rtm/activerecord.rb
CHANGED
@@ -1,105 +1,89 @@
|
|
1
1
|
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
2
|
# License: Apache License, Version 2.0
|
3
3
|
|
4
|
-
|
5
|
-
require 'rtm'
|
6
|
-
else
|
4
|
+
unless Object.const_defined?("Gem") && rtmgem = Gem.loaded_specs["rtm-activerecord"]
|
7
5
|
rtm_path = File.expand_path(File.join(File.dirname(__FILE__), "../../../rtm/lib"))
|
8
|
-
if File.directory?(rtm_path)
|
9
|
-
$LOAD_PATH.unshift rtm_path
|
10
|
-
require 'rtm'
|
11
|
-
end
|
6
|
+
$LOAD_PATH.unshift rtm_path if File.directory?(rtm_path)
|
12
7
|
end
|
8
|
+
require 'rtm'
|
13
9
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def method_missing(name, *args)
|
37
|
-
@instance.send(name, *args)
|
38
|
-
end
|
39
|
-
def respond_to?(name)
|
40
|
-
super.respond_to?(name) || @instance.respond_to?(name)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
10
|
+
require 'uri'
|
11
|
+
require "rtm/activerecord/tmdm"
|
12
|
+
require "rtm/activerecord/persistent_code_output"
|
13
|
+
require "rtm/activerecord/tm_delegator"
|
14
|
+
require "rtm/activerecord/tm_set_delegator"
|
15
|
+
require "rtm/activerecord/tm_construct"
|
16
|
+
require "rtm/activerecord/topic_map"
|
17
|
+
require "rtm/activerecord/traverse_associations"
|
18
|
+
require "rtm/activerecord/topic"
|
19
|
+
require "rtm/activerecord/association_and_role"
|
20
|
+
require "rtm/activerecord/name_variant_occurrence"
|
21
|
+
require "rtm/activerecord/locators"
|
22
|
+
require "rtm/activerecord/set_wrapper"
|
23
|
+
require "rtm/activerecord/base"
|
24
|
+
require "rtm/activerecord/literal_index"
|
25
|
+
require "rtm/activerecord/topic_map_system"
|
26
|
+
require "rtm/validation"
|
27
|
+
require "rtm/helpers/locator"
|
28
|
+
require "rtm/helpers/no_output"
|
29
|
+
require "rtm/helpers/uri"
|
44
30
|
|
45
31
|
module RTM::AR
|
46
32
|
module TraverseAssociations
|
47
33
|
end
|
48
|
-
require 'uri'
|
49
|
-
|
50
|
-
%w[
|
51
|
-
tmdm
|
52
|
-
persistent_code_output
|
53
|
-
tm_delegator
|
54
|
-
tm_set_delegator
|
55
|
-
tm_construct
|
56
|
-
topic_map
|
57
|
-
traverse_associations
|
58
|
-
topic
|
59
|
-
association_and_role
|
60
|
-
name_variant_occurrence
|
61
|
-
locators
|
62
|
-
set_wrapper
|
63
|
-
base
|
64
|
-
literal_index
|
65
|
-
].each {|f| require "rtm/activerecord/#{f}" }
|
66
|
-
require "rtm/activerecord/connect"
|
67
|
-
require "rtm/validation"
|
68
|
-
require "rtm/helpers/locator"
|
69
|
-
require "rtm/helpers/no_output"
|
70
|
-
require "rtm/helpers/uri"
|
71
|
-
|
72
34
|
|
73
|
-
|
74
|
-
|
75
35
|
class Topic
|
76
36
|
require 'rtm/activerecord/sugar/topic/characteristics'
|
77
|
-
include RTM::AR::Sugar::Topic::Characteristics
|
78
37
|
require 'rtm/activerecord/sugar/topic/counterparts'
|
79
|
-
include RTM::AR::Sugar::Topic::Counterparts
|
80
38
|
require 'rtm/activerecord/sugar/topic/identifier_direct'
|
81
|
-
include RTM::AR::Sugar::Topic::IdentifierDirect
|
82
39
|
require 'rtm/activerecord/sugar/topic/hash_access'
|
83
|
-
include RTM::AR::Sugar::Topic::HashAccess
|
84
40
|
require 'rtm/activerecord/sugar/topic/predefined_associations'
|
85
|
-
include RTM::AR::Sugar::Topic::PredefinedAssociations
|
86
41
|
require "rtm/activerecord/io/to_xtm2"
|
87
42
|
require "rtm/activerecord/io/to_xtm1"
|
88
43
|
require "rtm/activerecord/io/to_yaml"
|
89
44
|
require "rtm/activerecord/io/to_string"
|
90
45
|
require "rtm/activerecord/io/to_jtm"
|
91
|
-
|
46
|
+
include RTM::AR::Sugar::Topic::Characteristics
|
47
|
+
include RTM::AR::Sugar::Topic::Counterparts
|
48
|
+
include RTM::AR::Sugar::Topic::IdentifierDirect
|
49
|
+
include RTM::AR::Sugar::Topic::HashAccess
|
50
|
+
include RTM::AR::Sugar::Topic::PredefinedAssociations
|
92
51
|
end
|
52
|
+
|
93
53
|
class Association
|
94
54
|
require 'rtm/activerecord/sugar/association/hash_access'
|
95
|
-
include RTM::AR::Sugar::Association::HashAccess
|
96
55
|
require 'rtm/activerecord/sugar/role/counterparts'
|
56
|
+
include RTM::AR::Sugar::Association::HashAccess
|
97
57
|
include RTM::AR::Sugar::Role::Counterparts
|
98
58
|
end
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
|
103
59
|
|
60
|
+
class ActiveRecord < RTM::Engine
|
61
|
+
identifier :activerecord
|
62
|
+
include RTM::AR::TopicMapSystem
|
104
63
|
|
64
|
+
def initialize(params)
|
65
|
+
super
|
105
66
|
|
67
|
+
config = @params[:config]
|
68
|
+
case config
|
69
|
+
when :existing
|
70
|
+
# do nothing, reuse existing active_record connection
|
71
|
+
when nil
|
72
|
+
# use the existing or externally configured connection
|
73
|
+
connect unless connected?
|
74
|
+
when :memory
|
75
|
+
# explicityly connect to the sqlite3 in-memory backend
|
76
|
+
connect
|
77
|
+
when ::ActiveRecord::Base
|
78
|
+
# when it is a class which extends ActiveRecord::Base, use the connection of this one.
|
79
|
+
# FIXME: this is not implemented yet.
|
80
|
+
when Array
|
81
|
+
connect *config
|
82
|
+
when Hash
|
83
|
+
connect config
|
84
|
+
else
|
85
|
+
# fall through, like :existing
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Rtm01to02 < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
rename_table :association_roles, :roles
|
4
|
+
rename_table :topic_names, :names
|
5
|
+
rename_column :variants, :topic_name_id, :name_id
|
6
|
+
rename_column :item_identifiers, :topic_map_construct_id, :construct_id
|
7
|
+
rename_column :item_identifiers, :topic_map_construct_type, :construct_type
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
rename_table :roles, :association_roles
|
12
|
+
rename_table :names, :topic_names
|
13
|
+
rename_column :variants, :name_id, :topic_name_id
|
14
|
+
rename_column :item_identifiers, :construct_id, :topic_map_construct_id
|
15
|
+
rename_column :item_identifiers, :construct_type, :topic_map_construct_type
|
16
|
+
end
|
17
|
+
end
|
@@ -29,7 +29,7 @@ module RTM::AR
|
|
29
29
|
def filter_roles(*args)
|
30
30
|
if args.size == 1
|
31
31
|
t = topic_map.get(args.first)
|
32
|
-
return self.roles.find(:all,:conditions => ["ttype_id = ?", t.id])
|
32
|
+
return self.roles.find(:all,:conditions => ["ttype_id = ?", t.__getobj__.id])
|
33
33
|
end
|
34
34
|
false
|
35
35
|
end
|
@@ -2,8 +2,6 @@
|
|
2
2
|
# License: Apache License, Version 2.0
|
3
3
|
|
4
4
|
module RTM
|
5
|
-
|
6
|
-
|
7
5
|
module Construct
|
8
6
|
def find(*args)
|
9
7
|
RTM::AR.const_get(name.split("::").last).find(*args)
|
@@ -11,11 +9,11 @@ module RTM
|
|
11
9
|
end
|
12
10
|
module Reifiable
|
13
11
|
end
|
14
|
-
|
12
|
+
|
15
13
|
module TopicMap
|
16
14
|
extend Construct
|
17
15
|
end
|
18
|
-
|
16
|
+
|
19
17
|
module Topic
|
20
18
|
extend Construct
|
21
19
|
|
@@ -45,39 +43,20 @@ module RTM
|
|
45
43
|
extend Construct
|
46
44
|
|
47
45
|
end
|
48
|
-
|
46
|
+
|
49
47
|
module Locator
|
50
|
-
|
48
|
+
|
51
49
|
end
|
52
|
-
|
50
|
+
|
53
51
|
module ItemIdentifier
|
54
|
-
extend Locator
|
52
|
+
extend Locator
|
55
53
|
end
|
56
|
-
|
54
|
+
|
57
55
|
module SubjectIdentifier
|
58
56
|
extend Locator
|
59
57
|
end
|
60
|
-
|
58
|
+
|
61
59
|
module SubjectLocator
|
62
60
|
extend Locator
|
63
61
|
end
|
64
|
-
|
65
|
-
# module Topics
|
66
|
-
# end
|
67
|
-
# module Associations
|
68
|
-
# end
|
69
|
-
# module Names
|
70
|
-
# end
|
71
|
-
# module Occurrences
|
72
|
-
# end
|
73
|
-
# module Roles
|
74
|
-
# end
|
75
|
-
# module Reifiables
|
76
|
-
# end
|
77
|
-
# module Variants
|
78
|
-
# end
|
79
|
-
# module TopicMaps
|
80
|
-
# end
|
81
|
-
# module Locators
|
82
|
-
# end
|
83
62
|
end
|
@@ -194,8 +194,8 @@ module RTM::AR::IO
|
|
194
194
|
end
|
195
195
|
|
196
196
|
# Called when the end tag is reached. In the case of <tag/>, tag_end
|
197
|
-
# will be called
|
198
|
-
# @
|
197
|
+
# will be called immediately after tag_start
|
198
|
+
# @param the name of the tag
|
199
199
|
def end_element(uri, name, qname)
|
200
200
|
return unless uri == "http://www.topicmaps.org/xtm/"
|
201
201
|
#puts "end of tag: #{name}"
|
@@ -219,7 +219,7 @@ module RTM::AR::IO
|
|
219
219
|
# puts "after case"
|
220
220
|
end
|
221
221
|
# Called when text is encountered in the document
|
222
|
-
# @
|
222
|
+
# @param text the text content.
|
223
223
|
def characters(text)
|
224
224
|
if @options[:strip_whitespace]
|
225
225
|
text.strip!
|
@@ -22,8 +22,8 @@ module RTM
|
|
22
22
|
def merge_item_identifiers(other)
|
23
23
|
#self.item_identifiers.add_all other.item_identifiers
|
24
24
|
RTM::AR::TMDM::ItemIdentifier.move_all(
|
25
|
-
["
|
26
|
-
["
|
25
|
+
["construct_id", other.__getobj__.id, self.__getobj__.id],
|
26
|
+
["construct_type", other.__getobj__.class.name, self.__getobj__.class.name]
|
27
27
|
)
|
28
28
|
end
|
29
29
|
end
|
@@ -207,10 +207,10 @@ module RTM
|
|
207
207
|
|
208
208
|
# 8. Set C's [item identifiers] property to the union of the values of A and B's [item identifiers] properties.
|
209
209
|
#self.item_identifiers.add_all other.item_identifiers
|
210
|
-
#RTM::AR::TMDM::ItemIdentifier.update_all "
|
210
|
+
#RTM::AR::TMDM::ItemIdentifier.update_all "construct_id = #{self.__getobj__.id}, construct_type = '#{self.__getobj__.class.name}'", "construct_id = #{other.__getobj__.id} and construct_type = '#{other.__getobj__.class.name}'"
|
211
211
|
RTM::AR::TMDM::ItemIdentifier.move_all(
|
212
|
-
["
|
213
|
-
["
|
212
|
+
["construct_id", other.__getobj__.id, self.__getobj__.id],
|
213
|
+
["construct_type", other.__getobj__.class.name, self.__getobj__.class.name]
|
214
214
|
)
|
215
215
|
|
216
216
|
self.merge_rewrap other
|
@@ -9,7 +9,7 @@ module RTM
|
|
9
9
|
module TMDM
|
10
10
|
class Topic < ActiveRecord::Base;end
|
11
11
|
class ItemIdentifier < ActiveRecord::Base
|
12
|
-
belongs_to :
|
12
|
+
belongs_to :construct
|
13
13
|
end
|
14
14
|
class SubjectIdentifier < ActiveRecord::Base
|
15
15
|
belongs_to :topic
|
@@ -34,32 +34,32 @@ module RTM
|
|
34
34
|
rename_column "associations", "type_id", "ttype_id"
|
35
35
|
rename_column "associations", "topicmap_id", "topic_map_id"
|
36
36
|
|
37
|
-
rename_table "qtm_assocrole", "
|
38
|
-
rename_column "
|
39
|
-
rename_column "
|
37
|
+
rename_table "qtm_assocrole", "roles"
|
38
|
+
rename_column "roles", "type_id", "ttype_id"
|
39
|
+
rename_column "roles", "reference", "topic_id"
|
40
40
|
|
41
|
-
rename_table "qtm_topicname", "
|
42
|
-
rename_column "
|
41
|
+
rename_table "qtm_topicname", "names"
|
42
|
+
rename_column "names", "type_id", "ttype_id"
|
43
43
|
|
44
44
|
rename_table "qtm_occurrence", "occurrences"
|
45
45
|
rename_column "occurrences", "type_id", "ttype_id"
|
46
46
|
|
47
47
|
rename_table "qtm_variant", "variants"
|
48
|
-
rename_column "variants", "topicname_id", "
|
48
|
+
rename_column "variants", "topicname_id", "name_id"
|
49
49
|
|
50
50
|
rename_table "qtm_topicmapconstructref", "item_identifiers"
|
51
51
|
rename_column "item_identifiers", "locator", "reference"
|
52
52
|
add_column :item_identifiers, :topic_map_id, :integer
|
53
53
|
ItemIdentifier.reset_column_information
|
54
54
|
ItemIdentifier.find(:all).each do |si|
|
55
|
-
si.update_attribute :topic_map_id, si.
|
55
|
+
si.update_attribute :topic_map_id, si.construct.topic_map_id
|
56
56
|
end
|
57
57
|
|
58
58
|
create_table :item_identifiers do |t|
|
59
59
|
t.column :topic_map_id, :integer, :null => false
|
60
60
|
t.column :reference, :string, :null => false
|
61
|
-
t.column :
|
62
|
-
t.column :
|
61
|
+
t.column :construct_id, :integer
|
62
|
+
t.column :construct_type, :string
|
63
63
|
end
|
64
64
|
SubjectIdentifier.reset_column_information
|
65
65
|
SubjectIdentifier.find(:all).each do |si|
|
@@ -9,7 +9,7 @@ module RTM
|
|
9
9
|
module TMDM
|
10
10
|
class Topic < ActiveRecord::Base;end
|
11
11
|
class ItemIdentifier < ActiveRecord::Base
|
12
|
-
belongs_to :
|
12
|
+
belongs_to :construct
|
13
13
|
end
|
14
14
|
class SubjectIdentifier < ActiveRecord::Base
|
15
15
|
belongs_to :topic
|
@@ -39,14 +39,14 @@ module RTM
|
|
39
39
|
t.column :ttype_id
|
40
40
|
end
|
41
41
|
|
42
|
-
create_view "
|
42
|
+
create_view "roles", "select id, association_id, type_id, reference from qtm_assocrole" do |t|
|
43
43
|
t.column :id
|
44
44
|
t.column :association_id
|
45
45
|
t.column :ttype_id
|
46
46
|
t.column :topic_id
|
47
47
|
end
|
48
48
|
|
49
|
-
create_view "
|
49
|
+
create_view "names", "select id, topic_id, type_id, value from qtm_topicname" do |t|
|
50
50
|
t.column :id
|
51
51
|
t.column :topic_id
|
52
52
|
t.column :ttype_id
|
@@ -73,14 +73,14 @@ module RTM
|
|
73
73
|
add_column :item_identifiers, :topic_map_id, :integer
|
74
74
|
ItemIdentifier.reset_column_information
|
75
75
|
ItemIdentifier.find(:all).each do |si|
|
76
|
-
si.update_attribute :topic_map_id, si.
|
76
|
+
si.update_attribute :topic_map_id, si.construct.topic_map_id
|
77
77
|
end
|
78
78
|
|
79
79
|
create_table :item_identifiers do |t|
|
80
80
|
t.column :topic_map_id, :integer, :null => false
|
81
81
|
t.column :reference, :string, :null => false
|
82
|
-
t.column :
|
83
|
-
t.column :
|
82
|
+
t.column :construct_id, :integer
|
83
|
+
t.column :construct_type, :string
|
84
84
|
end
|
85
85
|
SubjectIdentifier.reset_column_information
|
86
86
|
SubjectIdentifier.find(:all).each do |si|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM::AR
|
5
|
+
module RdbmsConfig
|
6
|
+
|
7
|
+
# This function migrates the database schema using the default
|
8
|
+
# ActiveRecord connection.
|
9
|
+
def migrate_database
|
10
|
+
TMDM::InitialSchema.migrate(:up)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Checks if there is already an ActiveRecord connection of if one was configured.
|
14
|
+
# To do so, it's not enough to call +connected?+ but we also need to try to access something,
|
15
|
+
# as Rails will use the preconfigured database then.
|
16
|
+
def connected?(base_class=::ActiveRecord::Base)
|
17
|
+
begin
|
18
|
+
RTM::AR::TMDM::TopicMap.first # this is needed because Rails establishes the connection upon first usage
|
19
|
+
rescue
|
20
|
+
# puts "GOT AN EXCEPTION. I.e. we were not already connected and there was no connection configured -- or we were connected, but the topic_maps table was missing."
|
21
|
+
end
|
22
|
+
base_class.connected?
|
23
|
+
end
|
24
|
+
|
25
|
+
# Connects Active Record to a database or in Memory database if no parameters given.
|
26
|
+
def connect(*args)
|
27
|
+
base_class = ::ActiveRecord::Base
|
28
|
+
puts("WARNING: ActiveRecord::Base is already connected. Your're now disconnected and reconnected using the RTM connection you specified.") if connected?(base_class)
|
29
|
+
|
30
|
+
if args.size == 0
|
31
|
+
base_class.establish_connection(
|
32
|
+
:adapter => "#{"jdbc" if PLATFORM && PLATFORM =~ /java/}sqlite3",
|
33
|
+
:database => ":memory:"
|
34
|
+
)
|
35
|
+
no_output do
|
36
|
+
migrate_database
|
37
|
+
end
|
38
|
+
else
|
39
|
+
base_class.establish_connection(*args)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -108,9 +108,9 @@ module RTM::AR
|
|
108
108
|
a[:ttype] = a[:type]
|
109
109
|
a.delete(:type)
|
110
110
|
end
|
111
|
-
puts "#{"#"}{self.class}:#{prop} -- #{"#"}{args.first.inspect}"
|
112
|
-
puts
|
113
|
-
puts a.inspect
|
111
|
+
# puts "#{"#"}{self.class}:#{prop} -- #{"#"}{args.first.inspect}"
|
112
|
+
# puts
|
113
|
+
# puts a.inspect
|
114
114
|
b = {}
|
115
115
|
a.each do |k,v|
|
116
116
|
if RTM::AR::TMDM::#{options[:type]}.columns.map{|c| c.name}.include?(k)
|
@@ -150,8 +150,8 @@ EOS
|
|
150
150
|
# create_locator reference:string
|
151
151
|
# [ :name => :reference, :type => :String]
|
152
152
|
#
|
153
|
-
#
|
154
|
-
#
|
153
|
+
# create_name value:String, scope:Collection
|
154
|
+
# create_name value:String, type: Topic, scope:Collection
|
155
155
|
# [ {:name => :value, :type => :String}, {:name => :type, :type => :Topic, :optional => true}, {:name => :scope, :type => :Collection} ]
|
156
156
|
#
|
157
157
|
# create_occurrence value:String, type: Topic, scope:Collection
|
@@ -36,7 +36,7 @@ module RTM::AR
|
|
36
36
|
when :ItemIdentifier
|
37
37
|
if @parent.class.name.to_s =~ /::Topic$/
|
38
38
|
tbi = @parent.topic_map._item_identifier(obj)
|
39
|
-
if tbi && tmc=tbi.
|
39
|
+
if tbi && tmc=tbi.construct
|
40
40
|
if tmc.class.name =~ /::Topic$/
|
41
41
|
return @parent if tmc == @parent.__getobj__
|
42
42
|
result = Topic.wrap(tmc).merge @parent
|
@@ -61,26 +61,26 @@ module RTM::AR
|
|
61
61
|
|
62
62
|
when :SubjectIdentifier
|
63
63
|
# check for existing item identifier
|
64
|
-
puts
|
65
|
-
puts "trying to add SI to a topic"
|
64
|
+
# puts
|
65
|
+
# puts "trying to add SI to a topic"
|
66
66
|
tbi = @parent.topic_map._item_identifier(obj)
|
67
67
|
if tbi && tmc=tbi.construct
|
68
|
-
puts "something with this II exists"
|
68
|
+
# puts "something with this II exists"
|
69
69
|
if tmc.class.name =~ /::Topic$/
|
70
|
-
puts "it exists as a topic"
|
71
|
-
puts tmc == @parent.__getobj__
|
70
|
+
# puts "it exists as a topic"
|
71
|
+
# puts tmc == @parent.__getobj__
|
72
72
|
return @parent if tmc == @parent.__getobj__
|
73
73
|
|
74
|
-
puts "trying to merge"
|
75
|
-
puts "BEFORE"
|
74
|
+
# puts "trying to merge"
|
75
|
+
# puts "BEFORE"
|
76
76
|
begin
|
77
77
|
result = Topic.wrap(tmc).merge(@parent)
|
78
78
|
rescue Exception => e
|
79
79
|
puts e.inspect
|
80
80
|
raise e
|
81
81
|
end
|
82
|
-
puts "AFTER"
|
83
|
-
puts "done merging, now adding SI"
|
82
|
+
# puts "AFTER"
|
83
|
+
# puts "done merging, now adding SI"
|
84
84
|
|
85
85
|
#result = @parent.merge(Topic.wrap(tmc))
|
86
86
|
# after merging, we still need to add the SI
|
@@ -93,7 +93,7 @@ module RTM::AR
|
|
93
93
|
warn("This subject identifier IRI already belongs to another topic map construct (not a topic)")
|
94
94
|
end
|
95
95
|
end
|
96
|
-
puts "checking for existing SI"
|
96
|
+
# puts "checking for existing SI"
|
97
97
|
# check for existing subject identifier
|
98
98
|
tbsi = @parent.topic_map._subject_identifier(obj.to_s)
|
99
99
|
if tbsi
|
@@ -95,9 +95,9 @@ module RTM::AR
|
|
95
95
|
property_set :roles, :aka => [:r, :roles_played, :association_roles], :computable => true, :type => :Role, :wrap => true
|
96
96
|
|
97
97
|
def filter_roles(*args)
|
98
|
-
puts
|
99
|
-
puts "topic filter roles:"
|
100
|
-
puts args.inspect
|
98
|
+
# puts
|
99
|
+
# puts "topic filter roles:"
|
100
|
+
# puts args.inspect
|
101
101
|
if args.size == 1
|
102
102
|
a1 = args.shift
|
103
103
|
# if a1 == :any
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
require 'rtm/activerecord/rdbms_config'
|
5
|
+
require 'rtm/activerecord/001_initial_schema'
|
6
|
+
require "rtm/activerecord/io/from_xtm2"
|
7
|
+
# require "rtm/backend/active_record/io/from_xtm2_libxml"
|
8
|
+
|
9
|
+
module RTM::AR
|
10
|
+
module TopicMapSystem
|
11
|
+
include RTM::TopicMapSystem
|
12
|
+
include RTM::AR::RdbmsConfig
|
13
|
+
|
14
|
+
def create(base_locator)
|
15
|
+
TopicMap.create(base_locator)
|
16
|
+
end
|
17
|
+
|
18
|
+
def topic_maps
|
19
|
+
TopicMap.topic_maps
|
20
|
+
end
|
21
|
+
|
22
|
+
def [](*args)
|
23
|
+
if args.size == 0
|
24
|
+
return TopicMap.topic_maps
|
25
|
+
end
|
26
|
+
TopicMap.topic_maps[*args]
|
27
|
+
end
|
28
|
+
|
29
|
+
# Assignes a logger to active record (or STDOUT as default) which outputs
|
30
|
+
# the sql statements.
|
31
|
+
def log(to=STDOUT)
|
32
|
+
ActiveRecord::Base.logger = Logger.new(to)
|
33
|
+
ActiveRecord::Base.colorize_logging = false if PLATFORM =~ /mswin/
|
34
|
+
end
|
35
|
+
|
36
|
+
# This function generates the database schema using the default
|
37
|
+
# ActiveRecord connection.
|
38
|
+
def migrate_database
|
39
|
+
TMDM::InitialSchema.migrate(:up)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rtm-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Benjamin Bock
|
@@ -9,41 +14,53 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-04-13 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: rtm
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
version: 0.3.0
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: activesupport
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 3
|
44
|
+
- 5
|
33
45
|
version: 2.3.5
|
34
|
-
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
35
48
|
- !ruby/object:Gem::Dependency
|
36
49
|
name: activerecord
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
52
|
requirements:
|
41
53
|
- - ">="
|
42
54
|
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 2
|
57
|
+
- 3
|
58
|
+
- 5
|
43
59
|
version: 2.3.5
|
44
|
-
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
45
62
|
description: " Ruby Topic Maps is a Topic Maps engine written in Ruby.\n This is the backend engine which holds all data in ActiveRecord objects.\n It's available on all ruby platforms but currently does not pass all specs.\n"
|
46
|
-
email: rtm+rtm-activerecord-gem-
|
63
|
+
email: rtm+rtm-activerecord-gem-20100413@topicmapslab.de
|
47
64
|
executables: []
|
48
65
|
|
49
66
|
extensions: []
|
@@ -52,9 +69,9 @@ extra_rdoc_files: []
|
|
52
69
|
|
53
70
|
files:
|
54
71
|
- lib/rtm/activerecord/001_initial_schema.rb
|
72
|
+
- lib/rtm/activerecord/002_rtm01to02.rb
|
55
73
|
- lib/rtm/activerecord/association_and_role.rb
|
56
74
|
- lib/rtm/activerecord/base.rb
|
57
|
-
- lib/rtm/activerecord/connect.rb
|
58
75
|
- lib/rtm/activerecord/io/from_xtm2.rb
|
59
76
|
- lib/rtm/activerecord/io/from_xtm2_libxml.rb
|
60
77
|
- lib/rtm/activerecord/io/to_jtm.rb
|
@@ -69,6 +86,7 @@ files:
|
|
69
86
|
- lib/rtm/activerecord/persistent_code_output.rb
|
70
87
|
- lib/rtm/activerecord/quaaxtm2rtm.rb
|
71
88
|
- lib/rtm/activerecord/quaaxtm2rtmviews.rb
|
89
|
+
- lib/rtm/activerecord/rdbms_config.rb
|
72
90
|
- lib/rtm/activerecord/set_wrapper.rb
|
73
91
|
- lib/rtm/activerecord/sugar/association/hash_access.rb
|
74
92
|
- lib/rtm/activerecord/sugar/role/counterparts.rb
|
@@ -83,8 +101,10 @@ files:
|
|
83
101
|
- lib/rtm/activerecord/tmdm.rb
|
84
102
|
- lib/rtm/activerecord/topic.rb
|
85
103
|
- lib/rtm/activerecord/topic_map.rb
|
104
|
+
- lib/rtm/activerecord/topic_map_system.rb
|
86
105
|
- lib/rtm/activerecord/traverse_associations.rb
|
87
106
|
- lib/rtm/activerecord.rb
|
107
|
+
- lib/rtm-activerecord.rb
|
88
108
|
- LICENSE
|
89
109
|
- DISCLAIMER
|
90
110
|
- README
|
@@ -101,18 +121,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
121
|
requirements:
|
102
122
|
- - ">="
|
103
123
|
- !ruby/object:Gem::Version
|
124
|
+
segments:
|
125
|
+
- 0
|
104
126
|
version: "0"
|
105
|
-
version:
|
106
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
128
|
requirements:
|
108
129
|
- - ">="
|
109
130
|
- !ruby/object:Gem::Version
|
131
|
+
segments:
|
132
|
+
- 0
|
110
133
|
version: "0"
|
111
|
-
version:
|
112
134
|
requirements: []
|
113
135
|
|
114
136
|
rubyforge_project: rtm
|
115
|
-
rubygems_version: 1.3.
|
137
|
+
rubygems_version: 1.3.6
|
116
138
|
signing_key:
|
117
139
|
specification_version: 3
|
118
140
|
summary: "Ruby Topic Maps: Active Record Backend"
|
@@ -1,102 +0,0 @@
|
|
1
|
-
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
-
# License: Apache License, Version 2.0
|
3
|
-
|
4
|
-
require 'active_record'
|
5
|
-
require 'rtm/activerecord/001_initial_schema'
|
6
|
-
require "rtm/activerecord/io/from_xtm2"
|
7
|
-
# require "rtm/backend/active_record/io/from_xtm2_libxml"
|
8
|
-
|
9
|
-
module RTM
|
10
|
-
module AR
|
11
|
-
|
12
|
-
class TMS
|
13
|
-
include Singleton
|
14
|
-
include RTM::TopicMapSystem
|
15
|
-
|
16
|
-
|
17
|
-
def create(base_locator)
|
18
|
-
AR::TopicMap.create(base_locator)
|
19
|
-
end
|
20
|
-
|
21
|
-
def topic_maps
|
22
|
-
AR::TopicMap.topic_maps
|
23
|
-
end
|
24
|
-
|
25
|
-
def [](*args)
|
26
|
-
if args.size == 0
|
27
|
-
return AR::TopicMap.topic_maps
|
28
|
-
end
|
29
|
-
args.map { |m| AR::TopicMap.topic_maps[m] }
|
30
|
-
end
|
31
|
-
|
32
|
-
# Assignes a logger to active record (or STDOUT as default) which outputs
|
33
|
-
# the sql statements.
|
34
|
-
def log(to=STDOUT)
|
35
|
-
ActiveRecord::Base.logger = Logger.new(to)
|
36
|
-
ActiveRecord::Base.colorize_logging = false if PLATFORM =~ /mswin/
|
37
|
-
end
|
38
|
-
# This function generates the database schema using the default
|
39
|
-
# ActiveRecord connection.
|
40
|
-
def generate_database
|
41
|
-
TMDM::InitialSchema.migrate(:up)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Connects to the sqlite3 database given in the path or to
|
45
|
-
# a default database if no path is given.
|
46
|
-
def connect_sqlite3(dbname="tmdm.sqlite3")
|
47
|
-
ActiveRecord::Base.establish_connection(
|
48
|
-
:adapter => platform_specific_adapter("sqlite3"),
|
49
|
-
:database => dbname
|
50
|
-
)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Connects to a mysql database. Parameters are
|
54
|
-
# either
|
55
|
-
# database, username, password, host
|
56
|
-
# or
|
57
|
-
# only a keyword hash with these parameters.
|
58
|
-
def connect_mysql(database="rtm_development", username=nil, password=nil, host="localhost")
|
59
|
-
if database.is_a? Hash
|
60
|
-
return ActiveRecord::Base.establish_connection(database)
|
61
|
-
end
|
62
|
-
ActiveRecord::Base.establish_connection(
|
63
|
-
:adapter => platform_specific_adapter("mysql"),
|
64
|
-
:database => database,
|
65
|
-
:username => username,
|
66
|
-
:password => password,
|
67
|
-
:host => host
|
68
|
-
)
|
69
|
-
end
|
70
|
-
|
71
|
-
# Connects to a in-memory database. No parameters required.
|
72
|
-
# Schema will automatically be generated.
|
73
|
-
def connect_memory
|
74
|
-
ActiveRecord::Base.establish_connection(
|
75
|
-
:adapter => platform_specific_adapter("sqlite3"),
|
76
|
-
:database => ":memory:"
|
77
|
-
)
|
78
|
-
no_output do
|
79
|
-
generate_database
|
80
|
-
end
|
81
|
-
true
|
82
|
-
end
|
83
|
-
|
84
|
-
# Connects Active Record to a database or in Memory database if no parameters given.
|
85
|
-
def connect(*args)
|
86
|
-
if args.size == 0
|
87
|
-
return connect_memory
|
88
|
-
end
|
89
|
-
ActiveRecord::Base.establish_connection(*args)
|
90
|
-
end
|
91
|
-
|
92
|
-
private
|
93
|
-
def platform_specific_adapter(adapter)
|
94
|
-
if PLATFORM && PLATFORM =~ /java/
|
95
|
-
return "jdbc#{adapter}"
|
96
|
-
end
|
97
|
-
return adapter
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|