📄 defaultjpadialect.java
字号:
/*
* Copyright 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.orm.jpa;
import java.sql.SQLException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.datasource.ConnectionHandle;
import org.springframework.transaction.InvalidIsolationLevelException;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
/**
* Default implementation of the JpaDialect interface.
* Used as default dialect by JpaAccessor and JpaTransactionManager.
*
* <p>Simply begins a standard JPA transaction in <code>beginTransaction</code>
* and performs standard exception translation through EntityManagerFactoryUtils.
*
* @author Juergen Hoeller
* @since 2.0
* @see JpaAccessor#setJpaDialect
* @see JpaTransactionManager#setJpaDialect
*/
public class DefaultJpaDialect implements JpaDialect {
//-------------------------------------------------------------------------
// Hooks for transaction management (used by JpaTransactionManager)
//-------------------------------------------------------------------------
/**
* This implementation invokes the standard JPA <code>Transaction.begin</code>
* method. Throws an InvalidIsolationLevelException if a non-default isolation
* level is set.
* <p>This implementation does not return any transaction data Object, since there
* is no state to be kept for a standard JPA transaction. Hence, subclasses do not
* have to care about the return value (<code>null</code>) of this implementation
* and are free to return their own transaction data Object.
* @see javax.persistence.EntityTransaction#begin
* @see org.springframework.transaction.InvalidIsolationLevelException
* @see #cleanupTransaction
*/
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
throws PersistenceException, SQLException, TransactionException {
if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
throw new InvalidIsolationLevelException(
"Standard JPA does not support custom isolation levels - " +
"use a special JpaDialect for your JPA implementation");
}
entityManager.getTransaction().begin();
return null;
}
/**
* This implementation does nothing, since the default <code>beginTransaction</code>
* implementation does not require any cleanup.
* @see #beginTransaction
*/
public void cleanupTransaction(Object transactionData) {
}
/**
* This implementation always returns <code>null</code>,
* indicating that no JDBC Connection can be provided.
*/
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
throws PersistenceException, SQLException {
return null;
}
/**
* This implementation does nothing, assuming that the Connection
* will implicitly be closed with the EntityManager.
* <p>If the JPA implementation returns a Connection handle that it expects
* the application to close after use, the dialect implementation needs to invoke
* <code>Connection.close()</code> (or some other method with similar effect) here.
* @see java.sql.Connection#close()
*/
public void releaseJdbcConnection(ConnectionHandle conHandle, EntityManager em)
throws PersistenceException, SQLException {
}
//-----------------------------------------------------------------------------------
// Hook for exception translation (used by JpaTransactionManager and JpaTemplate)
//-----------------------------------------------------------------------------------
/**
* This implementation delegates to EntityManagerFactoryUtils.
* @see EntityManagerFactoryUtils#convertJpaAccessExceptionIfPossible
*/
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
return EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex);
}
public boolean supportsEntityManagerFactoryPlusOperations() {
return false;
}
public boolean supportsEntityManagerPlusOperations() {
return false;
}
public EntityManagerFactoryPlusOperations getEntityManagerFactoryPlusOperations(EntityManagerFactory rawEntityManager) {
throw new UnsupportedOperationException(getClass().getName() + " does not support EntityManagerFactoryPlusOperations");
}
public EntityManagerPlusOperations getEntityManagerPlusOperations(EntityManager rawEntityManager) {
throw new UnsupportedOperationException(getClass().getName() + " does not support EntityManagerPlusOperations");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -