Project

General

Profile

CDM Library » History » Version 94

Andreas Müller, 11/30/2008 11:17 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 69 Markus Döring
16 70 Markus Döring
## Implementation
17 69 Markus Döring
18 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:
19 1 Markus Döring
20 74 Markus Döring
* MavenSite:cdmlib-commons
21 1 Markus Döring
22 74 Markus Döring
* MavenSite:cdmlib-model
23 1 Markus Döring
24 74 Markus Döring
* MavenSite:cdmlib-persistence
25 69 Markus Döring
26 94 Andreas Müller
* MavenSite:cdmlib-ext
27
28 74 Markus Döring
* MavenSite:cdmlib-services
29 69 Markus Döring
30 74 Markus Döring
* MavenSite:cdmlib-remote
31 69 Markus Döring
32 74 Markus Döring
* MavenSite:cdmlib-io
33 69 Markus Döring
34
35 1 Markus Döring
36 83 Markus Döring
### Current layers
37 1 Markus Döring
38 83 Markus Döring
![](cdmlib-arch2.png)
39
40
41
### Planned layers
42
43
Reuse service layer for all clients (Eclipse editor, CDM Server, CATE webapplication) and create DTOs made of preloaded domain classes instead of seperate classes.
44
45
46
![](cdmlib-arch3.png)
47
48
49
50 1 Markus Döring
### Domain Model - _cdmlib-model_
51 70 Markus Döring
52 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.
53
54 1 Markus Döring
55 70 Markus Döring
56 1 Markus Döring
#### Property change support
57 65 Markus Döring
58 83 Markus Döring
We have implemented java.bean propertyChangeSupport methods for the entire cdm domain classes to send change events to registered listeners. 
59 1 Markus Döring
60 70 Markus Döring
The [[TaxonomicEditor]] makes use of these through a data binding framework. See wiki:JavaResources#DataBinding for more.
61 1 Markus Döring
62 65 Markus Döring
63
64 70 Markus Döring
#### XML binding
65 61 Markus Döring
66 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.
67 38 Markus Döring
68 1 Markus Döring
69 31 Markus Döring
70 72 Markus Döring
### Persistence Layer - _cdmlib-persistence_
71 1 Markus Döring
72 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.
73 21 Markus Döring
74 70 Markus Döring
75 1 Markus Döring
76 72 Markus Döring
### API - _cdmlib-services_
77 70 Markus Döring
78 72 Markus Döring
Work in progress. see "CdmLibrary#Servicelayer" or wiki:CdmAPI for now.
79 21 Markus Döring
80 1 Markus Döring
81
82 72 Markus Döring
### CDM Server - _cdmlib-remote_
83 1 Markus Döring
84 72 Markus Döring
That is the CdmServer community store.
85
86
87
88
### Import/Export - _cdmlib-io_
89
90
Supported import formats:
91
92
* [[BerlinModel]] database
93
94 94 Andreas Müller
* TCS
95
96
* ABCD
97
98
* SDD
99
100
* EDIT XML
101
102 72 Markus Döring
Planned:
103 1 Markus Döring
104 94 Andreas Müller
* DarwinCOre
105 1 Markus Döring
106
* TaxonX
107
108 84 Andreas Müller
For more information about data conversion see [[SampleDataConversion]]
109
110 82 Markus Döring
111
112
## Releases
113
114
Releases are currently in 2 flavours:
115
116
117 1 Markus Döring
118 82 Markus Döring
### Versioning strategy
119 1 Markus Döring
120 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. 
121 1 Markus Döring
122 82 Markus Döring
123 83 Markus Döring
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. 
124 82 Markus Döring
125 83 Markus Döring
   
126 82 Markus Döring
127
### Sourcecode via Subversion
128
129
The Maven project is available from our subversion server. For releases please see:
130
131
_http://dev.e-taxonomy.eu/svn/tags/cdmlib/_
132
133
134
135
136
### Eclipse plugin
137
138
For the cdmlib-service module we host an Eclipse plugin update site which is available here:
139
140
_http://wp5.e-taxonomy.eu/cdmlib/update/_
141
142
143
144
## CDM Library Usage
145
146 75 Markus Döring
147
148 76 Markus Döring
### Maven repository
149 75 Markus Döring
150 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/_
151 76 Markus Döring
152 86 Andreas Müller
To use the cdm service package add the following dependency to you POM (adapt the right version number !!)
153 76 Markus Döring
154
~~~
155
  	 <dependency>
