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 * StoreBean is a mapping of fl_store Table.
020 * <br>Meta Data Information (in progress):
021 * <ul>
022 *    <li>comments: 二进制数据存储表 </li>
023 * </ul>
024 * @author guyadong
025*/
026@ThriftStruct
027@ApiModel(description="二进制数据存储表")
028public final class StoreBean
029    implements Serializable,BaseBean<StoreBean>,Comparable<StoreBean>,Constant,Cloneable
030{
031    private static final long serialVersionUID = -1684185165668832146L;
032    /** NULL {@link StoreBean} bean , IMMUTABLE instance */
033    public static final StoreBean NULL = new StoreBean().asNULL().asImmutable();
034    /** comments:主键,md5检验码 */
035    @ApiModelProperty(value = "主键,md5检验码" ,required=true ,dataType="String")
036    private String md5;
037
038    /** comments:编码类型,GBK,UTF8... */
039    @ApiModelProperty(value = "编码类型,GBK,UTF8..."  ,dataType="String")
040    private String encoding;
041
042    /** comments:二进制数据(最大16MB) */
043    @ApiModelProperty(value = "二进制数据(最大16MB)"  ,dataType="ByteBuffer")
044    private java.nio.ByteBuffer data;
045
046    /** flag whether {@code this} can be modified */
047    private Boolean immutable;
048    /** columns modified flag */
049    @ApiModelProperty(value="columns modified flag",dataType="int",required=true)
050    private int modified;
051    /** columns initialized flag */
052    @ApiModelProperty(value="columns initialized flag",dataType="int",required=true)
053    private int initialized;
054    /** new record flag  */
055    @ApiModelProperty(value="new record flag",dataType="boolean",required=true)
056    private boolean isNew;        
057    /** 
058     * set immutable status
059     * @return {@code this} 
060     */
061    private StoreBean immutable(Boolean immutable) {
062        this.immutable = immutable;
063        return this;
064    }
065    /** 
066     * set {@code this} as immutable object
067     * @return {@code this} 
068     */
069    public StoreBean asImmutable() {
070        return immutable(Boolean.TRUE);
071    }
072    /**
073     * @return {@code true} if {@code this} is a mutable object  
074     */
075    public boolean mutable(){
076        return !Boolean.TRUE.equals(this.immutable);
077    }
078    /**
079     * @return {@code this}
080     * @throws IllegalStateException if {@code this} is a immutable object 
081     */
082    private StoreBean checkMutable(){
083        if(!mutable()){
084            throw new IllegalStateException("this is a immutable object");
085        }
086        return this;
087    }
088    /**
089     * @return return a new mutable copy of this object.
090     */
091    public StoreBean cloneMutable(){
092        return clone().immutable(null);
093    }
094    @ThriftField(value=1,name="_new",requiredness=Requiredness.REQUIRED)
095    @Override
096    public boolean isNew()
097    {
098        return this.isNew;
099    }
100
101
102    @Override
103    public void isNew(boolean isNew)
104    {
105        this.isNew = isNew;
106    }
107    /**
108     * Specifies to the object if it has been set as new.
109     *
110     * @param isNew the boolean value to be assigned to the isNew field
111     */
112    @ThriftField()
113    public void setNew(boolean isNew)
114    {
115        this.isNew = isNew;
116    }
117    /**
118     * @return the modified status of columns
119     */
120    @ThriftField(value=2,requiredness=Requiredness.REQUIRED)
121    public int getModified(){
122        return modified;
123    }
124
125    /**
126     * @param modified the modified status bit to be assigned to {@link #modified}
127     */
128    @ThriftField()
129    public void setModified(int modified){
130        this.modified = modified;
131    }
132    /**
133     * @return the initialized status of columns
134     */
135    @ThriftField(value=3,requiredness=Requiredness.REQUIRED)
136    public int getInitialized(){
137        return initialized;
138    }
139
140    /**
141     * @param initialized the initialized status bit to be assigned to {@link #initialized}
142     */
143    @ThriftField()
144    public void setInitialized(int initialized){
145        this.initialized = initialized;
146    }
147    protected static final <T extends Comparable<T>>boolean equals(T a, T b) {
148        return a == b || (a != null && 0==a.compareTo(b));
149    }
150    public StoreBean(){
151        super();
152        reset();
153    }
154    /**
155     * construct a new instance filled with primary keys
156     * @param md5 PK# 1 
157     */
158    public StoreBean(String md5){
159        this();
160        setMd5(md5);
161    }
162    /**
163     * Getter method for {@link #md5}.<br>
164     * PRIMARY KEY.<br>
165     * Meta Data Information (in progress):
166     * <ul>
167     * <li>full name: fl_store.md5</li>
168     * <li>comments: 主键,md5检验码</li>
169     * <li>NOT NULL</li>
170     * <li>column size: 32</li>
171     * <li>JDBC type returned by the driver: Types.CHAR</li>
172     * </ul>
173     *
174     * @return the value of md5
175     */
176    @ThriftField(value=4)
177    public String getMd5(){
178        return md5;
179    }
180    /**
181     * Setter method for {@link #md5}.<br>
182     * The new value is set only if equals() says it is different,
183     * or if one of either the new value or the current value is null.
184     * In case the new value is different, it is set and the field is marked as 'modified'.
185     *
186     * @param newVal the new value( NOT NULL) to be assigned to md5
187     */
188    public void setMd5(String newVal)
189    {
190        checkMutable();
191
192        modified |= FL_STORE_ID_MD5_MASK;
193        initialized |= FL_STORE_ID_MD5_MASK;
194
195        if (Objects.equals(newVal, md5)) {
196            return;
197        }
198        md5 = newVal;
199    }
200    /** 
201     * setter for thrift:swift support<br>
202     * without modification for {@link #modified} and {@link #initialized}<br>
203     * <b>NOTE:</b>DO NOT use the method in your code
204     */
205    @ThriftField(name = "md5")
206    public void writeMd5(String newVal){
207        checkMutable();
208        md5 = newVal;
209    }
210    /**
211     * Determines if the md5 has been modified.
212     *
213     * @return true if the field has been modified, false if the field has not been modified
214     */
215    public boolean checkMd5Modified()
216    {
217        return 0L !=  (modified & FL_STORE_ID_MD5_MASK);
218    }
219
220    /**
221     * Determines if the md5 has been initialized.<br>
222     *
223     * It is useful to determine if a field is null on purpose or just because it has not been initialized.
224     *
225     * @return true if the field has been initialized, false otherwise
226     */
227    public boolean checkMd5Initialized()
228    {
229        return 0L !=  (initialized & FL_STORE_ID_MD5_MASK);
230    }
231    /**
232     * Getter method for {@link #encoding}.<br>
233     * Meta Data Information (in progress):
234     * <ul>
235     * <li>full name: fl_store.encoding</li>
236     * <li>comments: 编码类型,GBK,UTF8...</li>
237     * <li>column size: 16</li>
238     * <li>JDBC type returned by the driver: Types.VARCHAR</li>
239     * </ul>
240     *
241     * @return the value of encoding
242     */
243    @ThriftField(value=5)
244    public String getEncoding(){
245        return encoding;
246    }
247    /**
248     * Setter method for {@link #encoding}.<br>
249     * The new value is set only if equals() says it is different,
250     * or if one of either the new value or the current value is null.
251     * In case the new value is different, it is set and the field is marked as 'modified'.
252     *
253     * @param newVal the new value to be assigned to encoding
254     */
255    public void setEncoding(String newVal)
256    {
257        checkMutable();
258
259        modified |= FL_STORE_ID_ENCODING_MASK;
260        initialized |= FL_STORE_ID_ENCODING_MASK;
261
262        if (Objects.equals(newVal, encoding)) {
263            return;
264        }
265        encoding = newVal;
266    }
267    /** 
268     * setter for thrift:swift support<br>
269     * without modification for {@link #modified} and {@link #initialized}<br>
270     * <b>NOTE:</b>DO NOT use the method in your code
271     */
272    @ThriftField(name = "encoding")
273    public void writeEncoding(String newVal){
274        checkMutable();
275        encoding = newVal;
276    }
277    /**
278     * Determines if the encoding has been modified.
279     *
280     * @return true if the field has been modified, false if the field has not been modified
281     */
282    public boolean checkEncodingModified()
283    {
284        return 0L !=  (modified & FL_STORE_ID_ENCODING_MASK);
285    }
286
287    /**
288     * Determines if the encoding has been initialized.<br>
289     *
290     * It is useful to determine if a field is null on purpose or just because it has not been initialized.
291     *
292     * @return true if the field has been initialized, false otherwise
293     */
294    public boolean checkEncodingInitialized()
295    {
296        return 0L !=  (initialized & FL_STORE_ID_ENCODING_MASK);
297    }
298    /**
299     * Getter method for {@link #data}.<br>
300     * Meta Data Information (in progress):
301     * <ul>
302     * <li>full name: fl_store.data</li>
303     * <li>comments: 二进制数据(最大16MB)</li>
304     * <li>column size: 16777215</li>
305     * <li>JDBC type returned by the driver: Types.LONGVARBINARY</li>
306     * </ul>
307     *
308     * @return the value of data
309     */
310    @ThriftField(value=6)
311    public java.nio.ByteBuffer getData(){
312        return data;
313    }
314    /**
315     * Setter method for {@link #data}.<br>
316     * The new value is set only if equals() says it is different,
317     * or if one of either the new value or the current value is null.
318     * In case the new value is different, it is set and the field is marked as 'modified'.
319     *
320     * @param newVal the new value to be assigned to data
321     */
322    public void setData(java.nio.ByteBuffer newVal)
323    {
324        checkMutable();
325
326        modified |= FL_STORE_ID_DATA_MASK;
327        initialized |= FL_STORE_ID_DATA_MASK;
328
329        if (Objects.equals(newVal, data)) {
330            return;
331        }
332        data = newVal;
333    }
334    /** 
335     * setter for thrift:swift support<br>
336     * without modification for {@link #modified} and {@link #initialized}<br>
337     * <b>NOTE:</b>DO NOT use the method in your code
338     */
339    @ThriftField(name = "data")
340    public void writeData(java.nio.ByteBuffer newVal){
341        checkMutable();
342        data = newVal;
343    }
344    /**
345     * Determines if the data has been modified.
346     *
347     * @return true if the field has been modified, false if the field has not been modified
348     */
349    public boolean checkDataModified()
350    {
351        return 0L !=  (modified & FL_STORE_ID_DATA_MASK);
352    }
353
354    /**
355     * Determines if the data has been initialized.<br>
356     *
357     * It is useful to determine if a field is null on purpose or just because it has not been initialized.
358     *
359     * @return true if the field has been initialized, false otherwise
360     */
361    public boolean checkDataInitialized()
362    {
363        return 0L !=  (initialized & FL_STORE_ID_DATA_MASK);
364    }
365
366    @Override
367    public boolean isModified()
368    {
369        return 0 != modified;
370    }
371  
372    @Override
373    public boolean isModified(int columnID){
374        switch ( columnID ){
375        case FL_STORE_ID_MD5:
376            return checkMd5Modified();
377        case FL_STORE_ID_ENCODING:
378            return checkEncodingModified();
379        case FL_STORE_ID_DATA:
380            return checkDataModified();
381        default:
382            return false;
383        }        
384    }
385
386    @Override
387    public boolean isInitialized(int columnID){
388        switch(columnID) {
389        case FL_STORE_ID_MD5:
390            return checkMd5Initialized();
391        case FL_STORE_ID_ENCODING:
392            return checkEncodingInitialized();
393        case FL_STORE_ID_DATA:
394            return checkDataInitialized();
395        default:
396            return false;
397        }
398    }
399    
400    @Override
401    public boolean isModified(String column){        
402        return isModified(columnIDOf(column));
403    }
404
405    @Override
406    public boolean isInitialized(String column){
407        return isInitialized(columnIDOf(column));
408    }
409    
410    @Override
411    public void resetIsModified()
412    {
413        checkMutable();
414        modified = 0;
415    }
416
417    @Override
418    public void resetPrimaryKeysModified()
419    {
420        modified &= (~(FL_STORE_ID_MD5_MASK));
421    }
422    /**
423     * Resets columns modification status except primary keys to 'not modified'.
424     */
425    public void resetModifiedExceptPrimaryKeys()
426    {
427        modified &= (~(FL_STORE_ID_ENCODING_MASK |
428            FL_STORE_ID_DATA_MASK));
429    }
430    /**
431     * Resets the object initialization status to 'not initialized'.
432     */
433    private void resetInitialized()
434    {
435        initialized = 0;
436    }
437    /** reset all fields to initial value, equal to a new bean */
438    public void reset(){
439        checkMutable();
440        this.md5 = null;
441        this.encoding = null;
442        this.data = null;
443        this.isNew = true;
444        this.modified = 0;
445        this.initialized = 0;
446    }
447    @Override
448    public boolean equals(Object object)
449    {
450        if (!(object instanceof StoreBean)) {
451            return false;
452        }
453
454        StoreBean obj = (StoreBean) object;
455        return new EqualsBuilder()
456            .append(getMd5(), obj.getMd5())
457            .append(getEncoding(), obj.getEncoding())
458            .append(getData(), obj.getData())
459            .isEquals();
460    }
461
462    @Override
463    public int hashCode()
464    {
465        return new HashCodeBuilder(-82280557, -700257973)
466            .append(getMd5())
467            .toHashCode();
468    }
469
470    @Override
471    public String toString() {
472        return toString(true,false);
473    }
474    /**
475     * cast byte array to HEX string
476     * 
477     * @param input
478     * @return {@code null} if {@code input} is null
479     */
480    private static final String toHex(byte[] input) {
481        if (null == input){
482            return null;
483        }
484        StringBuffer sb = new StringBuffer(input.length * 2);
485        for (int i = 0; i < input.length; i++) {
486            sb.append(Character.forDigit((input[i] & 240) >> 4, 16));
487            sb.append(Character.forDigit(input[i] & 15, 16));
488        }
489        return sb.toString();
490    }
491    protected static final StringBuilder append(StringBuilder buffer,boolean full,byte[] value){
492        if(full || null == value){
493            buffer.append(toHex(value));
494        }else{
495            buffer.append(value.length).append(" bytes");
496        }
497        return buffer;
498    }
499    private static int stringLimit = 64;
500    private static final int MINIMUM_LIMIT = 16;
501    protected static final StringBuilder append(StringBuilder buffer,boolean full,String value){
502        if(full || null == value || value.length() <= stringLimit){
503            buffer.append(value);
504        }else{
505            buffer.append(value.substring(0,stringLimit - 8)).append(" ...").append(value.substring(stringLimit-4,stringLimit));
506        }
507        return buffer;
508    }
509    protected static final <T>StringBuilder append(StringBuilder buffer,boolean full,T value){
510        return buffer.append(value);
511    }
512    public static final void setStringLimit(int limit){
513        if(limit < MINIMUM_LIMIT){
514            throw new IllegalArgumentException(String.format("INVALID limit %d,minimum value %d",limit,MINIMUM_LIMIT));
515        }
516        stringLimit = limit;
517    }
518    @Override
519    public String toString(boolean notNull, boolean fullIfStringOrBytes) {
520        // only output initialized field
521        StringBuilder builder = new StringBuilder(this.getClass().getName()).append("@").append(Integer.toHexString(this.hashCode())).append("[");
522        int count = 0;        
523        if(checkMd5Initialized()){
524            if(!notNull || null != getMd5()){
525                if(count++ >0){
526                    builder.append(",");
527                }
528                builder.append("md5=");
529                append(builder,fullIfStringOrBytes,getMd5());
530            }
531        }
532        if(checkEncodingInitialized()){
533            if(!notNull || null != getEncoding()){
534                if(count++ >0){
535                    builder.append(",");
536                }
537                builder.append("encoding=");
538                append(builder,fullIfStringOrBytes,getEncoding());
539            }
540        }
541        if(checkDataInitialized()){
542            if(!notNull || null != getData()){
543                if(count++ >0){
544                    builder.append(",");
545                }
546                builder.append("data=");
547                append(builder,fullIfStringOrBytes,getData());
548            }
549        }
550        builder.append("]");
551        return builder.toString();
552    }
553    @Override
554    public int compareTo(StoreBean object){
555        return new CompareToBuilder()
556            .append(getMd5(), object.getMd5())
557            .append(getEncoding(), object.getEncoding())
558            .append(getData(), object.getData())
559            .toComparison();
560    }
561    @Override
562    public StoreBean clone(){
563        try {
564            return (StoreBean) super.clone();
565        } catch (CloneNotSupportedException e) {
566            throw new RuntimeException(e);
567        }
568    }
569    /**
570     * Make {@code this} to a NULL bean<br>
571     * set all fields to null, {@link #modified} and {@link #initialized} be set to 0
572     * @return {@code this} bean
573     * @author guyadong
574     */
575    public StoreBean asNULL()
576    {   
577        checkMutable();
578        
579        setMd5((String)null);
580        setEncoding((String)null);
581        setData((java.nio.ByteBuffer)null);
582        isNew(true);
583        resetInitialized();
584        resetIsModified();
585        return this;
586    }
587    /**
588     * check whether this bean is a NULL bean 
589     * @return {@code true} if {@link #initialized} be set to zero
590     * @see #asNULL()
591     */
592    public boolean checkNULL(){
593        return 0 == getInitialized();
594    }
595    /** 
596     * @param source source list
597     * @return {@code source} replace {@code null} element with null instance({@link #NULL})
598     */
599    public static final List<StoreBean> replaceNull(List<StoreBean> source){
600        if(null != source){
601            for(int i = 0,endIndex = source.size();i<endIndex;++i){
602                if(null == source.get(i)){
603                    source.set(i, NULL);
604                }
605            }
606        }
607        return source;
608    }
609    /** 
610     * @param source input list
611     * @return replace null instance element with {@code null}
612     * @see #checkNULL()
613     */
614    public static final List<StoreBean> replaceNullInstance(List<StoreBean> source){
615        if(null != source){
616            for(int i = 0,endIndex = source.size();i<endIndex;++i){
617                if(source.get(i).checkNULL()){
618                    source.set(i, null);
619                }
620            }
621        }
622        return source;
623    }
624    @Override
625    public StoreBean copy(StoreBean bean)
626    {
627        return copy(bean,new int[]{});
628    }
629    @Override
630    public StoreBean copy(StoreBean bean, int... fieldList)
631    {
632        if (null == fieldList || 0 == fieldList.length){
633            fieldList = new int[]{0,1,2};
634        }
635        for (int i = 0; i < fieldList.length; ++i) {
636            if( bean.isInitialized(fieldList[i]) && !Objects.deepEquals(bean.getValue(fieldList[i]), getValue(fieldList[i]))){
637                setValue(fieldList[i], bean.getValue(fieldList[i]));
638            }
639        }
640        return this;
641    }
642        
643    @Override
644    public StoreBean copy(StoreBean bean, String... fieldList)
645    {
646        if (null == fieldList || 0 == fieldList.length){
647            copy(bean,(int[])null);
648        }else{
649            int field;
650            for (int i = 0; i < fieldList.length; i++) {
651                field = columnIDOf(fieldList[i].trim());
652                if(bean.isInitialized(field) && !Objects.deepEquals(bean.getValue(field), getValue(field))){
653                    setValue(field, bean.getValue(field));
654                }
655            }
656        }
657        return this;
658    }
659
660    @SuppressWarnings("unchecked")
661    @Override
662    public <T>T getValue(int columnID)
663    {
664        switch( columnID ){
665        case FL_STORE_ID_MD5: 
666            return (T)getMd5();        
667        case FL_STORE_ID_ENCODING: 
668            return (T)getEncoding();        
669        case FL_STORE_ID_DATA: 
670            return (T)getData();        
671        default:
672            return null;
673        }
674    }
675
676    @Override
677    public <T> void setValue(int columnID,T value)
678    {
679        switch( columnID ) {
680        case FL_STORE_ID_MD5:
681            setMd5((String)value);
682            break;
683        case FL_STORE_ID_ENCODING:
684            setEncoding((String)value);
685            break;
686        case FL_STORE_ID_DATA:
687            setData((java.nio.ByteBuffer)value);
688            break;
689        default:
690            break;
691        }
692    }
693    
694    @Override
695    public <T> T getValue(String column)
696    {
697        return getValue(columnIDOf(column));
698    }
699
700    @Override
701    public <T> void setValue(String column,T value)
702    {
703        setValue(columnIDOf(column),value);
704    }
705    
706    /**
707     * @param column column name
708     * @return column id for the given field name or negative if {@code column} is invalid name 
709     */
710    public static int columnIDOf(String column){
711        int index = FL_STORE_FIELDS_LIST.indexOf(column);
712        return  index < 0 
713            ? FL_STORE_JAVA_FIELDS_LIST.indexOf(column)
714            : index;
715    }
716    
717    public static String columnNameOf(int columnId){
718        try{
719            return FL_STORE_FIELDS_LIST.get(columnId);
720        } catch(IndexOutOfBoundsException e){
721            return null;
722        }
723    }
724    
725    public static Class<?> typeOf(int columnId){
726        try{
727            return FL_STORE_FIELD_TYPES[columnId];
728        } catch(IndexOutOfBoundsException e){
729            return null;
730        }
731    }
732    
733    public static final Builder builder(){
734        return new Builder().reset();
735    }
736    /** 
737     * a builder for StoreBean,the template instance is thread local variable
738     * a instance of Builder can be reused.
739     */
740    public static final class Builder{
741        /** StoreBean instance used for template to create new StoreBean instance. */
742        static final ThreadLocal<StoreBean> TEMPLATE = new ThreadLocal<StoreBean>(){
743            @Override
744            protected StoreBean initialValue() {
745                return new StoreBean();
746            }};
747        private Builder() {}
748        /** 
749         * reset the bean as template 
750         * @see StoreBean#reset()
751         */
752        public Builder reset(){
753            TEMPLATE.get().reset();
754            return this;
755        }
756        /** set a bean as template,must not be {@code null} */
757        public Builder template(StoreBean bean){
758            if(null == bean){
759                throw new NullPointerException();
760            }
761            TEMPLATE.set(bean);
762            return this;
763        }
764        /** return a clone instance of {@link #TEMPLATE}*/
765        public StoreBean build(){
766            return TEMPLATE.get().clone();
767        }
768        /** 
769         * fill the field : fl_store.md5
770         * @param md5 主键,md5检验码
771         * @see StoreBean#getMd5()
772         * @see StoreBean#setMd5(String)
773         */
774        public Builder md5(String md5){
775            TEMPLATE.get().setMd5(md5);
776            return this;
777        }
778        /** 
779         * fill the field : fl_store.encoding
780         * @param encoding 编码类型,GBK,UTF8...
781         * @see StoreBean#getEncoding()
782         * @see StoreBean#setEncoding(String)
783         */
784        public Builder encoding(String encoding){
785            TEMPLATE.get().setEncoding(encoding);
786            return this;
787        }
788        /** 
789         * fill the field : fl_store.data
790         * @param data 二进制数据(最大16MB)
791         * @see StoreBean#getData()
792         * @see StoreBean#setData(java.nio.ByteBuffer)
793         */
794        public Builder data(java.nio.ByteBuffer data){
795            TEMPLATE.get().setData(data);
796            return this;
797        }
798    }
799}