View Javadoc
1   /*
2    * This file is part of Waarp Project (named also Waarp or GG).
3    *
4    *  Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
5    *  tags. See the COPYRIGHT.txt in the distribution for a full listing of
6    * individual contributors.
7    *
8    *  All Waarp Project is free software: you can redistribute it and/or
9    * modify it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation, either version 3 of the License, or (at your
11   * option) any later version.
12   *
13   * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
14   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15   * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License along with
18   * Waarp . If not, see <http://www.gnu.org/licenses/>.
19   */
20  
21  package org.waarp.openr66.dao;
22  
23  import org.waarp.openr66.dao.exception.DAOConnectionException;
24  import org.waarp.openr66.dao.exception.DAONoDataException;
25  
26  import java.util.List;
27  
28  /**
29   * Interface to interact with objects in the persistance layer
30   *
31   * @param <E>
32   */
33  public interface AbstractDAO<E> extends Cloneable {
34  
35    /**
36     * Retrieve all objects in a List from the persistance layer
37     *
38     * @throws DAOConnectionException If data access error occurs
39     */
40    List<E> getAll() throws DAOConnectionException;
41  
42    /**
43     * Retrieve all objects corresponding to the given filters in a List
44     * from the persistance layer
45     *
46     * @param filters List of filter
47     *
48     * @throws DAOConnectionException If data access error occurs
49     */
50    List<E> find(List<Filter> filters) throws DAOConnectionException;
51  
52    /**
53     * Retrieve all objects corresponding to the given filters in a List
54     * from the persistance layer
55     *
56     * @param filters List of filter
57     * @param limit max number of items to get
58     *
59     * @throws DAOConnectionException If data access error occurs
60     */
61    List<E> find(List<Filter> filters, int limit) throws DAOConnectionException;
62  
63    /**
64     * Retrieve all objects corresponding to the given filters in a List
65     * from the persistance layer
66     *
67     * @param filters List of filter
68     * @param field field to sort on
69     * @param asc True for ascending, False for descending order
70     *
71     * @throws DAOConnectionException If data access error occurs
72     */
73    List<E> find(List<Filter> filters, String field, boolean asc)
74        throws DAOConnectionException;
75  
76    /**
77     * Retrieve all objects corresponding to the given filters in a List
78     * from the persistance layer
79     *
80     * @param filters List of filter
81     * @param field field to sort on
82     * @param asc True for ascending, False for descending order
83     * @param limit max number of items to get
84     *
85     * @throws DAOConnectionException If data access error occurs
86     */
87    List<E> find(List<Filter> filters, String field, boolean asc, int limit)
88        throws DAOConnectionException;
89  
90    /**
91     * Retrieve all objects corresponding to the given filters in a List
92     * from the persistance layer
93     *
94     * @param filters List of filter
95     * @param field field to sort on
96     * @param asc True for ascending, False for descending order
97     * @param limit max number of items to get
98     * @param offset start for items to get
99     *
100    * @throws DAOConnectionException If data access error occurs
101    */
102   List<E> find(List<Filter> filters, String field, boolean asc, int limit,
103                int offset) throws DAOConnectionException;
104 
105   /**
106    * Update all objects corresponding to the given filters in a List
107    * from the persistance layer
108    *
109    * @param filters List of filter
110    * @param toSet field to update as "field1 = value1, field2 = value2, ..."
111    *
112    * @throws DAOConnectionException If data access error occurs
113    */
114   void update(List<Filter> filters, String toSet) throws DAOConnectionException;
115 
116   /**
117    * Count all objects corresponding to the given filters
118    * from the persistance layer
119    *
120    * @param filters List of filter
121    *
122    * @throws DAOConnectionException If data access error occurs
123    */
124   long count(List<Filter> filters) throws DAOConnectionException;
125 
126   /**
127    * Retrieve the object with the specified id from the persistance
128    * layer
129    *
130    * @param id id of the object requested
131    *
132    * @throws DAOConnectionException If a data access error occurs
133    * @throws DAONoDataException if no data are available
134    */
135   E select(String id) throws DAOConnectionException, DAONoDataException;
136 
137   /**
138    * Verify if an object with the specified id exists in the
139    * persistance layer
140    *
141    * @param id id of the object verified
142    *
143    * @return true if a object with the specified id exist; false if
144    *     no object correspond to the
145    *     specified id.
146    *
147    * @throws DAOConnectionException If a data access error occurs
148    */
149   boolean exist(String id) throws DAOConnectionException;
150 
151   /**
152    * Insert the specified object in the persistance layer
153    *
154    * @param object object to insert
155    *
156    * @throws DAOConnectionException If a data access error occurs
157    */
158   void insert(E object) throws DAOConnectionException;
159 
160   /**
161    * Update the specified object in the persistance layer
162    *
163    * @param object object to update
164    *
165    * @throws DAOConnectionException If a data access error occurs
166    * @throws DAONoDataException if no data are available
167    */
168   void update(E object) throws DAOConnectionException, DAONoDataException;
169 
170   /**
171    * Remove the specified object from the persistance layer
172    *
173    * @param object object to delete
174    *
175    * @throws DAOConnectionException If a data access error occurs
176    * @throws DAONoDataException if no data are available
177    */
178   void delete(E object) throws DAOConnectionException, DAONoDataException;
179 
180   /**
181    * Remove all objects from the persistance layer
182    *
183    * @throws DAOConnectionException If a data access error occurs
184    */
185   void deleteAll() throws DAOConnectionException;
186 
187   void close();
188 }