156
  		<groupId>eu.etaxonomy</groupId>
157
  		<artifactId>cdmlib-service</artifactId>
158 86 Andreas Müller
  		<version>1.X</version>
159 1 Markus Döring
  	</dependency>
160
~~~
161 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 
162
163
~~~
164
   SET MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=512m
165
~~~
166 1 Markus Döring
167 79 Markus Döring
168 1 Markus Döring
### Eclipse setup
169 77 Markus Döring
170 1 Markus Döring
To use the entire cdmlibrary with Eclipse, you need some plugins and to follow this installation guide:
171
172 83 Markus Döring
* 
173 77 Markus Döring
174 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.
175 77 Markus Döring
176 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). 
177
178 79 Markus Döring
  * make sure Java JDK >= 1.5 is installed (JRE is not enough) and JAVA_HOME is set to JDK path
179 1 Markus Döring
180 90 Andreas Müller
  * checkout cdmlib and create eclipse artifacts (using e.g. tortoiseSVN):
181 1 Markus Döring
182 83 Markus Döring
  	<pre>
183 1 Markus Döring
184
$ svn co dev.e-taxonomy.eu/svn/trunk/cdmlib/
185
186
</pre>
187
188 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
189 88 Andreas Müller
190 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. 
191 1 Markus Döring
192 87 Andreas Müller
    * In OSX for example    /Users/USERNAME/.m2/repository 
193 1 Markus Döring
194 87 Andreas Müller
    * In WinXP for example  C:\Documents and Settings\USERNAME\.m2\repository
