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