Fix overridden methods nullability

Issue: SPR-15869
This commit is contained in:
Sebastien Deleuze
2017-08-17 14:30:14 +02:00
parent 6b6c1d3e53
commit 73cf07e9a4
488 changed files with 1016 additions and 34 deletions

View File

@@ -22,6 +22,7 @@ import org.hibernate.HibernateException;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.EntityManagerFactoryUtils;
/**
@@ -44,6 +45,7 @@ import org.springframework.orm.jpa.EntityManagerFactoryUtils;
public class HibernateExceptionTranslator implements PersistenceExceptionTranslator {
@Override
@Nullable
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
if (ex instanceof HibernateException) {
return convertHibernateAccessException((HibernateException) ex);

View File

@@ -328,6 +328,7 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
@Override
@Nullable
public <T> T execute(HibernateCallback<T> action) throws DataAccessException {
return doExecute(action, false);
}
@@ -453,11 +454,13 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
//-------------------------------------------------------------------------
@Override
@Nullable
public <T> T get(Class<T> entityClass, Serializable id) throws DataAccessException {
return get(entityClass, id, null);
}
@Override
@Nullable
public <T> T get(final Class<T> entityClass, final Serializable id, @Nullable final LockMode lockMode)
throws DataAccessException {
@@ -472,11 +475,13 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
}
@Override
@Nullable
public Object get(String entityName, Serializable id) throws DataAccessException {
return get(entityName, id, null);
}
@Override
@Nullable
public Object get(final String entityName, final Serializable id, @Nullable final LockMode lockMode)
throws DataAccessException {

View File

@@ -549,6 +549,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator
@Override
@Nullable
public SessionFactory getObject() {
return this.sessionFactory;
}

View File

@@ -495,6 +495,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
* @see EntityManagerFactoryUtils#convertJpaAccessExceptionIfPossible
*/
@Override
@Nullable
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
return (this.jpaDialect != null ? this.jpaDialect.translateExceptionIfPossible(ex) :
EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex));
@@ -522,11 +523,13 @@ public abstract class AbstractEntityManagerFactoryBean implements
}
@Override
@Nullable
public PersistenceUnitInfo getPersistenceUnitInfo() {
return null;
}
@Override
@Nullable
public DataSource getDataSource() {
return null;
}
@@ -536,6 +539,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
* Return the singleton EntityManagerFactory.
*/
@Override
@Nullable
public EntityManagerFactory getObject() {
return this.entityManagerFactory;
}

View File

@@ -57,6 +57,7 @@ public class DefaultJpaDialect implements JpaDialect, Serializable {
* @see #cleanupTransaction
*/
@Override
@Nullable
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
throws PersistenceException, SQLException, TransactionException {
@@ -70,6 +71,7 @@ public class DefaultJpaDialect implements JpaDialect, Serializable {
}
@Override
@Nullable
public Object prepareTransaction(EntityManager entityManager, boolean readOnly, @Nullable String name)
throws PersistenceException {
@@ -90,6 +92,7 @@ public class DefaultJpaDialect implements JpaDialect, Serializable {
* indicating that no JDBC Connection can be provided.
*/
@Override
@Nullable
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
throws PersistenceException, SQLException {
@@ -119,6 +122,7 @@ public class DefaultJpaDialect implements JpaDialect, Serializable {
* @see EntityManagerFactoryUtils#convertJpaAccessExceptionIfPossible
*/
@Override
@Nullable
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
return EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex);
}

View File

@@ -400,6 +400,7 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
}
@Override
@Nullable
public String getPersistenceUnitName() {
if (this.persistenceUnitInfo != null) {
return this.persistenceUnitInfo.getPersistenceUnitName();

View File

@@ -109,6 +109,7 @@ public class SharedEntityManagerBean extends EntityManagerFactoryAccessor
@Override
@Nullable
public EntityManager getObject() {
return this.shared;
}

View File

@@ -118,16 +118,19 @@ public abstract class AbstractJpaVendorAdapter implements JpaVendorAdapter {
@Override
@Nullable
public String getPersistenceProviderRootPackage() {
return null;
}
@Override
@Nullable
public Map<String, ?> getJpaPropertyMap() {
return null;
}
@Override
@Nullable
public JpaDialect getJpaDialect() {
return null;
}

View File

@@ -72,6 +72,7 @@ public class EclipseLinkJpaDialect extends DefaultJpaDialect {
@Override
@Nullable
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
throws PersistenceException, SQLException, TransactionException {

View File

@@ -216,6 +216,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect {
}
@Override
@Nullable
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
if (ex instanceof HibernateException) {
return convertHibernateAccessException((HibernateException) ex);

View File

@@ -22,6 +22,7 @@ import javax.persistence.EntityManagerFactory;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.EntityManagerFactoryAccessor;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
@@ -41,6 +42,7 @@ import org.springframework.util.ReflectionUtils;
public class HibernateJpaSessionFactoryBean extends EntityManagerFactoryAccessor implements FactoryBean<SessionFactory> {
@Override
@Nullable
public SessionFactory getObject() {
EntityManagerFactory emf = getEntityManagerFactory();
Assert.state(emf != null, "EntityManagerFactory must not be null");