1 /* 2 * Copyright 2002-2012 the original author or authors. 3 * 4 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0 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 17 package org.springframework.orm.jpa.vendor; 18 19 import java.util.Map; 20 import javax.persistence.EntityManager; 21 import javax.persistence.EntityManagerFactory; 22 23 import org.springframework.orm.jpa.JpaDialect; 24 import org.springframework.orm.jpa.JpaVendorAdapter; 25 26 /** 27 * Abstract {@link JpaVendorAdapter} implementation that defines common properties, 28 * to be translated into vendor-specific JPA properties by concrete subclasses. 29 * 30 * @author Juergen Hoeller 31 * @author Rod Johnson 32 * @since 2.0 33 */ 34 public abstract class AbstractJpaVendorAdapter implements JpaVendorAdapter { 35 36 private Database database = Database.DEFAULT; 37 38 private String databasePlatform; 39 40 private boolean generateDdl = false; 41 42 private boolean showSql = false; 43 44 45 /** 46 * Specify the target database to operate on, as a value of the {@code Database} enum: 47 * DB2, DERBY, H2, HSQL, INFORMIX, MYSQL, ORACLE, POSTGRESQL, SQL_SERVER, SYBASE 48 */ 49 public void setDatabase(Database database) { 50 this.database = database; 51 } 52 53 /** 54 * Return the target database to operate on. 55 */ 56 protected Database getDatabase() { 57 return this.database; 58 } 59 60 /** 61 * Specify the name of the target database to operate on. 62 * The supported values are vendor-dependent platform identifiers. 63 */ 64 public void setDatabasePlatform(String databasePlatform) { 65 this.databasePlatform = databasePlatform; 66 } 67 68 /** 69 * Return the name of the target database to operate on. 70 */ 71 protected String getDatabasePlatform() { 72 return this.databasePlatform; 73 } 74 75 /** 76 * Set whether to generate DDL after the EntityManagerFactory has been initialized, 77 * creating/updating all relevant tables. 78 * <p>Note that the exact semantics of this flag depend on the underlying 79 * persistence provider. For any more advanced needs, specify the appropriate 80 * vendor-specific settings as "jpaProperties". 81 * @see org.springframework.orm.jpa.AbstractEntityManagerFactoryBean#setJpaProperties 82 */ 83 public void setGenerateDdl(boolean generateDdl) { 84 this.generateDdl = generateDdl; 85 } 86 87 /** 88 * Return whether to generate DDL after the EntityManagerFactory has been initialized 89 * creating/updating all relevant tables. 90 */ 91 protected boolean isGenerateDdl() { 92 return this.generateDdl; 93 } 94 95 /** 96 * Set whether to show SQL in the log (or in the console). 97 * <p>For more specific logging configuration, specify the appropriate 98 * vendor-specific settings as "jpaProperties". 99 * @see org.springframework.orm.jpa.AbstractEntityManagerFactoryBean#setJpaProperties 100 */ 101 public void setShowSql(boolean showSql) { 102 this.showSql = showSql; 103 } 104 105 /** 106 * Return whether to show SQL in the log (or in the console). 107 */ 108 protected boolean isShowSql() { 109 return this.showSql; 110 } 111 112 113 @Override 114 public String getPersistenceProviderRootPackage() { 115 return null; 116 } 117 118 @Override 119 public Map<String, ?> getJpaPropertyMap() { 120 return null; 121 } 122 123 @Override 124 public JpaDialect getJpaDialect() { 125 return null; 126 } 127 128 @Override 129 public Class<? extends EntityManagerFactory> getEntityManagerFactoryInterface() { 130 return EntityManagerFactory.class; 131 } 132 133 @Override 134 public Class<? extends EntityManager> getEntityManagerInterface() { 135 return EntityManager.class; 136 } 137 138 /** 139 * Post-process the EntityManagerFactory after it has been initialized. 140 * @param emf the EntityManagerFactory to process 141 */ 142 @Override 143 public void postProcessEntityManagerFactory(EntityManagerFactory emf) { 144 } 145 146 }