rtm-ontopia 0.3.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/DISCLAIMER +15 -0
  2. data/LICENSE +201 -0
  3. data/README +8 -0
  4. data/lib/rtm-ontopia.rb +4 -0
  5. data/lib/rtm/ontopia.rb +271 -0
  6. data/lib/rtm/ontopia/io/to_cxtm.rb +40 -0
  7. data/lib/rtm/ontopia/javalibs/antlr-2.7.7.jar +0 -0
  8. data/lib/rtm/ontopia/javalibs/avalon-framework-4.1.3.jar +0 -0
  9. data/lib/rtm/ontopia/javalibs/backport-util-concurrent-3.1.jar +0 -0
  10. data/lib/rtm/ontopia/javalibs/commons-dbcp-1.3.jar +0 -0
  11. data/lib/rtm/ontopia/javalibs/commons-fileupload-1.1.jar +0 -0
  12. data/lib/rtm/ontopia/javalibs/commons-io-1.1.jar +0 -0
  13. data/lib/rtm/ontopia/javalibs/commons-pool-1.5.4.jar +0 -0
  14. data/lib/rtm/ontopia/javalibs/concurrent-1.3.4.jar +0 -0
  15. data/lib/rtm/ontopia/javalibs/dom4j-1.6.1.jar +0 -0
  16. data/lib/rtm/ontopia/javalibs/fontbox-1.1.0.jar +0 -0
  17. data/lib/rtm/ontopia/javalibs/geronimo-stax-api_1.0_spec-1.0.jar +0 -0
  18. data/lib/rtm/ontopia/javalibs/icu4j-3.4.4.jar +0 -0
  19. data/lib/rtm/ontopia/javalibs/iri-0.8.jar +0 -0
  20. data/lib/rtm/ontopia/javalibs/java-getopt-1.0.9.jar +0 -0
  21. data/lib/rtm/ontopia/javalibs/jempbox-1.1.0.jar +0 -0
  22. data/lib/rtm/ontopia/javalibs/jena-2.6.2.jar +0 -0
  23. data/lib/rtm/ontopia/javalibs/jflex-1.4.3.jar +0 -0
  24. data/lib/rtm/ontopia/javalibs/jgroups-2.6.10.GA.jar +0 -0
  25. data/lib/rtm/ontopia/javalibs/joda-time-1.6.jar +0 -0
  26. data/lib/rtm/ontopia/javalibs/jsp-api-2.0.jar +0 -0
  27. data/lib/rtm/ontopia/javalibs/jstl-1.1.2.jar +0 -0
  28. data/lib/rtm/ontopia/javalibs/jtidy-r8-20060801.jar +0 -0
  29. data/lib/rtm/ontopia/javalibs/logkit-1.0.1.jar +0 -0
  30. data/lib/rtm/ontopia/javalibs/ontopia-engine-5.1.0.jar +0 -0
  31. data/lib/rtm/ontopia/javalibs/ontopia-mio-0.1.0-SNAPSHOT.jar +0 -0
  32. data/lib/rtm/ontopia/javalibs/opencsv-1.8.jar +0 -0
  33. data/lib/rtm/ontopia/javalibs/pdfbox-1.1.0.jar +0 -0
  34. data/lib/rtm/ontopia/javalibs/poi-3.6.jar +0 -0
  35. data/lib/rtm/ontopia/javalibs/poi-ooxml-3.6.jar +0 -0
  36. data/lib/rtm/ontopia/javalibs/poi-ooxml-schemas-3.6.jar +0 -0
  37. data/lib/rtm/ontopia/javalibs/poi-scratchpad-3.6.jar +0 -0
  38. data/lib/rtm/ontopia/javalibs/saxon-6.5.3.jar +0 -0
  39. data/lib/rtm/ontopia/javalibs/servlet-api-2.4.jar +0 -0
  40. data/lib/rtm/ontopia/javalibs/standard-1.1.2.jar +0 -0
  41. data/lib/rtm/ontopia/javalibs/stax-api-1.0.1.jar +0 -0
  42. data/lib/rtm/ontopia/javalibs/tagsoup-1.2.jar +0 -0
  43. data/lib/rtm/ontopia/javalibs/velocity-1.3.jar +0 -0
  44. data/lib/rtm/ontopia/javalibs/wicket-1.4.8.jar +0 -0
  45. data/lib/rtm/ontopia/javalibs/wicket-datetime-1.4.8.jar +0 -0
  46. data/lib/rtm/ontopia/javalibs/wicket-extensions-1.4.8.jar +0 -0
  47. data/lib/rtm/ontopia/javalibs/xercesImpl-2.7.1.jar +0 -0
  48. data/lib/rtm/ontopia/javalibs/xml-apis-1.0.b2.jar +0 -0
  49. data/lib/rtm/ontopia/javalibs/xmlbeans-2.3.0.jar +0 -0
  50. data/lib/rtm/ontopia/ontopia_example.props +14 -0
  51. data/lib/rtm/ontopia/rdbms/properties.rb +149 -0
  52. data/lib/rtm/ontopia/rdbms/store.rb +39 -0
  53. data/res/rdbms/config/db.h2.props +8 -0
  54. data/res/rdbms/config/db.mysql.props +8 -0
  55. data/res/rdbms/config/db.oracle8.props +8 -0
  56. data/res/rdbms/config/db.oracle9i.props +8 -0
  57. data/res/rdbms/config/db.postgresql.props +8 -0
  58. data/res/rdbms/config/db.sqlserver.props +8 -0
  59. data/res/rdbms/setup/generic.create.sql +154 -0
  60. data/res/rdbms/setup/generic.drop.sql +16 -0
  61. data/res/rdbms/setup/h2.create.sql +154 -0
  62. data/res/rdbms/setup/h2.drop.sql +16 -0
  63. data/res/rdbms/setup/mysql.create.sql +170 -0
  64. data/res/rdbms/setup/mysql.drop.sql +16 -0
  65. data/res/rdbms/setup/mysql.force_drop.sql +16 -0
  66. data/res/rdbms/setup/oracle10g.create.sql +202 -0
  67. data/res/rdbms/setup/oracle10g.drop.sql +59 -0
  68. data/res/rdbms/setup/oracle8.create.sql +202 -0
  69. data/res/rdbms/setup/oracle8.drop.sql +59 -0
  70. data/res/rdbms/setup/oracle9i.create.sql +202 -0
  71. data/res/rdbms/setup/oracle9i.drop.sql +59 -0
  72. data/res/rdbms/setup/postgresql.create.sql +191 -0
  73. data/res/rdbms/setup/postgresql.drop.sql +53 -0
  74. data/res/rdbms/setup/sqlserver.create.sql +154 -0
  75. data/res/rdbms/setup/sqlserver.drop.sql +16 -0
  76. metadata +152 -0
