All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.gdface.facelog.db.mysql.ImageManager Maven / Gradle / Ivy

There is a newer version: 2.5.1
Show newest version
// ______________________________________________________
// Generated by sql2java - https://github.com/10km/sql2java-2-6-7 (custom branch) 
// modified by guyadong from
// sql2java original version https://sourceforge.net/projects/sql2java/ 
// JDBC driver used at code generation time: com.mysql.jdbc.Driver
// template: manager.java.vm
// ______________________________________________________
package net.gdface.facelog.db.mysql;

import java.util.concurrent.Callable;

import net.gdface.facelog.db.Constant;
import net.gdface.facelog.db.ImageBean;
import net.gdface.facelog.db.IBeanConverter;
import net.gdface.facelog.db.IDbConverter;
import net.gdface.facelog.db.TableManager;
import net.gdface.facelog.db.IImageManager;
import net.gdface.facelog.db.FaceBean;
import net.gdface.facelog.db.PersonBean;
import net.gdface.facelog.db.DeviceBean;
import net.gdface.facelog.db.TableListener;
import net.gdface.facelog.db.exception.RuntimeDaoException;
import net.gdface.facelog.db.exception.ObjectRetrievalException;

import net.gdface.facelog.dborm.exception.DaoException;

/**
 * Handles database calls (save, load, count, etc...) for the fl_image table.
* all {@link DaoException} be wrapped as {@link RuntimeDaoException} to throw.
* Remarks: 图像信息存储表,用于存储系统中所有用到的图像数据,表中只包含图像基本信息,图像二进制源数据存在在fl_store中(md5对应)
* @author guyadong */ public class ImageManager extends TableManager.BaseAdapter implements IImageManager { private net.gdface.facelog.dborm.image.FlImageManager nativeManager = net.gdface.facelog.dborm.image.FlImageManager.getInstance(); private IDbConverter< net.gdface.facelog.dborm.device.FlDeviceBean, net.gdface.facelog.dborm.device.FlDeviceGroupBean, net.gdface.facelog.dborm.face.FlFaceBean, net.gdface.facelog.dborm.face.FlFeatureBean, net.gdface.facelog.dborm.image.FlImageBean, net.gdface.facelog.dborm.log.FlLogBean, net.gdface.facelog.dborm.permit.FlPermitBean, net.gdface.facelog.dborm.person.FlPersonBean, net.gdface.facelog.dborm.person.FlPersonGroupBean, net.gdface.facelog.dborm.image.FlStoreBean, net.gdface.facelog.dborm.log.FlLogLightBean> dbConverter = DbConverter.INSTANCE; private IBeanConverter beanConverter = dbConverter.getImageBeanConverter(); private static ImageManager singleton = new ImageManager(); protected ImageManager(){} protected FaceManager instanceOfFaceManager(){ return FaceManager.getInstance(); } protected PersonManager instanceOfPersonManager(){ return PersonManager.getInstance(); } protected DeviceManager instanceOfDeviceManager(){ return DeviceManager.getInstance(); } @Override public String getTableName() { return this.nativeManager.getTableName(); } @Override public String getFields() { return this.nativeManager.getFields(); } @Override public String getFullFields() { return this.nativeManager.getFullFields(); } @Override public String[] getPrimarykeyNames() { return this.nativeManager.getPrimarykeyNames(); } /** * Get the {@link ImageManager} singleton. * * @return {@link ImageManager} */ public static ImageManager getInstance() { return singleton; } @Override protected Class beanType(){ return ImageBean.class; } ////////////////////////////////////// // PRIMARY KEY METHODS ////////////////////////////////////// //1 override IImageManager @Override public ImageBean loadByPrimaryKey(String md5) { try{ return loadByPrimaryKeyChecked(md5); }catch(ObjectRetrievalException e){ // not found return null; } } //1.1 override IImageManager @Override public ImageBean loadByPrimaryKeyChecked(String md5) throws ObjectRetrievalException { try{ return this.beanConverter.fromRight(nativeManager.loadByPrimaryKeyChecked(md5)); }catch(net.gdface.facelog.dborm.exception.ObjectRetrievalException e){ throw new ObjectRetrievalException(); }catch(DaoException e){ throw new RuntimeDaoException(e); } } //1.2 @Override public ImageBean loadByPrimaryKey(ImageBean bean) { return bean==null?null:loadByPrimaryKey(bean.getMd5()); } //1.2.2 @Override public ImageBean loadByPrimaryKeyChecked(ImageBean bean) throws ObjectRetrievalException { if(null == bean){ throw new NullPointerException(); } return loadByPrimaryKeyChecked(bean.getMd5()); } //1.3 @Override public ImageBean loadByPrimaryKey(Object ...keys){ try{ return loadByPrimaryKeyChecked(keys); }catch(ObjectRetrievalException e){ // not found return null; } } //1.3.2 @Override public ImageBean loadByPrimaryKeyChecked(Object ...keys) throws ObjectRetrievalException{ if(null == keys){ throw new NullPointerException(); } if(keys.length != FL_IMAGE_PK_COUNT){ throw new IllegalArgumentException("argument number mismatch with primary key number"); } if(! (keys[0] instanceof String)){ throw new IllegalArgumentException("invalid type for the No.1 argument,expected type:String"); } return loadByPrimaryKeyChecked((String)keys[0]); } //1.4 override IImageManager @Override public boolean existsPrimaryKey(String md5) { try{ return nativeManager.existsPrimaryKey(md5); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //1.6 @Override public boolean existsByPrimaryKey(ImageBean bean) { return null == bean ? false : existsPrimaryKey(bean.getMd5()); } //1.7 @Override public ImageBean checkDuplicate(ImageBean bean)throws ObjectRetrievalException{ if(null != bean){ checkDuplicate(bean.getMd5()); } return bean; } //1.4.1 override IImageManager @Override public String checkDuplicate(String md5)throws ObjectRetrievalException{ try{ return this.nativeManager.checkDuplicate(md5); }catch(net.gdface.facelog.dborm.exception.ObjectRetrievalException e){ throw new ObjectRetrievalException(e); }catch(DaoException e){ throw new RuntimeDaoException(e); } } //1.8 override IImageManager @Override public java.util.List loadByPrimaryKey(String... keys){ if(null == keys){ return new java.util.ArrayList(); } java.util.ArrayList list = new java.util.ArrayList(keys.length); for(int i = 0 ;i< keys.length;++i){ list.add(loadByPrimaryKey(keys[i])); } return list; } //1.9 override IImageManager @Override public java.util.List loadByPrimaryKey(java.util.Collection keys){ if(null == keys ){ return new java.util.ArrayList(); } java.util.ArrayList list = new java.util.ArrayList(keys.size()); if(keys instanceof java.util.List){ for(String key: keys){ list.add(loadByPrimaryKey(key)); } }else{ ImageBean bean; for(String key: keys){ if(null != (bean = loadByPrimaryKey(key))){ list.add(bean); } } } return list; } //2 override IImageManager @Override public int deleteByPrimaryKey(String md5) { try { return nativeManager.deleteByPrimaryKey(md5); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //2 @Override public int delete(ImageBean bean){ try { return nativeManager.delete(this.beanConverter.toRight(bean)); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //2.1 @Override public int deleteByPrimaryKey(Object ...keys){ if(null == keys){ throw new NullPointerException(); } if(keys.length != FL_IMAGE_PK_COUNT){ throw new IllegalArgumentException("argument number mismatch with primary key number"); } if(! (keys[0] instanceof String)){ throw new IllegalArgumentException("invalid type for the No.1 argument,expected type:String"); } return deleteByPrimaryKey((String)keys[0]); } //2.2 override IImageManager @Override public int deleteByPrimaryKey(String... keys){ int count = 0; if(null != keys){ for(String key:keys){ count += deleteByPrimaryKey(key); } } return count; } //2.3 override IImageManager @Override public int deleteByPrimaryKey(java.util.Collection keys){ int count = 0; if(null != keys){ for(String key :keys){ count += deleteByPrimaryKey(key); } } return count; } //2.4 override IImageManager @Override public int delete(ImageBean... beans){ int count = 0; if(null != beans){ for(ImageBean bean :beans){ count += delete(bean); } } return count; } //2.5 override IImageManager @Override public int delete(java.util.Collection beans){ int count = 0; if(null != beans){ for(ImageBean bean :beans){ count += delete(bean); } } return count; } ////////////////////////////////////// // IMPORT KEY GENERIC METHOD ////////////////////////////////////// private static final Class[] IMPORTED_BEAN_TYPES = new Class[]{FaceBean.class,PersonBean.class}; /** * @see #getImportedBeansAsList(ImageBean,int) */ @SuppressWarnings("unchecked") @Override public > T[] getImportedBeans(ImageBean bean, int ikIndex){ return getImportedBeansAsList(bean, ikIndex).toArray((T[])java.lang.reflect.Array.newInstance(IMPORTED_BEAN_TYPES[ikIndex],0)); } /** * Retrieves imported T objects by ikIndex.
* @param *
    *
  • {@link Constant#FL_IMAGE_IK_FL_FACE_IMAGE_MD5} TO {@link FaceBean}
  • *
  • {@link Constant#FL_IMAGE_IK_FL_PERSON_IMAGE_MD5} TO {@link PersonBean}
  • *
* @param bean the {@link ImageBean} object to use * @param ikIndex valid values: {@link Constant#FL_IMAGE_IK_FL_FACE_IMAGE_MD5},{@link Constant#FL_IMAGE_IK_FL_PERSON_IMAGE_MD5} * @return the associated T beans or {@code null} if {@code bean} is {@code null} */ @SuppressWarnings("unchecked") @Override public > java.util.List getImportedBeansAsList(ImageBean bean,int ikIndex){ switch(ikIndex){ case FL_IMAGE_IK_FL_FACE_IMAGE_MD5: return (java.util.List)this.getFaceBeansByImageMd5AsList(bean); case FL_IMAGE_IK_FL_PERSON_IMAGE_MD5: return (java.util.List)this.getPersonBeansByImageMd5AsList(bean); default: throw new IllegalArgumentException(String.format("invalid ikIndex %d", ikIndex)); } } /** * Set the T objects as imported beans of bean object by ikIndex.
* @param * *
    *
  • {@link Constant#FL_IMAGE_IK_FL_FACE_IMAGE_MD5} TO {@link FaceBean}
  • *
  • {@link Constant#FL_IMAGE_IK_FL_PERSON_IMAGE_MD5} TO {@link PersonBean}
  • *
* @param bean the {@link ImageBean} object to use * @param importedBeans the FlPersonBean array to associate to the {@link ImageBean} * @param ikIndex valid values: {@link Constant#FL_IMAGE_IK_FL_FACE_IMAGE_MD5},{@link Constant#FL_IMAGE_IK_FL_PERSON_IMAGE_MD5} * @return importedBeans always */ @SuppressWarnings("unchecked") @Override public > T[] setImportedBeans(ImageBean bean,T[] importedBeans,int ikIndex){ switch(ikIndex){ case FL_IMAGE_IK_FL_FACE_IMAGE_MD5: return (T[])setFaceBeansByImageMd5(bean,(FaceBean[])importedBeans); case FL_IMAGE_IK_FL_PERSON_IMAGE_MD5: return (T[])setPersonBeansByImageMd5(bean,(PersonBean[])importedBeans); default: throw new IllegalArgumentException(String.format("invalid ikIndex %d", ikIndex)); } } /** * Set the importedBeans associates to the bean by ikIndex
* @param *
    *
  • {@link Constant#FL_IMAGE_IK_FL_FACE_IMAGE_MD5} TO {@link FaceBean}
  • *
  • {@link Constant#FL_IMAGE_IK_FL_PERSON_IMAGE_MD5} TO {@link PersonBean}
  • *
* @param bean the {@link ImageBean} object to use * @param importedBeans the T object to associate to the {@link ImageBean} * @param ikIndex valid values: {@link Constant#FL_IMAGE_IK_FL_FACE_IMAGE_MD5},{@link Constant#FL_IMAGE_IK_FL_PERSON_IMAGE_MD5} * @return importedBeans always */ @SuppressWarnings("unchecked") @Override public ,C extends java.util.Collection> C setImportedBeans(ImageBean bean,C importedBeans,int ikIndex){ switch(ikIndex){ case FL_IMAGE_IK_FL_FACE_IMAGE_MD5: return (C)setFaceBeansByImageMd5(bean,(java.util.Collection)importedBeans); case FL_IMAGE_IK_FL_PERSON_IMAGE_MD5: return (C)setPersonBeansByImageMd5(bean,(java.util.Collection)importedBeans); default: throw new IllegalArgumentException(String.format("invalid ikIndex %d", ikIndex)); } } ////////////////////////////////////// // GET/SET IMPORTED KEY BEAN METHOD ////////////////////////////////////// //3.1 GET IMPORTED override IImageManager @Override public FaceBean[] getFaceBeansByImageMd5(ImageBean bean) { return this.getFaceBeansByImageMd5AsList(bean).toArray(new FaceBean[0]); } //3.1.2 GET IMPORTED override IImageManager @Override public FaceBean[] getFaceBeansByImageMd5(String md5OfImage) { ImageBean bean = new ImageBean(); bean.setMd5(md5OfImage); return getFaceBeansByImageMd5(bean); } //3.2 GET IMPORTED override IImageManager @Override public java.util.List getFaceBeansByImageMd5AsList(ImageBean bean) { return getFaceBeansByImageMd5AsList(bean,1,-1); } //3.2.2 GET IMPORTED override IImageManager @Override public java.util.List getFaceBeansByImageMd5AsList(String md5OfImage) { ImageBean bean = new ImageBean(); bean.setMd5(md5OfImage); return getFaceBeansByImageMd5AsList(bean); } //3.2.3 DELETE IMPORTED override IImageManager @Override public int deleteFaceBeansByImageMd5(String md5OfImage) { java.util.List list =getFaceBeansByImageMd5AsList(md5OfImage); return instanceOfFaceManager().delete(list); } //3.2.4 GET IMPORTED override IImageManager @Override public java.util.List getFaceBeansByImageMd5AsList(ImageBean bean,int startRow, int numRows) { try { return this.dbConverter.getFaceBeanConverter().fromRight(nativeManager.getFaceBeansByImageMd5AsList( this.beanConverter.toRight(bean),startRow,numRows)); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //3.3 SET IMPORTED override IImageManager @Override public FaceBean[] setFaceBeansByImageMd5(ImageBean bean , FaceBean[] importedBeans) { if(null != importedBeans){ for( FaceBean importBean : importedBeans ){ instanceOfFaceManager().setReferencedByImageMd5(importBean , bean); } } return importedBeans; } //3.4 SET IMPORTED override IImageManager @Override public > C setFaceBeansByImageMd5(ImageBean bean , C importedBeans) { if(null != importedBeans){ for( FaceBean importBean : importedBeans ){ instanceOfFaceManager().setReferencedByImageMd5(importBean , bean); } } return importedBeans; } //3.1 GET IMPORTED override IImageManager @Override public PersonBean[] getPersonBeansByImageMd5(ImageBean bean) { return this.getPersonBeansByImageMd5AsList(bean).toArray(new PersonBean[0]); } //3.1.2 GET IMPORTED override IImageManager @Override public PersonBean[] getPersonBeansByImageMd5(String md5OfImage) { ImageBean bean = new ImageBean(); bean.setMd5(md5OfImage); return getPersonBeansByImageMd5(bean); } //3.2 GET IMPORTED override IImageManager @Override public java.util.List getPersonBeansByImageMd5AsList(ImageBean bean) { return getPersonBeansByImageMd5AsList(bean,1,-1); } //3.2.2 GET IMPORTED override IImageManager @Override public java.util.List getPersonBeansByImageMd5AsList(String md5OfImage) { ImageBean bean = new ImageBean(); bean.setMd5(md5OfImage); return getPersonBeansByImageMd5AsList(bean); } //3.2.3 DELETE IMPORTED override IImageManager @Override public int deletePersonBeansByImageMd5(String md5OfImage) { java.util.List list =getPersonBeansByImageMd5AsList(md5OfImage); return instanceOfPersonManager().delete(list); } //3.2.4 GET IMPORTED override IImageManager @Override public java.util.List getPersonBeansByImageMd5AsList(ImageBean bean,int startRow, int numRows) { try { return this.dbConverter.getPersonBeanConverter().fromRight(nativeManager.getPersonBeansByImageMd5AsList( this.beanConverter.toRight(bean),startRow,numRows)); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //3.3 SET IMPORTED override IImageManager @Override public PersonBean[] setPersonBeansByImageMd5(ImageBean bean , PersonBean[] importedBeans) { if(null != importedBeans){ for( PersonBean importBean : importedBeans ){ instanceOfPersonManager().setReferencedByImageMd5(importBean , bean); } } return importedBeans; } //3.4 SET IMPORTED override IImageManager @Override public > C setPersonBeansByImageMd5(ImageBean bean , C importedBeans) { if(null != importedBeans){ for( PersonBean importBean : importedBeans ){ instanceOfPersonManager().setReferencedByImageMd5(importBean , bean); } } return importedBeans; } //3.5 SYNC SAVE override IImageManager @Override public ImageBean save(ImageBean bean , DeviceBean refDeviceByDeviceId , FaceBean[] impFaceByImageMd5 , PersonBean[] impPersonByImageMd5 ) { if(null == bean){ return null; } if(null != refDeviceByDeviceId){ this.setReferencedByDeviceId(bean,refDeviceByDeviceId); } bean = this.save( bean ); if(null != impFaceByImageMd5){ this.setFaceBeansByImageMd5(bean,impFaceByImageMd5); instanceOfFaceManager().save( impFaceByImageMd5 ); } if(null != impPersonByImageMd5){ this.setPersonBeansByImageMd5(bean,impPersonByImageMd5); instanceOfPersonManager().save( impPersonByImageMd5 ); } return bean; } //3.6 SYNC SAVE AS TRANSACTION override IImageManager @Override public ImageBean saveAsTransaction(final ImageBean bean ,final DeviceBean refDeviceByDeviceId ,final FaceBean[] impFaceByImageMd5 ,final PersonBean[] impPersonByImageMd5 ) { return this.runAsTransaction(new Callable(){ @Override public ImageBean call() throws Exception { return save(bean , refDeviceByDeviceId , impFaceByImageMd5 , impPersonByImageMd5 ); }}); } //3.7 SYNC SAVE override IImageManager @Override public ImageBean save(ImageBean bean , DeviceBean refDeviceByDeviceId , java.util.Collection impFaceByImageMd5 , java.util.Collection impPersonByImageMd5 ) { if(null == bean){ return null; } if(null != refDeviceByDeviceId){ this.setReferencedByDeviceId(bean,refDeviceByDeviceId); } bean = this.save( bean ); if(null != impFaceByImageMd5){ this.setFaceBeansByImageMd5(bean,impFaceByImageMd5); instanceOfFaceManager().save( impFaceByImageMd5 ); } if(null != impPersonByImageMd5){ this.setPersonBeansByImageMd5(bean,impPersonByImageMd5); instanceOfPersonManager().save( impPersonByImageMd5 ); } return bean; } //3.8 SYNC SAVE AS TRANSACTION override IImageManager @Override public ImageBean saveAsTransaction(final ImageBean bean ,final DeviceBean refDeviceByDeviceId ,final java.util.Collection impFaceByImageMd5 ,final java.util.Collection impPersonByImageMd5 ) { return this.runAsTransaction(new Callable(){ @Override public ImageBean call() throws Exception { return save(bean , refDeviceByDeviceId , impFaceByImageMd5 , impPersonByImageMd5 ); }}); } private static final int SYNC_SAVE_ARG_LEN = 3; private static final int SYNC_SAVE_ARG_0 = 0; private static final int SYNC_SAVE_ARG_1 = 1; private static final int SYNC_SAVE_ARG_2 = 2; //3.9 SYNC SAVE /** * Save the {@link ImageBean} bean and referenced beans and imported beans into the database. * * @param bean the {@link ImageBean} bean to be saved * @param inputs referenced beans or imported beans
* see also {@link #save(ImageBean , DeviceBean , FaceBean[] , PersonBean[] )} * @return the inserted or updated {@link ImageBean} bean */ @Override public ImageBean save(ImageBean bean,Object ...inputs) { if(null == inputs){ return save(bean); } if(inputs.length > SYNC_SAVE_ARG_LEN){ throw new IllegalArgumentException("too many dynamic arguments,max dynamic arguments number: 3"); } Object[] args = new Object[SYNC_SAVE_ARG_LEN]; System.arraycopy(inputs, 0, args, 0, inputs.length); if( null != args[SYNC_SAVE_ARG_0] && !(args[SYNC_SAVE_ARG_0] instanceof DeviceBean)){ throw new IllegalArgumentException("invalid type for the No.1 dynamic argument,expected type:DeviceBean"); } if( null != args[SYNC_SAVE_ARG_1] && !(args[SYNC_SAVE_ARG_1] instanceof FaceBean[])){ throw new IllegalArgumentException("invalid type for the No.2 argument,expected type:FaceBean[]"); } if( null != args[SYNC_SAVE_ARG_2] && !(args[SYNC_SAVE_ARG_2] instanceof PersonBean[])){ throw new IllegalArgumentException("invalid type for the No.3 argument,expected type:PersonBean[]"); } return save(bean, (DeviceBean)args[SYNC_SAVE_ARG_0], (FaceBean[])args[SYNC_SAVE_ARG_1], (PersonBean[])args[SYNC_SAVE_ARG_2]); } //3.10 SYNC SAVE /** * Save the {@link ImageBean} bean and referenced beans and imported beans into the database. * * @param bean the {@link ImageBean} bean to be saved * @param inputs referenced beans or imported beans
* see also {@link #save(ImageBean , DeviceBean , java.util.Collection , java.util.Collection )} * @return the inserted or updated {@link ImageBean} bean */ @SuppressWarnings("unchecked") @Override public ImageBean saveCollection(ImageBean bean,Object ...inputs) { if(null == inputs){ return save(bean); } if(inputs.length > SYNC_SAVE_ARG_LEN){ throw new IllegalArgumentException("too many dynamic arguments,max dynamic arguments number: 3"); } Object[] args = new Object[SYNC_SAVE_ARG_LEN]; System.arraycopy(inputs, 0, args, 0, inputs.length); if( null != args[SYNC_SAVE_ARG_0] && !(args[SYNC_SAVE_ARG_0] instanceof DeviceBean)){ throw new IllegalArgumentException("invalid type for the No.1 dynamic argument,expected type:DeviceBean"); } if( null != args[SYNC_SAVE_ARG_1] && !(args[SYNC_SAVE_ARG_1] instanceof java.util.Collection)){ throw new IllegalArgumentException("invalid type for the No.2 argument,expected type:java.util.Collection"); } if( null != args[SYNC_SAVE_ARG_2] && !(args[SYNC_SAVE_ARG_2] instanceof java.util.Collection)){ throw new IllegalArgumentException("invalid type for the No.3 argument,expected type:java.util.Collection"); } return save(bean, (DeviceBean)args[SYNC_SAVE_ARG_0], (java.util.Collection)args[SYNC_SAVE_ARG_1], (java.util.Collection)args[SYNC_SAVE_ARG_2]); } ////////////////////////////////////// // FOREIGN KEY GENERIC METHOD ////////////////////////////////////// /** * Retrieves the bean object referenced by fkIndex.
* @param *
    *
  • {@link Constant#FL_IMAGE_FK_DEVICE_ID} TO {@link DeviceBean}
  • *
* @param bean the {@link ImageBean} object to use * @param fkIndex valid values:
* {@link Constant#FL_IMAGE_FK_DEVICE_ID} * @return the associated T bean or {@code null} if {@code bean} or {@code beanToSet} is {@code null} */ @SuppressWarnings("unchecked") @Override public > T getReferencedBean(ImageBean bean,int fkIndex){ switch(fkIndex){ case FL_IMAGE_FK_DEVICE_ID: return (T)this.getReferencedByDeviceId(bean); default: throw new IllegalArgumentException(String.format("invalid fkIndex %d", fkIndex)); } } /** * Associates the {@link ImageBean} object to the bean object by fkIndex field.
* * @param see also {@link #getReferencedBean(ImageBean,int)} * @param bean the {@link ImageBean} object to use * @param beanToSet the T object to associate to the {@link ImageBean} * @param fkIndex valid values: see also {@link #getReferencedBean(ImageBean,int)} * @return always beanToSet saved */ @SuppressWarnings("unchecked") @Override public > T setReferencedBean(ImageBean bean,T beanToSet,int fkIndex){ switch(fkIndex){ case FL_IMAGE_FK_DEVICE_ID: return (T)this.setReferencedByDeviceId(bean, (DeviceBean)beanToSet); default: throw new IllegalArgumentException(String.format("invalid fkIndex %d", fkIndex)); } } ////////////////////////////////////// // GET/SET FOREIGN KEY BEAN METHOD ////////////////////////////////////// //5.1 GET REFERENCED VALUE override IImageManager @Override public DeviceBean getReferencedByDeviceId(ImageBean bean) { if(null == bean){ return null; } bean.setReferencedByDeviceId(instanceOfDeviceManager().loadByPrimaryKey(bean.getDeviceId())); return bean.getReferencedByDeviceId(); } //5.2 SET REFERENCED override IImageManager @Override public DeviceBean setReferencedByDeviceId(ImageBean bean, DeviceBean beanToSet) { try{ net.gdface.facelog.dborm.image.FlImageBean nativeBean = this.beanConverter.toRight(bean); IBeanConverter foreignConverter = this.dbConverter.getDeviceBeanConverter(); net.gdface.facelog.dborm.device.FlDeviceBean foreignNativeBean = foreignConverter.toRight(beanToSet); this.nativeManager.setReferencedByDeviceId(nativeBean,foreignNativeBean); this.beanConverter.fromRight(bean, nativeBean); foreignConverter.fromRight(beanToSet,foreignNativeBean); return beanToSet; } catch(DaoException e) { throw new RuntimeDaoException(e); } } ////////////////////////////////////// // SQL 'WHERE' METHOD ////////////////////////////////////// //11 @Override public int deleteByWhere(String where) { try{ return this.nativeManager.deleteByWhere(where); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //_____________________________________________________________________ // // SAVE //_____________________________________________________________________ //13 @Override protected ImageBean insert(ImageBean bean) { try{ return this.beanConverter.fromRight(bean,this.nativeManager.insert(this.beanConverter.toRight(bean))); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //14 @Override protected ImageBean update(ImageBean bean) { try{ return this.beanConverter.fromRight(bean,this.nativeManager.update(this.beanConverter.toRight(bean))); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //_____________________________________________________________________ // // USING TEMPLATE //_____________________________________________________________________ //18 @Override public ImageBean loadUniqueUsingTemplate(ImageBean bean) { try{ return this.beanConverter.fromRight(this.nativeManager.loadUniqueUsingTemplate(this.beanConverter.toRight(bean))); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //18-1 @Override public ImageBean loadUniqueUsingTemplateChecked(ImageBean bean) throws ObjectRetrievalException { try{ return this.beanConverter.fromRight(this.nativeManager.loadUniqueUsingTemplateChecked(this.beanConverter.toRight(bean))); } catch(net.gdface.facelog.dborm.exception.ObjectRetrievalException e) { throw new ObjectRetrievalException(); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //20-5 @Override public int loadUsingTemplate(ImageBean bean, int[] fieldList, int startRow, int numRows,int searchType, Action action) { try { return this.nativeManager.loadUsingTemplate(this.beanConverter.toRight(bean),fieldList,startRow,numRows,searchType,this.toNative(action)); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //21 @Override public int deleteUsingTemplate(ImageBean bean) { try{ return this.nativeManager.deleteUsingTemplate(this.beanConverter.toRight(bean)); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //_____________________________________________________________________ // // USING INDICES //_____________________________________________________________________ // override IImageManager @Override public ImageBean[] loadByIndexDeviceId(Integer deviceId) { return this.loadByIndexDeviceIdAsList(deviceId).toArray(new ImageBean[0]); } // override IImageManager @Override public java.util.List loadByIndexDeviceIdAsList(Integer deviceId) { try{ return this.beanConverter.fromRight(this.nativeManager.loadByIndexDeviceIdAsList(deviceId)); } catch(DaoException e) { throw new RuntimeDaoException(e); } } // override IImageManager @Override public int deleteByIndexDeviceId(Integer deviceId) { try{ return this.nativeManager.deleteByIndexDeviceId(deviceId); } catch(DaoException e) { throw new RuntimeDaoException(e); } } /** * Retrieves a list of ImageBean using the index specified by keyIndex. * @param keyIndex valid values:
* {@link Constant#FL_IMAGE_INDEX_DEVICE_ID} * @param keys key values of index * @return a list of ImageBean */ @Override public java.util.List loadByIndexAsList(int keyIndex,Object ...keys) { try{ return this.beanConverter.fromRight(this.nativeManager.loadByIndexAsList(keyIndex,keys)); }catch(DaoException e){ throw new RuntimeDaoException(e); } } /** * Deletes rows using key. * @param keyIndex valid values:
* {@link Constant#FL_IMAGE_INDEX_DEVICE_ID} * @param keys key values of index * @return the number of deleted objects */ @Override public int deleteByIndex(int keyIndex,Object ...keys) { try{ return this.nativeManager.deleteByIndex(keyIndex,keys); }catch(DaoException e){ throw new RuntimeDaoException(e); } } //_____________________________________________________________________ // // COUNT //_____________________________________________________________________ //25 @Override public int countWhere(String where) { try{ return this.nativeManager.countWhere(where); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //20 @Override public int countUsingTemplate(ImageBean bean, int searchType) { try{ return this.nativeManager.countUsingTemplate(this.beanConverter.toRight(bean),searchType); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //_____________________________________________________________________ // // LISTENER //_____________________________________________________________________ //35 /** * @return {@link WrapListener} instance */ @Override public TableListener registerListener(TableListener listener) { WrapListener wrapListener; if(listener instanceof WrapListener){ wrapListener = (WrapListener)listener; this.nativeManager.registerListener(wrapListener.nativeListener); }else{ wrapListener = new WrapListener(listener); this.nativeManager.registerListener(wrapListener.nativeListener); } return wrapListener; } //36 @Override public void unregisterListener(TableListener listener) { if(!(listener instanceof WrapListener)){ throw new IllegalArgumentException("invalid listener type: " + WrapListener.class.getName() +" required"); } this.nativeManager.unregisterListener(((WrapListener)listener).nativeListener); } //37 @Override public void fire(TableListener.Event event, ImageBean bean){ fire(event.ordinal(), bean); } //37-1 @Override public void fire(int event, ImageBean bean){ try{ this.nativeManager.fire(event, this.beanConverter.toRight(bean)); } catch(DaoException e) { throw new RuntimeDaoException(e); } } //37-2 /** * bind foreign key listener to foreign table for DELETE RULE */ void bindForeignKeyListenerForDeleteRule(){ this.nativeManager.bindForeignKeyListenerForDeleteRule(); } //37-3 /** * unbind foreign key listener from all of foreign tables
* @see #bindForeignKeyListenerForDeleteRule() */ void unbindForeignKeyListenerForDeleteRule(){ this.nativeManager.unbindForeignKeyListenerForDeleteRule(); } /** * wrap {@code TableListener} as native listener */ public class WrapListener implements TableListener{ private final TableListener listener; private final net.gdface.facelog.dborm.TableListener nativeListener; private WrapListener(final TableListener listener) { if(null == listener){ throw new NullPointerException(); } this.listener = listener; this.nativeListener = new net.gdface.facelog.dborm.TableListener (){ @Override public void beforeInsert(net.gdface.facelog.dborm.image.FlImageBean bean) throws DaoException { listener.beforeInsert(ImageManager.this.beanConverter.fromRight(bean)); } @Override public void afterInsert(net.gdface.facelog.dborm.image.FlImageBean bean) throws DaoException { listener.afterInsert(ImageManager.this.beanConverter.fromRight(bean)); } @Override public void beforeUpdate(net.gdface.facelog.dborm.image.FlImageBean bean) throws DaoException { listener.beforeUpdate(ImageManager.this.beanConverter.fromRight(bean)); } @Override public void afterUpdate(net.gdface.facelog.dborm.image.FlImageBean bean) throws DaoException { listener.afterUpdate(ImageManager.this.beanConverter.fromRight(bean)); } @Override public void beforeDelete(net.gdface.facelog.dborm.image.FlImageBean bean) throws DaoException { listener.beforeDelete(ImageManager.this.beanConverter.fromRight(bean)); } @Override public void afterDelete(net.gdface.facelog.dborm.image.FlImageBean bean) throws DaoException { listener.afterDelete(ImageManager.this.beanConverter.fromRight(bean)); } @Override public void done() throws DaoException { listener.done(); }}; } @Override public void beforeInsert(ImageBean bean) { listener.beforeInsert(bean); } @Override public void afterInsert(ImageBean bean) { listener.afterInsert(bean); } @Override public void beforeUpdate(ImageBean bean) { listener.beforeUpdate(bean); } @Override public void afterUpdate(ImageBean bean) { listener.afterUpdate(bean); } @Override public void beforeDelete(ImageBean bean) { listener.beforeDelete(bean); } @Override public void afterDelete(ImageBean bean) { listener.afterDelete(bean); } @Override public void done() { listener.done(); } } //_____________________________________________________________________ // // UTILS //_____________________________________________________________________ //43 @Override public boolean isPrimaryKey(String column){ return this.nativeManager.isPrimaryKey(column); } @Override public int loadBySqlForAction(String sql, Object[] argList, int[] fieldList,int startRow, int numRows,Action action){ try{ return this.nativeManager.loadBySqlForAction(sql,argList,fieldList,startRow,numRows,this.toNative(action)); } catch(DaoException e) { throw new RuntimeDaoException(e); } } @Override public T runAsTransaction(Callable fun) { try{ return this.nativeManager.runAsTransaction(fun); } catch(DaoException e) { throw new RuntimeDaoException(e); } } @Override public void runAsTransaction(Runnable fun) { try{ this.nativeManager.runAsTransaction(fun); } catch(DaoException e) { throw new RuntimeDaoException(e); } } private net.gdface.facelog.dborm.TableManager.Action toNative(final Action action){ if(null == action){ throw new NullPointerException(); } return new net.gdface.facelog.dborm.TableManager.Action(){ @Override public void call(net.gdface.facelog.dborm.image.FlImageBean bean) { action.call(ImageManager.this.beanConverter.fromRight(bean)); } @Override public net.gdface.facelog.dborm.image.FlImageBean getBean() { return ImageManager.this.beanConverter.toRight(action.getBean()); }}; } //45 override IImageManager @Override public java.util.List toPrimaryKeyList(ImageBean... beans){ if(null == beans){ return new java.util.ArrayList(); } java.util.ArrayList list = new java.util.ArrayList(beans.length); for(ImageBean bean:beans){ list.add(null == bean ? null : bean.getMd5()); } return list; } //46 override IImageManager @Override public java.util.List toPrimaryKeyList(java.util.Collection beans){ if(null == beans){ return new java.util.ArrayList(); } java.util.ArrayList list = new java.util.ArrayList(beans.size()); for(ImageBean bean:beans){ list.add(null == bean ? null : bean.getMd5()); } return list; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy