2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.api
.service
;
13 import java
.util
.Collection
;
14 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import org
.springframework
.transaction
.annotation
.Propagation
;
19 import org
.springframework
.transaction
.annotation
.Transactional
;
21 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 @Transactional(propagation
=Propagation
.SUPPORTS
)
29 public interface IService
<T
extends CdmBase
>{
32 * Returns a count of all entities of type <T>
33 * @return a count of all entities
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
42 public <TYPE
extends T
> int count(Class
<TYPE
> clazz
);
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
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
53 public List
<T
> list(int limit
, int start
);
56 * Returns a List of entities of type <TYPE> which must extend
58 * TODO would like to substitute List with Pager, but we need
59 * to agree on how to implement paging first
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
66 public <TYPE
extends T
> List
<TYPE
> list(Class
<TYPE
> type
, int limit
, int start
);
68 public List
<T
> rows(String tableName
, int limit
, int start
);
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
75 public UUID
save(T newInstance
);
78 * Save a new entity or update the persistent state of an existing
79 * transient entity that has been persisted previously
81 * @param transientObject the entity to be persisted
82 * @return The unique identifier of the persisted entity
84 public UUID
saveOrUpdate(T transientObject
);
87 * Update the persistent state of an existing transient entity
88 * that has been persisted previously
90 * @param transientObject the entity to be persisted
91 * @return The unique identifier of the persisted entity
93 public UUID
update(T transientObject
);
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
101 public Map
<UUID
,T
> saveAll(Collection
<T
> newInstances
);
104 * Re-read the state of the given instance from the underlying database.
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
110 * http://forum.hibernate.org/viewtopic.php?t=974544
112 * @param persistentObject the object to be refreshed
113 * @return the unique identifier
115 public UUID
refresh(T persistentObject
);
118 * Delete an existing persistent object
120 * @param persistentObject the object to be deleted
121 * @return the unique identifier of the deleted entity
123 public UUID
delete(T persistentObject
);
126 * Return a persisted entity that matches the unique identifier
127 * supplied as an argument, or null if the entity does not exist
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
132 public T
findByUuid(UUID uuid
);
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
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
141 public boolean exists(UUID uuid
);