001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.orm.jpa.vendor;
018
019import java.util.Collections;
020import java.util.Map;
021import javax.persistence.EntityManager;
022import javax.persistence.EntityManagerFactory;
023import javax.persistence.spi.PersistenceUnitInfo;
024
025import org.springframework.orm.jpa.JpaDialect;
026import org.springframework.orm.jpa.JpaVendorAdapter;
027
028/**
029 * Abstract {@link JpaVendorAdapter} implementation that defines common properties,
030 * to be translated into vendor-specific JPA properties by concrete subclasses.
031 *
032 * @author Juergen Hoeller
033 * @author Rod Johnson
034 * @since 2.0
035 */
036public abstract class AbstractJpaVendorAdapter implements JpaVendorAdapter {
037
038        private Database database = Database.DEFAULT;
039
040        private String databasePlatform;
041
042        private boolean generateDdl = false;
043
044        private boolean showSql = false;
045
046
047        /**
048         * Specify the target database to operate on, as a value of the {@code Database} enum:
049         * DB2, DERBY, H2, HSQL, INFORMIX, MYSQL, ORACLE, POSTGRESQL, SQL_SERVER, SYBASE
050         * <p><b>NOTE:</b> This setting will override your JPA provider's default algorithm.
051         * Custom vendor properties may still fine-tune the database dialect. However,
052         * there may nevertheless be conflicts: For example, specify either this setting
053         * or Hibernate's "hibernate.dialect_resolvers" property, not both.
054         */
055        public void setDatabase(Database database) {
056                this.database = database;
057        }
058
059        /**
060         * Return the target database to operate on.
061         */
062        protected Database getDatabase() {
063                return this.database;
064        }
065
066        /**
067         * Specify the name of the target database to operate on.
068         * The supported values are vendor-dependent platform identifiers.
069         */
070        public void setDatabasePlatform(String databasePlatform) {
071                this.databasePlatform = databasePlatform;
072        }
073
074        /**
075         * Return the name of the target database to operate on.
076         */
077        protected String getDatabasePlatform() {
078                return this.databasePlatform;
079        }
080
081        /**
082         * Set whether to generate DDL after the EntityManagerFactory has been initialized,
083         * creating/updating all relevant tables.
084         * <p>Note that the exact semantics of this flag depend on the underlying
085         * persistence provider. For any more advanced needs, specify the appropriate
086         * vendor-specific settings as "jpaProperties".
087         * <p><b>NOTE: Do not set this flag to 'true' while also setting JPA 2.1's
088         * {@code javax.persistence.schema-generation.database.action} property.</b>
089         * These two schema generation mechanisms - standard JPA versus provider-native -
090         * are mutually exclusive, e.g. with Hibernate 5.
091         * @see org.springframework.orm.jpa.AbstractEntityManagerFactoryBean#setJpaProperties
092         */
093        public void setGenerateDdl(boolean generateDdl) {
094                this.generateDdl = generateDdl;
095        }
096
097        /**
098         * Return whether to generate DDL after the EntityManagerFactory has been initialized
099         * creating/updating all relevant tables.
100         */
101        protected boolean isGenerateDdl() {
102                return this.generateDdl;
103        }
104
105        /**
106         * Set whether to show SQL in the log (or in the console).
107         * <p>For more specific logging configuration, specify the appropriate
108         * vendor-specific settings as "jpaProperties".
109         * @see org.springframework.orm.jpa.AbstractEntityManagerFactoryBean#setJpaProperties
110         */
111        public void setShowSql(boolean showSql) {
112                this.showSql = showSql;
113        }
114
115        /**
116         * Return whether to show SQL in the log (or in the console).
117         */
118        protected boolean isShowSql() {
119                return this.showSql;
120        }
121
122
123        @Override
124        public String getPersistenceProviderRootPackage() {
125                return null;
126        }
127
128        @Override
129        public Map<String, ?> getJpaPropertyMap(PersistenceUnitInfo pui) {
130                return getJpaPropertyMap();
131        }
132
133        @Override
134        public Map<String, ?> getJpaPropertyMap() {
135                return Collections.emptyMap();
136        }
137
138        @Override
139        public JpaDialect getJpaDialect() {
140                return null;
141        }
142
143        @Override
144        public Class<? extends EntityManagerFactory> getEntityManagerFactoryInterface() {
145                return EntityManagerFactory.class;
146        }
147
148        @Override
149        public Class<? extends EntityManager> getEntityManagerInterface() {
150                return EntityManager.class;
151        }
152
153        @Override
154        public void postProcessEntityManagerFactory(EntityManagerFactory emf) {
155        }
156
157}