001package gu.sql2java;
002
003import java.util.Map;
004
005/**
006 * @author guyadong
007 *
008 */
009public interface BaseBean {
010    /**
011     * Determines if the current object is new.
012     *
013     * @return true if the current object is new, false if the object is not new
014     */
015    public boolean isNew();
016    /**
017     * Specifies to the object if it has been set as new.
018     *
019     * @param isNew the boolean value to be assigned to the isNew field
020     */
021    public void setNew(boolean isNew);
022
023    /**
024     * Determines if the object has been modified since the last time this method was called.<br>
025     * We can also determine if this object has ever been modified since its creation.
026     *
027     * @return true if the object has been modified, false if the object has not been modified
028     */
029    public boolean isModified();
030    /**
031     * Resets the object modification status to 'not modified'.
032     */
033    public void resetIsModified();
034    /**
035     * Resets the primary keys modification status to 'not modified'.
036     */
037    public void resetPrimaryKeysModified();
038    /**
039     * Determines if the {@code columnID} has been initialized.<br>
040     * It is useful to determine if a field is null on purpose or just because it has not been initialized.
041     * @param columnID column id
042     * @return true if the field has been initialized, false otherwise
043     */
044    public boolean isInitialized(int columnID);
045    /**
046     * Determines if the {@code column} has been modified.
047     * @param columnID column id
048     * @return true if the field has been modified, false if the field has not been modified
049     */
050    public boolean isModified(int columnID);
051    /**
052     * Determines if the {@code column} has been initialized.<br>
053     * It is useful to determine if a field is null on purpose or just because it has not been initialized.
054     * @param column column name
055     * @return true if the field has been initialized, false otherwise
056     */
057    public boolean isInitialized(String column);
058    /**
059     * Determines if the {@code column} has been modified.
060     * @param column column name
061     * @return true if the field has been modified, false if the field has not been modified
062     */
063    public boolean isModified(String column);
064    /**
065     * Copies the passed bean into the current bean.
066     *
067     * @param bean the bean to copy into the current bean
068     * @return this bean
069     */
070    public <B extends BaseBean> B copy(B bean);
071    /**
072     * Copies the passed bean into the current bean.
073     *
074     * @param bean the bean to copy into the current bean
075     * @param fieldList the column id list to copy into the current bean,if null or empty,copy all fields
076     * @return always this bean
077     */
078    public <B extends BaseBean> B copy(B bean, int... fieldList);
079    /**
080     * Copies the passed bean into the current bean.
081     *
082     * @param bean the bean to copy into the current bean
083     * @param fieldList the column name list to copy into the current bean
084     * @return always this bean
085     */
086    public <B extends BaseBean> B copy(B bean, String... fieldList);
087    /**
088     * Copies the passed F bean into the current bean.
089     * @param <B> from bean type
090     * @param <F> this bean type
091     * @param from
092     * @param columnsMap columns map from F to B 
093     * @return always this bean
094     */
095    <B extends BaseBean, F extends BaseBean> B copy(F from, Map<Integer,Integer> columnsMap);
096    
097    /**
098     * Copies the passed values into the current bean.
099     * @param values
100     * @return always this bean
101     */
102    public <B extends BaseBean> B copy(Map<Integer, Object>values);
103        /**
104     * 
105     * @param columnID column id
106     * @return return a object representation of the given column id
107     */
108    public <T> T getValue(int columnID);
109    /**
110     * set a value representation of the given column id
111     * @param columnID column id
112     * @param value
113     */
114    public <T> void setValue(int columnID,T value);
115    /**
116     * 
117     * @param column column name
118     * @return return a object representation of the given field
119     */
120    public <T> T getValue(String column);
121    /**
122     * 
123     * @param columnID column id
124     * @return return a object representation of the given column id or throw {@link NullPointerException} if value is null
125     */
126    public <T> T getValueChecked(int columnID);
127    /**
128     * 
129     * @param column column name
130     * @return return a object representation of the given field or throw {@link NullPointerException} if value is null
131     */
132    public <T> T getValueChecked(String column);
133    /**
134     * set a value representation of the given field
135     * @param column column name
136     * @param value
137     */
138    public <T> void setValue(String column,T value);
139    
140    /**
141     * @param columnIds column id that will be output, if null or empty,output all columns
142     * @return values array for all fields
143     */
144    public Object[] asValueArray(int...columnIds);
145    /**
146         * @return values map for all fields, column name -- value
147         */
148        public Map<String, Object> asNameValueMap();
149
150    /**
151     * @return values array for all primary key, empty array if no primary key
152     */
153    public Object[] primaryValues();
154    /**
155     * @param <T> PK type
156     * @return value for primary key, throw {@link UnsupportedOperationException} if there is more than one primary key
157     */
158    public <T> T primaryValue();
159   
160    /**
161     * @return table name
162     */
163    public String tableName();
164
165        /**
166     * @param notNull output not null field only if {@code true}
167     * @param fullIfStringOrBytes for string or bytes field,output full content if {@code true},otherwise output length.
168     * @return Returns a string representation of the object
169     */
170    public String toString(boolean notNull, boolean fullIfStringOrBytes);
171
172}