configurable bean initialization methods
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / persistence / dao / common / ICdmEntityDao.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.cdm.persistence.dao.common;
11
12 import java.util.Collection;
13 import java.util.List;
14 import java.util.Map;
15 import java.util.UUID;
16
17 import org.springframework.dao.DataAccessException;
18
19 import eu.etaxonomy.cdm.model.common.CdmBase;
20 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
21 import eu.etaxonomy.cdm.persistence.dao.BeanInitializer;
22 import eu.etaxonomy.cdm.persistence.query.OrderHint;
23
24 /**
25 * an data access interface that all data access classes implement
26 * @author m.doering
27 * @version 1.0
28 * @created 02-Nov-2007 19:36:10
29 */
30 public interface ICdmEntityDao<T extends CdmBase> {
31
32 /**
33 * @param transientObject
34 * @return
35 * @throws DataAccessException
36 */
37 public UUID saveOrUpdate(T transientObject) throws DataAccessException;
38
39 //public UUID saveOrUpdateAll(Collection<T> transientObjects) throws DataAccessException;
40
41 /**
42 * @param newOrManagedObject
43 * @return
44 * @throws DataAccessException
45 */
46 public UUID save(T newOrManagedObject) throws DataAccessException;
47
48 public Map<UUID, T> saveAll(Collection<T> cdmObjCollection) throws DataAccessException;
49
50 /**
51 * @param transientObject
52 * @return
53 * @throws DataAccessException
54 */
55 public UUID update(T transientObject) throws DataAccessException;
56
57 /**
58 * @param persistentObject
59 * @return
60 * @throws DataAccessException
61 */
62 public UUID refresh(T persistentObject) throws DataAccessException;
63
64 /**
65 * @param persistentObject
66 * @return
67 * @throws DataAccessException
68 */
69 public UUID delete(T persistentObject) throws DataAccessException;
70
71 /**
72 * Returns a sublist of CdmBase instances stored in the database.
73 * A maximum of 'limit' objects are returned, starting at object with index 'start'.
74 * @param limit the maximum number of entities returned (can be null to return all entities)
75 * @param start
76 * @return
77 * @throws DataAccessException
78 */
79 public List<T> list(Integer limit, Integer start) throws DataAccessException;
80
81 /**
82 * Returns a sublist of CdmBase instances stored in the database. A maximum
83 * of 'limit' objects are returned, starting at object with index 'start'.
84 *
85 * @param limit
86 * the maximum number of entities returned (can be null to return
87 * all entities)
88 * @param start
89 * @param orderHints
90 * Supports path like <code>orderHints.propertyNames</code> which
91 * include *-to-one properties like createdBy.username or
92 * authorTeam.persistentTitleCache
93 * @return
94 * @throws DataAccessException
95 */
96 public <TYPE extends T> List<TYPE> list(Integer limit, Integer start, List<OrderHint> orderHints);
97
98 /**
99 * Returns a sublist of CdmBase instances of type <TYPE> stored in the database.
100 * A maximum of 'limit' objects are returned, starting at object with index 'start'.
101 * @param limit the maximum number of entities returned (can be null to return all entities)
102 * @param start
103 * @return
104 * @throws DataAccessException
105 */
106 public <TYPE extends T> List<TYPE> list(Class<TYPE> type, Integer limit, Integer start) throws DataAccessException;
107
108
109 public List<T> rows(String tableName, int limit, int start) throws DataAccessException;
110
111 /**
112 * @param id
113 * @return
114 * @throws DataAccessException
115 */
116 public T findById(int id) throws DataAccessException;
117
118 /**
119 * @param Uuid
120 * @return
121 * @throws DataAccessException
122 */
123 public T findByUuid(UUID Uuid) throws DataAccessException;
124
125 /**
126 * Finds the cdm entity specified by the <code>uuid</code> parameter and
127 * initializes all its *ToOne relations.
128 *
129 * @param uuid
130 * @return
131 */
132 public T load(UUID uuid);
133
134 /**
135 * Finds the cdm entity specified by the <code>uuid</code> parameter and
136 * recursively initializes all bean properties given in the
137 * <code>propertyPaths</code> parameter.
138 * <p>
139 * For detailed description and examples <b>please refer to:</b>
140 * {@link BeanInitializer#initializeProperties(Object, List)}
141 *
142 * @param uuid
143 * @return
144 */
145 public T load(UUID uuid, List<String> propertyPaths);
146
147 /**
148 * @param uuid
149 * @return
150 * @throws DataAccessException
151 */
152 public Boolean exists(UUID uuid) throws DataAccessException;
153
154 public int count();
155
156 /**
157 * Returns the number of objects of type <TYPE> - which must extend T
158 * @param <TYPE>
159 * @param clazz
160 * @return
161 */
162 public <TYPE extends T> int count(Class<TYPE> clazz);
163
164 /**
165 * FIXME Should this method exist : I would expect flushing of a session to be
166 * something that a DAO should hide?
167 */
168 public void flush();
169
170 /**
171 * Convenience method which makes it easy to discover what type of object this DAO returns at runtime
172 *
173 * @return
174 */
175 public Class<T> getType();
176 }