PropertyProjector.java
biz/hammurapi/sql/PropertyProjector.java
Violations
Inspector |
Message |
Severity |
Location |
Java Inspector 048 |
Copyrights information should be present in each file. |
1 |
|
Java Inspector 089 |
Constructor documentation is too short. It is only 1 words. Should be at least 3 words. |
2 |
55:9
|
Java Inspector 089 |
Javadoc contains tag for non-existent parameter lenient |
2 |
55:9
|
Java Inspector 089 |
Javadoc contains tag for non-existent parameter toLowerCase |
2 |
55:9
|
Java Inspector 089 |
Undocumented parameter rs |
2 |
64:9
|
Java Inspector 089 |
Undocumented exception SQLException |
2 |
64:9
|
Java Inspector 089 |
Method return value is not documented |
2 |
64:9
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23package biz.hammurapi.sql;
24
25import java.sql.ResultSet;
26import java.sql.ResultSetMetaData;
27import java.sql.SQLException;
28import java.util.HashMap;
29import java.util.Map;
30
31import biz.hammurapi.config.ConfigurationException;
32import biz.hammurapi.config.DomConfigFactory;
33import biz.hammurapi.config.MapContext;
34
35
36
37
38
39
40public class PropertyProjector extends BaseReflectionProjector implements Projector {
41 private Class objectClass;
42 private Map fieldMap;
43
44
45
46
47
48
49
50
51
52
53
54
55 public PropertyProjector(Class objectClass, Map typeMap, Map fieldMap) {
56 super(typeMap);
57 this.objectClass=objectClass;
58 this.fieldMap=fieldMap;
59 }
60
61
62
63
64 public Object project(ResultSet rs) throws SQLException {
65 try {
66 Object instance = objectClass.newInstance();
67 ResultSetMetaData metaData = rs.getMetaData();
68 int cc=metaData.getColumnCount();
69 Map contextMap=new HashMap();
70 for (int i=1; i<=cc; i++) {
71 String colName=metaData.getColumnName(i);
72 String propertyName=propertyName(colName);
73
74 if (fieldMap!=null && fieldMap.containsKey(propertyName)) {
75 propertyName=(String) fieldMap.get(propertyName);
76 }
77
78 if (propertyName!=null) {
79 contextMap.put(propertyName, getColumn(rs, colName));
80 }
81 }
82 DomConfigFactory.inject(instance, new MapContext(contextMap));
83 return instance;
84 } catch (SQLException e) {
85 throw e;
86 } catch (Exception e) {
87 throw new SQLExceptionEx(e);
88 }
89 }
90
91}
92