Project

General

Profile

CDM Library » History » Version 98

Andreas Müller, 12/09/2008 09:15 PM

1 1 Markus Döring
2
# CDM Java Library
3
4
5
{{>toc}}
6
7
8
9 22 Markus Döring
The CDM Library is meant to be a shared library for the between several applications which can be of any kind, i.e. J2EE having an application container, simple command line tools or swing desktop applications.
10 1 Markus Döring
11 82 Markus Döring
The library defines a persistent domain model, EDITs [[CommonDataModel]], that can be serialised and read in XML. Business logic shared between applications should be part of this library as much as possible, while application specific logic has to stay out. We are developing this library in collaboration with the [CATE](http://www.cate-project.org/) project initially, but we seeking development collaboration with other projects like Key2Nature and PESI as well.
12 10 Markus Döring
13
14 65 Markus Döring
15 95 Andreas Müller
## Download
16
17
18
The latest version is available at the [[CdmLibraryDownload|CDM Library Download site]]
19
20
21
22 69 Markus Döring
23 70 Markus Döring
## Implementation
24 69 Markus Döring
25 74 Markus Döring
We use Wikipedia:Apache_Maven 2 for this project. The CDM library itself is devided into several maven subprojects, providing the following seperation of concerns:
26 1 Markus Döring
27 74 Markus Döring
* MavenSite:cdmlib-commons
28 1 Markus Döring
29 74 Markus Döring
* MavenSite:cdmlib-model
30 1 Markus Döring
31 74 Markus Döring
* MavenSite:cdmlib-persistence
32 69 Markus Döring
33 94 Andreas Müller
* MavenSite:cdmlib-ext
34
35 74 Markus Döring
* MavenSite:cdmlib-services
36 69 Markus Döring
37 74 Markus Döring
* MavenSite:cdmlib-remote
38 69 Markus Döring
39 74 Markus Döring
* MavenSite:cdmlib-io
40 69 Markus Döring
41
42 1 Markus Döring
43 83 Markus Döring
### Current layers
44 1 Markus Döring
45 83 Markus Döring
![](cdmlib-arch2.png)
46
47
48
### Planned layers
49
50
Reuse service layer for all clients (Eclipse editor, CDM Server, CATE webapplication) and create DTOs made of preloaded domain classes instead of seperate classes.
51
52
53
![](cdmlib-arch3.png)
54
55
56
57 1 Markus Döring
### Domain Model - _cdmlib-model_
58 70 Markus Döring
59 69 Markus Döring
Domain objects (also called business objects sometimes) are directly taken as POJOs from the [[CommonDataModel]]. The logic inherent to the domain objects are restricted to their own object graph, i.e. their own properties and related objects. But not unrelated objects available through DAOs only. Typical logic includes validation and calculations.
60
61 1 Markus Döring
62 70 Markus Döring
63 1 Markus Döring
#### Property change support
64 65 Markus Döring
65 83 Markus Döring
We have implemented java.bean propertyChangeSupport methods for the entire cdm domain classes to send change events to registered listeners. 
66 1 Markus Döring
67 70 Markus Döring
The [[TaxonomicEditor]] makes use of these through a data binding framework. See wiki:JavaResources#DataBinding for more.
68 1 Markus Döring
69 65 Markus Döring
70
71 70 Markus Döring
#### XML binding
72 61 Markus Döring
73 85 Anahit Babadshanjan
For data exchange purposes, we want to serialize/deserialize the domain objects of the cdmlib-model to/from XML format using the [JAXB](https://jaxb.dev.java.net/) framework.
74 38 Markus Döring
75 1 Markus Döring
76 31 Markus Döring
77 72 Markus Döring
### Persistence Layer - _cdmlib-persistence_
78 1 Markus Döring
79 70 Markus Döring
we use Hibernate for persistence. We run unit and integration tests for [[MySQL]], Hypersonic, Postgres and MS SQL Server on a regular basis.
80 21 Markus Döring
81 70 Markus Döring
82 1 Markus Döring
83 72 Markus Döring
### API - _cdmlib-services_
84 70 Markus Döring
85 72 Markus Döring
Work in progress. see "CdmLibrary#Servicelayer" or wiki:CdmAPI for now.
86 21 Markus Döring
87 1 Markus Döring
88
89 72 Markus Döring
### CDM Server - _cdmlib-remote_
90 1 Markus Döring
91 72 Markus Döring
That is the CdmServer community store.
92
93
94
95
### Import/Export - _cdmlib-io_
96
97
Supported import formats:
98
99
* [[BerlinModel]] database
100
101 94 Andreas Müller
* TCS
102
103
* ABCD
104
105
* SDD
106
107
* EDIT XML
108
109 72 Markus Döring
Planned:
110 1 Markus Döring
111 94 Andreas Müller
* DarwinCOre
112 1 Markus Döring
113
* TaxonX
114
115 84 Andreas Müller
For more information about data conversion see [[SampleDataConversion]]
116
117 82 Markus Döring
118
119
## Releases
120
121
Releases are currently in 2 flavours:
122
123
124 1 Markus Döring
125 82 Markus Döring
### Versioning strategy
126 1 Markus Döring
127 83 Markus Döring
Starting with the frozen [[CommonDataModel]] v1 we release minor upgrades for every model change in the library. Inferior version numbers (3rd level) are for bug-fixes and library extensions, which do not change the core model classes. This guarantees that all bug-fix releases are still working on the same database structure. 
128 1 Markus Döring
129 82 Markus Döring
130 98 Andreas Müller
For example: Svn:tags/cdmlib/rel_1.1.0 and rel_1.1.8 will work both on the same database structure as generated by hibernate. But for rel_1.2.0 you will have to update or better recreate your database, currently still losing all your data. In a later stage we will provide stable import/export formats to migrate your data to new versions.
131
132
133
134
### Change Log
135
136
All substantial changes to the library should be documented. This applies very strictly to all <B>model changes</B>. For them a separate changelog site has been setup at [[CdmChanges]].<BR>
137
138
All other changes should be documented at [[CdmLibraryChanges]].
139
140
Beside the model changes the highest priority for documentation have changes to signatures of visible methods and changes to semantics of existing methods.
141
142
If you just add some new functionality we highly appreciate it's documentation but documentation should not run into a unproductive overhead.
143
144 82 Markus Döring
145 83 Markus Döring
   
146 82 Markus Döring
147
### Sourcecode via Subversion
148
149
The Maven project is available from our subversion server. For releases please see:
150
151
_http://dev.e-taxonomy.eu/svn/tags/cdmlib/_
152
153
154
155
156
### Eclipse plugin
157
158
For the cdmlib-service module we host an Eclipse plugin update site which is available here:
159
160
_http://wp5.e-taxonomy.eu/cdmlib/update/_
161
162
163
164
## CDM Library Usage
165
166 75 Markus Döring
167
168 76 Markus Döring
### Maven repository
169 75 Markus Döring
170 1 Markus Döring
To integrate the cdmlibray into your personal Maven project pelase add our Maven repository to your POM: _http://wp5.e-taxonomy.eu/cdmlib/mavenrepo/_
171 76 Markus Döring
172 86 Andreas Müller
To use the cdm service package add the following dependency to you POM (adapt the right version number !!)
173 76 Markus Döring
174
~~~
175
  	 <dependency>
176
  		<groupId>eu.etaxonomy</groupId>
177
  		<artifactId>cdmlib-service</artifactId>
178 86 Andreas Müller
  		<version>1.X</version>
179 1 Markus Döring
  	</dependency>
180
~~~
181 93 Andreas Müller
To create a project site use mvn site:site. Due to the number of depencies you will have to increase the available memory by setting the MAVEN_OPTS parameter to 
182
183
~~~
184
   SET MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=512m
185
~~~
186 1 Markus Döring
187 97 Andreas Kohlbecker
In order to install a file (e.g. a JAR) in you local repositry:
188
189
~~~
190
mvn install:install-file
191
      -DgroupId=<group-id>
192
      -DartifactId=<artifact-id>
193
      -Dversion=<version>
194
      -Dfile=<path-to-file>
195
      -Dpackaging=<packaging> (i.e. jar)
196
      -DgeneratePom=true
197
~~~
198
Also see: [How do I install a file in my local repository along with a generic POM](http://docs.codehaus.org/display/MAVENUSER/FAQs-1#FAQs-1-HowdoIinstallafileinmylocalrepositoryalongwithagenericPOM)
199 96 Andreas Kohlbecker
200 79 Markus Döring
201 1 Markus Döring
### Eclipse setup
202 77 Markus Döring
203 1 Markus Döring
To use the entire cdmlibrary with Eclipse, you need some plugins and to follow this installation guide:
204
205 83 Markus Döring
* 
206 77 Markus Döring
207 87 Andreas Müller
  * install maven 2.0.x commandline tools locally (http://maven.apache.org/download.html). Follow the instruction to install maven on your local machine.
208 77 Markus Döring
209 90 Andreas Müller
  * install subclipse 1.4.x in eclipse if not yet installed (Update Site: http://subclipse.tigris.org/update_1.4.x). 
210
211 79 Markus Döring
  * make sure Java JDK >= 1.5 is installed (JRE is not enough) and JAVA_HOME is set to JDK path
212 1 Markus Döring
213 90 Andreas Müller
  * checkout cdmlib and create eclipse artifacts (using e.g. tortoiseSVN):
214 1 Markus Döring
215 83 Markus Döring
  	<pre>
216 1 Markus Döring
217
$ svn co dev.e-taxonomy.eu/svn/trunk/cdmlib/
218
219
</pre>
220
221 92 Andreas Müller
  * make sure maven has run at least one time (to create the .m2 folder). If unsure how to do this, run `mvn install` in the new checked out folder ../cdmlib/cmlib-commons
222 88 Andreas Müller
223 92 Andreas Müller
  * Set in Eclipse preferences (not project properties) M2_REPO java class variable (menue: java-buildPath-Classpath), pointing to your local repository. 
224 1 Markus Döring
225 87 Andreas Müller
    * In OSX for example    /Users/USERNAME/.m2/repository 
226 1 Markus Döring
227 87 Andreas Müller
    * In WinXP for example  C:\Documents and Settings\USERNAME\.m2\repository
228 1 Markus Döring
229
  * setup new eclipse workspace (where ever you want but using the cdmlib folder may be comfortable
230 88 Andreas Müller
231 1 Markus Döring
  * create new Java project within the new workspace. Check "Create project from existing source" in the dialog. Choose ../cdmlib/cdmlib-commons as the source directory. Use project name "cdmlib-commons".
232
233
  * repeat the last step at least for all projects starting with "cdmlib-"
234
235 92 Andreas Müller
  * Install AspectJ Development Tools (AJDT) - Plugin (for eclipse) (Update-Site:http://download.eclipse.org/tools/ajdt/33/dev/update)
236 1 Markus Döring
237 92 Andreas Müller
  * run 
238
239
  <pre>
240
241
$ mvn install
242
243
$ mvn eclipse:eclipse 
244
245
</pre> 
246
247
  in the cdmlib directory
248
249
  * Referesh cdmlib-model project within eclipse 
250 87 Andreas Müller
251 88 Andreas Müller
  * Convert the cdmlib-model to AspectJ (right mouse click on project -> AspectJ Tools -> ...).
252 87 Andreas Müller
253 1 Markus Döring
![]()
254 91 Pepe Ciardelli
255
* It wasn't clear to me (PC) from the above that at some point, the following must be executed in the "cdmlib" directory. I did this _after_ all the above steps were completed, and the build was successful.
256
257
 	<pre>
258
259
$ mvn install
260
261
$ mvn eclipse:eclipse
262
263
</pre>
264
265 1 Markus Döring
266
267 69 Markus Döring
268 1 Markus Döring
269 79 Markus Döring
### Spring applications with cdmlib
270 1 Markus Döring
271 79 Markus Döring
272
In your own applicationContext.xml you can simply import the cdm service spring beans from the library. In addition it also needs a datasource bean and a hibernateProperties bean specific for that datasource. The CDM Library comes with an embedded hypersonic database that is super easy to use. All you need to do is to import that hsql specific spring configuration like this:
273
274
275 1 Markus Döring
applicationContext.xml
276
277
~~~
278
<?xml version="1.0" encoding="UTF-8"?>
279
<beans xmlns="http://www.springframework.org/schema/beans"
280
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
281
    xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
282
283 79 Markus Döring
	<import resource="classpath:/eu/etaxonomy/cdm/services.xml" />
284
	<import resource="classpath:/eu/etaxonomy/cdm/hsql-datasource.xml" />
285 1 Markus Döring
    
286
</beans>
287
~~~
288
289 83 Markus Döring
In case you want to define the datasource within your own applicationContext you can surely do so. For a typical mysql database it looks like this: 
290 1 Markus Döring
291 79 Markus Döring
applicationContext.xml
292 1 Markus Döring
293 34 Markus Döring
~~~
294 79 Markus Döring
<?xml version="1.0" encoding="UTF-8"?>
295
<beans xmlns="http://www.springframework.org/schema/beans"
296
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
297
    xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
298 1 Markus Döring
299 79 Markus Döring
	<import resource="classpath:/eu/etaxonomy/cdm/services.xml" />
300
301 81 Markus Döring
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
302 79 Markus Döring
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
303
        <property name="url" value="jdbc:mysql://192.168.2.10/cdm_build"/>
304 80 Markus Döring
        <property name="username" value="cdm_user"/>
305
        <property name="password" value="why_do_i_need_this"/>
306 79 Markus Döring
    </bean>
307
    
308
    <bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
309
        <property name="properties">
310
            <props>
311
                <prop key="hibernate.hbm2ddl.auto">validate</prop>
312
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
313
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
314
                <prop key="hibernate.show_sql">false</prop>
315
                <prop key="hibernate.format_sql">false</prop>
316
            </props>
317
        </property>
318
    </bean>    
319
</beans>
320 43 Markus Döring
~~~
321 1 Markus Döring
322 42 Markus Döring
323 41 Markus Döring
324 43 Markus Döring
325 41 Markus Döring
----
326 38 Markus Döring
327
328
329 69 Markus Döring
## Background
330 38 Markus Döring
331 39 Markus Döring
332
### Hibernate
333 69 Markus Döring
334 32 Markus Döring
* Hibernate works with most current RDBMS. See  [supported databases](http://www.hibernate.org/80.html) 
335 10 Markus Döring
336 69 Markus Döring
337 6 Markus Döring
338 69 Markus Döring
### Spring 2.0 Framework
339 6 Markus Döring
340 50 Andreas Müller
We use the Spring 2.0 framework to develop the library and keep the coupling of components low.
341
342 69 Markus Döring
*  [Spring2.0 Documentation](http://static.springframework.org/spring/docs/2.0.x/reference/index.html) 
343 50 Andreas Müller
344 69 Markus Döring
*  [Introduction to the Spring Framework](http://www.theserverside.com/tt/articles/content/SpringFramework/article.html) 
345 50 Andreas Müller
346 69 Markus Döring
*  [Die Rückkehr der POJOs. Das Spring-Framework: leichtgewichtiges Komponentenmodell als Alternative zu EJB](http://javamagazin.de/itr/online_artikel/psecom,id,608,nodeid,11.html) 
347 50 Andreas Müller
348 69 Markus Döring
349 50 Andreas Müller
350 1 Markus Döring
### Domain Models
351
352
* [Domain Models and Validation. An Architectural Discussion](http://forum.springframework.org/showthread.php?t=18699)
353
354
* [Avoiding anemic domain models with Hibernate](http://www.theserverside.com/patterns/thread.tss?thread_id=31010)
355
356
* [Business Object Pattern](http://www.corej2eepatterns.com/Patterns2ndEd/BusinessObject.htm)
357 69 Markus Döring
358 50 Andreas Müller
*  [AnemicDomainModel Anti Pattern](http://www.martinfowler.com/bliki/AnemicDomainModel.html) 
359
360 78 Markus Döring
361
362
#### Property Change
363
364
* http://www.onjava.com/pub/a/onjava/2004/06/02/desktop.html
365
366
* http://www.javalobby.org/java/forums/t19476.html
367 35 Andreas Müller
368
369
370 69 Markus Döring
### Useful Patterns
371 35 Andreas Müller
372 69 Markus Döring
* [ApplicationService Pattern](http://www.corej2eepatterns.com/Patterns2ndEd/ApplicationService.htm)
373 35 Andreas Müller
374
375
376
377 69 Markus Döring
### Aspect Oriented Programming
378 35 Andreas Müller
379 69 Markus Döring
We use AspectJ to implement the change property crosscutting concern:
380 35 Andreas Müller
381 69 Markus Döring
* AspectJ
382 35 Andreas Müller
383 69 Markus Döring
  * http://today.java.net/pub/a/today/2005/12/15/writing-mixins-with-aop.html
384 45 Markus Döring
385 69 Markus Döring
* JBoss AOP
386 45 Markus Döring
387 69 Markus Döring
  * http://www.damnhandy.com/javabean-aspect/
388
389
* Spring AOP
390
391
  * http://forum.springframework.org/archive/index.php/t-13293.html
392
393
  * http://forum.springframework.com/viewtopic.php?t=301