1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.service.impl;
17
18 import org.apache.ojb.broker.metadata.ClassDescriptor;
19 import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
20 import org.apache.ojb.broker.metadata.DescriptorRepository;
21 import org.apache.ojb.broker.metadata.FieldDescriptor;
22 import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
23 import org.kuali.rice.core.api.config.property.ConfigContext;
24 import org.kuali.rice.core.framework.persistence.ojb.BaseOjbConfigurer;
25 import org.kuali.rice.krad.bo.PersistableBusinessObject;
26 import org.kuali.rice.krad.bo.PersistableBusinessObjectExtension;
27 import org.kuali.rice.krad.exception.ClassNotPersistableException;
28 import org.kuali.rice.krad.util.LegacyDataFramework;
29 import org.kuali.rice.krad.util.LegacyUtils;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34 @Deprecated
35 @LegacyDataFramework
36 public class PersistenceServiceStructureImplBase {
37 protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PersistenceServiceStructureImplBase.class);
38 private DescriptorRepository descriptorRepository;
39
40
41
42
43 public PersistenceServiceStructureImplBase() {
44 String ojbPropertyFileLocation = ConfigContext.getCurrentContextConfig().getProperty(BaseOjbConfigurer.RICE_OJB_PROPERTIES_PARAM);
45 String currentValue = System.getProperty(BaseOjbConfigurer.OJB_PROPERTIES_PROP);
46 try {
47 System.setProperty(BaseOjbConfigurer.OJB_PROPERTIES_PROP, ojbPropertyFileLocation);
48 org.apache.ojb.broker.metadata.MetadataManager metadataManager = org.apache.ojb.broker.metadata.MetadataManager.getInstance();
49 descriptorRepository = metadataManager.getGlobalRepository();
50 } finally {
51 if (currentValue == null) {
52 System.getProperties().remove(BaseOjbConfigurer.OJB_PROPERTIES_PROP);
53 } else {
54 System.setProperty(BaseOjbConfigurer.OJB_PROPERTIES_PROP, currentValue);
55 }
56 }
57 }
58
59
60
61
62 protected DescriptorRepository getDescriptorRepository() {
63 return descriptorRepository;
64 }
65
66
67
68
69
70
71
72
73
74
75
76 public List listPrimaryKeyFieldNames(Class clazz) {
77
78 List fieldNamesLegacy = new ArrayList();
79 ClassDescriptor classDescriptor = getClassDescriptor(clazz);
80 FieldDescriptor keyDescriptors[] = classDescriptor.getPkFields();
81
82 for (int i = 0; i < keyDescriptors.length; ++i) {
83 FieldDescriptor keyDescriptor = keyDescriptors[i];
84 fieldNamesLegacy.add(keyDescriptor.getAttributeName());
85 }
86 return fieldNamesLegacy;
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122 protected ClassDescriptor getClassDescriptor(Class persistableClass) {
123 if (persistableClass == null) {
124 throw new IllegalArgumentException("invalid (null) object");
125 }
126
127 ClassDescriptor classDescriptor = null;
128 DescriptorRepository globalRepository = getDescriptorRepository();
129 try {
130 classDescriptor = globalRepository.getDescriptorFor(persistableClass);
131 } catch (ClassNotPersistenceCapableException e) {
132 throw new ClassNotPersistableException("class '" + persistableClass.getName() + "' is not persistable", e);
133 }
134
135 return classDescriptor;
136 }
137
138
139
140
141
142
143
144 public boolean isJpaEnabledForKradClass(Class clazz) {
145 return !LegacyUtils.useLegacy(clazz);
146 }
147
148
149
150
151
152 public Class<? extends PersistableBusinessObjectExtension> getBusinessObjectAttributeClass(Class<? extends PersistableBusinessObject> clazz, String attributeName) {
153 String baseAttributeName = attributeName;
154 String subAttributeString = null;
155 if (attributeName.contains(".")) {
156 baseAttributeName = attributeName.substring(0, attributeName.indexOf('.'));
157 subAttributeString = attributeName.substring(attributeName.indexOf('.') + 1);
158 }
159
160
161 Class attributeClassLegacy = null;
162 ClassDescriptor classDescriptor = null;
163 try{
164 classDescriptor = this.getClassDescriptor(clazz);
165 }catch (ClassNotPersistableException e){
166 LOG.warn("Class descriptor for "+ clazz.getName() +"was not found");
167 }
168
169 ObjectReferenceDescriptor refDescriptor = null;
170 if(classDescriptor != null){
171 refDescriptor = classDescriptor.getObjectReferenceDescriptorByName(baseAttributeName);
172 }
173
174 if (refDescriptor != null) {
175 attributeClassLegacy = refDescriptor.getItemClass();
176 }
177
178
179 if (subAttributeString != null) {
180 attributeClassLegacy = getBusinessObjectAttributeClass(attributeClassLegacy, subAttributeString);
181 }
182
183 return attributeClassLegacy;
184 }
185
186 }