Wiki source code of TopicMap Engine

Last modified by christoph_lechleitner@iteg_at on 2013-02-02 07.31:25

Show last authors
1 //**TM2JDBC** is a implementation of the TopicMaps API ([[TMAPI 2.0.2>>url:http://www.tmapi.org/2.0/||shape="rect"]]). It is a fast, production-grade Topic Maps Engine with a small dependency footprint. TM2JDBC uses a relational database to store its data, and is verified to operate with Apache Derby, MySQL, MSSQL Server and Oracle databases.//
2
3 TM2JDBC is released in version 1.0.1. This release features some dependency updates and minor corrections of inconsistencies within the code, but is fully compatible to version 0.9.0.
4
5 * Updated TMAPI dependency to version 2.0.2 (the prior version already was compliant with TMAPI 2.0.2, but still referenced a snapshot as the final library was not released)
6 * OSGi support – The library now comes packaged as an OSGi-bundle, which allows it to be deployed to your OSGi container of choice. This has no side-effencts on non-OSGi projects
7 * Updated clazzes.org-dependencies to the current version
8
9 If you are using maven, you can use the new version by adding the following snippets to your {{code language="none"}}pom.xml{{/code}} file:
10
11 (((
12
13
14 {{code language="none"}}
15 <dependency>
16 <groupId>org.clazzes</groupId>
17 <artifactId>tm2jdbc</artifactId>
18 <version>1.0.1</version>
19 </dependency>
20
21  
22 ...
23  
24 <repository>
25 <id>org.clazzes</id>
26 <name>Clazzes.org repository.</name>
27 <url>http://maven.clazzes.org</url>
28 </repository>
29 {{/code}}
30
31
32 )))
33
34 If you do not use maven, you can download the .jar files manually from our repository at [[http:~~/~~/maven.clazzes.org/org/clazzes/tm2jdbc>>url:http://maven.clazzes.org/org/clazzes/tm2jdbc||shape="rect"]].
35 Alternatively, you can check out the sources directly from our SVN Repository:
36
37 {{code language="none"}}
38 http://svn.clazzes.org/svn/topicmaps/trunk/tm2jdbc/
39
40 {{/code}}
41
42 = {{id name="TopicMapEngineHome-SetupandUsageNotes"/}}Setup and Usage Notes =
43
44 TM2JDBC needs a relational database and the appropriate JDBC 4.0 compatible driver to function. However it does not have any direct dependencies to a specific JDBC connector. Instead, it expects a {{code language="none"}}javax.sql.DataSource{{/code}} to be set as a property (see below), which it will use to obtain database connections. Although the engine should function with any DataSource implementation, we strongly recommend to use the [[Apache Commons DBCP>>url:http://commons.apache.org/dbcp/||shape="rect"]] library. A rudimentary set-up for a {{code language="none"}}BasicDataSource{{/code}} can be found in the class {{code language="none"}}org.clazzes.tm2jdbc.util.test.DataSourceProvider{{/code}}.
45
46 === {{id name="TopicMapEngineHome-ProvidingaDataSource"/}}Providing a DataSource ===
47
48 To handle database connectivity, the TM2JDBC engine relies on a{{code language="none"}}javax.sql.DataSource{{/code}} to be set for the property ##(% class="nolink" %)http:~/~/psi.clazzes.org/topicmaps/db-connection/datatsource(%%)## in the Factory (attempting to call {{code language="none"}}newTopicMapSystem(){{/code}} without the property being set causes an{{code language="none"}}IllegalStateException{{/code}} to be thrown. The property string can also be accessed directly via the Enum object{{code language="none"}}org.clazzes.tm2jdbc.voc.PropertyKey.CONNECTION_DATASOURCE{{/code}}. The most basic setup could look like this:
49
50 (((
51
52
53 {{code language="java"}}
54 BasicDataSource datasource = new BasicDataSource();
55 datasource.setDefaultAutoCommit(false);
56
57 datasource.setInitialSize(4);
58 datasource.setMinIdle(1);
59 datasource.setMaxIdle(8);
60 datasource.setMaxActive(8);
61 datasource.setMaxWait(3000);
62
63 datasource.setDriverClassName(driver);
64
65 datasource.setPassword(password);
66 datasource.setUsername(user);
67 datasource.setUrl(url);
68
69 TopicMapSystemFactory factory = TopicMapSystemFactory.newInstance();
70 factory.setProperty(PropertyKey.CONNECTION_DATASOURCE.getURI(), dsProvider.getDataSource());
71
72 TopicMapSystem system = factory.newTopicMapSystem();
73 {{/code}}
74
75
76 )))
77
78 === {{id name="TopicMapEngineHome-RunningtheDBSetupUtilityincommandline"/}}Running the DBSetup Utility in commandline ===
79
80 The engine provides a setup-utility to create the tables it needs in a provided database schema. This utility can either be run as a standalone java executable (in the command line, via a shell script etc.) or instanciated as a Java Object by your own code (see below). The class name is {{code language="none"}}org.clazzes.tm2jdbc.jdbc.setup.DBSetup{{/code}}. For testing and development, it may be useful to run the setup utility in commandline or the development evironment of your choice. The standard use-case is to set up the database schema, but you can also use it to drop all tables in the schema.
81 Making sure that the appropriate database drivers are added to the classpath, the accepts arguments like this:
82
83 (((
84
85
86 {{code language="none"}}
87 DBSetup {derby|mssql|mysql|oracle} {{ [-h <HOSTNAME>] [-t <PORT>] [-n <SCHEMA NAME>] } | {--url <DATABASE-URL>}} -u <USER> -p <PASSWORD> [-d <DRIVER-CLASSNAME> ] [--debug] [--drop|--force-drop] [--nosetup]
88 {{/code}}
89
90
91 )))
92
93 Below is a listing of all argument flags and the default values:
94
95 |=(((
96 Flag
97 )))|=(((
98 Default Value
99 )))|=(((
100 Description
101 )))
102 |(((
103 {{code language="none"}}
104 -h
105 {{/code}}
106 )))|(((
107 127.0.0.1
108 )))|(((
109 The hostname/address of your database server. **Caution: When using Oracle database systems, the hostname is interpreted as a TNS name, which is resolved to an IP locally. Alternatively, you may also specify a string like{{code language="none"}}<IP-HOST>/<SID>{{/code}}**
110 )))
111 |(((
112 {{code language="none"}}
113 -t
114 {{/code}}
115 )))|(((
116 //default port//
117 )))|(((
118 If omitted, the default port for the specified database server is used
119 )))
120 |(((
121 {{code language="none"}}
122 -n
123 {{/code}}
124 )))|(((
125 topicmaps
126 )))|(((
127
128 )))
129 |(((
130 {{code language="none"}}
131 --url
132 {{/code}}
133 )))|(((
134 //none//
135 )))|(((
136 Alternatively to entering the hostname, port and schema name, you can supply the jdbc url directly.
137 )))
138 |(((
139 {{code language="none"}}
140 -u
141 {{/code}}
142 )))|(((
143 //none//
144 )))|(((
145 You must enter a username and password
146 )))
147 |(((
148 {{code language="none"}}
149 -p
150 {{/code}}
151 )))|(((
152 //none//
153 )))|(((
154
155 )))
156 |(((
157 {{code language="none"}}
158 -d
159 {{/code}}
160 )))|(((
161 //default driver class//
162 )))|(((
163 If you want to use a different driver class than the default, you can specify the fully qualified classname using this flag. Make sure that the class is added to the classpath.
164 )))
165 |(((
166 {{code language="none"}}
167 --debug
168 {{/code}}
169 )))|(((
170 //false//
171 )))|(((
172 Produces a verbose output
173 )))
174 |(((
175 {{code language="none"}}
176 --drop
177 {{/code}}
178 )))|(((
179 //false//
180 )))|(((
181 Drops all tables in the schema, causes the utility to fail on errors
182 )))
183 |(((
184 {{code language="none"}}
185 --force-drop
186 {{/code}}
187 )))|(((
188 //false//
189 )))|(((
190 Drops all tables in the schema, ignoring any errors (Use to clean the schema if it was corrupted or not created completely)
191 )))
192 |(((
193 {{code language="none"}}
194 --nosetup
195 {{/code}}
196 )))|(((
197 //false//
198 )))|(((
199 Skip setting up the schema.
200 )))
201
202 === {{id name="TopicMapEngineHome-RunningtheDBSetupUtilityinJava"/}}Running the DBSetup Utility in Java ===
203
204 The database setup-utility also can be run in java. For this case it provides a constructor which takes a {{code language="none"}}javax.sql.DataSource{{/code}}, and provides the methods {{code language="none"}}setUpDB(boolean debug){{/code}} and {{code language="none"}}dropAllTables(boolean supressErrors){{/code}}. It is recommended to use these instead of running the {{code language="none"}}main(String[] args){{/code}} method with the appropriate arguments.
205
206 === {{id name="TopicMapEngineHome-JUnittesting"/}}JUnit testing ===
207
208 TMAPI provides an extensive suite of Testcases to assure compliancy, which is also included in the TM2JDBC package. As the original tests were not conceived for engines which are based on an RDBMS, the {{code language="none"}}setUp(){{/code}} and {{code language="none"}}tearDown(){{/code}} methods where modified to initialize and drop the database schema between every test. You are welcome to subject the engine to additional tests (we would especially appreciate you to share the results with us), and for this purpose TM2JDBC provides the utility class{{code language="none"}}org.clazzes.tm2jdbc.util.test.DataSourceProvider{{/code}} (depends on Apache commons DBCP).
209 It is recommended to use this utility in all test cases as follows:
210
211 (((
212
213
214 {{code language="java"}}
215 protected DataSourceProvider dsProvider;
216
217 protected void setUp() throws Exception {
218 super.setUp();
219 if (dsProvider == null) {
220 dsProvider = DataSourceProvider.getProvider();
221 dsProvider.setUpDB();
222
223 //set up factory etc. here ...
224 factory.setProperty(PropertyKey.CONNECTION_DATASOURCE.getURI(), dsProvider.getDataSource());
225 //...
226 }
227 }
228
229 protected void tearDown() throws Exception {
230 dsProvider.dropDB();
231 }
232 {{/code}}
233
234 = {{id name="TopicMapEngineHome-Sourcecodeandissuetracker"/}}Source code and issue tracker =
235
236 Subversion: [[http:~~/~~/svn.clazzes.org/svn/topicmaps>>url:http://svn.clazzes.org/svn/topicmaps||shape="rect"]]
237
238 Jira: [[TME>>url:https://jira.clazzes.org/browse/TME||shape="rect"]]
239 )))