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