1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.dataaccess.impl;
17
18 import java.lang.reflect.Field;
19 import java.util.Map;
20
21 import org.apache.ojb.broker.PersistenceBroker;
22 import org.apache.ojb.broker.accesslayer.QueryCustomizerDefaultImpl;
23 import org.apache.ojb.broker.metadata.CollectionDescriptor;
24 import org.apache.ojb.broker.query.Criteria;
25 import org.apache.ojb.broker.query.Query;
26 import org.apache.ojb.broker.query.QueryByCriteria;
27 import org.kuali.rice.krad.util.ObjectUtils;
28
29 public class OjbQueryCustomizer extends QueryCustomizerDefaultImpl {
30
31 protected static final String FIELD_PREFIX = "parent.";
32
33 @Override
34 public Query customizeQuery(Object arg0, PersistenceBroker arg1, CollectionDescriptor arg2, QueryByCriteria arg3) {
35
36
37
38 Field field = null;
39 try {
40 field = this.getClass().getSuperclass().getDeclaredField("m_attributeList");
41 }
42 catch (Exception e) {
43 throw new RuntimeException(e);
44 }
45 field.setAccessible(true);
46 Map<String, String> m_attributeList = null;
47 try {
48 m_attributeList = (Map) field.get(this);
49 }
50 catch (Exception e) {
51 throw new RuntimeException(e);
52 }
53
54
55 Criteria criteria = arg3.getCriteria();
56 for (String key : m_attributeList.keySet()) {
57
58
59
60
61
62
63 if (this.getAttribute(key).startsWith(FIELD_PREFIX)) {
64 criteria.addEqualTo(key, ObjectUtils.getPropertyValue(arg0, this.getAttribute(key).substring(FIELD_PREFIX.length())));
65 }
66 else {
67 criteria.addEqualTo(key, this.getAttribute(key));
68 }
69 }
70 arg3.setCriteria(criteria);
71 return arg3;
72 }
73 }