1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.app.persistence.jpa; |
17 | |
|
18 | |
import org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo; |
19 | |
import org.springframework.orm.jpa.persistenceunit.PersistenceUnitPostProcessor; |
20 | |
|
21 | |
import javax.sql.DataSource; |
22 | |
|
23 | 0 | public class RicePersistenceUnitPostProcessor implements PersistenceUnitPostProcessor { |
24 | 0 | static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RicePersistenceUnitPostProcessor.class); |
25 | |
|
26 | |
public static final String KRAD_APPLICATION_PERSISTENCE_UNIT_NAME = "krad-application-unit"; |
27 | |
public static final String KRAD_SERVER_PERSISTENCE_UNIT_NAME = "krad-server-unit"; |
28 | |
|
29 | |
private DataSource jtaDataSource; |
30 | |
|
31 | |
public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo mutablePersistenceUnitInfo) { |
32 | 0 | mutablePersistenceUnitInfo.setJtaDataSource(getJtaDataSource()); |
33 | 0 | addKRADManagedClassNames(mutablePersistenceUnitInfo); |
34 | 0 | if (mutablePersistenceUnitInfo.getPersistenceUnitName().equals(KRAD_APPLICATION_PERSISTENCE_UNIT_NAME) || mutablePersistenceUnitInfo.getPersistenceUnitName().equals( |
35 | |
KRAD_SERVER_PERSISTENCE_UNIT_NAME)) { |
36 | 0 | addRiceManagedClassNamesToKRADPersistenceUnit(mutablePersistenceUnitInfo); |
37 | |
} |
38 | 0 | } |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public void addKRADManagedClassNames(MutablePersistenceUnitInfo mutablePersistenceUnitInfo) { |
48 | 0 | addManagedClassNames(mutablePersistenceUnitInfo, new KRADPersistableBusinessObjectClassExposer()); |
49 | 0 | } |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public void addManagedClassNames(MutablePersistenceUnitInfo mutablePersistenceUnitInfo, PersistableBusinessObjectClassExposer exposer) { |
58 | 0 | for (String exposedClassName : exposer.exposePersistableBusinessObjectClassNames()) { |
59 | 0 | if (LOG.isDebugEnabled()) { |
60 | 0 | LOG.debug("JPA will now be managing class: "+exposedClassName); |
61 | |
} |
62 | 0 | mutablePersistenceUnitInfo.addManagedClassName(exposedClassName); |
63 | |
} |
64 | 0 | } |
65 | |
|
66 | |
public void addRiceManagedClassNamesToKRADPersistenceUnit(MutablePersistenceUnitInfo mutablePersistenceUnitInfo) { |
67 | 0 | addManagedClassNames(mutablePersistenceUnitInfo, new RiceToNervousSystemBusinessObjectClassExposer()); |
68 | 0 | } |
69 | |
|
70 | |
public DataSource getJtaDataSource() { |
71 | 0 | return jtaDataSource; |
72 | |
} |
73 | |
|
74 | |
public void setJtaDataSource(DataSource jtaDataSource) { |
75 | 0 | this.jtaDataSource = jtaDataSource; |
76 | 0 | } |
77 | |
|
78 | |
} |