195 1 Markus Döring
196
  * setup new eclipse workspace (where ever you want but using the cdmlib folder may be comfortable
197 88 Andreas Müller
198 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".
199
200
  * repeat the last step at least for all projects starting with "cdmlib-"
201
202 92 Andreas Müller
  * Install AspectJ Development Tools (AJDT) - Plugin (for eclipse) (Update-Site:http://download.eclipse.org/tools/ajdt/33/dev/update)
203 1 Markus Döring
204 92 Andreas Müller
  * run 
205
206
  <pre>
207
208
$ mvn install
209
210
$ mvn eclipse:eclipse 
211
212
</pre> 
213
214
  in the cdmlib directory
215
216
  * Referesh cdmlib-model project within eclipse 
217 87 Andreas Müller
218 88 Andreas Müller
  * Convert the cdmlib-model to AspectJ (right mouse click on project -> AspectJ Tools -> ...).
219 87 Andreas Müller
220 1 Markus Döring
![]()
221 91 Pepe Ciardelli
222
* 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.
223
224
 	<pre>
225
226
$ mvn install
227
228
$ mvn eclipse:eclipse
229
230
</pre>
231
232 1 Markus Döring
233
234 69 Markus Döring
235 1 Markus Döring
236 79 Markus Döring
### Spring applications with cdmlib
237 1 Markus Döring
238 79 Markus Döring
239
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:
240
241
242 1 Markus Döring
applicationContext.xml
243
244
~~~
245
<?xml version="1.0" encoding="UTF-8"?>
246
<beans xmlns="http://www.springframework.org/schema/beans"
247
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
248
    xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
249
250 79 Markus Döring
	<import resource="classpath:/eu/etaxonomy/cdm/services.xml" />
251
	<import resource="classpath:/eu/etaxonomy/cdm/hsql-datasource.xml" />
252 1 Markus Döring
    
253
</beans>
254
~~~
255
256 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: 
257 1 Markus Döring
258 79 Markus Döring
applicationContext.xml
259 1 Markus Döring
260 34 Markus Döring
~~~
261 79 Markus Döring
<?xml version="1.0" encoding="UTF-8"?>
262
<beans xmlns="http://www.springframework.org/schema/beans"
263
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
264
    xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
265 1 Markus Döring
266 79 Markus Döring
	<import resource="classpath:/eu/etaxonomy/cdm/services.xml" />
267
268 81 Markus Döring
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
269 79 Markus Döring
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
270
        <property name="url" value="jdbc:mysql://192.168.2.10/cdm_build"/>
271 80 Markus Döring
        <property name="username" value="cdm_user"/>
272
        <property name="password" value="why_do_i_need_this"/>
273 79 Markus Döring
    </bean>
274
    
275
    <bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
276
        <property name="properties">
277
            <props>
278
                <prop key="hibernate.hbm2ddl.auto">validate</prop>
279
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
280
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
281
                <prop key="hibernate.show_sql">false</prop>
282
                <prop key="hibernate.format_sql">false</prop>
283
            </props>
284
        </property>
285
    </bean>    
286
</beans>
287 43 Markus Döring
~~~
288 1 Markus Döring
289 42 Markus Döring
290 41 Markus Döring
291 43 Markus Döring
292 41 Markus Döring
----
293 38 Markus Döring
294
295
296 69 Markus Döring
## Background
297 38 Markus Döring
298 39 Markus Döring
299
### Hibernate
300 69 Markus Döring
301 32 Markus Döring
* Hibernate works with most current RDBMS. See  [supported databases](http://www.hibernate.org/80.html) 
302 10 Markus Döring
303 69 Markus Döring
304 6 Markus Döring
305 69 Markus Döring
### Spring 2.0 Framework
306 6 Markus Döring
307 50 Andreas Müller
We use the Spring 2.0 framework to develop the library and keep the coupling of components low.
308
309 69 Markus Döring
*  [Spring2.0 Documentation](http://static.springframework.org/spring/docs/2.0.x/reference/index.html) 
310 50 Andreas Müller
311 69 Markus Döring
*  [Introduction to the Spring Framework](http://www.theserverside.com/tt/articles/content/SpringFramework/article.html) 
312 50 Andreas Müller
313 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) 
314 50 Andreas Müller
315 69 Markus Döring
316 50 Andreas Müller
317 1 Markus Döring
### Domain Models
318
319
* [Domain Models and Validation. An Architectural Discussion](http://forum.springframework.org/showthread.php?t=18699)
320
321
* [Avoiding anemic domain models with Hibernate](http://www.theserverside.com/patterns/thread.tss?thread_id=31010)
322
323
* [Business Object Pattern](http://www.corej2eepatterns.com/Patterns2ndEd/BusinessObject.htm)
324 69 Markus Döring
325 50 Andreas Müller
*  [AnemicDomainModel Anti Pattern](http://www.martinfowler.com/bliki/AnemicDomainModel.html) 
326
327 78 Markus Döring
328
329
#### Property Change
330
331
* http://www.onjava.com/pub/a/onjava/2004/06/02/desktop.html
332
333
* http://www.javalobby.org/java/forums/t19476.html
334 35 Andreas Müller
335
336
337 69 Markus Döring
### Useful Patterns
338 35 Andreas Müller
339 69 Markus Döring
* [ApplicationService Pattern](http://www.corej2eepatterns.com/Patterns2ndEd/ApplicationService.htm)
340 35 Andreas Müller
341
342
343
344 69 Markus Döring
### Aspect Oriented Programming
345 35 Andreas Müller
346 69 Markus Döring
We use AspectJ to implement the change property crosscutting concern:
347 35 Andreas Müller
348 69 Markus Döring
* AspectJ
349 35 Andreas Müller
350 69 Markus Döring
  * http://today.java.net/pub/a/today/2005/12/15/writing-mixins-with-aop.html
351 45 Markus Döring
352 69 Markus Döring
* JBoss AOP
353 45 Markus Döring
354 69 Markus Döring
  * http://www.damnhandy.com/javabean-aspect/
355
356
* Spring AOP
357
358
  * http://forum.springframework.org/archive/index.php/t-13293.html
359
360
  * http://forum.springframework.com/viewtopic.php?t=301