1 16 17 package org.springframework.orm.jpa.vendor; 18 19 import java.util.Map ; 20 import java.util.Properties ; 21 import java.util.logging.Level ; 22 23 import javax.persistence.EntityManager; 24 import javax.persistence.spi.PersistenceProvider; 25 26 import oracle.toplink.essentials.config.TargetDatabase; 27 import oracle.toplink.essentials.config.TopLinkProperties; 28 import oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider; 29 30 import org.springframework.orm.jpa.JpaDialect; 31 32 45 public class TopLinkJpaVendorAdapter extends AbstractJpaVendorAdapter { 46 47 private final PersistenceProvider persistenceProvider = new EntityManagerFactoryProvider(); 48 49 private final JpaDialect jpaDialect = new TopLinkJpaDialect(); 50 51 52 public PersistenceProvider getPersistenceProvider() { 53 return this.persistenceProvider; 54 } 55 56 public Map getJpaPropertyMap() { 57 Properties jpaProperties = new Properties (); 58 59 if (getDatabasePlatform() != null) { 60 jpaProperties.setProperty(TopLinkProperties.TARGET_DATABASE, getDatabasePlatform()); 61 } 62 else if (getDatabase() != null) { 63 String targetDatabase = determineTargetDatabaseName(getDatabase()); 64 if (targetDatabase != null) { 65 jpaProperties.setProperty(TopLinkProperties.TARGET_DATABASE, targetDatabase); 66 } 67 } 68 69 if (isGenerateDdl()) { 70 jpaProperties.setProperty(EntityManagerFactoryProvider.DDL_GENERATION, 71 EntityManagerFactoryProvider.CREATE_ONLY); 72 jpaProperties.setProperty(EntityManagerFactoryProvider.DDL_GENERATION_MODE, 73 EntityManagerFactoryProvider.DDL_DATABASE_GENERATION); 74 } 75 if (isShowSql()) { 76 jpaProperties.setProperty(TopLinkProperties.LOGGING_LEVEL, Level.FINE.toString()); 77 } 78 79 return jpaProperties; 80 } 81 82 87 protected String determineTargetDatabaseName(Database database) { 88 switch (database) { 89 case DB2: return TargetDatabase.DB2; 90 case HSQL: return TargetDatabase.HSQL; 91 case INFORMIX: return TargetDatabase.Informix; 92 case MYSQL: return TargetDatabase.MySQL4; 93 case ORACLE: return TargetDatabase.Oracle; 94 case POSTGRESQL: return TargetDatabase.PostgreSQL; 95 case SQL_SERVER: return TargetDatabase.SQLServer; 96 case SYBASE: return TargetDatabase.Sybase; 97 default: return null; 98 } 99 } 100 101 public Class <? extends EntityManager> getEntityManagerInterface() { 102 return oracle.toplink.essentials.ejb.cmp3.EntityManager.class; 103 } 104 105 public JpaDialect getJpaDialect() { 106 return this.jpaDialect; 107 } 108 109 } 110 | Popular Tags |