data/DISCLAIMER ADDED
@@ -0,0 +1,15 @@
1
+ Copyright 2006-2008 Benjamin Bock
2
+
3
+ Copyright 2008-2010 Topic Maps Lab, University of Leipzig.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and limitations
15
+ under the License.
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README ADDED
@@ -0,0 +1,8 @@
1
+ Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ License: Apache License, Version 2.0
3
+
4
+ See http://rtm.topicmapslab.de/ for instructions.
5
+
6
+ This Gem is bundled with the following third party libraries:
7
+ * Ontopia - http://code.google.com/p/ontopia/ (Apache 2.0 License)
8
+ * several others, see lib/ontopia/javalibs/
@@ -0,0 +1,4 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ require File.join(File.dirname(__FILE__), 'rtm/ontopia')
@@ -0,0 +1,271 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ unless Object.const_defined?("Gem") && rtmgem = Gem.loaded_specs["rtm-ontopia"]
5
+ javatmapi_path = File.expand_path(File.join(File.dirname(__FILE__), "../../../rtm-javatmapi/lib"))
6
+ $LOAD_PATH.unshift javatmapi_path if File.directory?(javatmapi_path)
7
+ end
8
+ require 'rtm/javatmapi'
9
+
10
+ Dir[File.join(File.dirname(__FILE__), 'ontopia/javalibs/*.jar')].each {|file| require file }
11
+ require File.join(File.dirname(__FILE__), '/ontopia/io/to_cxtm')
12
+
13
+ module RTM
14
+ class Ontopia < JavaTMAPI
15
+ identifier :ontopia
16
+
17
+ def initialize(*args)
18
+ super
19
+
20
+ tmsf = Java::NetOntopiaTopicmapsImplTmapi2::TopicMapSystemFactory.new
21
+ set_tmsf(tmsf)
22
+ set_properties(@params[:properties])
23
+ set_features(@params[:features])
24
+ create_system
25
+ end
26
+
27
+ def self.connect(*args)
28
+ params = args.first
29
+
30
+ # redirect to create an rdbms connection if an adapter is given and we did not already com from there
31
+ if params && params[:adapter] && self != OntopiaRdbms
32
+ OntopiaRdbms.connect(*args)
33
+ else
34
+ # adapter was not given or we already handled it and came back here through super
35
+ super
36
+ end
37
+ end
38
+ end
39
+
40
+ class OntopiaRdbms < Ontopia
41
+ require File.join(File.dirname(__FILE__), '/ontopia/rdbms/properties')
42
+ require File.join(File.dirname(__FILE__), '/ontopia/rdbms/store')
43
+ identifier :ontopia_rdbms
44
+
45
+ def initialize(params={})
46
+ require 'active_record' unless defined?(ActiveRecord)
47
+ require 'jdbc_adapter' unless defined?(ActiveRecord::ConnectionAdapters::Jdbc)
48
+ params2 = params || {} # XXX hack: maybe setting params in Engine#initialize is not the best idea
49
+
50
+ # enhance all ontopia properties from rails-style config
51
+ ontopia_properties = RTM::Ontopia::Rdbms::Properties.rails2ontopia(config(params2))
52
+
53
+ # FIXME: this works only if properties was not specified as file
54
+ params2[:properties] ||= {}
55
+ ontopia_properties.each do |k,v|
56
+ params2[:properties][k] = v.to_s unless params2[:properties].key?(k)
57
+ end
58
+ super
59
+ @params.merge(params2)
60
+ end
61
+
62
+ def config(params = @params)
63
+ # if no config-option is given, use params directly, but clean it up a bit
64
+ params[:config] || params.reject{|k,v| k == :identifier || k == :backend || k == :implementation}
65
+ end
66
+
67
+ # Migrate the Database to contain the Ontopia RDBMS schema. Uses the connection data provided with connect
68
+ def migrate_database
69
+ self.class.migrate_database(config)
70
+ end
71
+ alias migrate migrate_database
72
+
73
+ # Drops the Ontopia schema from the database. This corresponds to migrating the database down.
74
+ def migrate_database_down
75
+ self.class.migrate_database_down(config)
76
+ end
77
+ alias migrate_down migrate_database_down
78
+
79
+ def migrate_database_force_down
80
+ self.class.migrate_database_force_down(config)
81
+ end
82
+ alias migrate_force_down migrate_database_force_down
83
+
84
+ def migrate_database_custom(name)
85
+ self.class.migrate_database_custom(name, config)
86
+ end
87
+ alias migrate_custom migrate_database_custom
88
+
89
+ # Migrate the Database to contain the Ontopia RDBMS schema.
90
+ # Uses a Rails-style database configuration hash to connect to the database.
91
+ #
92
+ # Additional hash-keys to override the defaults:
93
+ # :connection => an existing connection to be used instead of creating using given parameters
94
+ # :schema_sql => directly supply sql to execute instead of :schema_file or autodetect
95
+ # :schema_file => directly supply sql file to execute instead of autodetect
96
+ # :adapter_schema_name => directly supply the schema name (generic, h2, mysql, oracle8, oracle9i, oracle10g, postresql, sqlserver)
97
+ # :direction => :up|:down create or drop schema (defaults to :up)
98
+ #
99
+ def self.migrate_database(config)
100
+ res = nil
101
+ connect_with(config) do |connection|
102
+ # see if we were provided with a schema directly or get it from file
103
+ schema_sql = config[:schema_sql]
104
+ unless schema_sql
105
+ # should we migrate up or down?
106
+ direction = config[:direction] || :up
107
+ create_or_drop = case direction.to_s
108
+ when "up"
109
+ "create"
110
+ when "down"
111
+ "drop"
112
+ when "force_down"
113
+ "force_drop"
114
+ else
115
+ direction.to_s
116
+ end
117
+
118
+ # get the adapter name for ontopia from the config
119
+ adapter_schema_name = config[:adapter_schema_name] || config[:adapter].sub(/^jdbc/, '')
120
+
121
+ # check if it is one of the available adapters
122
+ available_schemas = %w[generic h2 mysql oracle8 oracle9i oracle10g postresql sqlserver]
123
+ adapter_schema_name = "generic" unless available_schemas.include?(adapter_schema_name)
124
+
125
+ # find the corresponding schema file
126
+ schema_file = config[:schema_file] || File.join(File.dirname(__FILE__), "/../../res/rdbms/setup/#{adapter_schema_name}.#{create_or_drop}.sql")
127
+ raise "Could not find schema definition file #{File.expand_path(schema_file)}." unless File.exist?(schema_file)
128
+
129
+ # read the schema
130
+ schema_sql = File.read(schema_file)
131
+ end
132
+
133
+ # # execute the schema
134
+ # res = connection.execute(schema_sql)
135
+ # execute the schema, statement by statement
136
+ statement_list = schema_sql.split(/;/).map(&:strip).reject{|s| s.blank?}
137
+ statement_list.each do |statement|
138
+ connection.execute(statement)
139
+ end
140
+ end
141
+ res
142
+ end
143
+
144
+ # Drops the Ontopia schema from the database. This corresponds to migrating the database down.
145
+ def self.migrate_database_down(params={})
146
+ migrate_database(params.merge(:direction => :down))
147
+ end
148
+
149
+ def self.migrate_database_force_down(params={})
150
+ migrate_database(params.merge(:direction => :force_down))
151
+ end
152
+
153
+ def self.migrate_database_custom(name, params={})
154
+ migrate_database(params.merge(:direction => name))
155
+ end
156
+
157
+ # Provides a given block with a (temporary) connection using the given
158
+ # configuration. Either an existing connection is used (and kept open) or
159
+ # a new connection is opened, yielded to the block and then closed again.
160
+ #
161
+ # This is needed for migrations and for the connection check.
162
+ # Within the connection check it loads the needed JDBC connectors via
163
+ # ActiveRecord.
164
+ def self.connect_with(config)
165
+ require 'active_record' unless defined?(ActiveRecord)
166
+ require 'jdbc_adapter' unless defined?(ActiveRecord::ConnectionAdapters::Jdbc)
167
+
168
+ # prepare variable for separate connection class (if needed)
169
+ anonymous_active_record_base = nil
170
+
171
+ # use a supplied connection or create one using the config
172
+ connection = config[:connection]
173
+ unless connection
174
+ # create a new anonymous class extending ActiveRecord::Base for a separate connection
175
+ anonymous_active_record_base = Class.new(ActiveRecord::Base)
176
+
177
+ # connect to backend using the anonymous base class
178
+ anonymous_active_record_base.establish_connection(config)
179
+ connection = anonymous_active_record_base.connection
180
+ end
181
+
182
+ begin
183
+ yield connection if block_given?
184
+ ensure
185
+ # close connection if we created a new one
186
+ anonymous_active_record_base.remove_connection if anonymous_active_record_base
187
+ end
188
+ end
189
+
190
+ def check
191
+ check_ok = false
192
+ self.class.connect_with(config) do |connection|
193
+ check_ok = true if connection.table_exists?('tm_topic_map') || connection.table_exists?('TM_TOPIC_MAP') # MySQL needs ALLCAPS, but e.g. H2 needs small letters. Dunno why.
194
+ end
195
+ check_ok
196
+ end
197
+ end
198
+ end
199
+
200
+
201
+ Java::OrgTmapiCore::TopicMap.register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::TopicMapImpl
202
+
203
+ module Java::OrgTmapiCore::Topic
204
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::TopicImpl
205
+ end
206
+
207
+ module Java::OrgTmapiCore::Association
208
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::AssociationImpl
209
+ end
210
+
211
+ module Java::OrgTmapiCore::Name
212
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::NameImpl
213
+ end
214
+
215
+ module Java::OrgTmapiCore::Occurrence
216
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::OccurrenceImpl
217
+ end
218
+
219
+ module Java::OrgTmapiCore::Variant
220
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::VariantImpl
221
+ end
222
+
223
+ module Java::OrgTmapiCore::Role
224
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::RoleImpl
225
+ end
226
+
227
+ module Java::OrgTmapiCore::Scoped
228
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::ScopedImpl
229
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::AssociationImpl
230
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::NameImpl
231
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::OccurrenceImpl
232
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::VariantImpl
233
+ end
234
+
235
+ module Java::OrgTmapiCore::Typed
236
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::AssociationImpl
237
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::NameImpl
238
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::OccurrenceImpl
239
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::RoleImpl
240
+ end
241
+
242
+ module Java::OrgTmapiCore::Construct
243
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::ConstructImpl
244
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::TopicMapImpl
245
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::TopicImpl
246
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::AssociationImpl
247
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::NameImpl
248
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::OccurrenceImpl
249
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::VariantImpl
250
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::RoleImpl
251
+ end
252
+
253
+ module Java::OrgTmapiCore::Reifiable
254
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::ReifiableImpl
255
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::TopicMapImpl
256
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::AssociationImpl
257
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::NameImpl
258
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::OccurrenceImpl
259
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::VariantImpl
260
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::RoleImpl
261
+ end
262
+
263
+ module Java::OrgTmapiCore::Locator
264
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::LocatorImpl
265
+ end
266
+
267
+ module Java::OrgTmapiCore::DatatypeAware
268
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::DatatypeAwareImpl
269
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::VariantImpl
270
+ register_java_implementation Java::NetOntopiaTopicmapsImplTmapi2::OccurrenceImpl
271
+ end