1616
1717/**
1818 * 对应数据库表的实体类
19- *
19+ * The simple entity which reference the table in database;<BR>
20+ * required:<BR>
21+ * <li>the attribute(property) name in this entity need same as the column name in database table
22+ * <li>the first attribute in this entity map to the primary key column in database table
2023 * @author dmj
2124 */
2225public abstract class Entity extends AbstractRow {
@@ -41,13 +44,11 @@ public ColumnAttribute[] getColumnAttributes() {
4144 propertyNames = new String [fields .length ];
4245 for (int i = 0 ; i < propertyNames .length ; i ++) {
4346 propertyNames [i ] = fields [i ].getName ();
44- ColumnAttribute columnAttribute = new ColumnAttribute (
45- propertyNames [i ], propertyNames [i ]);
47+ ColumnAttribute columnAttribute = new ColumnAttribute (propertyNames [i ], propertyNames [i ]);
4648 if (i == 0 ) {
4749 columnAttribute .setIdType (IDType .MANUAL );
4850 Class <?> type = fields [i ].getType ();
49- if (type == int .class || type == long .class
50- || type == Integer .class || type == Long .class ) {
51+ if (type == int .class || type == long .class || type == Integer .class || type == Long .class ) {
5152 columnAttribute .setIdType (IDType .AUTO );
5253 }
5354 }
@@ -62,13 +63,10 @@ public ColumnAttribute[] getColumnAttributes() {
6263 return columnAttributeMapping .toArray ();
6364 }
6465
65- protected PropertyDescriptor getPropertyDescriptor (String propertyName )
66- throws IntrospectionException {
67- PropertyDescriptor propertyDescriptor = propertyDescMap
68- .get (propertyName );
66+ protected PropertyDescriptor getPropertyDescriptor (String propertyName ) throws IntrospectionException {
67+ PropertyDescriptor propertyDescriptor = propertyDescMap .get (propertyName );
6968 if (propertyDescriptor == null ) {
70- propertyDescriptor = new PropertyDescriptor (propertyName ,
71- getClass ());
69+ propertyDescriptor = new PropertyDescriptor (propertyName , getClass ());
7270 propertyDescMap .put (propertyName , propertyDescriptor );
7371 }
7472 return propertyDescriptor ;
@@ -93,14 +91,13 @@ public Object get(String propertyName) {
9391 } catch (Exception e ) {
9492 isThrow = true ;
9593 }
96- if (isThrow ) {
94+ if (isThrow ) {//get field value directly by access the filed
9795 try {
9896 Field filed = this .getClass ().getDeclaredField (propertyName );
9997 filed .setAccessible (true );
10098 ret = filed .get (this );
10199 } catch (Exception e ) {
102- throw new EntityReflectException (propertyName + "属性" ,
103- e .getCause ());
100+ throw new EntityReflectException (propertyName + "属性" , e .getCause ());
104101 }
105102 }
106103 return ret ;
@@ -123,8 +120,7 @@ public void set(String propertyName, Object e) {
123120 Method method = propertyDescriptor .getWriteMethod ();
124121 Class <?>[] parameterTypes = method .getParameterTypes ();
125122 if (parameterTypes != null && parameterTypes .length == 1 ) {
126- method .invoke (this ,
127- Converter .source (e ).convertToSingle (parameterTypes [0 ]));
123+ method .invoke (this , Converter .source (e ).convertToSingle (parameterTypes [0 ]));
128124 } else {
129125 method .invoke (this , e );
130126 }
@@ -134,15 +130,13 @@ public void set(String propertyName, Object e) {
134130 // + "方法", ex.getCause());
135131 isThrow = true ;
136132 }
137- if (isThrow ) {
133+ if (isThrow ) {//set field value directly by access the filed
138134 try {
139135 Field filed = getClass ().getDeclaredField (propertyName );
140136 filed .setAccessible (true );
141- filed .set (this ,
142- Converter .source (e ).convertToSingle (filed .getType ()));
137+ filed .set (this , Converter .source (e ).convertToSingle (filed .getType ()));
143138 } catch (Exception ex ) {
144- throw new EntityReflectException (propertyName + "属性" ,
145- ex .getCause ());
139+ throw new EntityReflectException (propertyName + "属性" , ex .getCause ());
146140 }
147141 }
148142 }
0 commit comments