1 |
|
package org.apache.torque.engine.database.model; |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collections; |
24 |
|
import java.util.Iterator; |
25 |
|
import java.util.List; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import org.apache.commons.collections.map.ListOrderedMap; |
29 |
|
import org.apache.commons.logging.Log; |
30 |
|
import org.apache.commons.logging.LogFactory; |
31 |
|
|
32 |
|
import org.apache.torque.engine.EngineException; |
33 |
|
|
34 |
|
import org.xml.sax.Attributes; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@author |
40 |
|
@author |
41 |
|
@author |
42 |
|
@version |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 60 (60) |
Complexity: 21 |
Complexity Density: 0.6 |
|
44 |
|
public class Index |
45 |
|
{ |
46 |
|
|
47 |
|
private static Log log = LogFactory.getLog(Index.class); |
48 |
|
|
49 |
|
private String indexName; |
50 |
|
|
51 |
|
private Table parentTable; |
52 |
|
|
53 |
|
private List indexColumns; |
54 |
|
|
55 |
|
private Map options; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
62 |
0
|
public Index()... |
63 |
|
{ |
64 |
0
|
indexColumns = new ArrayList(3); |
65 |
0
|
options = Collections.synchronizedMap(new ListOrderedMap()); |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
@link |
71 |
|
|
72 |
|
@param |
73 |
|
@param@link |
74 |
|
|
75 |
|
|
76 |
|
@exception |
77 |
|
@see |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
79 |
0
|
protected Index(Table table, List indexColumns)... |
80 |
|
throws EngineException |
81 |
|
{ |
82 |
0
|
this(); |
83 |
0
|
setTable(table); |
84 |
0
|
if (!indexColumns.isEmpty()) |
85 |
|
{ |
86 |
0
|
this.indexColumns = indexColumns; |
87 |
|
|
88 |
0
|
if (log.isDebugEnabled()) |
89 |
|
{ |
90 |
0
|
log.debug("Created Index named " + getName() |
91 |
|
+ " with " + indexColumns.size() + " columns"); |
92 |
|
} |
93 |
|
} |
94 |
|
else |
95 |
|
{ |
96 |
0
|
throw new EngineException("Cannot create a new Index using an " |
97 |
|
+ "empty list Column object"); |
98 |
|
} |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
@param |
105 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
0
|
public void loadFromXML(Attributes attrib)... |
107 |
|
{ |
108 |
0
|
indexName = attrib.getValue("name"); |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
@return |
115 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
116 |
0
|
public boolean isUnique()... |
117 |
|
{ |
118 |
0
|
return false; |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
@return |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
0
|
public String getName()... |
127 |
|
{ |
128 |
0
|
return indexName; |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
@param |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
0
|
public void setName(String name)... |
137 |
|
{ |
138 |
0
|
this.indexName = name; |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
@param |
145 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
146 |
0
|
public void setTable(Table parent)... |
147 |
|
{ |
148 |
0
|
parentTable = parent; |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
@return |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
0
|
public Table getTable()... |
157 |
|
{ |
158 |
0
|
return parentTable; |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
@return |
165 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
166 |
0
|
public String getTableName()... |
167 |
|
{ |
168 |
0
|
return parentTable.getName(); |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
@param |
175 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
176 |
0
|
public void addColumn(Attributes attrib)... |
177 |
|
{ |
178 |
0
|
indexColumns.add(attrib.getValue("name")); |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
@return |
185 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
186 |
0
|
public String getColumnList()... |
187 |
|
{ |
188 |
0
|
return Column.makeList(getColumns()); |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
@return |
195 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
196 |
0
|
public List getColumns()... |
197 |
|
{ |
198 |
0
|
return indexColumns; |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
@return |
208 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
209 |
0
|
protected List getColumnNames()... |
210 |
|
{ |
211 |
0
|
List names = new ArrayList(indexColumns.size() + 2); |
212 |
0
|
Iterator i = getColumns().iterator(); |
213 |
0
|
while (i.hasNext()) |
214 |
|
{ |
215 |
0
|
Column c = (Column) i.next(); |
216 |
0
|
names.add(c.getName()); |
217 |
|
} |
218 |
0
|
return names; |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
@return |
225 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
226 |
0
|
public String toString()... |
227 |
|
{ |
228 |
0
|
StringBuffer result = new StringBuffer(); |
229 |
0
|
result.append(" <index name=\"") |
230 |
|
.append(getName()) |
231 |
|
.append("\""); |
232 |
|
|
233 |
0
|
result.append(">\n"); |
234 |
|
|
235 |
0
|
for (int i = 0; i < indexColumns.size(); i++) |
236 |
|
{ |
237 |
0
|
result.append(" <index-column name=\"") |
238 |
|
.append(indexColumns.get(i)) |
239 |
|
.append("\"/>\n"); |
240 |
|
} |
241 |
0
|
result.append(" </index>\n"); |
242 |
0
|
return result.toString(); |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
@param |
249 |
|
@param |
250 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
251 |
0
|
public void addOption(String key, String value)... |
252 |
|
{ |
253 |
0
|
options.put(key, value); |
254 |
|
} |
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
@param |
261 |
|
@return |
262 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
263 |
0
|
public String getOption(String key)... |
264 |
|
{ |
265 |
0
|
return (String) options.get(key); |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
@return |
277 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
278 |
0
|
public Map getOptions()... |
279 |
|
{ |
280 |
0
|
return options; |
281 |
|
} |
282 |
|
} |