1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.jpa.spring; |
17 | |
|
18 | |
import java.util.Map; |
19 | |
import java.util.Properties; |
20 | |
|
21 | |
import javax.persistence.EntityManager; |
22 | |
import javax.persistence.spi.PersistenceProvider; |
23 | |
|
24 | |
import org.hibernate.cfg.Environment; |
25 | |
import org.hibernate.dialect.DB2Dialect; |
26 | |
import org.hibernate.dialect.HSQLDialect; |
27 | |
import org.hibernate.dialect.InformixDialect; |
28 | |
import org.hibernate.dialect.MySQLDialect; |
29 | |
import org.hibernate.dialect.Oracle9Dialect; |
30 | |
import org.hibernate.dialect.PostgreSQLDialect; |
31 | |
import org.hibernate.dialect.SQLServerDialect; |
32 | |
import org.hibernate.dialect.SybaseDialect; |
33 | |
import org.hibernate.ejb.HibernateEntityManager; |
34 | |
import org.springframework.beans.factory.InitializingBean; |
35 | |
import org.springframework.orm.jpa.JpaDialect; |
36 | |
import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter; |
37 | |
import org.springframework.orm.jpa.vendor.Database; |
38 | |
import org.springframework.orm.jpa.vendor.HibernateJpaDialect; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | public class DevHibernateJpaVendorAdapter extends AbstractJpaVendorAdapter implements InitializingBean { |
52 | |
|
53 | 0 | private final PersistenceProvider persistenceProvider = new DevHibernatePersistence(); |
54 | |
|
55 | 0 | private final JpaDialect jpaDialect = new HibernateJpaDialect(); |
56 | |
|
57 | |
private String serializationFilename; |
58 | |
private boolean useSerialization; |
59 | |
|
60 | |
public void afterPropertiesSet() throws Exception { |
61 | 0 | ((DevHibernatePersistence)persistenceProvider).setSerializationFilename(serializationFilename); |
62 | 0 | ((DevHibernatePersistence)persistenceProvider).setUseSerialization(useSerialization); |
63 | 0 | } |
64 | |
|
65 | |
public PersistenceProvider getPersistenceProvider() { |
66 | 0 | return this.persistenceProvider; |
67 | |
} |
68 | |
|
69 | |
public Map getJpaPropertyMap() { |
70 | 0 | Properties jpaProperties = new Properties(); |
71 | |
|
72 | 0 | if (getDatabasePlatform() != null) { |
73 | 0 | jpaProperties.setProperty(Environment.DIALECT, getDatabasePlatform()); |
74 | |
} |
75 | 0 | else if (getDatabase() != null) { |
76 | 0 | Class databaseDialectClass = determineDatabaseDialectClass(getDatabase()); |
77 | 0 | if (databaseDialectClass != null) { |
78 | 0 | jpaProperties.setProperty(Environment.DIALECT, databaseDialectClass.getName()); |
79 | |
} |
80 | |
} |
81 | |
|
82 | 0 | if (isGenerateDdl()) { |
83 | 0 | jpaProperties.setProperty(Environment.HBM2DDL_AUTO, "update"); |
84 | |
} |
85 | 0 | if (isShowSql()) { |
86 | 0 | jpaProperties.setProperty(Environment.SHOW_SQL, "true"); |
87 | |
} |
88 | |
|
89 | 0 | return jpaProperties; |
90 | |
} |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
protected Class determineDatabaseDialectClass(Database database) { |
98 | 0 | switch (database) { |
99 | 0 | case DB2: return DB2Dialect.class; |
100 | 0 | case HSQL: return HSQLDialect.class; |
101 | 0 | case INFORMIX: return InformixDialect.class; |
102 | 0 | case MYSQL: return MySQLDialect.class; |
103 | 0 | case ORACLE: return Oracle9Dialect.class; |
104 | 0 | case POSTGRESQL: return PostgreSQLDialect.class; |
105 | 0 | case SQL_SERVER: return SQLServerDialect.class; |
106 | 0 | case SYBASE: return SybaseDialect.class; |
107 | 0 | default: return null; |
108 | |
} |
109 | |
} |
110 | |
|
111 | |
public Class<? extends EntityManager> getEntityManagerInterface() { |
112 | 0 | return HibernateEntityManager.class; |
113 | |
} |
114 | |
|
115 | |
public JpaDialect getJpaDialect() { |
116 | 0 | return this.jpaDialect; |
117 | |
} |
118 | |
|
119 | |
public void setSerializationFilename(String serializationFilename) { |
120 | 0 | this.serializationFilename = serializationFilename; |
121 | 0 | } |
122 | |
|
123 | |
public void setUseSerialization(boolean useSerialization) { |
124 | 0 | this.useSerialization = useSerialization; |
125 | 0 | } |
126 | |
|
127 | |
} |