001// ______________________________________________________
002// Generated by sql2java - https://github.com/10km/sql2java-2-6-7 (custom branch) 
003// modified by guyadong from
004// sql2java original version https://sourceforge.net/projects/sql2java/ 
005// JDBC driver used at code generation time: com.mysql.jdbc.Driver
006// template: table.manager.java.vm
007// ______________________________________________________
008package net.gdface.facelog.db;
009import java.util.List;
010import java.util.LinkedList;
011import java.lang.reflect.Array;
012import java.util.ArrayList;
013import java.util.Collection;
014import java.util.concurrent.Callable;
015import net.gdface.facelog.db.exception.RuntimeDaoException;
016import net.gdface.facelog.db.exception.ObjectRetrievalException;
017/**
018 * Interface to handle database calls (save, load, count, etc...) for table.
019 * @author guyadong
020 */
021public interface TableManager<B extends BaseBean<?>> extends Constant {
022
023    public interface Action<B>{
024        public abstract class BaseAdapter<B> implements Action<B>{
025            @Override
026            public B getBean() {return null;}            
027        }
028        /**
029         * do action for {@code bean}
030         * @param bean input bean
031         * @throws RuntimeDaoException
032         */
033        void call(B bean)throws RuntimeDaoException;
034        /**
035         * return a B instance
036         * @return B bean
037         */
038        B getBean();
039    }
040    public abstract static class BaseAdapter<B extends BaseBean<B>> implements TableManager<B>{
041        /**
042         * return the B bean class
043         * @return 
044         */
045        protected abstract Class<B> beanType();
046        /**
047         * @param columnId column id
048         * @return table column name,or NULL if columnId is invalid 
049         */
050        protected abstract String columnNameOf(int columnId);
051
052        //13
053        /**
054         * Insert the B bean into the database.
055         * 
056         * @param bean the B bean to be saved
057         * @return the inserted bean
058         * @throws RuntimeDaoException
059         */
060        protected abstract B insert(B bean)throws RuntimeDaoException;
061        //14
062        /**
063         * Update the B bean record in the database according to the changes.
064         *
065         * @param bean the B bean to be updated
066         * @return the updated bean
067         * @throws RuntimeDaoException
068         */
069        protected abstract B update(B bean)throws RuntimeDaoException;
070        
071        public class ListAction implements Action<B> {
072            final List<B> list;
073            public ListAction() {
074                list=new LinkedList<B>();
075            }
076
077            public List<B> getList() {
078                return list;
079            }
080
081            @Override
082            public void call(B bean) {
083                list.add(bean);
084            }
085
086            @Override
087            public B getBean() {
088                return null;
089            }
090        }
091        @Override
092        public int countAll()throws RuntimeDaoException{
093            return this.countWhere("");
094        }
095
096        @Override
097        public int countUsingTemplate(B bean)throws RuntimeDaoException{
098            return this.countUsingTemplate(bean, SEARCH_EXACT);
099        }
100
101        @Override
102        public int deleteAll()throws RuntimeDaoException{
103            return this.deleteByWhere("");
104        }
105
106
107        @Override
108        public B[] loadAll()throws RuntimeDaoException{
109            return this.loadUsingTemplate(null, 1, -1, SEARCH_EXACT);
110        }
111
112        @Override
113        public int loadAll(Action<B> action)throws RuntimeDaoException{
114            return this.loadUsingTemplate(null,null,1,-1, SEARCH_EXACT, action);
115        }
116
117        @Override
118        public B[] loadAll(int startRow, int numRows)throws RuntimeDaoException{
119            return this.loadUsingTemplate(null, startRow, numRows, SEARCH_EXACT);
120        }
121
122        @Override
123        public int loadAll(int startRow, int numRows, Action<B> action)throws RuntimeDaoException{
124            return this.loadUsingTemplate(null, null, startRow, numRows, SEARCH_EXACT, action);
125        }
126
127        @Override
128        public List<B> loadAllAsList()throws RuntimeDaoException{
129            return this.loadUsingTemplateAsList(null,1, -1, SEARCH_EXACT);
130        }
131
132        @Override
133        public List<B> loadAllAsList(int startRow, int numRows)throws RuntimeDaoException{
134            return this.loadUsingTemplateAsList(null, startRow, numRows, SEARCH_EXACT);
135        }
136
137        @Override
138        public boolean existsByPrimaryKey(B bean)throws RuntimeDaoException{
139            return null!=loadByPrimaryKey(bean);
140        }
141        @Override
142        public B checkDuplicate(B bean)throws RuntimeDaoException,ObjectRetrievalException{
143            throw new UnsupportedOperationException();
144        }
145        @Override
146        public boolean existsPrimaryKey(Object ...keys)throws RuntimeDaoException{
147            return null!=loadByPrimaryKey(keys);
148        }
149        
150        @Override
151        public B[] loadByWhere(String where)throws RuntimeDaoException{
152            return this.loadByWhere(where, (int[])null);
153        }
154
155        @Override
156        public int loadByWhere(String where, Action<B> action)throws RuntimeDaoException{
157            return this.loadByWhere(where, null, action);
158        }
159
160        @Override
161        public B[] loadByWhere(String where, int[] fieldList)throws RuntimeDaoException{
162            return this.loadByWhere(where, fieldList, 1, -1);
163        }
164
165        @Override
166        public int loadByWhere(String where, int[] fieldList, Action<B> action)throws RuntimeDaoException{
167            return this.loadByWhere(where, fieldList, 1, -1, action);
168        }
169
170        @SuppressWarnings("unchecked")
171        @Override
172        public B[] loadByWhere(String where, int[] fieldList, int startRow, int numRows)throws RuntimeDaoException{
173            return this.loadByWhereAsList(where, fieldList, startRow, numRows).toArray((B[])Array.newInstance(beanType(),0));
174        }
175
176        @Override
177        public int loadByWhere(String where, int[] fieldList, int startRow, int numRows,
178                Action<B> action)throws RuntimeDaoException{
179            return this.loadByWhereForAction(where, fieldList, startRow, numRows, action);
180        }
181
182        @Override
183        public List<B> loadByWhereAsList(String where)throws RuntimeDaoException{
184            return this.loadByWhereAsList(where, null, 1, -1);
185        }
186
187        @Override
188        public List<B> loadByWhereAsList(String where, int[] fieldList)throws RuntimeDaoException{
189            return this.loadByWhereAsList(where, fieldList, 1, -1);
190        }
191
192        @Override
193        public List<B> loadByWhereAsList(String where, int[] fieldList, int startRow, int numRows)throws RuntimeDaoException{
194            ListAction action = new ListAction();
195            loadByWhereForAction(where, fieldList, startRow, numRows, action);              
196            return action.getList();
197        }
198    
199        @Override
200        public int loadByWhereForAction(String where, int[] fieldList, int startRow, int numRows,Action<B> action)throws RuntimeDaoException{
201            String sql=createSelectSql(fieldList, where);
202            // System.out.println("loadByWhere: " + sql);
203            return this.loadBySqlForAction(sql, null, fieldList, startRow, numRows, action);
204        }
205    
206        @Override
207        public B[] loadUsingTemplate(B bean)throws RuntimeDaoException{
208            return this.loadUsingTemplate(bean, 1, -1, SEARCH_EXACT);
209        }
210
211        @Override
212        public int loadUsingTemplate(B bean, Action<B> action)throws RuntimeDaoException{
213            return this.loadUsingTemplate(bean, null, 1, -1, SEARCH_EXACT, action);
214        }
215
216        @Override
217        public B[] loadUsingTemplate(B bean, int startRow, int numRows)throws RuntimeDaoException{
218            return this.loadUsingTemplate(bean, startRow, numRows, SEARCH_EXACT);
219        }
220
221        @Override
222        public int loadUsingTemplate(B bean, int startRow, int numRows,
223                Action<B> action)throws RuntimeDaoException{
224            return this.loadUsingTemplate(bean, null, startRow, numRows,SEARCH_EXACT, action);
225        }
226
227        @SuppressWarnings("unchecked")
228        @Override
229        public B[] loadUsingTemplate(B bean, int startRow, int numRows, int searchType)throws RuntimeDaoException{
230            return this.loadUsingTemplateAsList(bean, startRow, numRows, searchType).toArray((B[])Array.newInstance(beanType(),0));
231        }
232
233        @Override
234        public List<B> loadUsingTemplateAsList(B bean)throws RuntimeDaoException{
235            return this.loadUsingTemplateAsList(bean, 1, -1, SEARCH_EXACT);
236        }
237
238        @Override
239        public List<B> loadUsingTemplateAsList(B bean, int startRow, int numRows)throws RuntimeDaoException{
240            return this.loadUsingTemplateAsList(bean, startRow, numRows, SEARCH_EXACT);
241        }
242
243        @Override
244        public List<B> loadUsingTemplateAsList(B bean, int startRow, int numRows, int searchType)throws RuntimeDaoException{
245            ListAction action = new ListAction();
246            loadUsingTemplate(bean,null,startRow,numRows,searchType, action);
247            return action.getList();
248        }
249        
250        @Override
251        public B save(B bean)throws RuntimeDaoException{
252            if(null != bean){
253                if (bean.isNew()) {
254                    this.insert(bean);
255                } else {
256                    this.update(bean);
257                }
258            }
259            return bean;
260        }
261        
262        @Override
263        public B[] save(B[] beans)throws RuntimeDaoException{
264            if(null != beans){
265                for (B bean : beans) 
266                {
267                    this.save(bean);
268                }
269            }
270            return beans;
271        }
272
273        @Override
274        public <C extends Collection<B>> C save(C beans)throws RuntimeDaoException{
275            if(null != beans){
276                for (B bean : beans) 
277                {
278                    this.save(bean);
279                }
280            }
281            return beans;
282        }
283        
284        @Override
285        public <C extends Collection<B>> C saveAsTransaction(final C beans)throws RuntimeDaoException{
286            return this.runAsTransaction(new Callable<C>(){
287                @Override
288                public C call() throws Exception {
289                    return save(beans);
290                }});
291        }
292
293        @Override
294        public B[] saveAsTransaction(final B[] beans)throws RuntimeDaoException{
295            return this.runAsTransaction(new Callable<B[]>(){
296                @Override
297                public B[] call() throws Exception {
298                    return save(beans);
299                }});
300        }
301
302        @SuppressWarnings("unchecked")
303        @Override
304        public B[] loadBySql(String sql, Object[] argList, int[] fieldList)throws RuntimeDaoException{
305            return loadBySqlAsList(sql, argList, fieldList).toArray((B[])Array.newInstance(beanType(),0));
306        }
307
308        @Override
309        public List<B> loadBySqlAsList(String sql, Object[] argList, int[] fieldList)throws RuntimeDaoException{
310            ListAction action = new ListAction();
311            loadBySqlForAction(sql,argList,fieldList,1,-1,action);
312            return action.getList();
313        }
314        
315        @Override
316        public <T> List<T> loadColumnAsList(String column,boolean distinct,String where,int startRow,int numRows)throws RuntimeDaoException{
317            int columnId = columnIDOf(column);
318            if(columnId < 0){
319                throw new IllegalArgumentException(String.format("INVALID column name %s",column));
320            }
321            String fieldName = columnNameOf(columnId);
322            String sql = String.format("SELECT %s " + fieldName + " from %s %s",
323                    distinct ? "DISTINCT" : "",
324                    getTableName(),
325                    where == null ? "" : where);
326            ListAction action = new ListAction();
327            loadBySqlForAction(sql, null, new int[]{columnId}, startRow, numRows, action);
328            List<B> beans = action.getList();
329            List<T> values=new ArrayList<>(beans.size());
330            T v;
331            B b;
332            for(int i = 0 ; i < beans.size(); ++ i){
333                if((b = beans.get(i)) != null && (v = b.<T>getValue(columnId)) != null){
334                    values.add(v);
335                }
336            }
337            return values;
338        }
339        /**
340         * generate SQL query(SELECT) statement,such as: 'SELECT id,name from mytable WHERE id=1'
341         * @param fieldList
342         * @param where where condition expression statement that start with 'WHERE',or {@code null},or empty string
343         * @return SQL statement string
344         * @throws IllegalArgumentException where condition expression don't start with 'WHERE'
345         */
346        protected String createSelectSql(int[] fieldList, String where){
347            StringBuffer sql = new StringBuffer(128);
348            String fullFields = this.getFullFields();
349            if(null == fieldList || 0 == fieldList.length) {
350                sql.append("SELECT ").append(fullFields);
351            } else{
352                sql.append("SELECT ");
353                String[] names=fullFields.split(",");
354                for(int i = 0; i < fieldList.length; ++i){
355                    if(i > 0) {
356                        sql.append(",");
357                    }
358                    sql.append(names[fieldList[i]]);
359                }      
360            }
361            sql.append(" FROM " + this.getTableName() + " ");
362            if(null != where && where.length() > 0){
363                if( ! where.trim().toUpperCase().startsWith("WHERE")){
364                    throw new IllegalArgumentException("WHERE expression must start with 'WHERE'(case insensitive):[" + where + "]");
365                }
366                sql.append(where);
367            }
368            return sql.toString();
369        }
370
371        @Override
372        public int delete(B bean)throws RuntimeDaoException{
373            throw new UnsupportedOperationException();
374        }
375        
376        @Override
377        public <T extends BaseBean<T>> T getReferencedBean(B bean, int fkIndex)throws RuntimeDaoException{
378            throw new UnsupportedOperationException();
379        }
380
381        @Override
382        public <T extends BaseBean<T>> T setReferencedBean(B bean, T beanToSet, int fkIndex)throws RuntimeDaoException{
383            throw new UnsupportedOperationException();
384        }
385
386        @Override
387        public <T extends BaseBean<T>> T[] getImportedBeans(B bean, int ikIndex)throws RuntimeDaoException{
388            throw new UnsupportedOperationException();
389        }
390
391        @Override
392        public <T extends BaseBean<T>> List<T> getImportedBeansAsList(B bean, int ikIndex)throws RuntimeDaoException{
393            throw new UnsupportedOperationException();
394        }
395
396        @Override
397        public <T extends BaseBean<T>> T[] setImportedBeans(B bean, T[] importedBeans, int ikIndex)throws RuntimeDaoException{
398            throw new UnsupportedOperationException();
399        }
400
401        @Override
402        public <T extends BaseBean<T>, C extends Collection<T>> C setImportedBeans(B bean, C importedBeans,
403                int ikIndex)throws RuntimeDaoException{
404            throw new UnsupportedOperationException();
405        }
406
407        @Override
408        public B loadByPrimaryKey(B bean)throws RuntimeDaoException{
409            throw new UnsupportedOperationException();
410        }
411        @Override
412        public B loadByPrimaryKeyChecked(B bean)throws RuntimeDaoException,ObjectRetrievalException{
413            throw new UnsupportedOperationException();
414        }
415        @Override
416        public B loadByPrimaryKey(Object ...keys)throws RuntimeDaoException{
417            throw new UnsupportedOperationException();
418        }
419        @Override
420        public B loadByPrimaryKeyChecked(Object ...keys)throws RuntimeDaoException,ObjectRetrievalException{
421            throw new UnsupportedOperationException();
422        }
423        @Override
424        public int deleteByPrimaryKey(Object ...keys)throws RuntimeDaoException{
425            throw new UnsupportedOperationException();
426        }
427        
428        @SuppressWarnings("unchecked")
429        @Override
430        public B[] loadByIndex(int keyIndex,Object ...keys)throws RuntimeDaoException{
431            return this.loadByIndexAsList(keyIndex,keys).toArray((B[])Array.newInstance(beanType(),0));
432        }
433        
434        @Override
435        public List<B> loadByIndexAsList(int keyIndex,Object ...keys)throws RuntimeDaoException{
436            throw new UnsupportedOperationException();
437        }
438        
439        @Override
440        public int deleteByIndex(int keyIndex,Object ...keys)throws RuntimeDaoException{
441            throw new UnsupportedOperationException();
442        }
443        
444        @Override
445        public B save(B bean,Object ...args)throws RuntimeDaoException{
446            throw new UnsupportedOperationException();
447        }
448        
449        @Override
450        public B saveCollection(B bean,Object ...args)throws RuntimeDaoException{
451            throw new UnsupportedOperationException();
452        }
453        
454        @Override
455        public B saveAsTransaction(final B bean,final Object ...args)throws RuntimeDaoException{
456            return this.runAsTransaction(new Callable<B>(){
457                @Override
458                public B call() throws Exception {
459                    return save(bean , args );
460                }});
461        }
462        
463        @Override
464        public B saveCollectionAsTransaction(final B bean,final Object ...args)throws RuntimeDaoException{
465            return this.runAsTransaction(new Callable<B>(){
466                @Override
467                public B call() throws Exception {
468                    return saveCollection(bean , args );
469                }});
470        }
471    }    
472
473    /**
474     * return the all of filed names
475     * @return 
476     */     
477    public String getFields();
478    
479    /**
480     * return all of primary key names
481     * @return 
482     */     
483    public String[] getPrimarykeyNames();
484    /**
485     * @param column clomn name or java field name of B
486     * @return column id,-1 if column is invalid
487     */
488    public int columnIDOf(String column);
489    /**
490     * return type of column specified by columnId
491     * @param columnId column id
492     * @return 
493     */ 
494    public Class<?> typeOf(int columnId);
495    /**
496     * return the table name
497     * @return 
498     */    
499    public String getTableName();
500        
501    /**
502     * return the all of full filed names
503     * @return 
504     */   
505    public String getFullFields();
506    
507    //43
508    /**
509     * return true if @{code column}(case insensitive)is primary key,otherwise return false <br>
510     * return false if @{code column} is null or empty 
511     * @param column
512     * @return
513     */
514    public boolean isPrimaryKey(String column);
515    
516    //_____________________________________________________________________
517    //
518    // COUNT
519    //_____________________________________________________________________
520    //24
521    /**
522     * Retrieves the number of rows of the table.
523     *
524     * @return the number of rows returned
525     * @throws RuntimeDaoException
526     */
527    public int countAll()throws RuntimeDaoException;
528    
529    //27
530    /**
531     * count the number of elements of a specific bean
532     *
533     * @param bean the bean to look for ant count
534     * @return the number of rows returned
535     * @throws RuntimeDaoException
536     */
537    public int countUsingTemplate( B bean)throws RuntimeDaoException;
538  
539    //20
540    /**
541     * count the number of elements of a specific bean given the search type
542     *
543     * @param bean the template to look for
544     * @param searchType exact ?  like ? starting like ? ending link ? <br>
545     *                {@value Constant#SEARCH_EXACT}   {@link Constant#SEARCH_EXACT} <br>
546     *                {@value Constant#SEARCH_LIKE}   {@link Constant#SEARCH_LIKE} <br>
547     *                {@value Constant#SEARCH_STARTING_LIKE}   {@link Constant#SEARCH_STARTING_LIKE} <br>
548     *                {@value Constant#SEARCH_ENDING_LIKE}   {@link Constant#SEARCH_ENDING_LIKE} <br>  
549     * @return the number of rows returned
550     * @throws RuntimeDaoException
551     */
552    public int countUsingTemplate(B bean, int searchType)throws RuntimeDaoException;
553
554    //25
555    /**
556     * Retrieves the number of rows of the table with a 'where' clause.
557     * It is up to you to pass the 'WHERE' in your where clauses.
558     *
559     * @param where the restriction clause
560     * @return the number of rows returned
561     * @throws RuntimeDaoException
562     */
563    public int countWhere(String where)throws RuntimeDaoException;
564
565    //10
566    /**
567     * Deletes all rows from table.
568     * @return the number of deleted rows.
569     * @throws RuntimeDaoException
570     */
571    public int deleteAll()throws RuntimeDaoException;
572
573    //11
574    /**
575     * Deletes rows from the table using a 'where' clause.
576     * It is up to you to pass the 'WHERE' in your where clauses.
577     * <br>Attention, if 'WHERE' is omitted it will delete all records.
578     *
579     * @param where the sql 'where' clause
580     * @return the number of deleted rows
581     * @throws RuntimeDaoException
582     */
583    public int deleteByWhere(String where)throws RuntimeDaoException;
584
585    //21
586    /**
587     * Deletes rows using a template.
588     *
589     * @param bean the template object(s) to be deleted
590     * @return the number of deleted objects
591     * @throws RuntimeDaoException
592     */
593    public int deleteUsingTemplate(B bean)throws RuntimeDaoException;
594
595    //2.1
596    /**
597     * Delete row according to its primary keys.
598     *
599     * @param keys primary keys value<br>
600     *      for fl_device table<br>
601     *          PK# 1 fl_device.id type Integer<br>
602     *      for fl_device_group table<br>
603     *          PK# 1 fl_device_group.id type Integer<br>
604     *      for fl_face table<br>
605     *          PK# 1 fl_face.id type Integer<br>
606     *      for fl_feature table<br>
607     *          PK# 1 fl_feature.md5 type String<br>
608     *      for fl_image table<br>
609     *          PK# 1 fl_image.md5 type String<br>
610     *      for fl_log table<br>
611     *          PK# 1 fl_log.id type Integer<br>
612     *      for fl_permit table<br>
613     *          PK# 1 fl_permit.device_group_id type Integer,PK# 2 fl_permit.person_group_id type Integer<br>
614     *      for fl_person table<br>
615     *          PK# 1 fl_person.id type Integer<br>
616     *      for fl_person_group table<br>
617     *          PK# 1 fl_person_group.id type Integer<br>
618     *      for fl_store table<br>
619     *          PK# 1 fl_store.md5 type String<br>
620     * @return the number of deleted rows
621     * @throws RuntimeDaoException
622     */   
623    public int deleteByPrimaryKey(Object ...keys)throws RuntimeDaoException;
624
625    //2.2
626    /**
627     * Delete row according to primary keys of bean.<br>
628     * 
629     * @param bean will be deleted ,all keys must not be null
630     * @return the number of deleted rows,0 returned if bean is null
631     * @throws RuntimeDaoException
632     */
633    public int delete(B bean)throws RuntimeDaoException;
634
635
636    //////////////////////////////////////
637    // LOAD ALL
638    //////////////////////////////////////
639
640    //5
641    /**
642     * Loads all the rows from table.
643     *
644     * @return an array of B bean
645     * @throws RuntimeDaoException
646     */
647    public B[] loadAll()throws RuntimeDaoException;
648
649    //5-1    
650    /**
651     * Loads each row from table and dealt with action.
652     * @param action  Action object for do something(not null)
653     * @return the count dealt by action
654     * @throws RuntimeDaoException
655     */
656    public int loadAll(Action<B> action)throws RuntimeDaoException;
657
658    //6
659    /**
660     * Loads the given number of rows from table, given the start row.
661     *
662     * @param startRow the start row to be used (first row = 1, last row = -1)
663     * @param numRows the number of rows to be retrieved (all rows = a negative number)
664     * @return an array of B bean
665     * @throws RuntimeDaoException
666     */
667    public B[] loadAll(int startRow, int numRows)throws RuntimeDaoException;
668
669    //6-1    
670    /**
671     *  Loads the given number of rows from table, given the start row and dealt with action.
672     * @param startRow the start row to be used (first row = 1, last row = -1)
673     * @param numRows the number of rows to be retrieved (all rows = a negative number)
674     * @param action  Action object for do something(not null)
675     * @return the count dealt by action
676     * @throws RuntimeDaoException
677     */
678    public int loadAll(int startRow, int numRows,Action<B> action)throws RuntimeDaoException;
679
680    //5-2
681    /**
682     * Loads all the rows from table.
683     *
684     * @return a list of B bean
685     * @throws RuntimeDaoException
686     */
687    public List<B> loadAllAsList()throws RuntimeDaoException;
688
689    //6-2
690    /**
691     * Loads the given number of rows from table, given the start row.
692     *
693     * @param startRow the start row to be used (first row = 1, last row = -1)
694     * @param numRows the number of rows to be retrieved (all rows = a negative number)
695     * @return a list of B bean
696     * @throws RuntimeDaoException
697     */
698    public List<B> loadAllAsList(int startRow, int numRows)throws RuntimeDaoException;
699
700    //1.2
701    /**
702     * Loads a B bean from the table using primary key fields of {@code bean}.
703     * @param bean the B bean with primary key fields
704     * @return a unique B or {@code null} if not found or bean is null
705     * @throws RuntimeDaoException
706     */
707    public B loadByPrimaryKey(B bean)throws RuntimeDaoException;
708    
709    //1.2.2
710    /**
711     * see also {@link #loadByPrimaryKey(BaseBean)} 
712     * @param bean
713     * @return a unique B ,otherwise throw exception
714     * @throws ObjectRetrievalException not found
715     * @throws RuntimeDaoException
716     */
717    public B loadByPrimaryKeyChecked(B bean)throws RuntimeDaoException,ObjectRetrievalException;
718    //1.3
719    /**
720     * Loads a B bean from the table using primary key fields.
721     * when you don't know which is primary key of table,you can use the method.
722     * @param keys primary keys value:<br> 
723     *      for fl_device table<br>
724     *          PK# 1 fl_device.id type Integer<br>
725     *      for fl_device_group table<br>
726     *          PK# 1 fl_device_group.id type Integer<br>
727     *      for fl_face table<br>
728     *          PK# 1 fl_face.id type Integer<br>
729     *      for fl_feature table<br>
730     *          PK# 1 fl_feature.md5 type String<br>
731     *      for fl_image table<br>
732     *          PK# 1 fl_image.md5 type String<br>
733     *      for fl_log table<br>
734     *          PK# 1 fl_log.id type Integer<br>
735     *      for fl_permit table<br>
736     *          PK# 1 fl_permit.device_group_id type Integer,PK# 2 fl_permit.person_group_id type Integer<br>
737     *      for fl_person table<br>
738     *          PK# 1 fl_person.id type Integer<br>
739     *      for fl_person_group table<br>
740     *          PK# 1 fl_person_group.id type Integer<br>
741     *      for fl_store table<br>
742     *          PK# 1 fl_store.md5 type String<br>
743     * @return a unique B or {@code null} if not found
744     * @throws RuntimeDaoException
745     */
746    public B loadByPrimaryKey(Object ...keys)throws RuntimeDaoException;
747
748    //1.3.2
749    /**
750     * see also {@link #loadByPrimaryKey(Object...)}
751     * @param keys
752     * @return a unique B,otherwise throw exception
753     * @throws ObjectRetrievalException not found
754     * @throws RuntimeDaoException
755     */
756    public B loadByPrimaryKeyChecked(Object ...keys)throws RuntimeDaoException,ObjectRetrievalException;
757    
758    //1.5
759    /**
760     * Returns true if this table contains row with primary key fields.
761     * @param keys primary keys value
762     * @see #loadByPrimaryKey(Object...)
763     * @return 
764     * @throws RuntimeDaoException
765     */
766    public boolean existsPrimaryKey(Object ...keys)throws RuntimeDaoException;
767    
768    //1.6
769    /**
770     * Returns true if this table contains row specified by primary key fields of B.<br>
771     * when you don't know which is primary key of table,you can use the method.
772     * @param bean the B bean with primary key fields
773     * @return 
774     * @see #loadByPrimaryKey(BaseBean)
775     * @throws RuntimeDaoException
776     */
777    public boolean existsByPrimaryKey(B bean)throws RuntimeDaoException;
778    //1.7
779    /**
780     * Check duplicated row by primary keys,if row exists throw exception
781     * @param bean the B bean with primary key fields
782     * @return always bean
783     * @see #existsByPrimaryKey(BaseBean)
784     * @throws ObjectRetrievalException has duplicated record
785     * @throws RuntimeDaoException
786     */
787    public B checkDuplicate(B bean)throws RuntimeDaoException,ObjectRetrievalException;
788   
789    //////////////////////////////////////
790    // SQL 'WHERE' METHOD
791    //////////////////////////////////////
792    //7 
793    /**
794     * Retrieves an array of B given a sql 'where' clause.
795     *
796     * @param where the sql 'where' clause
797     * @return 
798     * @throws RuntimeDaoException
799     */
800    public B[] loadByWhere(String where)throws RuntimeDaoException;
801    
802    //7-1
803    /**
804     * Retrieves each row of B bean given a sql 'where' clause and dealt with action.
805     * @param where the sql 'where' clause
806     * @param action  Action object for do something(not null)
807     * @return the count dealt by action
808     * @throws RuntimeDaoException
809     */
810    public int loadByWhere(String where,Action<B> action)throws RuntimeDaoException;
811
812    //8
813    /**
814     * Retrieves an array of B bean given a sql where clause, and a list of fields.
815     * It is up to you to pass the 'WHERE' in your where clauses.
816     *
817     * @param where the sql 'WHERE' clause
818     * @param fieldList array of field's ID
819     * @return 
820     * @throws RuntimeDaoException
821     */
822    public B[] loadByWhere(String where, int[] fieldList)throws RuntimeDaoException;
823   
824    //8-1 
825    /**
826     * Retrieves each row of B bean given a sql where clause, and a list of fields,
827     * and dealt with action.
828     * It is up to you to pass the 'WHERE' in your where clauses.
829     * @param where the sql 'WHERE' clause
830     * @param fieldList array of field's ID
831     * @param action Action object for do something(not null)
832     * @return the count dealt by action
833     * @throws RuntimeDaoException
834     */
835    public int loadByWhere(String where, int[] fieldList,Action<B> action)throws RuntimeDaoException;
836
837    //9
838    /**
839     * Retrieves an array of B bean given a sql where clause and a list of fields, and startRow and numRows.
840     * It is up to you to pass the 'WHERE' in your where clauses.
841     *
842     * @param where the sql 'where' clause
843     * @param fieldList table of the field's associated constants
844     * @param startRow the start row to be used (first row = 1, last row = -1)
845     * @param numRows the number of rows to be retrieved (all rows = a negative number)
846     * @return 
847     * @throws RuntimeDaoException
848     */
849    public B[] loadByWhere(String where, int[] fieldList, int startRow, int numRows)throws RuntimeDaoException;
850
851    //9-1    
852    /**
853     * Retrieves each row of B bean given a sql where clause and a list of fields, and startRow and numRows,
854     * and dealt with action.
855     * It is up to you to pass the 'WHERE' in your where clauses.
856     *
857     * @param where the sql 'where' clause
858     * @param fieldList table of the field's associated constants
859     * @param startRow the start row to be used (first row = 1, last row = -1)
860     * @param numRows the number of rows to be retrieved (all rows = a negative number)
861     * @param action Action object for do something(not null)
862     * @return the count dealt by action
863     * @throws RuntimeDaoException
864     */
865    public int loadByWhere(String where, int[] fieldList, int startRow, int numRows,Action<B> action)throws RuntimeDaoException;
866    //7
867    /**
868     * Retrieves a list of B bean given a sql 'where' clause.
869     *
870     * @param where the sql 'where' clause
871     * @return
872     * @throws RuntimeDaoException
873     */
874    public List<B> loadByWhereAsList(String where)throws RuntimeDaoException;
875
876    //8
877    /**
878     * Retrieves a list of B bean given a sql where clause, and a list of fields.
879     * It is up to you to pass the 'WHERE' in your where clauses.
880     *
881     * @param where the sql 'WHERE' clause
882     * @param fieldList array of field's ID
883     * @return
884     * @throws RuntimeDaoException
885     */
886    public List<B> loadByWhereAsList(String where, int[] fieldList)throws RuntimeDaoException;
887    
888    //9-2
889    /**
890     * Retrieves a list of B bean given a sql where clause and a list of fields, and startRow and numRows.
891     * It is up to you to pass the 'WHERE' in your where clauses.
892     *
893     * @param where the sql 'where' clause
894     * @param fieldList table of the field's associated constants
895     * @param startRow the start row to be used (first row = 1, last row = -1)
896     * @param numRows the number of rows to be retrieved (all rows = a negative number)
897     * @return
898     * @throws RuntimeDaoException
899     */
900    public List<B> loadByWhereAsList(String where, int[] fieldList, int startRow, int numRows)throws RuntimeDaoException;
901
902    //9-3
903    /**
904     * Retrieves each row of B bean given a sql where clause and a list of fields, and startRow and numRows,
905     * and dealt wity action
906     * It is up to you to pass the 'WHERE' in your where clauses.
907     *
908     * @param where the sql 'where' clause
909     * @param fieldList table of the field's associated constants
910     * @param startRow the start row to be used (first row = 1, last row = -1)
911     * @param numRows the number of rows to be retrieved (all rows = a negative number)
912     * @param action Action object for do something(not null)
913     * @return the count dealt by action
914     * @throws RuntimeDaoException
915     */
916    public int loadByWhereForAction(String where, int[] fieldList, int startRow, int numRows,Action<B> action)throws RuntimeDaoException;
917
918    //_____________________________________________________________________
919    //
920    // USING TEMPLATE
921    //_____________________________________________________________________
922    //18   
923    /**
924     * Loads a unique B bean from a template one giving a c
925     *
926     * @param bean the B bean to look for
927     * @return the bean matching the template,or {@code null} if not found or null input argument
928     * @throws ObjectRetrievalException more than one row
929     * @throws RuntimeDaoException
930     */
931    public B loadUniqueUsingTemplate(B bean)throws RuntimeDaoException;
932
933    //18-1
934    /**
935     * Loads a unique B bean from a template one giving a c
936     *
937     * @param bean the B bean to look for
938     * @return the bean matching the template
939     * @throws ObjectRetrievalException not found or more than one row
940     * @throws RuntimeDaoException
941     */
942    public B loadUniqueUsingTemplateChecked(B bean)throws RuntimeDaoException,ObjectRetrievalException;
943
944    //19
945    /**
946     * Loads an array of B from a template one.
947     *
948     * @param bean the B bean template to look for
949     * @return all the B beans matching the template
950     * @throws RuntimeDaoException
951     */
952    public B[] loadUsingTemplate(B bean)throws RuntimeDaoException;
953    
954    //19-1
955    /**
956     * Loads each row from a template one and dealt with action.
957     *
958     * @param bean the B bean template to look for
959     * @param action Action object for do something(not null)
960     * @return the count dealt by action
961     * @throws RuntimeDaoException
962     */
963    public int loadUsingTemplate(B bean,Action<B> action)throws RuntimeDaoException;
964
965    //20
966    /**
967     * Loads an array of B bean from a template one, given the start row and number of rows.
968     *
969     * @param bean the B bean template to look for
970     * @param startRow the start row to be used (first row = 1, last row=-1)
971     * @param numRows the number of rows to be retrieved (all rows = a negative number)
972     * @return all the B matching the template
973     * @throws RuntimeDaoException
974     */
975    public B[] loadUsingTemplate(B bean, int startRow, int numRows)throws RuntimeDaoException;
976    
977    //20-1
978    /**
979     * Loads each row from a template one, given the start row and number of rows and dealt with action.
980     *
981     * @param bean the B bean template to look for
982     * @param startRow the start row to be used (first row = 1, last row=-1)
983     * @param numRows the number of rows to be retrieved (all rows = a negative number)
984     * @param action Action object for do something(not null)
985     * @return the count dealt by action
986     * @throws RuntimeDaoException
987     */
988    public int loadUsingTemplate(B bean, int startRow, int numRows,Action<B> action)throws RuntimeDaoException;
989
990    //20-5
991    /**
992     * Loads each row from a template one, given the start row and number of rows and dealt with action.
993     *
994     * @param bean the B template to look for
995     * @param fieldList table of the field's associated constants
996     * @param startRow the start row to be used (first row = 1, last row=-1)
997     * @param numRows the number of rows to be retrieved (all rows = a negative number)
998     * @param searchType exact ?  like ? starting like ? ending link ? <br>
999     *                {@value Constant#SEARCH_EXACT}   {@link Constant#SEARCH_EXACT} <br>
1000     *                {@value Constant#SEARCH_LIKE}   {@link Constant#SEARCH_LIKE} <br>
1001     *                {@value Constant#SEARCH_STARTING_LIKE}   {@link Constant#SEARCH_STARTING_LIKE} <br>
1002     *                {@value Constant#SEARCH_ENDING_LIKE}   {@link Constant#SEARCH_ENDING_LIKE} <br>  
1003     * @param action Action object for do something(not null)
1004     * @return the count dealt by action
1005     * @throws RuntimeDaoException
1006     */
1007    public int loadUsingTemplate(B bean, int[] fieldList, int startRow, int numRows,int searchType, Action<B> action)throws RuntimeDaoException;
1008    //20-4
1009    /**
1010     * Loads a list of B bean from a template one, given the start row and number of rows.
1011     *
1012     * @param bean the B bean template to look for
1013     * @param startRow the start row to be used (first row = 1, last row=-1)
1014     * @param numRows the number of rows to be retrieved (all rows = a negative number)
1015     * @param searchType exact ?  like ? starting like ? ending link ? <br>
1016     *                {@value Constant#SEARCH_EXACT}   {@link Constant#SEARCH_EXACT} <br>
1017     *                {@value Constant#SEARCH_LIKE}   {@link Constant#SEARCH_LIKE} <br>
1018     *                {@value Constant#SEARCH_STARTING_LIKE}   {@link Constant#SEARCH_STARTING_LIKE} <br>
1019     *                {@value Constant#SEARCH_ENDING_LIKE}   {@link Constant#SEARCH_ENDING_LIKE} <br>  
1020     * @return all the B bean matching the template
1021     * @throws RuntimeDaoException
1022     */
1023    public B[] loadUsingTemplate(B bean, int startRow, int numRows, int searchType)throws RuntimeDaoException;
1024
1025    //19-2
1026    /**
1027     * Loads a list of B bean from a template one.
1028     *
1029     * @param bean the B bean template to look for
1030     * @return all the B beans matching the template
1031     * @throws RuntimeDaoException
1032     */
1033    public List<B> loadUsingTemplateAsList(B bean)throws RuntimeDaoException;
1034
1035    //20-2
1036    /**
1037     * Loads a list of B bean from a template one, given the start row and number of rows.
1038     *
1039     * @param bean the B bean template to look for
1040     * @param startRow the start row to be used (first row = 1, last row=-1)
1041     * @param numRows the number of rows to be retrieved (all rows = a negative number)
1042     * @return all the B bean matching the template
1043     * @throws RuntimeDaoException
1044     */
1045    public List<B> loadUsingTemplateAsList(B bean, int startRow, int numRows)throws RuntimeDaoException;
1046
1047    //20-3
1048    /**
1049     * Loads an array of B bean from a template one, given the start row and number of rows.
1050     *
1051     * @param bean the B bean template to look for
1052     * @param startRow the start row to be used (first row = 1, last row=-1)
1053     * @param numRows the number of rows to be retrieved (all rows = a negative number)
1054     * @param searchType exact ?  like ? starting like ? ending link? <br>
1055     *                {@value Constant#SEARCH_EXACT}   {@link Constant#SEARCH_EXACT} <br>
1056     *                {@value Constant#SEARCH_LIKE}   {@link Constant#SEARCH_LIKE} <br>
1057     *                {@value Constant#SEARCH_STARTING_LIKE}   {@link Constant#SEARCH_STARTING_LIKE} <br>
1058     *                {@value Constant#SEARCH_ENDING_LIKE}   {@link Constant#SEARCH_ENDING_LIKE} <br>  
1059     * @return all the B beans matching the template
1060     * @throws RuntimeDaoException
1061     */
1062    public List<B> loadUsingTemplateAsList(B bean, int startRow, int numRows, int searchType)throws RuntimeDaoException;
1063
1064    //_____________________________________________________________________
1065    //
1066    // USING INDICES
1067    //_____________________________________________________________________    
1068    /**
1069     * Retrieves a array of B bean using the index specified by keyIndex.
1070     * @param keyIndex valid values:see also {@link #loadByIndexAsList(int,Object ...)}
1071     * @param keys key values of index
1072     * @return
1073     * @throws RuntimeDaoException
1074     * @see #loadByIndexAsList(int ,Object ...)
1075     */
1076    public B[] loadByIndex(int keyIndex,Object ...keys)throws RuntimeDaoException;
1077    
1078    /**
1079     * Retrieves a list of B bean using the index specified by keyIndex.
1080     * @param keyIndex valid values: <br>
1081     *        for fl_device table<br>
1082     *        {@link Constant#FL_DEVICE_INDEX_MAC},{@link Constant#FL_DEVICE_INDEX_SERIAL_NO},{@link Constant#FL_DEVICE_INDEX_GROUP_ID}<br>     
1083     *        for fl_device_group table<br>
1084     *        {@link Constant#FL_DEVICE_GROUP_INDEX_PARENT}<br>     
1085     *        for fl_face table<br>
1086     *        {@link Constant#FL_FACE_INDEX_FEATURE_MD5},{@link Constant#FL_FACE_INDEX_IMAGE_MD5}<br>     
1087     *        for fl_feature table<br>
1088     *        {@link Constant#FL_FEATURE_INDEX_VERSION},{@link Constant#FL_FEATURE_INDEX_PERSON_ID}<br>     
1089     *        for fl_image table<br>
1090     *        {@link Constant#FL_IMAGE_INDEX_DEVICE_ID}<br>     
1091     *        for fl_log table<br>
1092     *        {@link Constant#FL_LOG_INDEX_COMPARE_FACE},{@link Constant#FL_LOG_INDEX_DEVICE_ID},{@link Constant#FL_LOG_INDEX_PERSON_ID},{@link Constant#FL_LOG_INDEX_VERIFY_FEATURE}<br>     
1093     *        for fl_person table<br>
1094     *        {@link Constant#FL_PERSON_INDEX_IMAGE_MD5},{@link Constant#FL_PERSON_INDEX_MOBILE_PHONE},{@link Constant#FL_PERSON_INDEX_PAPERS_NUM},{@link Constant#FL_PERSON_INDEX_EXPIRY_DATE},{@link Constant#FL_PERSON_INDEX_GROUP_ID}<br>     
1095     *        for fl_person_group table<br>
1096     *        {@link Constant#FL_PERSON_GROUP_INDEX_PARENT}<br>     
1097     * @param keys key values of index
1098     * @return a list of B bean
1099     * @throws RuntimeDaoException
1100     */
1101    public java.util.List<B> loadByIndexAsList(int keyIndex,Object ...keys)throws RuntimeDaoException;
1102    
1103    /**
1104     * Deletes rows using key.
1105     * @param keyIndex valid values: see also {@link #loadByIndexAsList(int,Object ...)}
1106     * @param keys key values of index
1107     * @return the number of deleted objects
1108     * @throws RuntimeDaoException
1109     */
1110    public int deleteByIndex(int keyIndex,Object ...keys)throws RuntimeDaoException;
1111    //_____________________________________________________________________
1112    //
1113    // LISTENER
1114    //_____________________________________________________________________
1115
1116    //35
1117    /**
1118     * Registers a unique {@link TableListener} listener.<br>
1119     * do nothing if {@code TableListener} instance exists
1120     * @param listener
1121     * @return 
1122     */
1123    public TableListener<B> registerListener(TableListener<B> listener);
1124
1125    //36
1126    /**
1127     * remove listener.
1128     * @param listener 
1129     */
1130    public void unregisterListener(TableListener<B> listener);
1131
1132    //37
1133    /**
1134     * see also {@link TableListener.Event#fire(TableListener.ListenerContainer, Object)}
1135     * @param event
1136     * @param bean
1137     * @throws RuntimeDaoException
1138     */
1139    public void fire(TableListener.Event event, B bean) throws RuntimeDaoException;
1140    
1141    //37-1
1142    /**
1143     * see also #fire(TableListener.Event, B)
1144     * @param event 
1145     * @param bean
1146     * @throws IllegalArgumentException invalid event id
1147     * @throws RuntimeDaoException
1148     */
1149    public void fire(int event, B bean) throws RuntimeDaoException;
1150    //_____________________________________________________________________
1151    //
1152    // SAVE
1153    //_____________________________________________________________________
1154    //12
1155    /**
1156     * Saves the B bean into the database.
1157     *
1158     * @param bean the B bean to be saved
1159     * @return the inserted or updated bean,or null if bean is null
1160     * @throws RuntimeDaoException
1161     */
1162    public B save(B bean)throws RuntimeDaoException;
1163
1164    //15
1165    /**
1166     * Saves an array of B bean into the database.
1167     *
1168     * @param beans the array of  B bean to be saved
1169     * @return always beans saved
1170     * @throws RuntimeDaoException
1171     */
1172    public B[] save(B[] beans)throws RuntimeDaoException;
1173    
1174    //15-2
1175    /**
1176     * Saves a collection of B bean into the database.
1177     *
1178     * @param beans the B bean table to be saved
1179     * @return alwarys beans saved
1180     * @throws RuntimeDaoException
1181     */
1182    public <C extends Collection<B>> C saveAsTransaction(C beans)throws RuntimeDaoException;
1183    
1184    //15-3
1185    /**
1186     * Saves an array of B bean into the database as transaction.
1187     *
1188     * @param beans the B bean table to be saved
1189     * @return alwarys beans saved
1190     * @see #save(BaseBean[])
1191     * @throws RuntimeDaoException
1192     */
1193    public B[] saveAsTransaction(B[] beans)throws RuntimeDaoException;
1194
1195    //15-4
1196    /**
1197     * Saves a collection of B bean into the database as transaction.
1198     *
1199     * @param beans the B bean table to be saved
1200     * @return alwarys beans saved
1201     * @throws RuntimeDaoException
1202     */
1203    public <C extends Collection<B>> C save(C beans)throws RuntimeDaoException;
1204
1205    //3.9 SYNC SAVE 
1206    /**
1207     * Save the B bean and referenced beans and imported beans (array) into the database.
1208     *
1209     * @param bean the B bean to be saved
1210     * @param args referenced beans or imported beans,for each table,each argument's type is different:<br>
1211            for fl_device table:<br>
1212                {@code  DeviceGroupBean ImageBean[] LogBean[]}<br>
1213            for fl_device_group table:<br>
1214                {@code  DeviceGroupBean DeviceBean[] DeviceGroupBean[] PermitBean[]}<br>
1215            for fl_face table:<br>
1216                {@code  FeatureBean ImageBean LogBean[]}<br>
1217            for fl_feature table:<br>
1218                {@code  PersonBean FaceBean[] LogBean[]}<br>
1219            for fl_image table:<br>
1220                {@code  DeviceBean FaceBean[] PersonBean[]}<br>
1221            for fl_log table:<br>
1222                {@code  DeviceBean FaceBean FeatureBean PersonBean}<br>
1223            for fl_permit table:<br>
1224                {@code  DeviceGroupBean PersonGroupBean}<br>
1225            for fl_person table:<br>
1226                {@code  ImageBean PersonGroupBean FeatureBean[] LogBean[]}<br>
1227            for fl_person_group table:<br>
1228                {@code  PersonGroupBean PermitBean[] PersonBean[] PersonGroupBean[]}<br>
1229     * @return the inserted or updated B bean
1230      * @throws RuntimeDaoException
1231     */
1232    public B save(B bean,Object ...args)throws RuntimeDaoException;
1233    
1234    //3.10 SYNC SAVE 
1235    /**
1236     * Save the B bean and referenced beans and imported beans (collection) into the database.
1237     *
1238     * @param bean the B bean to be saved
1239     * @param args referenced beans or imported beans,for each table,each argument's type is different:<br>
1240            for fl_device table:<br>
1241                {@code  DeviceGroupBean Collection<ImageBean> Collection<LogBean>}<br>
1242            for fl_device_group table:<br>
1243                {@code  DeviceGroupBean Collection<DeviceBean> Collection<DeviceGroupBean> Collection<PermitBean>}<br>
1244            for fl_face table:<br>
1245                {@code  FeatureBean ImageBean Collection<LogBean>}<br>
1246            for fl_feature table:<br>
1247                {@code  PersonBean Collection<FaceBean> Collection<LogBean>}<br>
1248            for fl_image table:<br>
1249                {@code  DeviceBean Collection<FaceBean> Collection<PersonBean>}<br>
1250            for fl_log table:<br>
1251                {@code  DeviceBean FaceBean FeatureBean PersonBean}<br>
1252            for fl_permit table:<br>
1253                {@code  DeviceGroupBean PersonGroupBean}<br>
1254            for fl_person table:<br>
1255                {@code  ImageBean PersonGroupBean Collection<FeatureBean> Collection<LogBean>}<br>
1256            for fl_person_group table:<br>
1257                {@code  PersonGroupBean Collection<PermitBean> Collection<PersonBean> Collection<PersonGroupBean>}<br>
1258     * @return the inserted or updated B bean
1259     * @throws RuntimeDaoException
1260     */
1261    public B saveCollection(B bean,Object ...args)throws RuntimeDaoException;
1262    
1263    //3.11 SYNC SAVE 
1264    /**
1265     *  Transaction version for sync save
1266     * @see #save(BaseBean ,Object ...)
1267     * @param bean the B bean to be saved
1268     * @param args referenced beans or imported beans<br>
1269     * @return the inserted or updated B bean
1270     * @throws RuntimeDaoException
1271     */
1272    public B saveAsTransaction(B bean,Object ...args)throws RuntimeDaoException;
1273    
1274    //3.12 SYNC SAVE 
1275    /**
1276     *  Transaction version for sync save
1277     * @see #saveCollection(BaseBean ,Object ...)
1278     * @param bean the B bean to be saved
1279     * @param args referenced beans or imported beans<br>
1280     * @return the inserted or updated B bean
1281     * @throws RuntimeDaoException
1282     */
1283    public B saveCollectionAsTransaction(B bean,Object ...args)throws RuntimeDaoException;
1284        
1285    /**
1286     * Load all the elements using a SQL statement specifying a list of fields to be retrieved.
1287     * @param sql the SQL statement for retrieving
1288     * @param argList the arguments to use fill given prepared statement,may be null
1289     * @param fieldList table of the field's associated constants
1290     * @return an array of B bean
1291     * @throws RuntimeDaoException
1292     */
1293    public B[] loadBySql(String sql, Object[] argList, int[] fieldList)throws RuntimeDaoException;
1294    
1295    /**
1296     * Load all elements using a SQL statement specifying a list of fields to be retrieved.
1297     * @param sql the SQL statement for retrieving
1298     * @param argList the arguments to use fill given prepared statement,may be null
1299     * @param fieldList table of the field's associated constants
1300     * @return an list of B bean
1301     * @throws RuntimeDaoException
1302     */
1303    public List<B> loadBySqlAsList(String sql, Object[] argList, int[] fieldList)throws RuntimeDaoException;
1304    /**
1305     * Load column from table.
1306     * @param column column name or java file name of B
1307     * @param distinct select distinct values
1308     * @param where the sql 'where' clause
1309     * @param startRow the start row to be used (first row = 1, last row = -1)
1310     * @param numRows the number of rows to be retrieved (all rows = a negative number)
1311     * @return an list of column
1312     * @throws RuntimeDaoException
1313     */
1314    public <T>List<T> loadColumnAsList(String column,boolean distinct,String where,int startRow,int numRows)throws RuntimeDaoException;
1315    /**
1316     * Load each the elements using a SQL statement specifying a list of fields to be retrieved and dealt by action.
1317     * @param sql the SQL statement for retrieving
1318     * @param argList the arguments to use fill given prepared statement,may be null
1319     * @param fieldList table of the field's associated constants
1320     * @param startRow the start row to be used (first row = 1, last row = -1)
1321     * @param numRows the number of rows to be retrieved (all rows = a negative number)
1322     * @param action Action object for do something(not null)
1323     * @return the count dealt by action
1324     * @throws RuntimeDaoException
1325     */
1326    public int loadBySqlForAction(String sql, Object[] argList, int[] fieldList,int startRow, int numRows,Action<B> action)throws RuntimeDaoException;
1327    /**
1328     * Run {@code Callable<T>} as a transaction.<br>
1329     * all exceptions but {@code SQLException} threw by {@code Callable<T>} is warpped into {@code RuntimeException}<br>
1330     * throw {@code NullPointerException} if {@code fun} be {@code null}<br>
1331     * @param <T>  type of return result
1332     * @param fun
1333     * @return
1334     * @throws RuntimeDaoException
1335     */
1336    public<T> T runAsTransaction(Callable<T> fun)throws RuntimeDaoException;
1337
1338    /**
1339     * Run {@code Runnable} as a transaction.no return
1340     * @param fun
1341     * @see #runAsTransaction(Runnable)
1342     * @throws RuntimeDaoException
1343     */
1344    public void runAsTransaction(Runnable fun)throws RuntimeDaoException;
1345    
1346    /**
1347     * Retrieves the T object referenced by fkName.<br>
1348     * @param <T>
1349     * <ul>
1350     *     <li> for fl_device:
1351     *     <li> {@link Constant#FL_DEVICE_FK_GROUP_ID} - DeviceGroupBean</li>
1352     * </ul>
1353     * <ul>
1354     *     <li> for fl_device_group:
1355     *     <li> {@link Constant#FL_DEVICE_GROUP_FK_PARENT} - DeviceGroupBean</li>
1356     * </ul>
1357     * <ul>
1358     *     <li> for fl_face:
1359     *     <li> {@link Constant#FL_FACE_FK_FEATURE_MD5} - FeatureBean</li>
1360     *     <li> {@link Constant#FL_FACE_FK_IMAGE_MD5} - ImageBean</li>
1361     * </ul>
1362     * <ul>
1363     *     <li> for fl_feature:
1364     *     <li> {@link Constant#FL_FEATURE_FK_PERSON_ID} - PersonBean</li>
1365     * </ul>
1366     * <ul>
1367     *     <li> for fl_image:
1368     *     <li> {@link Constant#FL_IMAGE_FK_DEVICE_ID} - DeviceBean</li>
1369     * </ul>
1370     * <ul>
1371     *     <li> for fl_log:
1372     *     <li> {@link Constant#FL_LOG_FK_DEVICE_ID} - DeviceBean</li>
1373     *     <li> {@link Constant#FL_LOG_FK_COMPARE_FACE} - FaceBean</li>
1374     *     <li> {@link Constant#FL_LOG_FK_VERIFY_FEATURE} - FeatureBean</li>
1375     *     <li> {@link Constant#FL_LOG_FK_PERSON_ID} - PersonBean</li>
1376     * </ul>
1377     * <ul>
1378     *     <li> for fl_permit:
1379     *     <li> {@link Constant#FL_PERMIT_FK_DEVICE_GROUP_ID} - DeviceGroupBean</li>
1380     *     <li> {@link Constant#FL_PERMIT_FK_PERSON_GROUP_ID} - PersonGroupBean</li>
1381     * </ul>
1382     * <ul>
1383     *     <li> for fl_person:
1384     *     <li> {@link Constant#FL_PERSON_FK_IMAGE_MD5} - ImageBean</li>
1385     *     <li> {@link Constant#FL_PERSON_FK_GROUP_ID} - PersonGroupBean</li>
1386     * </ul>
1387     * <ul>
1388     *     <li> for fl_person_group:
1389     *     <li> {@link Constant#FL_PERSON_GROUP_FK_PARENT} - PersonGroupBean</li>
1390     * </ul>
1391     * @param bean the B object to use
1392     * @param fkIndex foreign key name.<br>
1393     *        for for fl_device table:<br>
1394     *        {@link Constant#FL_DEVICE_FK_GROUP_ID}<br>
1395     *        for for fl_device_group table:<br>
1396     *        {@link Constant#FL_DEVICE_GROUP_FK_PARENT}<br>
1397     *        for for fl_face table:<br>
1398     *        {@link Constant#FL_FACE_FK_FEATURE_MD5},{@link Constant#FL_FACE_FK_IMAGE_MD5}<br>
1399     *        for for fl_feature table:<br>
1400     *        {@link Constant#FL_FEATURE_FK_PERSON_ID}<br>
1401     *        for for fl_image table:<br>
1402     *        {@link Constant#FL_IMAGE_FK_DEVICE_ID}<br>
1403     *        for for fl_log table:<br>
1404     *        {@link Constant#FL_LOG_FK_DEVICE_ID},{@link Constant#FL_LOG_FK_COMPARE_FACE},{@link Constant#FL_LOG_FK_VERIFY_FEATURE},{@link Constant#FL_LOG_FK_PERSON_ID}<br>
1405     *        for for fl_permit table:<br>
1406     *        {@link Constant#FL_PERMIT_FK_DEVICE_GROUP_ID},{@link Constant#FL_PERMIT_FK_PERSON_GROUP_ID}<br>
1407     *        for for fl_person table:<br>
1408     *        {@link Constant#FL_PERSON_FK_IMAGE_MD5},{@link Constant#FL_PERSON_FK_GROUP_ID}<br>
1409     *        for for fl_person_group table:<br>
1410     *        {@link Constant#FL_PERSON_GROUP_FK_PARENT}<br>
1411     * @return the associated T bean or {@code null} if {@code bean}  is {@code null}
1412     * @throws RuntimeDaoException
1413     */
1414    public <T extends BaseBean<T>> T getReferencedBean(B bean,int fkIndex)throws RuntimeDaoException;
1415    
1416    /**
1417     * Associates the B object to the T object by fkName field.<br>
1418     * @param <T> see also {@link #getReferencedBean(BaseBean, int)}
1419     * @param bean the B object to use
1420     * @param beanToSet the T object to associate to the B bean
1421     * @param fkIndex see also {@link #getReferencedBean(BaseBean, int)}
1422     * @return always beanToSet saved
1423     * @throws RuntimeDaoException
1424     */
1425    public <T extends BaseBean<T>> T setReferencedBean(B bean,T beanToSet,int fkIndex)throws RuntimeDaoException;
1426    
1427    /**
1428     * Retrieves imported T objects by fkIndex.<br>
1429     * @param <T>
1430     * <ul>
1431     *     <li> for fl_device table:
1432     *     <li> {@link Constant#FL_DEVICE_IK_FL_IMAGE_DEVICE_ID} - PersonGroupBean</li>
1433     *     <li> {@link Constant#FL_DEVICE_IK_FL_LOG_DEVICE_ID} - PersonGroupBean</li>
1434     * </ul>
1435     * <ul>
1436     *     <li> for fl_device_group table:
1437     *     <li> {@link Constant#FL_DEVICE_GROUP_IK_FL_DEVICE_GROUP_ID} - PersonGroupBean</li>
1438     *     <li> {@link Constant#FL_DEVICE_GROUP_IK_FL_DEVICE_GROUP_PARENT} - PersonGroupBean</li>
1439     *     <li> {@link Constant#FL_DEVICE_GROUP_IK_FL_PERMIT_DEVICE_GROUP_ID} - PersonGroupBean</li>
1440     * </ul>
1441     * <ul>
1442     *     <li> for fl_face table:
1443     *     <li> {@link Constant#FL_FACE_IK_FL_LOG_COMPARE_FACE} - PersonGroupBean</li>
1444     * </ul>
1445     * <ul>
1446     *     <li> for fl_feature table:
1447     *     <li> {@link Constant#FL_FEATURE_IK_FL_FACE_FEATURE_MD5} - PersonGroupBean</li>
1448     *     <li> {@link Constant#FL_FEATURE_IK_FL_LOG_VERIFY_FEATURE} - PersonGroupBean</li>
1449     * </ul>
1450     * <ul>
1451     *     <li> for fl_image table:
1452     *     <li> {@link Constant#FL_IMAGE_IK_FL_FACE_IMAGE_MD5} - PersonGroupBean</li>
1453     *     <li> {@link Constant#FL_IMAGE_IK_FL_PERSON_IMAGE_MD5} - PersonGroupBean</li>
1454     * </ul>
1455     * <ul>
1456     *     <li> for fl_person table:
1457     *     <li> {@link Constant#FL_PERSON_IK_FL_FEATURE_PERSON_ID} - PersonGroupBean</li>
1458     *     <li> {@link Constant#FL_PERSON_IK_FL_LOG_PERSON_ID} - PersonGroupBean</li>
1459     * </ul>
1460     * <ul>
1461     *     <li> for fl_person_group table:
1462     *     <li> {@link Constant#FL_PERSON_GROUP_IK_FL_PERMIT_PERSON_GROUP_ID} - PersonGroupBean</li>
1463     *     <li> {@link Constant#FL_PERSON_GROUP_IK_FL_PERSON_GROUP_ID} - PersonGroupBean</li>
1464     *     <li> {@link Constant#FL_PERSON_GROUP_IK_FL_PERSON_GROUP_PARENT} - PersonGroupBean</li>
1465     * </ul>
1466     * @param bean the B object to use
1467     * @param ikIndex foreign key name.<br>
1468     *        for fl_device table:<br>
1469     *        {@link Constant#FL_IMAGE_FK_DEVICE_ID},{@link Constant#FL_LOG_FK_DEVICE_ID}<br>
1470     *        for fl_device_group table:<br>
1471     *        {@link Constant#FL_DEVICE_FK_GROUP_ID},{@link Constant#FL_DEVICE_GROUP_FK_PARENT},{@link Constant#FL_PERMIT_FK_DEVICE_GROUP_ID}<br>
1472     *        for fl_face table:<br>
1473     *        {@link Constant#FL_LOG_FK_COMPARE_FACE}<br>
1474     *        for fl_feature table:<br>
1475     *        {@link Constant#FL_FACE_FK_FEATURE_MD5},{@link Constant#FL_LOG_FK_VERIFY_FEATURE}<br>
1476     *        for fl_image table:<br>
1477     *        {@link Constant#FL_FACE_FK_IMAGE_MD5},{@link Constant#FL_PERSON_FK_IMAGE_MD5}<br>
1478     *        for fl_person table:<br>
1479     *        {@link Constant#FL_FEATURE_FK_PERSON_ID},{@link Constant#FL_LOG_FK_PERSON_ID}<br>
1480     *        for fl_person_group table:<br>
1481     *        {@link Constant#FL_PERMIT_FK_PERSON_GROUP_ID},{@link Constant#FL_PERSON_FK_GROUP_ID},{@link Constant#FL_PERSON_GROUP_FK_PARENT}<br>
1482     * @return the associated T beans or {@code null} if {@code bean} is {@code null}
1483     * @throws RuntimeDaoException
1484     */
1485    public <T extends BaseBean<T>> T[] getImportedBeans(B bean,int ikIndex)throws RuntimeDaoException;
1486    
1487    /**
1488     * Retrieves imported T objects by ikIndex.<br>
1489     * @param <T> see also {@link #getImportedBeans(BaseBean, int)}
1490     * @param bean the B object to use
1491     * @param ikIndex foreign key name.see also {@link #getImportedBeans(BaseBean, int)}
1492     * @return the associated T beans or {@code null} if {@code bean} is {@code null}
1493     * @throws RuntimeDaoException
1494     */
1495    public <T extends BaseBean<T>> List<T> getImportedBeansAsList(B bean,int ikIndex)throws RuntimeDaoException;
1496    
1497    /**
1498     * Set the importedBeans associates to the bean by {@code ikIndex}<br>
1499     * 
1500     * @param <T> see also {@link #getImportedBeans(BaseBean, int)}
1501     * @param bean the bean object to use
1502     * @param importedBeans the T object to associate to bean
1503     * @param ikIndex foreign key name.see also {@link #getImportedBeans(BaseBean, int)}
1504     * @return importedBeans always
1505     * @throws RuntimeDaoException
1506     */
1507    public <T extends BaseBean<T>> T[] setImportedBeans(B bean,T[] importedBeans,int ikIndex)throws RuntimeDaoException;
1508    
1509    /**
1510     * Set the importedBeans associates to the bean by fkIndex<br>
1511     * 
1512     * @param <T> see also {@link #getImportedBeans(BaseBean, int)}
1513     * @param bean the bean object to use
1514     * @param importedBeans the T object to associate to bean
1515     * @param ikIndex foreign key name. see also {@link #getImportedBeans(BaseBean, int)}
1516     * @return importedBeans always
1517     * @throws RuntimeDaoException
1518     */
1519    public <T extends BaseBean<T>,C extends Collection<T>> C setImportedBeans(B bean,C importedBeans,int ikIndex)throws RuntimeDaoException;
1520}