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: bean.java.vm
007// ______________________________________________________
008package net.gdface.facelog.db;
009import java.io.Serializable;
010import java.util.List;
011import java.util.Objects;
012
013import com.facebook.swift.codec.ThriftStruct;
014import com.facebook.swift.codec.ThriftField;
015import com.facebook.swift.codec.ThriftField.Requiredness;
016import io.swagger.annotations.ApiModel;
017import io.swagger.annotations.ApiModelProperty;
018/**
019 * ImageBean is a mapping of fl_image Table.
020 * <br>Meta Data Information (in progress):
021 * <ul>
022 *    <li>comments: 图像信息存储表,用于存储系统中所有用到的图像数据,表中只包含图像基本信息,图像二进制源数据存在在fl_store中(md5对应) </li>
023 * </ul>
024 * @author guyadong
025*/
026@ThriftStruct
027@ApiModel(description="图像信息存储表,用于存储系统中所有用到的图像数据,表中只包含图像基本信息,图像二进制源数据存在在fl_store中(md5对应)")
028public final class ImageBean
029    implements Serializable,BaseBean<ImageBean>,Comparable<ImageBean>,Constant,Cloneable
030{
031    private static final long serialVersionUID = -5491214114261088424L;
032    /** NULL {@link ImageBean} bean , IMMUTABLE instance */
033    public static final ImageBean NULL = new ImageBean().asNULL().asImmutable();
034    /** comments:主键,图像md5检验码,同时也是从 fl_store 获取图像数据的key */
035    @ApiModelProperty(value = "主键,图像md5检验码,同时也是从 fl_store 获取图像数据的key" ,required=true ,dataType="String")
036    private String md5;
037
038    /** comments:图像格式 */
039    @ApiModelProperty(value = "图像格式"  ,dataType="String")
040    private String format;
041
042    /** comments:图像宽度 */
043    @ApiModelProperty(value = "图像宽度" ,required=true ,dataType="Integer")
044    private Integer width;
045
046    /** comments:图像高度 */
047    @ApiModelProperty(value = "图像高度" ,required=true ,dataType="Integer")
048    private Integer height;
049
050    /** comments:通道数 */
051    @ApiModelProperty(value = "通道数"  ,dataType="Integer")
052    private Integer depth;
053
054    /** comments:图像中的人脸数目 */
055    @ApiModelProperty(value = "图像中的人脸数目"  ,dataType="Integer")
056    private Integer faceNum;
057
058    /** comments:缩略图md5,图像数据存储在 fl_imae_store(md5) */
059    @ApiModelProperty(value = "缩略图md5,图像数据存储在 fl_imae_store(md5)"  ,dataType="String")
060    private String thumbMd5;
061
062    /** comments:外键,图像来源设备 */
063    @ApiModelProperty(value = "外键,图像来源设备"  ,dataType="Integer")
064    private Integer deviceId;
065
066    /** flag whether {@code this} can be modified */
067    private Boolean immutable;
068    /** columns modified flag */
069    @ApiModelProperty(value="columns modified flag",dataType="int",required=true)
070    private int modified;
071    /** columns initialized flag */
072    @ApiModelProperty(value="columns initialized flag",dataType="int",required=true)
073    private int initialized;
074    /** new record flag  */
075    @ApiModelProperty(value="new record flag",dataType="boolean",required=true)
076    private boolean isNew;        
077    /** 
078     * set immutable status
079     * @return {@code this} 
080     */
081    private ImageBean immutable(Boolean immutable) {
082        this.immutable = immutable;
083        return this;
084    }
085    /** 
086     * set {@code this} as immutable object
087     * @return {@code this} 
088     */
089    public ImageBean asImmutable() {
090        return immutable(Boolean.TRUE);
091    }
092    /**
093     * @return {@code true} if {@code this} is a mutable object  
094     */
095    public boolean mutable(){
096        return !Boolean.TRUE.equals(this.immutable);
097    }
098    /**
099     * @return {@code this}
100     * @throws IllegalStateException if {@code this} is a immutable object 
101     */
102    private ImageBean checkMutable(){
103        if(!mutable()){
104            throw new IllegalStateException("this is a immutable object");
105        }
106        return this;
107    }
108    /**
109     * @return return a new mutable copy of this object.
110     */
111    public ImageBean cloneMutable(){
112        return clone().immutable(null);
113    }
114    @ThriftField(value=1,name="_new",requiredness=Requiredness.REQUIRED)
115    @Override
116    public boolean isNew()
117    {
118        return this.isNew;
119    }
120
121
122    @Override
123    public void isNew(boolean isNew)
124    {
125        this.isNew = isNew;
126    }
127    /**
128     * Specifies to the object if it has been set as new.
129     *
130     * @param isNew the boolean value to be assigned to the isNew field
131     */
132    @ThriftField()
133    public void setNew(boolean isNew)
134    {
135        this.isNew = isNew;
136    }
137    /**
138     * @return the modified status of columns
139     */
140    @ThriftField(value=2,requiredness=Requiredness.REQUIRED)
141    public int getModified(){
142        return modified;
143    }
144
145    /**
146     * @param modified the modified status bit to be assigned to {@link #modified}
147     */
148    @ThriftField()
149    public void setModified(int modified){
150        this.modified = modified;
151    }
152    /**
153     * @return the initialized status of columns
154     */
155    @ThriftField(value=3,requiredness=Requiredness.REQUIRED)
156    public int getInitialized(){
157        return initialized;
158    }
159
160    /**
161     * @param initialized the initialized status bit to be assigned to {@link #initialized}
162     */
163    @ThriftField()
164    public void setInitialized(int initialized){
165        this.initialized = initialized;
166    }
167    protected static final <T extends Comparable<T>>boolean equals(T a, T b) {
168        return a == b || (a != null && 0==a.compareTo(b));
169    }
170    public ImageBean(){
171        super();
172        reset();
173    }
174    /**
175     * construct a new instance filled with primary keys
176     * @param md5 PK# 1 
177     */
178    public ImageBean(String md5){
179        this();
180        setMd5(md5);
181    }
182    /**
183     * Getter method for {@link #md5}.<br>
184     * PRIMARY KEY.<br>
185     * Meta Data Information (in progress):
186     * <ul>
187     * <li>full name: fl_image.md5</li>
188     * <li> imported key: fl_face.image_md5</li>
189     * <li> imported key: fl_person.image_md5</li>
190     * <li>comments: 主键,图像md5检验码,同时也是从 fl_store 获取图像数据的key</li>
191     * <li>NOT NULL</li>
192     * <li>column size: 32</li>
193     * <li>JDBC type returned by the driver: Types.CHAR</li>
194     * </ul>
195     *
196     * @return the value of md5
197     */
198    @ThriftField(value=4)
199    public String getMd5(){
200        return md5;
201    }
202    /**
203     * Setter method for {@link #md5}.<br>
204     * The new value is set only if equals() says it is different,
205     * or if one of either the new value or the current value is null.
206     * In case the new value is different, it is set and the field is marked as 'modified'.
207     *
208     * @param newVal the new value( NOT NULL) to be assigned to md5
209     */
210    public void setMd5(String newVal)
211    {
212        checkMutable();
213
214        modified |= FL_IMAGE_ID_MD5_MASK;
215        initialized |= FL_IMAGE_ID_MD5_MASK;
216
217        if (Objects.equals(newVal, md5)) {
218            return;
219        }
220        md5 = newVal;
221    }
222    /** 
223     * setter for thrift:swift support<br>
224     * without modification for {@link #modified} and {@link #initialized}<br>
225     * <b>NOTE:</b>DO NOT use the method in your code
226     */
227    @ThriftField(name = "md5")
228    public void writeMd5(String newVal){
229        checkMutable();
230        md5 = newVal;
231    }
232    /**
233     * Determines if the md5 has been modified.
234     *
235     * @return true if the field has been modified, false if the field has not been modified
236     */
237    public boolean checkMd5Modified()
238    {
239        return 0L !=  (modified & FL_IMAGE_ID_MD5_MASK);
240    }
241
242    /**
243     * Determines if the md5 has been initialized.<br>
244     *
245     * It is useful to determine if a field is null on purpose or just because it has not been initialized.
246     *
247     * @return true if the field has been initialized, false otherwise
248     */
249    public boolean checkMd5Initialized()
250    {
251        return 0L !=  (initialized & FL_IMAGE_ID_MD5_MASK);
252    }
253    /**
254     * Getter method for {@link #format}.<br>
255     * Meta Data Information (in progress):
256     * <ul>
257     * <li>full name: fl_image.format</li>
258     * <li>comments: 图像格式</li>
259     * <li>column size: 32</li>
260     * <li>JDBC type returned by the driver: Types.VARCHAR</li>
261     * </ul>
262     *
263     * @return the value of format
264     */
265    @ThriftField(value=5)
266    public String getFormat(){
267        return format;
268    }
269    /**
270     * Setter method for {@link #format}.<br>
271     * The new value is set only if equals() says it is different,
272     * or if one of either the new value or the current value is null.
273     * In case the new value is different, it is set and the field is marked as 'modified'.
274     *
275     * @param newVal the new value to be assigned to format
276     */
277    public void setFormat(String newVal)
278    {
279        checkMutable();
280
281        modified |= FL_IMAGE_ID_FORMAT_MASK;
282        initialized |= FL_IMAGE_ID_FORMAT_MASK;
283
284        if (Objects.equals(newVal, format)) {
285            return;
286        }
287        format = newVal;
288    }
289    /** 
290     * setter for thrift:swift support<br>
291     * without modification for {@link #modified} and {@link #initialized}<br>
292     * <b>NOTE:</b>DO NOT use the method in your code
293     */
294    @ThriftField(name = "format")
295    public void writeFormat(String newVal){
296        checkMutable();
297        format = newVal;
298    }
299    /**
300     * Determines if the format has been modified.
301     *
302     * @return true if the field has been modified, false if the field has not been modified
303     */
304    public boolean checkFormatModified()
305    {
306        return 0L !=  (modified & FL_IMAGE_ID_FORMAT_MASK);
307    }
308
309    /**
310     * Determines if the format has been initialized.<br>
311     *
312     * It is useful to determine if a field is null on purpose or just because it has not been initialized.
313     *
314     * @return true if the field has been initialized, false otherwise
315     */
316    public boolean checkFormatInitialized()
317    {
318        return 0L !=  (initialized & FL_IMAGE_ID_FORMAT_MASK);
319    }
320    /**
321     * Getter method for {@link #width}.<br>
322     * Meta Data Information (in progress):
323     * <ul>
324     * <li>full name: fl_image.width</li>
325     * <li>comments: 图像宽度</li>
326     * <li>NOT NULL</li>
327     * <li>column size: 10</li>
328     * <li>JDBC type returned by the driver: Types.INTEGER</li>
329     * </ul>
330     *
331     * @return the value of width
332     */
333    @ThriftField(value=6)
334    public Integer getWidth(){
335        return width;
336    }
337    /**
338     * Setter method for {@link #width}.<br>
339     * The new value is set only if equals() says it is different,
340     * or if one of either the new value or the current value is null.
341     * In case the new value is different, it is set and the field is marked as 'modified'.
342     *
343     * @param newVal the new value( NOT NULL) to be assigned to width
344     */
345    public void setWidth(Integer newVal)
346    {
347        checkMutable();
348
349        modified |= FL_IMAGE_ID_WIDTH_MASK;
350        initialized |= FL_IMAGE_ID_WIDTH_MASK;
351
352        if (Objects.equals(newVal, width)) {
353            return;
354        }
355        width = newVal;
356    }
357    /** 
358     * setter for thrift:swift support<br>
359     * without modification for {@link #modified} and {@link #initialized}<br>
360     * <b>NOTE:</b>DO NOT use the method in your code
361     */
362    @ThriftField(name = "width")
363    public void writeWidth(Integer newVal){
364        checkMutable();
365        width = newVal;
366    }
367    /**
368     * Setter method for {@link #width}.<br>
369     * Convenient for those who do not want to deal with Objects for primary types.
370     *
371     * @param newVal the new value to be assigned to width
372     */
373    public void setWidth(int newVal)
374    {
375        setWidth(new Integer(newVal));
376    }
377    /**
378     * Determines if the width has been modified.
379     *
380     * @return true if the field has been modified, false if the field has not been modified
381     */
382    public boolean checkWidthModified()
383    {
384        return 0L !=  (modified & FL_IMAGE_ID_WIDTH_MASK);
385    }
386
387    /**
388     * Determines if the width has been initialized.<br>
389     *
390     * It is useful to determine if a field is null on purpose or just because it has not been initialized.
391     *
392     * @return true if the field has been initialized, false otherwise
393     */
394    public boolean checkWidthInitialized()
395    {
396        return 0L !=  (initialized & FL_IMAGE_ID_WIDTH_MASK);
397    }
398    /**
399     * Getter method for {@link #height}.<br>
400     * Meta Data Information (in progress):
401     * <ul>
402     * <li>full name: fl_image.height</li>
403     * <li>comments: 图像高度</li>
404     * <li>NOT NULL</li>
405     * <li>column size: 10</li>
406     * <li>JDBC type returned by the driver: Types.INTEGER</li>
407     * </ul>
408     *
409     * @return the value of height
410     */
411    @ThriftField(value=7)
412    public Integer getHeight(){
413        return height;
414    }
415    /**
416     * Setter method for {@link #height}.<br>
417     * The new value is set only if equals() says it is different,
418     * or if one of either the new value or the current value is null.
419     * In case the new value is different, it is set and the field is marked as 'modified'.
420     *
421     * @param newVal the new value( NOT NULL) to be assigned to height
422     */
423    public void setHeight(Integer newVal)
424    {
425        checkMutable();
426
427        modified |= FL_IMAGE_ID_HEIGHT_MASK;
428        initialized |= FL_IMAGE_ID_HEIGHT_MASK;
429
430        if (Objects.equals(newVal, height)) {
431            return;
432        }
433        height = newVal;
434    }
435    /** 
436     * setter for thrift:swift support<br>
437     * without modification for {@link #modified} and {@link #initialized}<br>
438     * <b>NOTE:</b>DO NOT use the method in your code
439     */
440    @ThriftField(name = "height")
441    public void writeHeight(Integer newVal){
442        checkMutable();
443        height = newVal;
444    }
445    /**
446     * Setter method for {@link #height}.<br>
447     * Convenient for those who do not want to deal with Objects for primary types.
448     *
449     * @param newVal the new value to be assigned to height
450     */
451    public void setHeight(int newVal)
452    {
453        setHeight(new Integer(newVal));
454    }
455    /**
456     * Determines if the height has been modified.
457     *
458     * @return true if the field has been modified, false if the field has not been modified
459     */
460    public boolean checkHeightModified()
461    {
462        return 0L !=  (modified & FL_IMAGE_ID_HEIGHT_MASK);
463    }
464
465    /**
466     * Determines if the height has been initialized.<br>
467     *
468     * It is useful to determine if a field is null on purpose or just because it has not been initialized.
469     *
470     * @return true if the field has been initialized, false otherwise
471     */
472    public boolean checkHeightInitialized()
473    {
474        return 0L !=  (initialized & FL_IMAGE_ID_HEIGHT_MASK);
475    }
476    /**
477     * Getter method for {@link #depth}.<br>
478     * Meta Data Information (in progress):
479     * <ul>
480     * <li>full name: fl_image.depth</li>
481     * <li>comments: 通道数</li>
482     * <li>default value: '0'</li>
483     * <li>NOT NULL</li>
484     * <li>column size: 10</li>
485     * <li>JDBC type returned by the driver: Types.INTEGER</li>
486     * </ul>
487     *
488     * @return the value of depth
489     */
490    @ThriftField(value=8)
491    public Integer getDepth(){
492        return depth;
493    }
494    /**
495     * Setter method for {@link #depth}.<br>
496     * The new value is set only if equals() says it is different,
497     * or if one of either the new value or the current value is null.
498     * In case the new value is different, it is set and the field is marked as 'modified'.
499     *
500     * @param newVal the new value( NOT NULL) to be assigned to depth
501     */
502    public void setDepth(Integer newVal)
503    {
504        checkMutable();
505
506        modified |= FL_IMAGE_ID_DEPTH_MASK;
507        initialized |= FL_IMAGE_ID_DEPTH_MASK;
508
509        if (Objects.equals(newVal, depth)) {
510            return;
511        }
512        depth = newVal;
513    }
514    /** 
515     * setter for thrift:swift support<br>
516     * without modification for {@link #modified} and {@link #initialized}<br>
517     * <b>NOTE:</b>DO NOT use the method in your code
518     */
519    @ThriftField(name = "depth")
520    public void writeDepth(Integer newVal){
521        checkMutable();
522        depth = newVal;
523    }
524    /**
525     * Setter method for {@link #depth}.<br>
526     * Convenient for those who do not want to deal with Objects for primary types.
527     *
528     * @param newVal the new value to be assigned to depth
529     */
530    public void setDepth(int newVal)
531    {
532        setDepth(new Integer(newVal));
533    }
534    /**
535     * Determines if the depth has been modified.
536     *
537     * @return true if the field has been modified, false if the field has not been modified
538     */
539    public boolean checkDepthModified()
540    {
541        return 0L !=  (modified & FL_IMAGE_ID_DEPTH_MASK);
542    }
543
544    /**
545     * Determines if the depth has been initialized.<br>
546     *
547     * It is useful to determine if a field is null on purpose or just because it has not been initialized.
548     *
549     * @return true if the field has been initialized, false otherwise
550     */
551    public boolean checkDepthInitialized()
552    {
553        return 0L !=  (initialized & FL_IMAGE_ID_DEPTH_MASK);
554    }
555    /**
556     * Getter method for {@link #faceNum}.<br>
557     * Meta Data Information (in progress):
558     * <ul>
559     * <li>full name: fl_image.face_num</li>
560     * <li>comments: 图像中的人脸数目</li>
561     * <li>default value: '0'</li>
562     * <li>NOT NULL</li>
563     * <li>column size: 10</li>
564     * <li>JDBC type returned by the driver: Types.INTEGER</li>
565     * </ul>
566     *
567     * @return the value of faceNum
568     */
569    @ThriftField(value=9)
570    public Integer getFaceNum(){
571        return faceNum;
572    }
573    /**
574     * Setter method for {@link #faceNum}.<br>
575     * The new value is set only if equals() says it is different,
576     * or if one of either the new value or the current value is null.
577     * In case the new value is different, it is set and the field is marked as 'modified'.
578     *
579     * @param newVal the new value( NOT NULL) to be assigned to faceNum
580     */
581    public void setFaceNum(Integer newVal)
582    {
583        checkMutable();
584
585        modified |= FL_IMAGE_ID_FACE_NUM_MASK;
586        initialized |= FL_IMAGE_ID_FACE_NUM_MASK;
587
588        if (Objects.equals(newVal, faceNum)) {
589            return;
590        }
591        faceNum = newVal;
592    }
593    /** 
594     * setter for thrift:swift support<br>
595     * without modification for {@link #modified} and {@link #initialized}<br>
596     * <b>NOTE:</b>DO NOT use the method in your code
597     */
598    @ThriftField(name = "faceNum")
599    public void writeFaceNum(Integer newVal){
600        checkMutable();
601        faceNum = newVal;
602    }
603    /**
604     * Setter method for {@link #faceNum}.<br>
605     * Convenient for those who do not want to deal with Objects for primary types.
606     *
607     * @param newVal the new value to be assigned to faceNum
608     */
609    public void setFaceNum(int newVal)
610    {
611        setFaceNum(new Integer(newVal));
612    }
613    /**
614     * Determines if the faceNum has been modified.
615     *
616     * @return true if the field has been modified, false if the field has not been modified
617     */
618    public boolean checkFaceNumModified()
619    {
620        return 0L !=  (modified & FL_IMAGE_ID_FACE_NUM_MASK);
621    }
622
623    /**
624     * Determines if the faceNum has been initialized.<br>
625     *
626     * It is useful to determine if a field is null on purpose or just because it has not been initialized.
627     *
628     * @return true if the field has been initialized, false otherwise
629     */
630    public boolean checkFaceNumInitialized()
631    {
632        return 0L !=  (initialized & FL_IMAGE_ID_FACE_NUM_MASK);
633    }
634    /**
635     * Getter method for {@link #thumbMd5}.<br>
636     * Meta Data Information (in progress):
637     * <ul>
638     * <li>full name: fl_image.thumb_md5</li>
639     * <li>comments: 缩略图md5,图像数据存储在 fl_imae_store(md5)</li>
640     * <li>column size: 32</li>
641     * <li>JDBC type returned by the driver: Types.CHAR</li>
642     * </ul>
643     *
644     * @return the value of thumbMd5
645     */
646    @ThriftField(value=10)
647    public String getThumbMd5(){
648        return thumbMd5;
649    }
650    /**
651     * Setter method for {@link #thumbMd5}.<br>
652     * The new value is set only if equals() says it is different,
653     * or if one of either the new value or the current value is null.
654     * In case the new value is different, it is set and the field is marked as 'modified'.
655     *
656     * @param newVal the new value to be assigned to thumbMd5
657     */
658    public void setThumbMd5(String newVal)
659    {
660        checkMutable();
661
662        modified |= FL_IMAGE_ID_THUMB_MD5_MASK;
663        initialized |= FL_IMAGE_ID_THUMB_MD5_MASK;
664
665        if (Objects.equals(newVal, thumbMd5)) {
666            return;
667        }
668        thumbMd5 = newVal;
669    }
670    /** 
671     * setter for thrift:swift support<br>
672     * without modification for {@link #modified} and {@link #initialized}<br>
673     * <b>NOTE:</b>DO NOT use the method in your code
674     */
675    @ThriftField(name = "thumbMd5")
676    public void writeThumbMd5(String newVal){
677        checkMutable();
678        thumbMd5 = newVal;
679    }
680    /**
681     * Determines if the thumbMd5 has been modified.
682     *
683     * @return true if the field has been modified, false if the field has not been modified
684     */
685    public boolean checkThumbMd5Modified()
686    {
687        return 0L !=  (modified & FL_IMAGE_ID_THUMB_MD5_MASK);
688    }
689
690    /**
691     * Determines if the thumbMd5 has been initialized.<br>
692     *
693     * It is useful to determine if a field is null on purpose or just because it has not been initialized.
694     *
695     * @return true if the field has been initialized, false otherwise
696     */
697    public boolean checkThumbMd5Initialized()
698    {
699        return 0L !=  (initialized & FL_IMAGE_ID_THUMB_MD5_MASK);
700    }
701    /**
702     * Getter method for {@link #deviceId}.<br>
703     * Meta Data Information (in progress):
704     * <ul>
705     * <li>full name: fl_image.device_id</li>
706     * <li> foreign key: fl_device.id</li>
707     * <li>comments: 外键,图像来源设备</li>
708     * <li>column size: 10</li>
709     * <li>JDBC type returned by the driver: Types.INTEGER</li>
710     * </ul>
711     *
712     * @return the value of deviceId
713     */
714    @ThriftField(value=11)
715    public Integer getDeviceId(){
716        return deviceId;
717    }
718    /**
719     * Setter method for {@link #deviceId}.<br>
720     * The new value is set only if equals() says it is different,
721     * or if one of either the new value or the current value is null.
722     * In case the new value is different, it is set and the field is marked as 'modified'.
723     *
724     * @param newVal the new value to be assigned to deviceId
725     */
726    public void setDeviceId(Integer newVal)
727    {
728        checkMutable();
729
730        modified |= FL_IMAGE_ID_DEVICE_ID_MASK;
731        initialized |= FL_IMAGE_ID_DEVICE_ID_MASK;
732
733        if (Objects.equals(newVal, deviceId)) {
734            return;
735        }
736        deviceId = newVal;
737    }
738    /** 
739     * setter for thrift:swift support<br>
740     * without modification for {@link #modified} and {@link #initialized}<br>
741     * <b>NOTE:</b>DO NOT use the method in your code
742     */
743    @ThriftField(name = "deviceId")
744    public void writeDeviceId(Integer newVal){
745        checkMutable();
746        deviceId = newVal;
747    }
748    /**
749     * Setter method for {@link #deviceId}.<br>
750     * Convenient for those who do not want to deal with Objects for primary types.
751     *
752     * @param newVal the new value to be assigned to deviceId
753     */
754    public void setDeviceId(int newVal)
755    {
756        setDeviceId(new Integer(newVal));
757    }
758    /**
759     * Determines if the deviceId has been modified.
760     *
761     * @return true if the field has been modified, false if the field has not been modified
762     */
763    public boolean checkDeviceIdModified()
764    {
765        return 0L !=  (modified & FL_IMAGE_ID_DEVICE_ID_MASK);
766    }
767
768    /**
769     * Determines if the deviceId has been initialized.<br>
770     *
771     * It is useful to determine if a field is null on purpose or just because it has not been initialized.
772     *
773     * @return true if the field has been initialized, false otherwise
774     */
775    public boolean checkDeviceIdInitialized()
776    {
777        return 0L !=  (initialized & FL_IMAGE_ID_DEVICE_ID_MASK);
778    }
779    //////////////////////////////////////
780    // referenced bean for FOREIGN KEYS
781    //////////////////////////////////////
782    /** 
783     * The referenced {@link DeviceBean} by {@link #deviceId} . <br>
784     * FOREIGN KEY (device_id) REFERENCES fl_device(id)
785     */
786    @ApiModelProperty(hidden = true)
787    private DeviceBean referencedByDeviceId;
788    /**
789     * Getter method for {@link #referencedByDeviceId}.
790     * @return DeviceBean
791     */
792    public DeviceBean getReferencedByDeviceId() {
793        return this.referencedByDeviceId;
794    }
795    /**
796     * Setter method for {@link #referencedByDeviceId}.
797     * @param reference DeviceBean
798     */
799    public void setReferencedByDeviceId(DeviceBean reference) {
800        this.referencedByDeviceId = reference;
801    }
802
803    @Override
804    public boolean isModified()
805    {
806        return 0 != modified;
807    }
808  
809    @Override
810    public boolean isModified(int columnID){
811        switch ( columnID ){
812        case FL_IMAGE_ID_MD5:
813            return checkMd5Modified();
814        case FL_IMAGE_ID_FORMAT:
815            return checkFormatModified();
816        case FL_IMAGE_ID_WIDTH:
817            return checkWidthModified();
818        case FL_IMAGE_ID_HEIGHT:
819            return checkHeightModified();
820        case FL_IMAGE_ID_DEPTH:
821            return checkDepthModified();
822        case FL_IMAGE_ID_FACE_NUM:
823            return checkFaceNumModified();
824        case FL_IMAGE_ID_THUMB_MD5:
825            return checkThumbMd5Modified();
826        case FL_IMAGE_ID_DEVICE_ID:
827            return checkDeviceIdModified();
828        default:
829            return false;
830        }        
831    }
832
833    @Override
834    public boolean isInitialized(int columnID){
835        switch(columnID) {
836        case FL_IMAGE_ID_MD5:
837            return checkMd5Initialized();
838        case FL_IMAGE_ID_FORMAT:
839            return checkFormatInitialized();
840        case FL_IMAGE_ID_WIDTH:
841            return checkWidthInitialized();
842        case FL_IMAGE_ID_HEIGHT:
843            return checkHeightInitialized();
844        case FL_IMAGE_ID_DEPTH:
845            return checkDepthInitialized();
846        case FL_IMAGE_ID_FACE_NUM:
847            return checkFaceNumInitialized();
848        case FL_IMAGE_ID_THUMB_MD5:
849            return checkThumbMd5Initialized();
850        case FL_IMAGE_ID_DEVICE_ID:
851            return checkDeviceIdInitialized();
852        default:
853            return false;
854        }
855    }
856    
857    @Override
858    public boolean isModified(String column){        
859        return isModified(columnIDOf(column));
860    }
861
862    @Override
863    public boolean isInitialized(String column){
864        return isInitialized(columnIDOf(column));
865    }
866    
867    @Override
868    public void resetIsModified()
869    {
870        checkMutable();
871        modified = 0;
872    }
873
874    @Override
875    public void resetPrimaryKeysModified()
876    {
877        modified &= (~(FL_IMAGE_ID_MD5_MASK));
878    }
879    /**
880     * Resets columns modification status except primary keys to 'not modified'.
881     */
882    public void resetModifiedExceptPrimaryKeys()
883    {
884        modified &= (~(FL_IMAGE_ID_FORMAT_MASK |
885            FL_IMAGE_ID_WIDTH_MASK |
886            FL_IMAGE_ID_HEIGHT_MASK |
887            FL_IMAGE_ID_DEPTH_MASK |
888            FL_IMAGE_ID_FACE_NUM_MASK |
889            FL_IMAGE_ID_THUMB_MD5_MASK |
890            FL_IMAGE_ID_DEVICE_ID_MASK));
891    }
892    /**
893     * Resets the object initialization status to 'not initialized'.
894     */
895    private void resetInitialized()
896    {
897        initialized = 0;
898    }
899    /** reset all fields to initial value, equal to a new bean */
900    public void reset(){
901        checkMutable();
902        this.md5 = null;
903        this.format = null;
904        this.width = null;
905        this.height = null;
906        /* DEFAULT:'0'*/
907        this.depth = new Integer(0);
908        /* DEFAULT:'0'*/
909        this.faceNum = new Integer(0);
910        this.thumbMd5 = null;
911        this.deviceId = null;
912        this.isNew = true;
913        this.modified = 0;
914        this.initialized = (FL_IMAGE_ID_DEPTH_MASK | FL_IMAGE_ID_FACE_NUM_MASK);
915    }
916    @Override
917    public boolean equals(Object object)
918    {
919        if (!(object instanceof ImageBean)) {
920            return false;
921        }
922
923        ImageBean obj = (ImageBean) object;
924        return new EqualsBuilder()
925            .append(getMd5(), obj.getMd5())
926            .append(getFormat(), obj.getFormat())
927            .append(getWidth(), obj.getWidth())
928            .append(getHeight(), obj.getHeight())
929            .append(getDepth(), obj.getDepth())
930            .append(getFaceNum(), obj.getFaceNum())
931            .append(getThumbMd5(), obj.getThumbMd5())
932            .append(getDeviceId(), obj.getDeviceId())
933            .isEquals();
934    }
935
936    @Override
937    public int hashCode()
938    {
939        return new HashCodeBuilder(-82280557, -700257973)
940            .append(getMd5())
941            .toHashCode();
942    }
943
944    @Override
945    public String toString() {
946        return toString(true,false);
947    }
948    /**
949     * cast byte array to HEX string
950     * 
951     * @param input
952     * @return {@code null} if {@code input} is null
953     */
954    private static final String toHex(byte[] input) {
955        if (null == input){
956            return null;
957        }
958        StringBuffer sb = new StringBuffer(input.length * 2);
959        for (int i = 0; i < input.length; i++) {
960            sb.append(Character.forDigit((input[i] & 240) >> 4, 16));
961            sb.append(Character.forDigit(input[i] & 15, 16));
962        }
963        return sb.toString();
964    }
965    protected static final StringBuilder append(StringBuilder buffer,boolean full,byte[] value){
966        if(full || null == value){
967            buffer.append(toHex(value));
968        }else{
969            buffer.append(value.length).append(" bytes");
970        }
971        return buffer;
972    }
973    private static int stringLimit = 64;
974    private static final int MINIMUM_LIMIT = 16;
975    protected static final StringBuilder append(StringBuilder buffer,boolean full,String value){
976        if(full || null == value || value.length() <= stringLimit){
977            buffer.append(value);
978        }else{
979            buffer.append(value.substring(0,stringLimit - 8)).append(" ...").append(value.substring(stringLimit-4,stringLimit));
980        }
981        return buffer;
982    }
983    protected static final <T>StringBuilder append(StringBuilder buffer,boolean full,T value){
984        return buffer.append(value);
985    }
986    public static final void setStringLimit(int limit){
987        if(limit < MINIMUM_LIMIT){
988            throw new IllegalArgumentException(String.format("INVALID limit %d,minimum value %d",limit,MINIMUM_LIMIT));
989        }
990        stringLimit = limit;
991    }
992    @Override
993    public String toString(boolean notNull, boolean fullIfStringOrBytes) {
994        // only output initialized field
995        StringBuilder builder = new StringBuilder(this.getClass().getName()).append("@").append(Integer.toHexString(this.hashCode())).append("[");
996        int count = 0;        
997        if(checkMd5Initialized()){
998            if(!notNull || null != getMd5()){
999                if(count++ >0){
1000                    builder.append(",");
1001                }
1002                builder.append("md5=");
1003                append(builder,fullIfStringOrBytes,getMd5());
1004            }
1005        }
1006        if(checkFormatInitialized()){
1007            if(!notNull || null != getFormat()){
1008                if(count++ >0){
1009                    builder.append(",");
1010                }
1011                builder.append("format=");
1012                append(builder,fullIfStringOrBytes,getFormat());
1013            }
1014        }
1015        if(checkWidthInitialized()){
1016            if(!notNull || null != getWidth()){
1017                if(count++ >0){
1018                    builder.append(",");
1019                }
1020                builder.append("width=");
1021                append(builder,fullIfStringOrBytes,getWidth());
1022            }
1023        }
1024        if(checkHeightInitialized()){
1025            if(!notNull || null != getHeight()){
1026                if(count++ >0){
1027                    builder.append(",");
1028                }
1029                builder.append("height=");
1030                append(builder,fullIfStringOrBytes,getHeight());
1031            }
1032        }
1033        if(checkDepthInitialized()){
1034            if(!notNull || null != getDepth()){
1035                if(count++ >0){
1036                    builder.append(",");
1037                }
1038                builder.append("depth=");
1039                append(builder,fullIfStringOrBytes,getDepth());
1040            }
1041        }
1042        if(checkFaceNumInitialized()){
1043            if(!notNull || null != getFaceNum()){
1044                if(count++ >0){
1045                    builder.append(",");
1046                }
1047                builder.append("face_num=");
1048                append(builder,fullIfStringOrBytes,getFaceNum());
1049            }
1050        }
1051        if(checkThumbMd5Initialized()){
1052            if(!notNull || null != getThumbMd5()){
1053                if(count++ >0){
1054                    builder.append(",");
1055                }
1056                builder.append("thumb_md5=");
1057                append(builder,fullIfStringOrBytes,getThumbMd5());
1058            }
1059        }
1060        if(checkDeviceIdInitialized()){
1061            if(!notNull || null != getDeviceId()){
1062                if(count++ >0){
1063                    builder.append(",");
1064                }
1065                builder.append("device_id=");
1066                append(builder,fullIfStringOrBytes,getDeviceId());
1067            }
1068        }
1069        builder.append("]");
1070        return builder.toString();
1071    }
1072    @Override
1073    public int compareTo(ImageBean object){
1074        return new CompareToBuilder()
1075            .append(getMd5(), object.getMd5())
1076            .append(getFormat(), object.getFormat())
1077            .append(getWidth(), object.getWidth())
1078            .append(getHeight(), object.getHeight())
1079            .append(getDepth(), object.getDepth())
1080            .append(getFaceNum(), object.getFaceNum())
1081            .append(getThumbMd5(), object.getThumbMd5())
1082            .append(getDeviceId(), object.getDeviceId())
1083            .toComparison();
1084    }
1085    @Override
1086    public ImageBean clone(){
1087        try {
1088            return (ImageBean) super.clone();
1089        } catch (CloneNotSupportedException e) {
1090            throw new RuntimeException(e);
1091        }
1092    }
1093    /**
1094     * Make {@code this} to a NULL bean<br>
1095     * set all fields to null, {@link #modified} and {@link #initialized} be set to 0
1096     * @return {@code this} bean
1097     * @author guyadong
1098     */
1099    public ImageBean asNULL()
1100    {   
1101        checkMutable();
1102        
1103        setMd5((String)null);
1104        setFormat((String)null);
1105        setWidth((Integer)null);
1106        setHeight((Integer)null);
1107        setDepth((Integer)null);
1108        setFaceNum((Integer)null);
1109        setThumbMd5((String)null);
1110        setDeviceId((Integer)null);
1111        isNew(true);
1112        resetInitialized();
1113        resetIsModified();
1114        return this;
1115    }
1116    /**
1117     * check whether this bean is a NULL bean 
1118     * @return {@code true} if {@link #initialized} be set to zero
1119     * @see #asNULL()
1120     */
1121    public boolean checkNULL(){
1122        return 0 == getInitialized();
1123    }
1124    /** 
1125     * @param source source list
1126     * @return {@code source} replace {@code null} element with null instance({@link #NULL})
1127     */
1128    public static final List<ImageBean> replaceNull(List<ImageBean> source){
1129        if(null != source){
1130            for(int i = 0,endIndex = source.size();i<endIndex;++i){
1131                if(null == source.get(i)){
1132                    source.set(i, NULL);
1133                }
1134            }
1135        }
1136        return source;
1137    }
1138    /** 
1139     * @param source input list
1140     * @return replace null instance element with {@code null}
1141     * @see #checkNULL()
1142     */
1143    public static final List<ImageBean> replaceNullInstance(List<ImageBean> source){
1144        if(null != source){
1145            for(int i = 0,endIndex = source.size();i<endIndex;++i){
1146                if(source.get(i).checkNULL()){
1147                    source.set(i, null);
1148                }
1149            }
1150        }
1151        return source;
1152    }
1153    @Override
1154    public ImageBean copy(ImageBean bean)
1155    {
1156        return copy(bean,new int[]{});
1157    }
1158    @Override
1159    public ImageBean copy(ImageBean bean, int... fieldList)
1160    {
1161        if (null == fieldList || 0 == fieldList.length){
1162            fieldList = new int[]{0,1,2,3,4,5,6,7};
1163        }
1164        for (int i = 0; i < fieldList.length; ++i) {
1165            if( bean.isInitialized(fieldList[i]) && !Objects.deepEquals(bean.getValue(fieldList[i]), getValue(fieldList[i]))){
1166                setValue(fieldList[i], bean.getValue(fieldList[i]));
1167            }
1168        }
1169        return this;
1170    }
1171        
1172    @Override
1173    public ImageBean copy(ImageBean bean, String... fieldList)
1174    {
1175        if (null == fieldList || 0 == fieldList.length){
1176            copy(bean,(int[])null);
1177        }else{
1178            int field;
1179            for (int i = 0; i < fieldList.length; i++) {
1180                field = columnIDOf(fieldList[i].trim());
1181                if(bean.isInitialized(field) && !Objects.deepEquals(bean.getValue(field), getValue(field))){
1182                    setValue(field, bean.getValue(field));
1183                }
1184            }
1185        }
1186        return this;
1187    }
1188
1189    @SuppressWarnings("unchecked")
1190    @Override
1191    public <T>T getValue(int columnID)
1192    {
1193        switch( columnID ){
1194        case FL_IMAGE_ID_MD5: 
1195            return (T)getMd5();        
1196        case FL_IMAGE_ID_FORMAT: 
1197            return (T)getFormat();        
1198        case FL_IMAGE_ID_WIDTH: 
1199            return (T)getWidth();        
1200        case FL_IMAGE_ID_HEIGHT: 
1201            return (T)getHeight();        
1202        case FL_IMAGE_ID_DEPTH: 
1203            return (T)getDepth();        
1204        case FL_IMAGE_ID_FACE_NUM: 
1205            return (T)getFaceNum();        
1206        case FL_IMAGE_ID_THUMB_MD5: 
1207            return (T)getThumbMd5();        
1208        case FL_IMAGE_ID_DEVICE_ID: 
1209            return (T)getDeviceId();        
1210        default:
1211            return null;
1212        }
1213    }
1214
1215    @Override
1216    public <T> void setValue(int columnID,T value)
1217    {
1218        switch( columnID ) {
1219        case FL_IMAGE_ID_MD5:
1220            setMd5((String)value);
1221            break;
1222        case FL_IMAGE_ID_FORMAT:
1223            setFormat((String)value);
1224            break;
1225        case FL_IMAGE_ID_WIDTH:
1226            setWidth((Integer)value);
1227            break;
1228        case FL_IMAGE_ID_HEIGHT:
1229            setHeight((Integer)value);
1230            break;
1231        case FL_IMAGE_ID_DEPTH:
1232            setDepth((Integer)value);
1233            break;
1234        case FL_IMAGE_ID_FACE_NUM:
1235            setFaceNum((Integer)value);
1236            break;
1237        case FL_IMAGE_ID_THUMB_MD5:
1238            setThumbMd5((String)value);
1239            break;
1240        case FL_IMAGE_ID_DEVICE_ID:
1241            setDeviceId((Integer)value);
1242            break;
1243        default:
1244            break;
1245        }
1246    }
1247    
1248    @Override
1249    public <T> T getValue(String column)
1250    {
1251        return getValue(columnIDOf(column));
1252    }
1253
1254    @Override
1255    public <T> void setValue(String column,T value)
1256    {
1257        setValue(columnIDOf(column),value);
1258    }
1259    
1260    /**
1261     * @param column column name
1262     * @return column id for the given field name or negative if {@code column} is invalid name 
1263     */
1264    public static int columnIDOf(String column){
1265        int index = FL_IMAGE_FIELDS_LIST.indexOf(column);
1266        return  index < 0 
1267            ? FL_IMAGE_JAVA_FIELDS_LIST.indexOf(column)
1268            : index;
1269    }
1270    
1271    public static String columnNameOf(int columnId){
1272        try{
1273            return FL_IMAGE_FIELDS_LIST.get(columnId);
1274        } catch(IndexOutOfBoundsException e){
1275            return null;
1276        }
1277    }
1278    
1279    public static Class<?> typeOf(int columnId){
1280        try{
1281            return FL_IMAGE_FIELD_TYPES[columnId];
1282        } catch(IndexOutOfBoundsException e){
1283            return null;
1284        }
1285    }
1286    
1287    public static final Builder builder(){
1288        return new Builder().reset();
1289    }
1290    /** 
1291     * a builder for ImageBean,the template instance is thread local variable
1292     * a instance of Builder can be reused.
1293     */
1294    public static final class Builder{
1295        /** ImageBean instance used for template to create new ImageBean instance. */
1296        static final ThreadLocal<ImageBean> TEMPLATE = new ThreadLocal<ImageBean>(){
1297            @Override
1298            protected ImageBean initialValue() {
1299                return new ImageBean();
1300            }};
1301        private Builder() {}
1302        /** 
1303         * reset the bean as template 
1304         * @see ImageBean#reset()
1305         */
1306        public Builder reset(){
1307            TEMPLATE.get().reset();
1308            return this;
1309        }
1310        /** set a bean as template,must not be {@code null} */
1311        public Builder template(ImageBean bean){
1312            if(null == bean){
1313                throw new NullPointerException();
1314            }
1315            TEMPLATE.set(bean);
1316            return this;
1317        }
1318        /** return a clone instance of {@link #TEMPLATE}*/
1319        public ImageBean build(){
1320            return TEMPLATE.get().clone();
1321        }
1322        /** 
1323         * fill the field : fl_image.md5
1324         * @param md5 主键,图像md5检验码,同时也是从 fl_store 获取图像数据的key
1325         * @see ImageBean#getMd5()
1326         * @see ImageBean#setMd5(String)
1327         */
1328        public Builder md5(String md5){
1329            TEMPLATE.get().setMd5(md5);
1330            return this;
1331        }
1332        /** 
1333         * fill the field : fl_image.format
1334         * @param format 图像格式
1335         * @see ImageBean#getFormat()
1336         * @see ImageBean#setFormat(String)
1337         */
1338        public Builder format(String format){
1339            TEMPLATE.get().setFormat(format);
1340            return this;
1341        }
1342        /** 
1343         * fill the field : fl_image.width
1344         * @param width 图像宽度
1345         * @see ImageBean#getWidth()
1346         * @see ImageBean#setWidth(Integer)
1347         */
1348        public Builder width(Integer width){
1349            TEMPLATE.get().setWidth(width);
1350            return this;
1351        }
1352        /** 
1353         * fill the field : fl_image.height
1354         * @param height 图像高度
1355         * @see ImageBean#getHeight()
1356         * @see ImageBean#setHeight(Integer)
1357         */
1358        public Builder height(Integer height){
1359            TEMPLATE.get().setHeight(height);
1360            return this;
1361        }
1362        /** 
1363         * fill the field : fl_image.depth
1364         * @param depth 通道数
1365         * @see ImageBean#getDepth()
1366         * @see ImageBean#setDepth(Integer)
1367         */
1368        public Builder depth(Integer depth){
1369            TEMPLATE.get().setDepth(depth);
1370            return this;
1371        }
1372        /** 
1373         * fill the field : fl_image.face_num
1374         * @param faceNum 图像中的人脸数目
1375         * @see ImageBean#getFaceNum()
1376         * @see ImageBean#setFaceNum(Integer)
1377         */
1378        public Builder faceNum(Integer faceNum){
1379            TEMPLATE.get().setFaceNum(faceNum);
1380            return this;
1381        }
1382        /** 
1383         * fill the field : fl_image.thumb_md5
1384         * @param thumbMd5 缩略图md5,图像数据存储在 fl_imae_store(md5)
1385         * @see ImageBean#getThumbMd5()
1386         * @see ImageBean#setThumbMd5(String)
1387         */
1388        public Builder thumbMd5(String thumbMd5){
1389            TEMPLATE.get().setThumbMd5(thumbMd5);
1390            return this;
1391        }
1392        /** 
1393         * fill the field : fl_image.device_id
1394         * @param deviceId 外键,图像来源设备
1395         * @see ImageBean#getDeviceId()
1396         * @see ImageBean#setDeviceId(Integer)
1397         */
1398        public Builder deviceId(Integer deviceId){
1399            TEMPLATE.get().setDeviceId(deviceId);
1400            return this;
1401        }
1402    }
1403}