| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.kuali.rice.kns.dao.proxy; |
| 18 |
|
|
| 19 |
|
import org.apache.commons.lang.StringUtils; |
| 20 |
|
import org.kuali.rice.core.api.config.ConfigurationException; |
| 21 |
|
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
| 22 |
|
import org.kuali.rice.kns.bo.ModuleConfiguration; |
| 23 |
|
import org.kuali.rice.kns.dao.BusinessObjectDao; |
| 24 |
|
import org.kuali.rice.kns.dao.DocumentDao; |
| 25 |
|
import org.kuali.rice.kns.dao.impl.DocumentDaoJpa; |
| 26 |
|
import org.kuali.rice.kns.dao.impl.DocumentDaoOjb; |
| 27 |
|
import org.kuali.rice.kns.document.Document; |
| 28 |
|
import org.kuali.rice.kns.service.DocumentAdHocService; |
| 29 |
|
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
| 30 |
|
import org.kuali.rice.kns.service.KualiModuleService; |
| 31 |
|
import org.kuali.rice.kns.service.ModuleService; |
| 32 |
|
import org.springframework.transaction.annotation.Transactional; |
| 33 |
|
|
| 34 |
|
import javax.persistence.EntityManager; |
| 35 |
|
import java.util.List; |
| 36 |
|
import java.util.Map; |
| 37 |
|
import java.util.concurrent.ConcurrentHashMap; |
| 38 |
|
|
| 39 |
|
@Transactional |
|
|
|
| 0% |
Uncovered Elements: 65 (65) |
Complexity: 22 |
Complexity Density: 0.61 |
|
| 40 |
|
public class DocumentDaoProxy implements DocumentDao { |
| 41 |
|
|
| 42 |
|
private DocumentDao documentDaoJpa; |
| 43 |
|
private DocumentDao documentDaoOjb; |
| 44 |
|
|
| 45 |
|
private static KualiModuleService kualiModuleService; |
| 46 |
|
private static Map<String, DocumentDao> documentDaoValues = new ConcurrentHashMap<String, DocumentDao>(); |
| 47 |
|
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 11 |
Complexity Density: 0.5 |
|
| 48 |
0
|
private DocumentDao getDao(Class<? extends Document> clazz) {... |
| 49 |
0
|
ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(clazz); |
| 50 |
0
|
if (moduleService != null) { |
| 51 |
0
|
ModuleConfiguration moduleConfig = moduleService.getModuleConfiguration(); |
| 52 |
0
|
String dataSourceName = ""; |
| 53 |
0
|
EntityManager entityManager = null; |
| 54 |
0
|
if (moduleConfig != null) { |
| 55 |
0
|
dataSourceName = moduleConfig.getDataSourceName(); |
| 56 |
0
|
entityManager = moduleConfig.getEntityManager(); |
| 57 |
|
} |
| 58 |
|
|
| 59 |
0
|
if (StringUtils.isNotEmpty(dataSourceName)) { |
| 60 |
0
|
if (documentDaoValues.get(dataSourceName) != null) { |
| 61 |
0
|
return documentDaoValues.get(dataSourceName); |
| 62 |
|
} |
| 63 |
0
|
if (OrmUtils.isJpaAnnotated(clazz) && (OrmUtils.isJpaEnabled() || OrmUtils.isJpaEnabled("rice.kns"))) { |
| 64 |
|
|
| 65 |
0
|
if (entityManager != null) { |
| 66 |
|
|
| 67 |
0
|
DocumentDaoJpa documentDaoJpaInstance = |
| 68 |
|
new DocumentDaoJpa(entityManager, this.documentDaoJpa.getBusinessObjectDao(), |
| 69 |
|
this.documentDaoJpa.getDocumentAdHocService()); |
| 70 |
|
|
| 71 |
0
|
documentDaoValues.put(dataSourceName, documentDaoJpaInstance); |
| 72 |
0
|
return documentDaoJpaInstance; |
| 73 |
|
} |
| 74 |
0
|
throw new ConfigurationException("EntityManager is null. EntityManager must be set in the Module Configuration bean in the appropriate spring beans xml. (see nested exception for details)."); |
| 75 |
|
} |
| 76 |
|
|
| 77 |
0
|
DocumentDaoOjb documentDaoOjbInstance = |
| 78 |
|
new DocumentDaoOjb( |
| 79 |
|
this.documentDaoOjb.getBusinessObjectDao(), |
| 80 |
|
this.documentDaoOjb.getDocumentAdHocService()); |
| 81 |
|
|
| 82 |
|
|
| 83 |
0
|
documentDaoOjbInstance.setJcdAlias(dataSourceName); |
| 84 |
|
|
| 85 |
0
|
documentDaoValues.put(dataSourceName, documentDaoOjbInstance); |
| 86 |
0
|
return documentDaoOjbInstance; |
| 87 |
|
|
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
} |
| 91 |
0
|
return (OrmUtils.isJpaAnnotated(clazz) && OrmUtils.isJpaEnabled()) ? documentDaoJpa : documentDaoOjb; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
@see |
| 96 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 97 |
0
|
@Override... |
| 98 |
|
public <T extends Document> T save(T document) { |
| 99 |
0
|
return getDao(document.getClass()).save(document); |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
|
| 103 |
|
@see |
| 104 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 105 |
0
|
@Override... |
| 106 |
|
public <T extends Document> T findByDocumentHeaderId(Class<T> clazz, String id) { |
| 107 |
0
|
return getDao(clazz).findByDocumentHeaderId(clazz, id); |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
|
| 111 |
|
@see |
| 112 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 113 |
0
|
@Override... |
| 114 |
|
public <T extends Document> List<T> findByDocumentHeaderIds(Class<T> clazz, List<String> idList) { |
| 115 |
0
|
return getDao(clazz).findByDocumentHeaderIds(clazz, idList); |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
|
| 119 |
|
@see |
| 120 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 121 |
0
|
@Override... |
| 122 |
|
public BusinessObjectDao getBusinessObjectDao() { |
| 123 |
0
|
if (OrmUtils.isJpaEnabled()) { |
| 124 |
0
|
return documentDaoJpa.getBusinessObjectDao(); |
| 125 |
|
} |
| 126 |
0
|
return documentDaoOjb.getBusinessObjectDao(); |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
|
| 130 |
|
@see |
| 131 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 132 |
0
|
@Override... |
| 133 |
|
public DocumentAdHocService getDocumentAdHocService() { |
| 134 |
0
|
if (OrmUtils.isJpaEnabled()) { |
| 135 |
0
|
return documentDaoJpa.getDocumentAdHocService(); |
| 136 |
|
} |
| 137 |
0
|
return documentDaoOjb.getDocumentAdHocService(); |
| 138 |
|
} |
| 139 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 140 |
0
|
public void setDocumentDaoJpa(DocumentDao documentDaoJpa) {... |
| 141 |
0
|
this.documentDaoJpa = documentDaoJpa; |
| 142 |
|
} |
| 143 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 144 |
0
|
public void setDocumentDaoOjb(DocumentDao documentDaoOjb) {... |
| 145 |
0
|
this.documentDaoOjb = documentDaoOjb; |
| 146 |
|
} |
| 147 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 148 |
0
|
private synchronized static KualiModuleService getKualiModuleService() {... |
| 149 |
0
|
if (kualiModuleService == null) { |
| 150 |
0
|
kualiModuleService = KNSServiceLocatorWeb.getKualiModuleService(); |
| 151 |
|
} |
| 152 |
0
|
return kualiModuleService; |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
} |