Merged branches/cdmlib/2.0 changes r5130:5370 into the trunk
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / IService.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.api.service;
11
12
13 import java.util.Collection;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.UUID;
17
18 import org.springframework.transaction.annotation.Propagation;
19 import org.springframework.transaction.annotation.Transactional;
20
21 import eu.etaxonomy.cdm.model.common.CdmBase;
22
23
24 /**
25 * @author a.mueller
26 *
27 */
28 @Transactional(propagation=Propagation.SUPPORTS)
29 public interface IService<T extends CdmBase>{
30
31 /**
32 * Returns a count of all entities of type <T>
33 * @return a count of all entities
34 */
35 public int count();
36
37 /**
38 * Returns a count of all entities of type <TYPE> that extend <T>
39 * @param clazz the class of entities to be counted
40 * @return a count of entities
41 */
42 public <TYPE extends T> int count(Class<TYPE> clazz);
43
44 /**
45 * Returns a List of entities of type <T>
46 * TODO would like to substitute List with Pager, but we need
47 * to agree on how to implement paging first
48 *
49 * @param limit The maximum number of entities returned
50 * @param start The offset from the start of the dataset
51 * @return a List of entities
52 */
53 public List<T> list(int limit, int start);
54
55 /**
56 * Returns a List of entities of type <TYPE> which must extend
57 * <T>
58 * TODO would like to substitute List with Pager, but we need
59 * to agree on how to implement paging first
60 *
61 * @param type The type of entities to return
62 * @param limit The maximum number of entities returned
63 * @param start The offset from the start of the dataset
64 * @return a List of entities
65 */
66 public <TYPE extends T> List<TYPE> list(Class<TYPE> type, int limit, int start);
67
68 public List<T> rows(String tableName, int limit, int start);
69
70 /**
71 * Save a new entity (persists the entity)
72 * @param newInstance the new entity to be persisted
73 * @return A generated UUID for the new persistent entity
74 */
75 public UUID save(T newInstance);
76
77 /**
78 * Save a new entity or update the persistent state of an existing
79 * transient entity that has been persisted previously
80 *
81 * @param transientObject the entity to be persisted
82 * @return The unique identifier of the persisted entity
83 */
84 public UUID saveOrUpdate(T transientObject);
85
86 /**
87 * Update the persistent state of an existing transient entity
88 * that has been persisted previously
89 *
90 * @param transientObject the entity to be persisted
91 * @return The unique identifier of the persisted entity
92 */
93 public UUID update(T transientObject);
94
95 /**
96 * Save a collection containing new entities (persists the entities)
97 * @param newInstances the new entities to be persisted
98 * @return A Map containing the new entities, keyed using the generated UUID's
99 * of those entities
100 */
101 public Map<UUID,T> saveAll(Collection<T> newInstances);
102
103 /**
104 * Re-read the state of the given instance from the underlying database.
105 *
106 * Hibernate claims that it is inadvisable to use refresh in long-running-sessions.
107 * I don't really see where we would get into a situation where problems as discussed
108 * this forum thread would apply for our scenario
109 *
110 * http://forum.hibernate.org/viewtopic.php?t=974544
111 *
112 * @param persistentObject the object to be refreshed
113 * @return the unique identifier
114 */
115 public UUID refresh(T persistentObject);
116
117 /**
118 * Delete an existing persistent object
119 *
120 * @param persistentObject the object to be deleted
121 * @return the unique identifier of the deleted entity
122 */
123 public UUID delete(T persistentObject);
124
125 /**
126 * Return a persisted entity that matches the unique identifier
127 * supplied as an argument, or null if the entity does not exist
128 *
129 * @param uuid the unique identifier of the entity required
130 * @return an entity of type <T>, or null if the entity does not exist
131 */
132 public T findByUuid(UUID uuid);
133
134 /**
135 * Returns true if an entity of type <T> with a unique identifier matching the
136 * identifier supplied exists in the database, or false if no such entity can be
137 * found.
138 * @param uuid the unique identifier of the entity required
139 * @return an entity of type <T> matching the uuid, or null if that entity does not exist
140 */
141 public boolean exists(UUID uuid);
142 }