Merge branch 'release/5.45.0'
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / persistence / dao / initializer / IBeanInitializer.java
1 /**
2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.persistence.dao.initializer;
10
11 import java.util.Collection;
12 import java.util.List;
13
14 import eu.etaxonomy.cdm.model.name.TaxonName;
15 import eu.etaxonomy.cdm.model.taxon.Taxon;
16
17 /**
18 * @author a.kohlbecker
19 * @since 25.03.2009
20 *
21 */
22 public interface IBeanInitializer {
23
24 /**
25 * Wildcard for initializing all *ToOne relations of a <code>bean</code>.
26 */
27 public static final String LOAD_2ONE_WILDCARD = "$";
28
29 /**
30 * Wildcard for initializing all *ToOne and all *ToMany relations of a <code>bean</code>.
31 */
32 public static final String LOAD_2ONE_2MANY_WILDCARD = "*";
33
34 /**
35 * Initializes all *ToOne relations of the <code>bean</code>.
36 *
37 * @param bean
38 */
39 public void load(Object bean);
40
41 /**
42 * Initializes all *ToOne and all *ToMany relations of the <code>bean</code>.
43 *
44 * @param bean
45 */
46 public void loadFully(Object bean);
47
48 /**
49 * Allows more fine grained initialization not only of the root bean
50 * identified by its <code>uuid</code> but also of specific paths of
51 * the object graph. The sub graph to initialize may be defined in the
52 * <code>propertyPaths</code> parameter as list of paths all starting at the
53 * root bean.
54 * <p>
55 * You can use wildcards <code>*</code> {@link LOAD_2ONE_2MANY_WILDCARD}
56 * and <code>$</code> {@link LOAD_2ONE_WILDCARD} for initializing
57 * all *ToOne and all *ToMany relations of a bean.
58 * NOTE: A wildcard subsequently terminates its property path.
59 * <p>
60 * <b>Example:</b> Assuming <code>cdmEntity</code> is a {@link Taxon}
61 * instance the following <code>propertyPaths</code> can be used for
62 * initializing bean properties of this instance. It is possible to
63 * initialized nested properties of properties with unlimited depth.
64 * <ul>
65 * <li><code>name</code>: initializes {@link Taxon#getName()}</li>
66 * <li><code>name.rank</code>: initializes {@link Taxon#getName()}.{@link TaxonName#getRank() getRank()}</li>
67 * <li><code>name.$</code>: initializes all *ToOne relations of the {@link Taxon#getName()}</li>
68 * </ul>
69 *
70 * @param bean
71 * @param propertyPaths
72 * a List of property names
73 */
74 public void initialize(Object bean, List<String> propertyPaths);
75
76 /**
77 * Initializes the entities given in the bean list according to the given
78 * <code>propertyPaths</code>.
79 *
80 * @param beanList
81 * @param propertyPaths
82 * @return
83 */
84 public <C extends Collection<?>> C initializeAll(C list, List<String> propertyPaths);
85
86 /**
87 * Initialize the the proxy, unwrap the target object and return it.
88 *
89 * @param proxy
90 * the proxy to initialize may wrap a single bean or a collection
91 * @return the unwrapped target object
92 */
93 public Object initializeInstance(Object proxy);
94
95
96 /*TODO implement:
97 public void loadBy(UUID uuid);
98 public void loadFullyByUuid(UUID uuid);*/
99
100 }