View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.service.impl;
17  
18  import org.kuali.rice.krad.bo.DataObjectRelationship;
19  import org.kuali.rice.krad.bo.PersistableBusinessObject;
20  import org.kuali.rice.krad.service.PersistenceStructureService;
21  import org.kuali.rice.krad.util.ForeignKeyFieldsPopulationState;
22  import org.kuali.rice.krad.util.LegacyDataFramework;
23  
24  import java.util.HashMap;
25  import java.util.List;
26  import java.util.Map;
27  
28  /**
29   * This class was originally introduced a proxy to decide between OJB and JPA implementations, but new work on krad-data
30   * module has rendered this service deprecated so this implementation is largely vestigial.
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   *
34   * @deprecated use new KRAD Data framework {@link org.kuali.rice.krad.data.DataObjectService}
35   */
36  @Deprecated
37  @LegacyDataFramework
38  public class PersistenceStructureServiceImpl extends PersistenceServiceImplBase implements PersistenceStructureService {
39  
40  	/**
41  	 *
42  	 * special case when the attributeClass passed in doesnt match the class of
43  	 * the reference-descriptor as defined in ojb-repository. Currently the only
44  	 * case of this happening is ObjectCode vs. ObjectCodeCurrent.
45  	 *
46  	 * NOTE: This method makes no real sense and is a product of a hack
47  	 * introduced by KFS for an unknown reason. If you find yourself using this
48  	 * map stop and go do something else.
49  	 *
50  	 * @param from
51  	 *            the class in the code
52  	 * @param to
53  	 *            the class in the repository
54  	 */
55  	public static Map<Class, Class> referenceConversionMap = new HashMap<Class, Class>();
56  
57  	private PersistenceStructureService persistenceStructureServiceOjb;
58  
59  	public void setPersistenceStructureServiceOjb(PersistenceStructureService persistenceStructureServiceOjb) {
60  		this.persistenceStructureServiceOjb = persistenceStructureServiceOjb;
61  	}
62  
63  	private PersistenceStructureService getService(Class clazz) {
64  		//return (isJpaEnabledForKradClass(clazz)) ?
65  		//				persistenceStructureServiceJpa : persistenceStructureServiceOjb;
66          // TODO remove this entirely, we are no longer sending any JPA stuff through this class as this class is now legacy!
67          return persistenceStructureServiceOjb;
68  	}
69  
70  	/**
71  	 * @see org.kuali.rice.krad.service.PersistenceService#isPersistable(java.lang.Class)
72  	 */
73  
74  	@Override
75  	public boolean isPersistable(Class clazz) {
76  		return getService(clazz).isPersistable(clazz);
77  	}
78  
79  	/**
80  	 * @see org.kuali.rice.krad.service.PersistenceService#getPrimaryKeys(java.lang.Class)
81  	 */
82  
83  	@Override
84  	public List getPrimaryKeys(Class clazz) {
85  		return getService(clazz).getPrimaryKeys(clazz);
86  	}
87  
88  	/**
89  	 * @see org.kuali.rice.krad.service.PersistenceMetadataExplorerService#listFieldNames(java.lang.Class)
90  	 */
91  
92  	@Override
93  	public List listFieldNames(Class clazz) {
94  		return getService(clazz).listFieldNames(clazz);
95  	}
96  
97  	/**
98  	 * @see org.kuali.rice.krad.service.PersistenceMetadataService#clearPrimaryKeyFields(java.lang.Object)
99  	 */
100 	// Unit tests only
101 	@Override
102 	public Object clearPrimaryKeyFields(Object persistableObject) {
103 		return getService(persistableObject.getClass()).clearPrimaryKeyFields(persistableObject);
104 	}
105 
106 	/**
107 	 * @see org.kuali.rice.krad.service.PersistenceMetadataExplorerService#listPersistableSubclasses(java.lang.Class)
108 	 */
109 
110 	// Unit tests only
111 	@Override
112 	public List listPersistableSubclasses(Class superclazz) {
113 		return getService(superclazz).listPersistableSubclasses(superclazz);
114 	}
115 
116 	/**
117 	 * @see org.kuali.rice.krad.service.PersistenceService#getRelationshipMetadata(java.lang.Class,
118 	 *      java.lang.String)
119 	 */
120 
121 	@Override
122 	public Map<String, DataObjectRelationship> getRelationshipMetadata(Class persistableClass, String attributeName, String attributePrefix) {
123 		return getService(persistableClass).getRelationshipMetadata(persistableClass, attributeName, attributePrefix);
124 	}
125 
126 
127 	// Unit tests only
128 	@Override
129 	public Map<String, DataObjectRelationship> getRelationshipMetadata(Class persistableClass, String attributeName) {
130 		return getService(persistableClass).getRelationshipMetadata(persistableClass, attributeName);
131 	}
132 
133 	/**
134 	 * @see org.kuali.rice.krad.service.PersistenceService#getForeignKeyFieldName(java.lang.Object,
135 	 *      java.lang.String, java.lang.String)
136 	 */
137 
138 	@Override
139 	public String getForeignKeyFieldName(Class persistableObjectClass, String attributeName, String pkName) {
140 		return getService(persistableObjectClass).getForeignKeyFieldName(persistableObjectClass, attributeName, pkName);
141 	}
142 
143 	/**
144 	 * @see org.kuali.rice.krad.service.PersistenceService#getReferencesForForeignKey(java.lang.Class,
145 	 *      java.lang.String)
146 	 */
147 
148 	@Override
149 	public Map getReferencesForForeignKey(Class persistableObjectClass, String attributeName) {
150 		return getService(persistableObjectClass).getReferencesForForeignKey(persistableObjectClass, attributeName);
151 	}
152 
153 	/**
154 	 * @see org.kuali.rice.krad.service.PersistenceService#getForeignKeysForReference(java.lang.Class, java.lang.String)
155 	 */
156 
157 	@Override
158 	public Map getForeignKeysForReference(Class clazz, String attributeName) {
159 		return getService(clazz).getForeignKeysForReference(clazz, attributeName);
160 	}
161 
162 
163 	@Override
164 	public Map<String, String> getInverseForeignKeysForCollection(Class boClass, String collectionName) {
165 		return getService(boClass).getInverseForeignKeysForCollection(boClass, collectionName);
166 	}
167 
168 	/**
169 	 * @see org.kuali.rice.krad.service.PersistenceService#getNestedForeignKeyMap(java.lang.Class)
170 	 */
171 
172 	@Override
173 	public Map getNestedForeignKeyMap(Class persistableObjectClass) {
174 		return getService(persistableObjectClass).getNestedForeignKeyMap(persistableObjectClass);
175 	}
176 
177 	/**
178 	 * @see org.kuali.rice.krad.service.PersistenceMetadataService#hasPrimaryKeyFieldValues(java.lang.Object)
179 	 */
180 	@Override
181 	public boolean hasPrimaryKeyFieldValues(Object persistableObject) {
182 		return getService(persistableObject.getClass()).hasPrimaryKeyFieldValues(persistableObject);
183 	}
184 
185 	/**
186 	 * @see org.kuali.rice.krad.service.PersistenceService#getForeignKeyFieldsPopulationState(org.kuali.rice.krad.bo.BusinessObject,
187 	 *      java.lang.String)
188 	 */
189 	@Override
190 	public ForeignKeyFieldsPopulationState getForeignKeyFieldsPopulationState(PersistableBusinessObject bo, String referenceName) {
191 		return getService(bo.getClass()).getForeignKeyFieldsPopulationState(bo, referenceName);
192 	}
193 
194 	/**
195 	 * @see org.kuali.rice.krad.service.PersistenceStructureService#listReferenceObjectFieldNames(java.lang.Class)
196 	 */
197 
198 	@Override
199 	public Map<String, Class> listReferenceObjectFields(Class boClass) {
200 		return getService(boClass).listReferenceObjectFields(boClass);
201 	}
202 
203 
204 	@Override
205 	public Map<String, Class> listCollectionObjectTypes(Class boClass) {
206 		return getService(boClass).listCollectionObjectTypes(boClass);
207 	}
208 
209 	@Override
210 	public Map<String, Class> listCollectionObjectTypes(PersistableBusinessObject bo) {
211 		return getService(bo.getClass()).listCollectionObjectTypes(bo);
212 	}
213 
214 	/**
215 	 * @see org.kuali.rice.krad.service.PersistenceStructureService#listReferenceObjectFieldNames(org.kuali.rice.krad.bo.BusinessObject)
216 	 */
217 	@Override
218 	public Map<String, Class> listReferenceObjectFields(PersistableBusinessObject bo) {
219 		return getService(bo.getClass()).listReferenceObjectFields(bo);
220 	}
221 
222 
223 	@Override
224 	public boolean isReferenceUpdatable(Class boClass, String referenceName) {
225 		return getService(boClass).isReferenceUpdatable(boClass, referenceName);
226 	}
227 
228 
229 	@Override
230 	public boolean isCollectionUpdatable(Class boClass, String collectionName) {
231 		return getService(boClass).isCollectionUpdatable(boClass, collectionName);
232 	}
233 
234 
235 	@Override
236 	public boolean hasCollection(Class boClass, String collectionName) {
237 		return getService(boClass).hasCollection(boClass, collectionName);
238 	}
239 
240 
241 	@Override
242 	public boolean hasReference(Class boClass, String referenceName) {
243 		return getService(boClass).hasReference(boClass, referenceName);
244 	}
245 
246 	/**
247 	 * This overridden method ...
248 	 *
249 	 * @see org.kuali.rice.krad.service.PersistenceStructureService#getTableName(java.lang.Class)
250 	 */
251 	@Override
252 	public String getTableName(
253 			Class<? extends PersistableBusinessObject> boClass) {
254 		return getService(boClass).getTableName(boClass);
255 	}
256 
257 
258 }