@@ -78,6 +78,7 @@ public List<T> getAll() throws AqualityException {
78
78
*/
79
79
public List <T > searchAll (T entity ) throws AqualityException {
80
80
List <Pair <String , String >> parameters = entity .getSearchParameters ();
81
+ checkSelectProcedure ();
81
82
return dtoMapper .mapObjects (CallStoredProcedure (select , parameters ).toString ());
82
83
}
83
84
@@ -95,6 +96,7 @@ public T getEntityById(Integer id) throws AqualityException {
95
96
}
96
97
97
98
List <Pair <String , String >> parameters = entity .getIdSearchParameters (id );
99
+ checkSelectProcedure ();
98
100
List <T > all = dtoMapper .mapObjects (CallStoredProcedure (select , parameters ).toString ());
99
101
100
102
return getSingleResult (all , id );
@@ -107,6 +109,7 @@ public T getEntityById(Integer id) throws AqualityException {
107
109
*/
108
110
public T getEntityById (T entity ) throws AqualityException {
109
111
List <Pair <String , String >> parameters = entity .getIdAndProjectIdSearchParameters ();
112
+ checkSelectProcedure ();
110
113
List <T > all = dtoMapper .mapObjects (CallStoredProcedure (select , parameters ).toString ());
111
114
112
115
return getSingleResult (all , entity .getIdOrOverrideId ());
@@ -129,6 +132,7 @@ public T update(T entity) throws AqualityException {
129
132
}
130
133
131
134
List <Pair <String , String >> parameters = entity .getParameters ();
135
+ checkInsertProcedure ();
132
136
List <T > results = dtoMapper .mapObjects (CallStoredProcedure (insert , parameters ).toString ());
133
137
if (!results .isEmpty ()) {
134
138
return results .get (0 );
@@ -144,7 +148,7 @@ public T update(T entity) throws AqualityException {
144
148
*/
145
149
public boolean delete (T entity ) throws AqualityException {
146
150
List <Pair <String , String >> parameters = entity .getDataBaseIDParameters ();
147
-
151
+ checkRemoveProcedure ();
148
152
CallStoredProcedure (remove , parameters );
149
153
return true ;
150
154
}
@@ -164,6 +168,7 @@ public T create(T entity) throws AqualityException {
164
168
165
169
if (id == null ){
166
170
List <Pair <String , String >> parameters = entity .getParameters ();
171
+ checkInsertProcedure ();
167
172
List <T > results = dtoMapper .mapObjects (CallStoredProcedure (insert , parameters ).toString ());
168
173
if (!results .isEmpty ()){
169
174
return results .get (0 );
@@ -330,4 +335,22 @@ private boolean areParametersEmpty(List<Pair<String, String>> parameters) {
330
335
331
336
return true ;
332
337
}
338
+
339
+ protected void checkSelectProcedure () throws AqualityException {
340
+ checkProcedure (select , "SELECT" );
341
+ }
342
+
343
+ protected void checkInsertProcedure () throws AqualityException {
344
+ checkProcedure (insert , "INSERT" );
345
+ }
346
+
347
+ protected void checkRemoveProcedure () throws AqualityException {
348
+ checkProcedure (remove , "REMOVE" );
349
+ }
350
+
351
+ private void checkProcedure (String sql , String sqlName ) throws AqualityException {
352
+ if (sql == null ){
353
+ throw new AqualityException (String .format ("SQL procedure '%s' is not define for DAO '%s'" , sqlName , getClass ()));
354
+ }
355
+ }
333
356
}
0 commit comments