01: /*
02: * JFox - The most lightweight Java EE Application Server!
03: * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
04: *
05: * JFox is licenced and re-distributable under GNU LGPL.
06: */
07: package org.jfox.entity;
08:
09: import java.io.Serializable;
10: import java.util.Collections;
11: import java.util.HashMap;
12: import java.util.Map;
13:
14: /**
15: * 使用 Map �统一�装数�
16: * 如果 Query 没有指定 ResultClass,则默认使用 MappedEntity
17: *
18: * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
19: */
20: public class MappedEntity implements Serializable {
21:
22: /**
23: * 用æ?¥å˜å‚¨æŸ¥è¯¢åˆ°çš„ column=>value 值对
24: */
25: private Map<String, Object> valueMap = new HashMap<String, Object>();
26:
27: public static MappedEntity newMappedEntity(
28: final Map<String, Object> map) {
29: return new MappedEntity(map);
30: }
31:
32: MappedEntity(Map<String, Object> _valueMap) {
33: putAll(_valueMap);
34: }
35:
36: void putAll(Map<String, Object> _valueMap) {
37: for (Map.Entry<String, Object> entry : _valueMap.entrySet()) {
38: // key 转�大写
39: setColumnValue(entry.getKey().toUpperCase(), entry
40: .getValue());
41: }
42: }
43:
44: public final Object getColumnValue(String colName) {
45: return valueMap.get(colName.toUpperCase());
46: }
47:
48: public final void setColumnValue(String colName, Object colValue) {
49: valueMap.put(colName.toUpperCase(), colValue);
50: }
51:
52: public boolean containsColumn(String colName) {
53: return valueMap.containsKey(colName);
54: }
55:
56: public String toString() {
57: StringBuffer sb = new StringBuffer();
58: sb.append(this .getClass().getSimpleName()).append("{");
59: int i = 0;
60: for (Map.Entry<String, Object> entry : valueMap.entrySet()) {
61: sb.append(entry.getKey()).append("=").append(
62: entry.getValue());
63: if (++i < valueMap.size()) {
64: sb.append(", ");
65: }
66: }
67: sb.append("}");
68: return sb.toString();
69: }
70:
71: public Object clone() throws CloneNotSupportedException {
72: MappedEntity entity = (MappedEntity) super .clone();
73: Map<String, Object> valueMap = new HashMap<String, Object>();
74: valueMap.putAll(this .valueMap);
75: entity.valueMap = valueMap;
76: return entity;
77: }
78:
79: public Map<String, Object> getValueMap() {
80: return Collections.unmodifiableMap(valueMap);
81: }
82:
83: public static void main(String[] args) {
84:
85: }
86: }
|