Coverage Report - org.kuali.rice.core.jpa.spring.DevHibernateJpaVendorAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
DevHibernateJpaVendorAdapter
0%
0/35
0%
0/19
3.625
DevHibernateJpaVendorAdapter$1
0%
0/1
N/A
3.625
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * A Hibernate JPA adapter to expose the Kuali DEV DevHibernatePersistence.  The DEV
 42  
  * mode enables extra caching of the EntityManagerFactory and object serialization
 43  
  * of the Ejb3Configuration so that Hibernate startup can be faster in development.
 44  
  * 
 45  
  * Note: This implementation should not be used in test or production environments
 46  
  * unless further testing determines is it appropriate.
 47  
  * 
 48  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
          * Determine the Hibernate database dialect class for the given target database.
 94  
          * @param database the target database
 95  
          * @return the Hibernate database dialect class, or <code>null<code> if none found
 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  
 }