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.apache.openjpa.persistence.OpenJPAEntityManager; 26 import org.apache.openjpa.persistence.PersistenceProviderImpl; 27 28 import org.springframework.orm.jpa.JpaDialect; 29 30 43 public class OpenJpaVendorAdapter extends AbstractJpaVendorAdapter { 44 45 private final PersistenceProvider persistenceProvider = new PersistenceProviderImpl(); 46 47 private final OpenJpaDialect jpaDialect = new OpenJpaDialect(); 48 49 50 public PersistenceProvider getPersistenceProvider() { 51 return this.persistenceProvider; 52 } 53 54 public Map getJpaPropertyMap() { 55 Properties jpaProperties = new Properties (); 56 57 if (getDatabasePlatform() != null) { 58 jpaProperties.setProperty("openjpa.jdbc.DBDictionary", getDatabasePlatform()); 59 } 60 else if (getDatabase() != null) { 61 String databaseDictonary = determineDatabaseDictionary(getDatabase()); 62 if (databaseDictonary != null) { 63 jpaProperties.setProperty("openjpa.jdbc.DBDictionary", databaseDictonary); 64 } 65 } 66 67 if (isGenerateDdl()) { 68 jpaProperties.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); 69 } 70 71 if (isShowSql()) { 72 jpaProperties.setProperty("openjpa.Log", "DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE"); 74 } 75 76 return jpaProperties; 77 } 78 79 84 protected String determineDatabaseDictionary(Database database) { 85 switch (database) { 86 case DB2: return "db2"; 87 case HSQL: return "hsql(SimulateLocking=true)"; 88 case INFORMIX: return "informix"; 89 case MYSQL: return "mysql"; 90 case ORACLE: return "oracle"; 91 case POSTGRESQL: return "postgres"; 92 case SQL_SERVER: return "sqlserver"; 93 case SYBASE: return "sybase"; 94 default: return null; 95 } 96 } 97 98 public Class <? extends EntityManager> getEntityManagerInterface() { 99 return OpenJPAEntityManager.class; 100 } 101 102 public JpaDialect getJpaDialect() { 103 return this.jpaDialect; 104 } 105 106 } 107 | Popular Tags |