1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <chapter version=
"5.0" xml:
id=
"basic-persistence"
3 xmlns=
"http://docbook.org/ns/docbook"
4 xmlns:
ns5=
"http://www.w3.org/1999/xhtml"
5 xmlns:
ns4=
"http://www.w3.org/2000/svg"
6 xmlns:
ns3=
"http://www.w3.org/1998/Math/MathML"
7 xmlns:
ns2=
"http://www.w3.org/1999/xlink"
8 xmlns:
ns=
"http://docbook.org/ns/docbook">
10 <title>Basic Persistence
</title>
14 <para>The persistence layer of the CDM primarily consists of a set of
15 <emphasis>data access objects (DAOs)
</emphasis>. These DAOs are generic,
16 strongly typed, and form a hierachy that reflects the inheritance of the
17 data entities that they provide access too. The root DAO implements
18 <interfacename>ICdmEntityDao
</interfacename>.
</para>
20 <table frame=
"all" xml:
id=
"icdmentitydao-methods">
21 <title><interfacename>ICdmEntityDao
</interfacename> methods
</title>
23 <tgroup align=
"left" cols=
"2" colsep=
"1" rowsep=
"1">
24 <colspec colname=
"c1" />
26 <colspec colname=
"c2" />
32 <entry>Description
</entry>
42 <methodname>saveOrUpdate
</methodname>
47 <parameter>newOrTransientEntity
</parameter>
53 <para>Makes a new object persistent, or persists the state of a
54 transient object.
</para>
61 <type>Map
<UUID,T
></type>
63 <methodname>save
</methodname>
66 <type>Collection
<T
></type>
68 <parameter>newEntities
</parameter>
74 <para>Makes a collection of new objects persistent.
</para>
83 <methodname>save
</methodname>
88 <parameter>newEntity
</parameter>
94 <para>Makes a new object persistent.
</para>
103 <methodname>update
</methodname>
108 <parameter>newEntity
</parameter>
114 <para>Makes changes to a transient object persistent.
</para>
123 <methodname>merge
</methodname>
128 <parameter>newEntity
</parameter>
134 <para>Merges the state of a detached object into the persisted
144 <methodname>delete
</methodname>
149 <parameter>persistentEntity
</parameter>
155 <para>Deletes a persistent object.
</para>
162 <type>List
<T
></type>
164 <methodname>list
</methodname>
167 <type>Class
<? extends T
></type>
169 <parameter>clazz
</parameter>
175 <parameter>limit
</parameter>
181 <parameter>start
</parameter>
185 <type>List
<OrderHint
></type>
187 <parameter>orderHints
</parameter>
191 <type>List
<String
></type>
193 <parameter>propertyPaths
</parameter>
199 <para>Returns a (sub-)list of objects matching the type
200 <parameter>clazz
</parameter>, sorted according to the order
201 hints and initialized according to the propertyPaths.
</para>
210 <methodname>count
</methodname>
213 <type>Class
<? extends T
></type>
215 <parameter>clazz
</parameter>
221 <para>Returns a count of objects matching the type
222 <parameter>clazz
</parameter>.
</para>
231 <methodname>find
</methodname>
236 <parameter>uuid
</parameter>
242 <para>Returns an object of type T matching the supplied uuid if
250 <type>Collection
<T
></type>
252 <methodname>find
</methodname>
255 <type>Collection
<UUID
></type>
257 <parameter>uuids
</parameter>
263 <para>Returns a collection of objects of type T matching the
264 uuids supplied, if they exist.
</para>
273 <methodname>load
</methodname>
278 <parameter>uuid
</parameter>
282 <type>Collection
<String
></type>
284 <parameter>propertyPaths
</parameter>
290 <para>Returns an object of type T with properties initialized
291 according to the rules described below.
</para>
298 <type>Set
<T
></type>
300 <methodname>load
</methodname>
303 <type>Collection
<UUID
></type>
305 <parameter>uuids
</parameter>
309 <type>Collection
<String
></type>
311 <parameter>propertyPaths
</parameter>
317 <para>Returns a collection of objects of type T matching the
318 uuids supplied, if they exist, initialized according to the
319 rules described below.
</para>
328 <methodname>exists
</methodname>
333 <parameter>uuid
</parameter>
339 <para>Returns true if there is an object of type T in the
340 database matching the supplied uuid.
</para>
347 <type>Class
<T
></type>
349 <methodname>getType
</methodname>
354 <para>Returns the class of objects that this DAO provides access
363 <title>An overview of the cdm persistence layer
</title>
366 <imageobject role=
"html">
367 <imagedata fileref=
"resources/images/dao.png" format=
"png" />
370 <imageobject role=
"fo">
371 <imagedata contentwidth=
"160mm"
372 fileref=
"resources/images/dao.png" format=
"png"
376 <caption>The DAO hierarchy in the CDM persistence layer. Data Access Objects are strongly typed
377 and their hierarchy follows the hierarchy of major entities in the CDM.
</caption>
383 <title>Object Initialization
</title>
386 <para>DAO methods that return objects, return entities without any
387 relationships initialized by default (to learn more about initialization
388 of related entities, lazy-loading etc, please consult the hibernate
389 documentation). Because some applications (particularly stateless
390 multi-user applications with concise units of work i.e. web
391 applications), may wish to limit the length of transactions, it is
392 important to be able to explicitly initialize related entities according
393 to the particular use-case. The CDM library allows application
394 developers to do this on a per-method call basis.
</para>
396 <para>Properties of the root object specified using java-beans-like
397 syntax and passed using the
<parameter>propertyPaths
</parameter>
398 parameter will be initialialised before the object(s) are returned and
399 can safely used. Applications that access other properties (that are
400 part of related entities) outside of the transaction in which the entity
401 was retrieved (i.e. the entity is detached) are likely to throw a
402 <exceptionname>LazyInitializationException
</exceptionname>. In addition
403 to specifying properties by name, developers can also use an asterisk
404 (*) to represent all *-to-many properties, and a dollar sign ($) to
405 represent all *-to-one properties of the root entity or a related
406 entity. Using a wildcard terminates the property path (i.e. it is not
407 valid syntax to include characters after a wildcard in a propertyPath
408 expression - the wildcard must be the final character in the
414 <title>Listing objects and sorting lists
</title>
417 <para>In addition to allowing single objects and collections of objects
418 matching specific UUIDs to be returned, the GenericDAO also allows lists
419 of objects of type T to be returned (to allow browsing of the entire
420 collection of entities, for example). In many cases, applications will
421 wish to restrict the total number of objects returned to a subset of the
422 total available objects (to reduce resource requirements, or increase
423 speed of rendering of a response, for example). This can be achieved by
424 supplying non-null
<parameter>limit
</parameter> and
425 <parameter>start
</parameter> parameters to restrict the total number of
426 objects returned. These parameters are analogous to the
"limit" and
427 "offset" parameters in SQL and are zero-based (i.e. the first result is
430 <para>Lists of objects are returned sorted according to the
431 <parameter>orderHints
</parameter> parameter. Like the
432 <parameter>propertyPaths
</parameter> parameter,
433 <classname>OrderHint
</classname> objects take a java-beans-style string
434 that indicates the property or related entity that the list of returned
435 objects should be ordered by, and a
<classname>SortOrder
</classname>
436 that determined whether the list is sorted in ascending or descending