1 /*
2 * Copyright 2010 James Pether Sörling
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * $Id$
17 * $HeadURL$
18 */
19
20 package com.hack23.cia.service.data.api;
21
22 import java.io.Serializable;
23 import java.util.List;
24
25 import javax.persistence.metamodel.SingularAttribute;
26
27 /**
28 * The Interface AbstractGenericDAO.
29 *
30 * @param <T>
31 * the generic type
32 * @param <I>
33 * the generic type
34 */
35 public interface AbstractGenericDAO<T extends Serializable, I extends Serializable> {
36
37 /**
38 * Delete.
39 *
40 * @param entity
41 * the entity
42 */
43 void delete(T entity);
44
45 /**
46 * Find first by property.
47 *
48 * @param property
49 * the property
50 * @param value
51 * the value
52 * @return the t
53 */
54 T findFirstByProperty(SingularAttribute<T, ? extends Object> property, Object value);
55
56 /**
57 * Find list by property.
58 *
59 * @param values
60 * the values
61 * @param properties
62 * the properties
63 * @return the list
64 */
65 List<T> findListByProperty(final Object[] values,final SingularAttribute<T, ? extends Object>... properties);
66
67
68 /**
69 * Find list by property.
70 *
71 * @param property
72 * the property
73 * @param value
74 * the value
75 * @return the list
76 */
77 List<T> findListByProperty(SingularAttribute<T, ? extends Object> property, Object value);
78
79 /**
80 * Find list by embedded property.
81 *
82 * @param <V>
83 * the value type
84 * @param property
85 * the property
86 * @param clazz2
87 * the clazz 2
88 * @param property2
89 * the property 2
90 * @param value
91 * the value
92 * @return the list
93 */
94 <V> List<T> findListByEmbeddedProperty(SingularAttribute<T, V> property,Class<V> clazz2,SingularAttribute<V, ? extends Object> property2, Object value);
95
96 /**
97 * Find ordered by property list by embedded property.
98 *
99 * @param <V>
100 * the value type
101 * @param property
102 * the property
103 * @param clazz2
104 * the clazz 2
105 * @param property2
106 * the property 2
107 * @param value
108 * the value
109 * @param orderByProperty
110 * the order by property
111 * @return the list
112 */
113 <V> List<T> findOrderedByPropertyListByEmbeddedProperty(final SingularAttribute<T, V> property,
114 final Class<V> clazz2, final SingularAttribute<V, ? extends Object> property2, final Object value,
115 final SingularAttribute<T, ? extends Object> orderByProperty);
116
117
118 /**
119 * Gets the all.
120 *
121 * @return the all
122 */
123 List<T> getAll();
124
125
126 /**
127 * Gets the all order by.
128 *
129 * @param orderBy
130 * the order by
131 * @return the all order by
132 */
133 List<T> getAllOrderBy(final SingularAttribute<T, ? extends Object> orderBy);
134
135
136 /**
137 * Gets the page.
138 *
139 * @param pageNr
140 * the page nr
141 * @param resultPerPage
142 * the result per page
143 * @return the page
144 */
145 List<T> getPage(int pageNr,int resultPerPage);
146
147 /**
148 * Gets the page order by.
149 *
150 * @param pageNr
151 * the page nr
152 * @param resultPerPage
153 * the result per page
154 * @param orderBy
155 * the order by
156 * @return the page order by
157 */
158 List<T> getPageOrderBy(int pageNr,int resultPerPage,final SingularAttribute<T, ? extends Object> orderBy);
159
160
161 /**
162 * Gets the size.
163 *
164 * @return the size
165 */
166 Long getSize();
167
168 /**
169 * Load.
170 *
171 * @param id
172 * the id
173 * @return the t
174 */
175 T load(I id);
176
177 /**
178 * Merge.
179 *
180 * @param entity
181 * the entity
182 * @return the t
183 */
184 T merge(T entity);
185
186 /**
187 * Persist.
188 *
189 * @param list
190 * the list
191 */
192 void persist(final List<T> list);
193
194 /**
195 * Persist.
196 *
197 * @param entity
198 * the entity
199 */
200 void persist(T entity);
201
202 /**
203 * Search.
204 *
205 * @param searchExpression
206 * the search expression
207 * @param maxResults
208 * the max results
209 * @param fields
210 * the fields
211 * @return the list
212 */
213 List<T> search(String searchExpression, Integer maxResults,String ...fields);
214
215 }