1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.exorcist.midgard;
18
19 import java.util.HashMap;
20 import java.util.HashSet;
21 import java.util.Iterator;
22 import java.util.Map;
23 import java.util.Set;
24
25 public class MidgardType {
26
27 private String name;
28
29 private String table;
30
31 private MidgardProperty timestamp;
32
33 private MidgardProperty primary;
34
35 private MidgardProperty parent;
36
37 private Map properties = new HashMap();
38
39 private Set children = new HashSet();
40
41 public String getName() {
42 return name;
43 }
44
45 public void setName(String name) {
46 this.name = name;
47 }
48
49 public String getTable() {
50 return table;
51 }
52
53 public void setTable(String table) {
54 this.table = table;
55 }
56
57 public MidgardProperty getTimestamp() {
58 return timestamp;
59 }
60
61 public void setTimestamp(MidgardProperty property) {
62 timestamp = property;
63 }
64
65 public MidgardProperty getPrimary() {
66 return primary;
67 }
68
69 public void setPrimary(MidgardProperty property) {
70 primary = property;
71 }
72
73 public MidgardProperty getParent() {
74 return parent;
75 }
76
77 public void setParent(MidgardProperty property) {
78 if (parent != null) {
79 parent.getLink().removeChild(this);
80 }
81 parent = property;
82 parent.getLink().addChild(this);
83 }
84
85 public MidgardProperty getProperty(String name) {
86 return (MidgardProperty) properties.get(name);
87 }
88
89 public Iterator getProperties() {
90 return properties.values().iterator();
91 }
92
93 public void addProperty(MidgardProperty property) {
94 properties.put(property.getName(), property);
95 }
96
97 public String getSQL() {
98 StringBuffer buffer = new StringBuffer();
99 buffer.append("SELECT ");
100 buffer.append(primary.getName());
101 Iterator iterator = properties.values().iterator();
102 while (iterator.hasNext()) {
103 buffer.append(", ");
104 MidgardProperty property = (MidgardProperty) iterator.next();
105 buffer.append(property.getName());
106 }
107 buffer.append(" FROM ");
108 buffer.append(table);
109 return buffer.toString();
110 }
111
112 public Iterator getChildren() {
113 return children.iterator();
114 }
115
116 public void addChild(MidgardType type) {
117 children.add(type);
118 }
119
120 public void removeChild(MidgardType type) {
121 children.remove(type);
122 }
123
124 }