001/* 002 * Copyright 2012-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 * http://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.boot.autoconfigure.orm.jpa; 018 019import java.util.ArrayList; 020import java.util.HashMap; 021import java.util.List; 022import java.util.Map; 023 024import javax.sql.DataSource; 025 026import org.springframework.boot.context.properties.ConfigurationProperties; 027import org.springframework.orm.jpa.vendor.Database; 028 029/** 030 * External configuration properties for a JPA EntityManagerFactory created by Spring. 031 * 032 * @author Dave Syer 033 * @author Andy Wilkinson 034 * @author Stephane Nicoll 035 * @author EddĂș MelĂ©ndez 036 * @author Madhura Bhave 037 * @since 1.1.0 038 */ 039@ConfigurationProperties(prefix = "spring.jpa") 040public class JpaProperties { 041 042 /** 043 * Additional native properties to set on the JPA provider. 044 */ 045 private Map<String, String> properties = new HashMap<>(); 046 047 /** 048 * Mapping resources (equivalent to "mapping-file" entries in persistence.xml). 049 */ 050 private final List<String> mappingResources = new ArrayList<>(); 051 052 /** 053 * Name of the target database to operate on, auto-detected by default. Can be 054 * alternatively set using the "Database" enum. 055 */ 056 private String databasePlatform; 057 058 /** 059 * Target database to operate on, auto-detected by default. Can be alternatively set 060 * using the "databasePlatform" property. 061 */ 062 private Database database; 063 064 /** 065 * Whether to initialize the schema on startup. 066 */ 067 private boolean generateDdl = false; 068 069 /** 070 * Whether to enable logging of SQL statements. 071 */ 072 private boolean showSql = false; 073 074 /** 075 * Register OpenEntityManagerInViewInterceptor. Binds a JPA EntityManager to the 076 * thread for the entire processing of the request. 077 */ 078 private Boolean openInView; 079 080 public Map<String, String> getProperties() { 081 return this.properties; 082 } 083 084 public void setProperties(Map<String, String> properties) { 085 this.properties = properties; 086 } 087 088 public List<String> getMappingResources() { 089 return this.mappingResources; 090 } 091 092 public String getDatabasePlatform() { 093 return this.databasePlatform; 094 } 095 096 public void setDatabasePlatform(String databasePlatform) { 097 this.databasePlatform = databasePlatform; 098 } 099 100 public Database getDatabase() { 101 return this.database; 102 } 103 104 public void setDatabase(Database database) { 105 this.database = database; 106 } 107 108 public boolean isGenerateDdl() { 109 return this.generateDdl; 110 } 111 112 public void setGenerateDdl(boolean generateDdl) { 113 this.generateDdl = generateDdl; 114 } 115 116 public boolean isShowSql() { 117 return this.showSql; 118 } 119 120 public void setShowSql(boolean showSql) { 121 this.showSql = showSql; 122 } 123 124 public Boolean getOpenInView() { 125 return this.openInView; 126 } 127 128 public void setOpenInView(Boolean openInView) { 129 this.openInView = openInView; 130 } 131 132 /** 133 * Determine the {@link Database} to use based on this configuration and the primary 134 * {@link DataSource}. 135 * @param dataSource the auto-configured data source 136 * @return {@code Database} 137 */ 138 public Database determineDatabase(DataSource dataSource) { 139 if (this.database != null) { 140 return this.database; 141 } 142 return DatabaseLookup.getDatabase(dataSource); 143 } 144 145}