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