1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.batch.dataaccess.impl;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.ojb.broker.metadata.ClassDescriptor;
22 import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
23 import org.apache.ojb.broker.metadata.DescriptorRepository;
24 import org.apache.ojb.broker.metadata.FieldDescriptor;
25 import org.apache.ojb.broker.metadata.MetadataManager;
26 import org.kuali.ole.gl.batch.dataaccess.ReconciliationDao;
27 import org.kuali.ole.gl.businessobject.OriginEntryFull;
28 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29 import org.kuali.rice.krad.exception.ClassNotPersistableException;
30
31
32
33
34 public class ReconciliationDaoOjb extends PlatformAwareDaoBaseOjb implements ReconciliationDao {
35
36 private DescriptorRepository descriptorRepository;
37
38
39
40
41 public ReconciliationDaoOjb() {
42 MetadataManager metadataManager = MetadataManager.getInstance();
43 descriptorRepository = metadataManager.getGlobalRepository();
44 }
45
46
47
48
49
50
51
52
53
54
55
56 public List<String> convertDBColumnNamesToJavaName(Class<? extends OriginEntryFull> clazz, String[] columnNames, boolean caseInsensitive) {
57 List<String> results = new ArrayList<String>();
58 ClassDescriptor classDescriptor = getClassDescriptor(clazz);
59 for (int i = 0; i < columnNames.length; i++) {
60 results.add(convertDBColumnNameToJavaName(classDescriptor, columnNames[i], caseInsensitive));
61 }
62 return results;
63 }
64
65
66
67
68
69
70
71
72
73 protected String convertDBColumnNameToJavaName(ClassDescriptor classDescriptor, String columnName, boolean caseInsensitive) {
74 FieldDescriptor[] fields = classDescriptor.getFieldDescriptions();
75 for (FieldDescriptor field : fields) {
76 if (caseInsensitive && field.getColumnName().equalsIgnoreCase(columnName)) {
77 return field.getAttributeName();
78 }
79 if (!caseInsensitive && field.getColumnName().equals(columnName)) {
80 return field.getAttributeName();
81 }
82 }
83 return null;
84 }
85
86
87
88
89
90
91
92
93 protected <E extends OriginEntryFull> ClassDescriptor getClassDescriptor(Class<E> persistableClass) {
94 if (persistableClass == null) {
95 throw new IllegalArgumentException("invalid (null) object");
96 }
97
98 ClassDescriptor classDescriptor = null;
99 DescriptorRepository globalRepository = getDescriptorRepository();
100 try {
101 classDescriptor = globalRepository.getDescriptorFor(persistableClass);
102 }
103 catch (ClassNotPersistenceCapableException e) {
104 throw new ClassNotPersistableException("class '" + persistableClass.getName() + "' is not persistable", e);
105 }
106
107 return classDescriptor;
108 }
109
110
111
112
113
114
115 protected DescriptorRepository getDescriptorRepository() {
116 return descriptorRepository;
117 }
118
119
120
121
122
123
124 public void setDescriptorRepository(DescriptorRepository descriptorRepository) {
125 this.descriptorRepository = descriptorRepository;
126 }
127 }