001/* 002 * Copyright 2002-2017 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; 018 019import java.util.Collections; 020import java.util.Map; 021 022import javax.persistence.EntityManager; 023import javax.persistence.EntityManagerFactory; 024import javax.persistence.spi.PersistenceProvider; 025import javax.persistence.spi.PersistenceUnitInfo; 026 027import org.springframework.lang.Nullable; 028 029/** 030 * SPI interface that allows to plug in vendor-specific behavior 031 * into Spring's EntityManagerFactory creators. Serves as single 032 * configuration point for all vendor-specific properties. 033 * 034 * @author Juergen Hoeller 035 * @author Rod Johnson 036 * @since 2.0 037 * @see AbstractEntityManagerFactoryBean#setJpaVendorAdapter 038 */ 039public interface JpaVendorAdapter { 040 041 /** 042 * Return the vendor-specific persistence provider. 043 */ 044 PersistenceProvider getPersistenceProvider(); 045 046 /** 047 * Return the name of the persistence provider's root package 048 * (e.g. "oracle.toplink.essentials"). Will be used for 049 * excluding provider classes from temporary class overriding. 050 * @since 2.5.2 051 */ 052 @Nullable 053 default String getPersistenceProviderRootPackage() { 054 return null; 055 } 056 057 /** 058 * Return a Map of vendor-specific JPA properties for the given persistence 059 * unit, typically based on settings in this JpaVendorAdapter instance. 060 * <p>Note that there might be further JPA properties defined on the 061 * EntityManagerFactory bean, which might potentially override individual 062 * JPA property values specified here. 063 * <p>This implementation delegates to {@link #getJpaPropertyMap()} for 064 * non-unit-dependent properties. Effectively, this PersistenceUnitInfo-based 065 * variant only needs to be implemented if there is an actual need to react 066 * to unit-specific characteristics such as the transaction type. 067 * <p><b>NOTE:</b> This variant will only be invoked in case of Java EE style 068 * container bootstrapping where a {@link PersistenceUnitInfo} is present 069 * (i.e. {@link LocalContainerEntityManagerFactoryBean}. In case of simple 070 * Java SE style bootstrapping via {@link javax.persistence.Persistence} 071 * (i.e. {@link LocalEntityManagerFactoryBean}), the parameter-less 072 * {@link #getJpaPropertyMap()} variant will be called directly. 073 * @param pui the PersistenceUnitInfo for the current persistence unit 074 * @return a Map of JPA properties, as accepted by the standard JPA bootstrap 075 * facilities, or an empty Map if there are no properties to expose 076 * @since 4.3.13 077 * @see PersistenceUnitInfo#getTransactionType() 078 * @see javax.persistence.spi.PersistenceProvider#createContainerEntityManagerFactory(PersistenceUnitInfo, Map) 079 */ 080 default Map<String, ?> getJpaPropertyMap(PersistenceUnitInfo pui) { 081 return getJpaPropertyMap(); 082 } 083 084 /** 085 * Return a Map of vendor-specific JPA properties, 086 * typically based on settings in this JpaVendorAdapter instance. 087 * <p>Note that there might be further JPA properties defined on the 088 * EntityManagerFactory bean, which might potentially override individual 089 * JPA property values specified here. 090 * @return a Map of JPA properties, as accepted by the standard JPA bootstrap 091 * facilities, or an empty Map if there are no properties to expose 092 * @see javax.persistence.Persistence#createEntityManagerFactory(String, Map) 093 */ 094 default Map<String, ?> getJpaPropertyMap() { 095 return Collections.emptyMap(); 096 } 097 098 /** 099 * Return the vendor-specific JpaDialect implementation for this 100 * provider, or {@code null} if there is none. 101 */ 102 @Nullable 103 default JpaDialect getJpaDialect() { 104 return null; 105 } 106 107 /** 108 * Return the vendor-specific EntityManagerFactory interface 109 * that the EntityManagerFactory proxy is supposed to implement. 110 * <p>If the provider does not offer any EntityManagerFactory extensions, 111 * the adapter should simply return the standard 112 * {@link javax.persistence.EntityManagerFactory} class here. 113 * @since 2.5.2 114 */ 115 default Class<? extends EntityManagerFactory> getEntityManagerFactoryInterface() { 116 return EntityManagerFactory.class; 117 } 118 119 /** 120 * Return the vendor-specific EntityManager interface 121 * that this provider's EntityManagers will implement. 122 * <p>If the provider does not offer any EntityManager extensions, 123 * the adapter should simply return the standard 124 * {@link javax.persistence.EntityManager} class here. 125 */ 126 default Class<? extends EntityManager> getEntityManagerInterface() { 127 return EntityManager.class; 128 } 129 130 /** 131 * Optional callback for post-processing the native EntityManagerFactory 132 * before active use. 133 * <p>This can be used for triggering vendor-specific initialization processes. 134 * While this is not expected to be used for most providers, it is included 135 * here as a general extension hook. 136 */ 137 default void postProcessEntityManagerFactory(EntityManagerFactory emf) { 138 } 139 140}