Project

General

Profile

CDM Library » History » Version 90

Andreas Müller, 08/05/2008 03:31 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
152 79 Markus Döring
153 1 Markus Döring
### Eclipse setup
154 77 Markus Döring
155 1 Markus Döring
To use the entire cdmlibrary with Eclipse, you need some plugins and to follow this installation guide:
156
157 83 Markus Döring
* 
158 77 Markus Döring
159 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.
160 77 Markus Döring
161 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). 
162
163 79 Markus Döring
  * make sure Java JDK >= 1.5 is installed (JRE is not enough) and JAVA_HOME is set to JDK path
164 1 Markus Döring
165 90 Andreas Müller
  * checkout cdmlib and create eclipse artifacts (using e.g. tortoiseSVN):
166 1 Markus Döring
167 83 Markus Döring
  	<pre>
168 1 Markus Döring
169
$ svn co dev.e-taxonomy.eu/svn/trunk/cdmlib/
170
171
$ cd cdmlib
172 77 Markus Döring
173 1 Markus Döring
$ mvn eclipse:eclipse
174
175
</pre>
176
177 88 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
178
179 87 Andreas Müller
  * Set in Eclipse preferences (not project) M2_REPO java class variable, pointing to your local repository. 
180 1 Markus Döring
181 87 Andreas Müller
    * In OSX for example    /Users/USERNAME/.m2/repository 
182 1 Markus Döring
183 87 Andreas Müller
    * In WinXP for example  C:\Documents and Settings\USERNAME\.m2\repository
184 1 Markus Döring
185 88 Andreas Müller
  * setup new eclipse workspace (where ever you want but using the cdmlib folder may be comfortable
186 1 Markus Döring
187 89 Andreas Müller
  * 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".
188 87 Andreas Müller
189 88 Andreas Müller
  * repeat the last step at least for all projects starting with "cdmlib-"
190 87 Andreas Müller
191 88 Andreas Müller
  * Install AspectJ Development Tools (AJDT) - Plugin (for eclipse)
192 87 Andreas Müller
193 88 Andreas Müller
  (Update-Site:http://download.eclipse.org/tools/ajdt/33/update)
194 87 Andreas Müller
195 88 Andreas Müller
  * Convert the cdmlib-model to AspectJ (right mouse click on project -> AspectJ Tools -> ...).
196 87 Andreas Müller
197 88 Andreas Müller
![]()
198 1 Markus Döring
199
200 69 Markus Döring
201 1 Markus Döring
202 79 Markus Döring
### Spring applications with cdmlib
203 1 Markus Döring
204 79 Markus Döring
205
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:
206
207
208 1 Markus Döring
applicationContext.xml
209
210
~~~
211
<?xml version="1.0" encoding="UTF-8"?>
212
<beans xmlns="http://www.springframework.org/schema/beans"
213
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
214
    xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
215
216 79 Markus Döring
	<import resource="classpath:/eu/etaxonomy/cdm/services.xml" />
217
	<import resource="classpath:/eu/etaxonomy/cdm/hsql-datasource.xml" />
218 1 Markus Döring
    
219
</beans>
220
~~~
221
222 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: 
223 1 Markus Döring
224 79 Markus Döring
applicationContext.xml
225 1 Markus Döring
226 34 Markus Döring
~~~
227 79 Markus Döring
<?xml version="1.0" encoding="UTF-8"?>
228
<beans xmlns="http://www.springframework.org/schema/beans"
229
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
230
    xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
231 1 Markus Döring
232 79 Markus Döring
	<import resource="classpath:/eu/etaxonomy/cdm/services.xml" />
233
234 81 Markus Döring
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
235 79 Markus Döring
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
236
        <property name="url" value="jdbc:mysql://192.168.2.10/cdm_build"/>
237 80 Markus Döring
        <property name="username" value="cdm_user"/>
238
        <property name="password" value="why_do_i_need_this"/>
239 79 Markus Döring
    </bean>
240
    
241
    <bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
242
        <property name="properties">
243
            <props>
244
                <prop key="hibernate.hbm2ddl.auto">validate</prop>
245
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
246
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
247
                <prop key="hibernate.show_sql">false</prop>
248
                <prop key="hibernate.format_sql">false</prop>
249
            </props>
250
        </property>
251
    </bean>    
252
</beans>
253 43 Markus Döring
~~~
254 1 Markus Döring
255 42 Markus Döring
256 41 Markus Döring
257 43 Markus Döring
258 41 Markus Döring
----
259 38 Markus Döring
260
261
262 69 Markus Döring
## Background
263 38 Markus Döring
264 39 Markus Döring
265
### Hibernate
266 69 Markus Döring
267 32 Markus Döring
* Hibernate works with most current RDBMS. See  [supported databases](http://www.hibernate.org/80.html) 
268 10 Markus Döring
269 69 Markus Döring
270 6 Markus Döring
271 69 Markus Döring
### Spring 2.0 Framework
272 6 Markus Döring
273 50 Andreas Müller
We use the Spring 2.0 framework to develop the library and keep the coupling of components low.
274
275 69 Markus Döring
*  [Spring2.0 Documentation](http://static.springframework.org/spring/docs/2.0.x/reference/index.html) 
276 50 Andreas Müller
277 69 Markus Döring
*  [Introduction to the Spring Framework](http://www.theserverside.com/tt/articles/content/SpringFramework/article.html) 
278 50 Andreas Müller
279 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) 
280 50 Andreas Müller
281 69 Markus Döring
282 50 Andreas Müller
283 1 Markus Döring
### Domain Models
284
285
* [Domain Models and Validation. An Architectural Discussion](http://forum.springframework.org/showthread.php?t=18699)
286
287
* [Avoiding anemic domain models with Hibernate](http://www.theserverside.com/patterns/thread.tss?thread_id=31010)
288
289
* [Business Object Pattern](http://www.corej2eepatterns.com/Patterns2ndEd/BusinessObject.htm)
290 69 Markus Döring
291 50 Andreas Müller
*  [AnemicDomainModel Anti Pattern](http://www.martinfowler.com/bliki/AnemicDomainModel.html) 
292
293 78 Markus Döring
294
295
#### Property Change
296
297
* http://www.onjava.com/pub/a/onjava/2004/06/02/desktop.html
298
299
* http://www.javalobby.org/java/forums/t19476.html
300 35 Andreas Müller
301
302
303 69 Markus Döring
### Useful Patterns
304 35 Andreas Müller
305 69 Markus Döring
* [ApplicationService Pattern](http://www.corej2eepatterns.com/Patterns2ndEd/ApplicationService.htm)
306 35 Andreas Müller
307
308
309
310 69 Markus Döring
### Aspect Oriented Programming
311 35 Andreas Müller
312 69 Markus Döring
We use AspectJ to implement the change property crosscutting concern:
313 35 Andreas Müller
314 69 Markus Döring
* AspectJ
315 35 Andreas Müller
316 69 Markus Döring
  * http://today.java.net/pub/a/today/2005/12/15/writing-mixins-with-aop.html
317 45 Markus Döring
318 69 Markus Döring
* JBoss AOP
319 45 Markus Döring
320 69 Markus Döring
  * http://www.damnhandy.com/javabean-aspect/
321
322
* Spring AOP
323
324
  * http://forum.springframework.org/archive/index.php/t-13293.html
325
326
  * http://forum.springframework.com/viewtopic.php?t=301