Project

General

Profile

CDM Library » History » Version 93

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