1 | |
package org.apache.ojb.broker.metadata.torque; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
import org.apache.ojb.broker.metadata.ClassDescriptor; |
19 | |
import org.apache.ojb.broker.metadata.DescriptorRepository; |
20 | |
import org.apache.ojb.broker.metadata.FieldDescriptor; |
21 | |
|
22 | |
import java.util.HashMap; |
23 | |
import java.util.Iterator; |
24 | |
|
25 | |
public class TorqueTablePreprocessor { |
26 | |
|
27 | |
private DescriptorRepository repository; |
28 | |
private HashMap standardTables = new HashMap(); |
29 | |
|
30 | |
public TorqueTablePreprocessor(DescriptorRepository repository) { |
31 | |
this.repository = repository; |
32 | |
} |
33 | |
|
34 | |
public void buildStandardTables() { |
35 | |
Iterator classDescriptorIterators = this.repository.iterator(); |
36 | |
while (classDescriptorIterators.hasNext()) { |
37 | |
ClassDescriptor cd = (ClassDescriptor) classDescriptorIterators.next(); |
38 | |
if(cd.isAbstract() || cd.isInterface()) |
39 | |
{ |
40 | |
System.out.println("Skip table build for abstract base class / interface called "+cd.getClassNameOfObject()); |
41 | |
} |
42 | |
else |
43 | |
{ |
44 | |
buildStandardTable(cd); |
45 | |
} |
46 | |
} |
47 | |
} |
48 | |
|
49 | |
public HashMap getStandardTables() { |
50 | |
return this.standardTables; |
51 | |
} |
52 | |
|
53 | |
private void buildStandardTable(ClassDescriptor cd) { |
54 | |
String tableName = cd.getFullTableName(); |
55 | |
TableDescriptor tableDescriptor = (TableDescriptor) this.standardTables.get(tableName); |
56 | |
if (tableDescriptor == null) { |
57 | |
tableDescriptor = new TableDescriptor(); |
58 | |
tableDescriptor.setName(tableName); |
59 | |
this.standardTables.put(tableName, tableDescriptor); |
60 | |
} |
61 | |
|
62 | |
buildStandardTableFieldDescriptors(cd.getFieldDescriptions(), tableDescriptor); |
63 | |
tableDescriptor.getIndices().addAll(cd.getIndexes()); |
64 | |
tableDescriptor.getReferences().addAll(cd.getObjectReferenceDescriptors()); |
65 | |
} |
66 | |
|
67 | |
private void buildStandardTableFieldDescriptors(FieldDescriptor fieldDescriptors[], TableDescriptor tableDescriptor) { |
68 | |
if (fieldDescriptors != null) { |
69 | |
for (int i = 0; i < fieldDescriptors.length; i++) { |
70 | |
tableDescriptor.addColumn(fieldDescriptors[i]); |
71 | |
} |
72 | |
} |
73 | |
} |
74 | |
} |