001package gu.sql2java;
002import java.util.List;
003import java.util.Map;
004
005import gu.sql2java.exception.ObjectRetrievalException;
006import gu.sql2java.exception.RuntimeDaoException;
007
008import java.util.Collection;
009/**
010 * Interface to handle database calls (save, load, count, etc...) for table.
011 * @author guyadong
012 */
013public interface TableManager<B extends BaseBean> extends SqlRunner{
014
015    public interface Action<B>{
016
017        /**
018         * do action for {@code bean}
019         * @param bean input bean
020         */
021        void call(B bean);
022    }
023    
024    //_____________________________________________________________________
025    //
026    // COUNT
027    //_____________________________________________________________________
028    //24
029    /**
030     * Retrieves the number of rows of the table.
031     *
032     * @return the number of rows returned
033     * @throws RuntimeDaoException
034     */
035    public int countAll()throws RuntimeDaoException;
036    
037    //27
038    /**
039     * count the number of elements of a specific bean
040     *
041     * @param bean the bean to look for ant count
042     * @return the number of rows returned
043     * @throws RuntimeDaoException
044     */
045    public int countUsingTemplate( B bean)throws RuntimeDaoException;
046  
047    //20
048    /**
049     * count the number of elements of a specific bean given the search type
050     *
051     * @param bean the template to look for
052     * @param searchType exact ?  like ? starting like ? ending link ? <br>
053     *                {@value Constant#SEARCH_EXACT}   {@link Constant#SEARCH_EXACT} <br>
054     *                {@value Constant#SEARCH_LIKE}   {@link Constant#SEARCH_LIKE} <br>
055     *                {@value Constant#SEARCH_STARTING_LIKE}   {@link Constant#SEARCH_STARTING_LIKE} <br>
056     *                {@value Constant#SEARCH_ENDING_LIKE}   {@link Constant#SEARCH_ENDING_LIKE} <br>  
057     * @return the number of rows returned
058     * @throws RuntimeDaoException
059     */
060    public int countUsingTemplate(B bean, int searchType)throws RuntimeDaoException;
061
062    //25
063    /**
064     * Retrieves the number of rows of the table with a 'where' clause.
065     * It is up to you to pass the 'WHERE' in your where clauses.
066     *
067     * @param where the restriction clause
068     * @return the number of rows returned
069     * @throws RuntimeDaoException
070     */
071    public int countWhere(String where)throws RuntimeDaoException;
072
073    //10
074    /**
075     * Deletes all rows from table.
076     * @return the number of deleted rows.
077     * @throws RuntimeDaoException
078     */
079    public int deleteAll()throws RuntimeDaoException;
080
081    //11
082    /**
083     * Deletes rows from the table using a 'where' clause.
084     * It is up to you to pass the 'WHERE' in your where clauses.
085     * <br>Attention, if 'WHERE' is omitted it will delete all records.
086     *
087     * @param where the sql 'where' clause
088     * @return the number of deleted rows
089     * @throws RuntimeDaoException
090     */
091    public int deleteByWhere(String where)throws RuntimeDaoException;
092
093    //21
094    /**
095     * Deletes rows using a template.
096     *
097     * @param bean the template object(s) to be deleted
098     * @return the number of deleted objects
099     * @throws RuntimeDaoException
100     */
101    public int deleteUsingTemplate(B bean)throws RuntimeDaoException;
102
103    //2.1
104    /**
105     * Delete row according to its primary keys.
106     *
107     * @param keys primary keys value<br>
108     *      for fd_face table<br>
109     *          PK# 1 fd_face.id type Integer<br>
110     *      for fd_feature table<br>
111     *          PK# 1 fd_feature.md5 type String<br>
112     *      for fd_image table<br>
113     *          PK# 1 fd_image.md5 type String<br>
114     *      for fd_store table<br>
115     *          PK# 1 fd_store.md5 type String<br>
116     * @return the number of deleted rows
117     * @throws RuntimeDaoException
118     */   
119    public int deleteByPrimaryKey(Object ...keys)throws RuntimeDaoException;
120
121    //2.2
122    /**
123     * Delete row according to primary keys of bean.<br>
124     * 
125     * @param bean will be deleted ,all keys must not be null
126     * @return the number of deleted rows,0 returned if bean is null
127     * @throws RuntimeDaoException
128     */
129    public int delete(B bean)throws RuntimeDaoException;
130
131    //2.4
132        /**
133         * Delete beans.<br>
134         *
135         * @param beans B array will be deleted
136         * @return the number of deleted rows
137         * @throws RuntimeDaoException
138         */
139    @SuppressWarnings("unchecked")
140        public int delete(B... beans)throws RuntimeDaoException;
141    
142    //2.5  
143        /**
144         * Delete beans.<br>
145         *
146         * @param beans B collection will be deleted
147         * @return the number of deleted rows
148         * @throws RuntimeDaoException
149         */
150        public int delete(Collection<B> beans)throws RuntimeDaoException;
151    //////////////////////////////////////
152    // LOAD ALL
153    //////////////////////////////////////
154
155    //5
156    /**
157     * Loads all the rows from table.
158     *
159     * @return an array of B bean
160     * @throws RuntimeDaoException
161     */
162    public B[] loadAll()throws RuntimeDaoException;
163
164    //5-1    
165    /**
166     * Loads each row from table and dealt with action.
167     * @param action  Action object for do something(not null)
168     * @return the count dealt by action
169     * @throws RuntimeDaoException
170     */
171    public int loadAll(Action<B> action)throws RuntimeDaoException;
172
173    //6
174    /**
175     * Loads the given number of rows from table, given the start row.
176     *
177     * @param startRow the start row to be used (first row = 1, last row = -1)
178     * @param numRows the number of rows to be retrieved (all rows = a negative number)
179     * @return an array of B bean
180     * @throws RuntimeDaoException
181     */
182    public B[] loadAll(int startRow, int numRows)throws RuntimeDaoException;
183
184    //6-1    
185    /**
186     *  Loads the given number of rows from table, given the start row and dealt with action.
187     * @param startRow the start row to be used (first row = 1, last row = -1)
188     * @param numRows the number of rows to be retrieved (all rows = a negative number)
189     * @param action  Action object for do something(not null)
190     * @return the count dealt by action
191     * @throws RuntimeDaoException
192     */
193    public int loadAll(int startRow, int numRows,Action<B> action)throws RuntimeDaoException;
194
195    //5-2
196    /**
197     * Loads all the rows from table.
198     *
199     * @return a list of B bean
200     * @throws RuntimeDaoException
201     */
202    public List<B> loadAllAsList()throws RuntimeDaoException;
203
204    //6-2
205    /**
206     * Loads the given number of rows from table, given the start row.
207     *
208     * @param startRow the start row to be used (first row = 1, last row = -1)
209     * @param numRows the number of rows to be retrieved (all rows = a negative number)
210     * @return a list of B bean
211     * @throws RuntimeDaoException
212     */
213    public List<B> loadAllAsList(int startRow, int numRows)throws RuntimeDaoException;
214
215    //1.2
216    /**
217     * Loads a B bean from the table using primary key fields of {@code bean}.
218     * @param bean the B bean with primary key fields
219     * @return a unique B or {@code null} if not found or bean is null
220     * @throws RuntimeDaoException
221     */
222    public B loadByPrimaryKey(B bean)throws RuntimeDaoException;
223    
224    //1.2.2
225    /**
226     * see also {@link #loadByPrimaryKey(BaseBean)} 
227     * @param bean
228     * @return a unique B ,otherwise throw exception
229     * @throws ObjectRetrievalException not found
230     * @throws RuntimeDaoException
231     */
232    public B loadByPrimaryKeyChecked(B bean)throws RuntimeDaoException,ObjectRetrievalException;
233    //1.3
234    /**
235     * Loads a B bean from the table using primary key fields.
236     * when you don't know which is primary key of table,you can use the method.
237     * @param keys primary keys value:<br> 
238     *      for fd_face table<br>
239     *          PK# 1 fd_face.id type Integer<br>
240     *      for fd_feature table<br>
241     *          PK# 1 fd_feature.md5 type String<br>
242     *      for fd_image table<br>
243     *          PK# 1 fd_image.md5 type String<br>
244     *      for fd_store table<br>
245     *          PK# 1 fd_store.md5 type String<br>
246     * @return a unique B or {@code null} if not found
247     * @throws RuntimeDaoException
248     */
249    public B loadByPrimaryKey(Object ...keys)throws RuntimeDaoException;
250
251    //1.3.2
252    /**
253     * see also {@link #loadByPrimaryKey(Object...)}
254     * @param keys
255     * @return a unique B,otherwise throw exception
256     * @throws ObjectRetrievalException not found
257     * @throws RuntimeDaoException
258     */
259    public B loadByPrimaryKeyChecked(Object ...keys)throws RuntimeDaoException,ObjectRetrievalException;
260    
261    //1.5
262    /**
263     * Returns true if this table contains row with primary key fields.
264     * @param keys primary keys value
265     * @see #loadByPrimaryKey(Object...)
266     * @return 
267     * @throws RuntimeDaoException
268     */
269    public boolean existsPrimaryKey(Object ...keys)throws RuntimeDaoException;
270    
271    //1.6
272    /**
273     * Returns true if this table contains row specified by primary key fields of B.<br>
274     * when you don't know which is primary key of table,you can use the method.
275     * @param bean the B bean with primary key fields
276     * @return 
277     * @see #loadByPrimaryKey(BaseBean)
278     * @throws RuntimeDaoException
279     */
280    public boolean existsByPrimaryKey(B bean)throws RuntimeDaoException;
281    //1.7
282    /**
283     * Check duplicated row by primary keys,if row exists throw exception
284     * @param bean the B bean with primary key fields
285     * @return always bean
286     * @see #existsByPrimaryKey(BaseBean)
287     * @throws ObjectRetrievalException has duplicated record
288     * @throws RuntimeDaoException
289     */
290    public B checkDuplicate(B bean)throws RuntimeDaoException,ObjectRetrievalException;
291   
292    //////////////////////////////////////
293    // SQL 'WHERE' METHOD
294    //////////////////////////////////////
295    //7 
296    /**
297     * Retrieves an array of B given a sql 'where' clause.
298     *
299     * @param where the sql 'where' clause
300     * @return 
301     * @throws RuntimeDaoException
302     */
303    public B[] loadByWhere(String where)throws RuntimeDaoException;
304    
305    //7-1
306    /**
307     * Retrieves each row of B bean given a sql 'where' clause and dealt with action.
308     * @param where the sql 'where' clause
309     * @param action  Action object for do something(not null)
310     * @return the count dealt by action
311     * @throws RuntimeDaoException
312     */
313    public int loadByWhere(String where,Action<B> action)throws RuntimeDaoException;
314
315    //8
316    /**
317     * Retrieves an array of B bean given a sql where clause, and a list of fields.
318     * It is up to you to pass the 'WHERE' in your where clauses.
319     *
320     * @param where the sql 'WHERE' clause
321     * @param fieldList array of field's ID
322     * @return 
323     * @throws RuntimeDaoException
324     */
325    public B[] loadByWhere(String where, int[] fieldList)throws RuntimeDaoException;
326   
327    //8-1 
328    /**
329     * Retrieves each row of B bean given a sql where clause, and a list of fields,
330     * and dealt with action.
331     * It is up to you to pass the 'WHERE' in your where clauses.
332     * @param where the sql 'WHERE' clause
333     * @param fieldList array of field's ID
334     * @param action Action object for do something(not null)
335     * @return the count dealt by action
336     * @throws RuntimeDaoException
337     */
338    public int loadByWhere(String where, int[] fieldList,Action<B> action)throws RuntimeDaoException;
339
340    //9
341    /**
342     * Retrieves an array of B bean given a sql where clause and a list of fields, and startRow and numRows.
343     * It is up to you to pass the 'WHERE' in your where clauses.
344     *
345     * @param where the sql 'where' clause
346     * @param fieldList table of the field's associated constants
347     * @param startRow the start row to be used (first row = 1, last row = -1)
348     * @param numRows the number of rows to be retrieved (all rows = a negative number)
349     * @return 
350     * @throws RuntimeDaoException
351     */
352    public B[] loadByWhere(String where, int[] fieldList, int startRow, int numRows)throws RuntimeDaoException;
353
354    //9-1    
355    /**
356     * Retrieves each row of B bean given a sql where clause and a list of fields, and startRow and numRows,
357     * and dealt with action.
358     * It is up to you to pass the 'WHERE' in your where clauses.
359     *
360     * @param where the sql 'where' clause
361     * @param fieldList table of the field's associated constants
362     * @param startRow the start row to be used (first row = 1, last row = -1)
363     * @param numRows the number of rows to be retrieved (all rows = a negative number)
364     * @param action Action object for do something(not null)
365     * @return the count dealt by action
366     * @throws RuntimeDaoException
367     */
368    public int loadByWhere(String where, int[] fieldList, int startRow, int numRows,Action<B> action)throws RuntimeDaoException;
369    //7
370    /**
371     * Retrieves a list of B bean given a sql 'where' clause.
372     *
373     * @param where the sql 'where' clause
374     * @return
375     * @throws RuntimeDaoException
376     */
377    public List<B> loadByWhereAsList(String where)throws RuntimeDaoException;
378
379    //8
380    /**
381     * Retrieves a list of B bean given a sql where clause, and a list of fields.
382     * It is up to you to pass the 'WHERE' in your where clauses.
383     *
384     * @param where the sql 'WHERE' clause
385     * @param fieldList array of field's ID
386     * @return
387     * @throws RuntimeDaoException
388     */
389    public List<B> loadByWhereAsList(String where, int[] fieldList)throws RuntimeDaoException;
390    
391    //9-2
392    /**
393     * Retrieves a list of B bean given a sql where clause and a list of fields, and startRow and numRows.
394     * It is up to you to pass the 'WHERE' in your where clauses.
395     *
396     * @param where the sql 'where' clause
397     * @param fieldList table of the field's associated constants
398     * @param startRow the start row to be used (first row = 1, last row = -1)
399     * @param numRows the number of rows to be retrieved (all rows = a negative number)
400     * @return
401     * @throws RuntimeDaoException
402     */
403    public List<B> loadByWhereAsList(String where, int[] fieldList, int startRow, int numRows)throws RuntimeDaoException;
404
405    //9-3
406    /**
407     * Retrieves each row of B bean given a sql where clause and a list of fields, and startRow and numRows,
408     * and dealt wity action
409     * It is up to you to pass the 'WHERE' in your where clauses.
410     *
411     * @param where the sql 'where' clause
412     * @param fieldList table of the field's associated constants
413     * @param startRow the start row to be used (first row = 1, last row = -1)
414     * @param numRows the number of rows to be retrieved (all rows = a negative number)
415     * @param action Action object for do something(not null)
416     * @return the count dealt by action
417     * @throws RuntimeDaoException
418     */
419    public int loadByWhereForAction(String where, int[] fieldList, int startRow, int numRows,Action<B> action)throws RuntimeDaoException;
420
421    //_____________________________________________________________________
422    //
423    // USING TEMPLATE
424    //_____________________________________________________________________
425    //18   
426    /**
427     * Loads a unique B bean from a template one giving a c
428     *
429     * @param bean the B bean to look for
430     * @return the bean matching the template,or {@code null} if not found or null input argument
431     * @throws ObjectRetrievalException more than one row
432     * @throws RuntimeDaoException
433     */
434    public B loadUniqueUsingTemplate(B bean)throws RuntimeDaoException;
435
436    //18-1
437    /**
438     * Loads a unique B bean from a template one giving a c
439     *
440     * @param bean the B bean to look for
441     * @return the bean matching the template
442     * @throws ObjectRetrievalException not found or more than one row
443     * @throws RuntimeDaoException
444     */
445    public B loadUniqueUsingTemplateChecked(B bean)throws RuntimeDaoException,ObjectRetrievalException;
446
447    //19
448    /**
449     * Loads an array of B from a template one.
450     *
451     * @param bean the B bean template to look for
452     * @return all the B beans matching the template
453     * @throws RuntimeDaoException
454     */
455    public B[] loadUsingTemplate(B bean)throws RuntimeDaoException;
456    
457    //19-1
458    /**
459     * Loads each row from a template one and dealt with action.
460     *
461     * @param bean the B bean template to look for
462     * @param action Action object for do something(not null)
463     * @return the count dealt by action
464     * @throws RuntimeDaoException
465     */
466    public int loadUsingTemplate(B bean,Action<B> action)throws RuntimeDaoException;
467
468    //20
469    /**
470     * Loads an array of B bean from a template one, given the start row and number of rows.
471     *
472     * @param bean the B bean template to look for
473     * @param startRow the start row to be used (first row = 1, last row=-1)
474     * @param numRows the number of rows to be retrieved (all rows = a negative number)
475     * @return all the B matching the template
476     * @throws RuntimeDaoException
477     */
478    public B[] loadUsingTemplate(B bean, int startRow, int numRows)throws RuntimeDaoException;
479    
480    //20-1
481    /**
482     * Loads each row from a template one, given the start row and number of rows and dealt with action.
483     *
484     * @param bean the B bean template to look for
485     * @param startRow the start row to be used (first row = 1, last row=-1)
486     * @param numRows the number of rows to be retrieved (all rows = a negative number)
487     * @param action Action object for do something(not null)
488     * @return the count dealt by action
489     * @throws RuntimeDaoException
490     */
491    public int loadUsingTemplate(B bean, int startRow, int numRows,Action<B> action)throws RuntimeDaoException;
492
493    //20-5
494    /**
495     * Loads each row from a template one, given the start row and number of rows and dealt with action.
496     *
497     * @param bean the B template to look for
498     * @param fieldList table of the field's associated constants
499     * @param startRow the start row to be used (first row = 1, last row=-1)
500     * @param numRows the number of rows to be retrieved (all rows = a negative number)
501     * @param searchType exact ?  like ? starting like ? ending link ? <br>
502     *                {@value Constant#SEARCH_EXACT}   {@link Constant#SEARCH_EXACT} <br>
503     *                {@value Constant#SEARCH_LIKE}   {@link Constant#SEARCH_LIKE} <br>
504     *                {@value Constant#SEARCH_STARTING_LIKE}   {@link Constant#SEARCH_STARTING_LIKE} <br>
505     *                {@value Constant#SEARCH_ENDING_LIKE}   {@link Constant#SEARCH_ENDING_LIKE} <br>  
506     * @param action Action object for do something(not null)
507     * @return the count dealt by action
508     * @throws RuntimeDaoException
509     */
510    public int loadUsingTemplate(B bean, int[] fieldList, int startRow, int numRows,int searchType, Action<B> action)throws RuntimeDaoException;
511    //20-4
512    /**
513     * Loads a list of B bean from a template one, given the start row and number of rows.
514     *
515     * @param bean the B bean template to look for
516     * @param startRow the start row to be used (first row = 1, last row=-1)
517     * @param numRows the number of rows to be retrieved (all rows = a negative number)
518     * @param searchType exact ?  like ? starting like ? ending link ? <br>
519     *                {@value Constant#SEARCH_EXACT}   {@link Constant#SEARCH_EXACT} <br>
520     *                {@value Constant#SEARCH_LIKE}   {@link Constant#SEARCH_LIKE} <br>
521     *                {@value Constant#SEARCH_STARTING_LIKE}   {@link Constant#SEARCH_STARTING_LIKE} <br>
522     *                {@value Constant#SEARCH_ENDING_LIKE}   {@link Constant#SEARCH_ENDING_LIKE} <br>  
523     * @return all the B bean matching the template
524     * @throws RuntimeDaoException
525     */
526    public B[] loadUsingTemplate(B bean, int startRow, int numRows, int searchType)throws RuntimeDaoException;
527
528    //19-2
529    /**
530     * Loads a list of B bean from a template one.
531     *
532     * @param bean the B bean template to look for
533     * @return all the B beans matching the template
534     * @throws RuntimeDaoException
535     */
536    public List<B> loadUsingTemplateAsList(B bean)throws RuntimeDaoException;
537
538    //20-2
539    /**
540     * Loads a list of B bean from a template one, given the start row and number of rows.
541     *
542     * @param bean the B bean template to look for
543     * @param startRow the start row to be used (first row = 1, last row=-1)
544     * @param numRows the number of rows to be retrieved (all rows = a negative number)
545     * @return all the B bean matching the template
546     * @throws RuntimeDaoException
547     */
548    public List<B> loadUsingTemplateAsList(B bean, int startRow, int numRows)throws RuntimeDaoException;
549
550    //20-3
551    /**
552     * Loads an array of B bean from a template one, given the start row and number of rows.
553     *
554     * @param bean the B bean template to look for
555     * @param startRow the start row to be used (first row = 1, last row=-1)
556     * @param numRows the number of rows to be retrieved (all rows = a negative number)
557     * @param searchType exact ?  like ? starting like ? ending link? <br>
558     *                {@value Constant#SEARCH_EXACT}   {@link Constant#SEARCH_EXACT} <br>
559     *                {@value Constant#SEARCH_LIKE}   {@link Constant#SEARCH_LIKE} <br>
560     *                {@value Constant#SEARCH_STARTING_LIKE}   {@link Constant#SEARCH_STARTING_LIKE} <br>
561     *                {@value Constant#SEARCH_ENDING_LIKE}   {@link Constant#SEARCH_ENDING_LIKE} <br>  
562     * @return all the B beans matching the template
563     * @throws RuntimeDaoException
564     */
565    public List<B> loadUsingTemplateAsList(B bean, int startRow, int numRows, int searchType)throws RuntimeDaoException;
566
567    //_____________________________________________________________________
568    //
569    // USING INDICES
570    //_____________________________________________________________________    
571    /**
572     * Retrieves a array of B bean using the index specified by keyIndex.
573     * @param indexName name of index
574     * @param indexValues key values of index
575     * @return B array
576     * @throws RuntimeDaoException
577     * @see #loadByIndexAsList(int ,Object ...)
578     */
579    public B[] loadByIndex(String indexName,Object ...indexValues)throws RuntimeDaoException;
580    
581    /**
582     * Retrieves a list of B bean using the index specified by indexName.
583     * @param indexName name of index<br>
584     * @param indexValues key values of index
585     * @return a list of B bean
586     * @throws RuntimeDaoException
587     */
588    public List<B> loadByIndexAsList(String indexName,Object ...indexValues)throws RuntimeDaoException;
589        
590    public B loadUniqueByIndex(String indexName,Object ...indexValues)throws RuntimeDaoException;
591    public B loadUniqueByIndexChecked(String indexName,Object ...indexValues)throws ObjectRetrievalException;
592    /**
593     * Deletes rows using key.
594     * @param indexName name of index
595     * @param indexValues key values of index
596     * @return the number of deleted objects
597     * @throws RuntimeDaoException
598     */
599    public int deleteByIndex(String indexName,Object ...indexValues)throws RuntimeDaoException;
600    //_____________________________________________________________________
601    //
602    // LISTENER
603    //_____________________________________________________________________
604
605    //35
606    /**
607     * Registers a unique {@link TableListener} listener.<br>
608     * do nothing if {@code TableListener} instance exists
609     * @param listener
610     * @return 
611     */
612    public TableListener<B> registerListener(TableListener<B> listener);
613
614    //36
615    /**
616     * remove listener.
617     * @param listener 
618     */
619    public void unregisterListener(TableListener<B> listener);
620
621    //_____________________________________________________________________
622    //
623    // SAVE
624    //_____________________________________________________________________
625    //12
626    /**
627     * Saves the B bean into the database.
628     *
629     * @param bean the B bean to be saved
630     * @return the inserted or updated bean,or null if bean is null
631     * @throws RuntimeDaoException
632     */
633    public B save(B bean)throws RuntimeDaoException;
634
635    //15
636    /**
637     * Saves an array of B bean into the database.
638     *
639     * @param beans the array of  B bean to be saved
640     * @return always beans saved
641     * @throws RuntimeDaoException
642     */
643    public B[] save(B[] beans)throws RuntimeDaoException;
644    
645    //15-2
646    /**
647     * Saves a collection of B bean into the database.
648     *
649     * @param beans the B bean table to be saved
650     * @return alwarys beans saved
651     * @throws RuntimeDaoException
652     */
653    public <C extends Collection<B>> C saveAsTransaction(C beans)throws RuntimeDaoException;
654    
655    //15-3
656    /**
657     * Saves an array of B bean into the database as transaction.
658     *
659     * @param beans the B bean table to be saved
660     * @return alwarys beans saved
661     * @see #save(BaseBean[])
662     * @throws RuntimeDaoException
663     */
664    public B[] saveAsTransaction(B[] beans)throws RuntimeDaoException;
665
666    //15-4
667    /**
668     * Saves a collection of B bean into the database as transaction.
669     *
670     * @param beans the B bean table to be saved
671     * @return alwarys beans saved
672     * @throws RuntimeDaoException
673     */
674    public <C extends Collection<B>> C save(C beans)throws RuntimeDaoException;
675
676    //3.9 SYNC SAVE 
677    /**
678     * Save the B bean and referenced beans and imported beans into the database.
679     *
680     * @param bean the B bean to be saved
681     * @param referenceBeans referenced beans beans<br>
682     * @param importedBeans imported beans <br>
683     * @return the inserted or updated B bean
684      * @throws RuntimeDaoException
685     */
686    public B save(B bean,Map<String, BaseBean> referenceBeans,Map<String, Collection<BaseBean>> importedBeans)throws RuntimeDaoException;
687    
688    //3.11 SYNC SAVE 
689    /**
690     *  Transaction version for sync save
691     * @see #save(BaseBean ,Map,Map)
692     * @param bean the B bean to be saved
693     * @param referenceBeans referenced beans beans<br>
694     * @param importedBeans imported beans <br>
695     * @return the inserted or updated B bean
696     * @throws RuntimeDaoException
697     */
698    public B saveAsTransaction(B bean,Map<String, BaseBean> referenceBeans,Map<String, Collection<BaseBean>> importedBeans)throws RuntimeDaoException;
699    
700    /**
701     * Load column from table.
702     * @param column column name or java file name of B
703     * @param distinct select distinct values
704     * @param where the sql 'where' clause
705     * @param startRow the start row to be used (first row = 1, last row = -1)
706     * @param numRows the number of rows to be retrieved (all rows = a negative number)
707     * @return an list of column
708     * @throws RuntimeDaoException
709     */
710    public <T>List<T> loadColumnAsList(String column,boolean distinct,String where,int startRow,int numRows)throws RuntimeDaoException;
711
712        /**
713     * Retrieves the T object referenced by fkName.<br>
714     * @param <T>
715     * @param bean the B object to use
716     * @param fkName foreign key name.<br>
717     * @return the associated T bean or {@code null} if {@code bean}  is {@code null}
718     * @throws RuntimeDaoException
719     */
720    public <T extends BaseBean> T getReferencedBean(B bean,String fkName)throws RuntimeDaoException;
721    
722    /**
723     * Associates the B object to the T object by fkName field.<br>
724     * @param <T> see also {@link #getReferencedBean(BaseBean, String)}
725     * @param bean the B object to use
726     * @param beanToSet the T object to associate to the B bean
727     * @param fkName see also {@link #getReferencedBean(BaseBean, String)}
728     * @return always beanToSet saved
729     * @throws RuntimeDaoException
730     */
731    public <T extends BaseBean> T setReferencedBean(B bean,T beanToSet,String fkName)throws RuntimeDaoException;
732    
733    /**
734     * Retrieves imported T objects by fkIndex.<br>
735     * @param <T>
736     * @param bean the B object to use
737     * @param fkName foreign key name.<br>
738     * @return the associated T beans or {@code null} if {@code bean} is {@code null}
739     * @throws RuntimeDaoException
740     */
741    public <T extends BaseBean> T[] getImportedBeans(B bean,String fkName)throws RuntimeDaoException;
742    
743    /**
744     * Retrieves imported T objects by ikIndex.<br>
745     * @param <T> see also {@link #getImportedBeans(BaseBean, String)}
746     * @param bean the B object to use
747     * @param fkname foreign key name.see also {@link #getImportedBeans(BaseBean, String)}
748     * @return the associated T beans or {@code null} if {@code bean} is {@code null}
749     * @throws RuntimeDaoException
750     */
751    public <T extends BaseBean> List<T> getImportedBeansAsList(B bean,String fkname)throws RuntimeDaoException;
752    
753    
754    /**
755     * Set the importedBeans associates to the bean by {@code ikIndex}<br>
756     * 
757     * @param <T> see also {@link #getImportedBeans(BaseBean, String)}
758     * @param bean the bean object to use
759     * @param importedBeans the T object to associate to bean
760     * @param fkName foreign key name.see also {@link #getImportedBeans(BaseBean, String)}
761     * @return importedBeans always
762     * @throws RuntimeDaoException
763     */
764    public <T extends BaseBean> T[] setImportedBeans(B bean,T[] importedBeans,String fkName)throws RuntimeDaoException;
765    
766    /**
767     * Set the importedBeans associates to the bean by fkIndex<br>
768     * 
769     * @param <T> see also {@link #getImportedBeans(BaseBean, String)}
770     * @param bean the bean object to use
771     * @param importedBeans the T object to associate to bean
772     * @param fkName foreign key name. see also {@link #getImportedBeans(BaseBean, String)}
773     * @return importedBeans always
774     * @throws RuntimeDaoException
775     */
776    public <T extends BaseBean,C extends Collection<T>> C setImportedBeans(B bean,C importedBeans,String fkName)throws RuntimeDaoException;
777
778    /**
779     * delete all imported beans by fkName 
780     * @param bean 
781     * @param fkName foreign key name
782     * @return deleted row count  
783     */
784    public int deleteImportedBeans(B bean,String fkName)throws RuntimeDaoException;
785}