1 16 17 package org.springframework.orm.jpa.vendor; 18 19 import java.util.Map ; 20 import java.util.Properties ; 21 22 import javax.persistence.EntityManager; 23 import javax.persistence.spi.PersistenceProvider; 24 25 import org.hibernate.cfg.Environment; 26 import org.hibernate.dialect.DB2Dialect; 27 import org.hibernate.dialect.HSQLDialect; 28 import org.hibernate.dialect.InformixDialect; 29 import org.hibernate.dialect.MySQLDialect; 30 import org.hibernate.dialect.Oracle9Dialect; 31 import org.hibernate.dialect.PostgreSQLDialect; 32 import org.hibernate.dialect.SQLServerDialect; 33 import org.hibernate.dialect.SybaseDialect; 34 import org.hibernate.ejb.HibernateEntityManager; 35 import org.hibernate.ejb.HibernatePersistence; 36 37 import org.springframework.orm.jpa.JpaDialect; 38 39 52 public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter { 53 54 private final PersistenceProvider persistenceProvider = new HibernatePersistence(); 55 56 private final JpaDialect jpaDialect = new HibernateJpaDialect(); 57 58 59 public PersistenceProvider getPersistenceProvider() { 60 return this.persistenceProvider; 61 } 62 63 public Map getJpaPropertyMap() { 64 Properties jpaProperties = new Properties (); 65 66 if (getDatabasePlatform() != null) { 67 jpaProperties.setProperty(Environment.DIALECT, getDatabasePlatform()); 68 } 69 else if (getDatabase() != null) { 70 Class databaseDialectClass = determineDatabaseDialectClass(getDatabase()); 71 if (databaseDialectClass != null) { 72 jpaProperties.setProperty(Environment.DIALECT, databaseDialectClass.getName()); 73 } 74 } 75 76 if (isGenerateDdl()) { 77 jpaProperties.setProperty(Environment.HBM2DDL_AUTO, "update"); 78 } 79 if (isShowSql()) { 80 jpaProperties.setProperty(Environment.SHOW_SQL, "true"); 81 } 82 83 return jpaProperties; 84 } 85 86 91 protected Class determineDatabaseDialectClass(Database database) { 92 switch (database) { 93 case DB2: return DB2Dialect.class; 94 case HSQL: return HSQLDialect.class; 95 case INFORMIX: return InformixDialect.class; 96 case MYSQL: return MySQLDialect.class; 97 case ORACLE: return Oracle9Dialect.class; 98 case POSTGRESQL: return PostgreSQLDialect.class; 99 case SQL_SERVER: return SQLServerDialect.class; 100 case SYBASE: return SybaseDialect.class; 101 default: return null; 102 } 103 } 104 105 public Class <? extends EntityManager> getEntityManagerInterface() { 106 return HibernateEntityManager.class; 107 } 108 109 public JpaDialect getJpaDialect() { 110 return this.jpaDialect; 111 } 112 113 } 114 | Popular Tags |