HHH-11944 Make the AbstractDelegatingSessionBuilder hierarchy generic

This commit is contained in:
Guillaume Smet 2017-08-25 18:11:22 +02:00
parent 3620e1e47e
commit 123ef45975
5 changed files with 156 additions and 78 deletions

View File

@ -40,7 +40,7 @@ import org.jboss.jandex.IndexView;
* to a specialization of {@link MetadataBuilderImplementor}
*/
@SuppressWarnings("unused")
public abstract class AbstractDelegatingMetadataBuilderImplementor<T extends AbstractDelegatingMetadataBuilderImplementor<T>> implements MetadataBuilderImplementor {
public abstract class AbstractDelegatingMetadataBuilderImplementor<T extends MetadataBuilderImplementor> implements MetadataBuilderImplementor {
private final MetadataBuilderImplementor delegate;

View File

@ -39,7 +39,7 @@ import org.hibernate.tuple.entity.EntityTuplizerFactory;
* @param <T> The type of a specific sub-class; Allows sub-classes to narrow down the return-type of the contract methods
* to a specialization of {@link SessionFactoryBuilder}
*/
public abstract class AbstractDelegatingSessionFactoryBuilder<T extends AbstractDelegatingSessionFactoryBuilder<T>> implements SessionFactoryBuilder {
public abstract class AbstractDelegatingSessionFactoryBuilder<T extends SessionFactoryBuilder> implements SessionFactoryBuilder {
private final SessionFactoryBuilder delegate;
public AbstractDelegatingSessionFactoryBuilder(SessionFactoryBuilder delegate) {

View File

@ -10,10 +10,12 @@ import java.sql.Connection;
import java.util.TimeZone;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.FlushMode;
import org.hibernate.Interceptor;
import org.hibernate.Session;
import org.hibernate.SessionBuilder;
import org.hibernate.SessionEventListener;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
/**
@ -21,8 +23,9 @@ import org.hibernate.resource.jdbc.spi.StatementInspector;
* while forwarding other method invocations to a delegate instance.
*
* @author Gunnar Morling
* @author Guillaume Smet
*/
public abstract class AbstractDelegatingSessionBuilder implements SessionBuilder {
public abstract class AbstractDelegatingSessionBuilder<T extends SessionBuilder> implements SessionBuilder<T> {
private final SessionBuilder delegate;
@ -30,86 +33,115 @@ public abstract class AbstractDelegatingSessionBuilder implements SessionBuilder
this.delegate = delegate;
}
@SuppressWarnings("unchecked")
protected T getThis() {
return (T) this;
}
protected SessionBuilder getDelegate() {
return delegate;
}
@Override
public Session openSession() {
return delegate.openSession();
}
@Override
public SessionBuilder interceptor(Interceptor interceptor) {
public T interceptor(Interceptor interceptor) {
delegate.interceptor( interceptor );
return this;
return getThis();
}
@Override
public SessionBuilder noInterceptor() {
public T noInterceptor() {
delegate.noInterceptor();
return this;
return getThis();
}
@Override
public SessionBuilder statementInspector(StatementInspector statementInspector) {
public T statementInspector(StatementInspector statementInspector) {
delegate.statementInspector( statementInspector );
return this;
return getThis();
}
@Override
public SessionBuilder connection(Connection connection) {
public T connection(Connection connection) {
delegate.connection( connection );
return this;
return getThis();
}
@SuppressWarnings("deprecation")
@Override
public SessionBuilder connectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
public T connectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
delegate.connectionReleaseMode( connectionReleaseMode );
return this;
return getThis();
}
@Override
public SessionBuilder autoJoinTransactions(boolean autoJoinTransactions) {
public T autoJoinTransactions(boolean autoJoinTransactions) {
delegate.autoJoinTransactions( autoJoinTransactions );
return this;
return getThis();
}
@Override
public SessionBuilder autoClose(boolean autoClose) {
public T autoClose(boolean autoClose) {
delegate.autoClose( autoClose );
return this;
return getThis();
}
@SuppressWarnings("deprecation")
@Override
public SessionBuilder flushBeforeCompletion(boolean flushBeforeCompletion) {
public T flushBeforeCompletion(boolean flushBeforeCompletion) {
delegate.flushBeforeCompletion( flushBeforeCompletion );
return this;
return getThis();
}
@Override
public SessionBuilder tenantIdentifier(String tenantIdentifier) {
public T tenantIdentifier(String tenantIdentifier) {
delegate.tenantIdentifier( tenantIdentifier );
return this;
return getThis();
}
@Override
public SessionBuilder eventListeners(SessionEventListener... listeners) {
public T eventListeners(SessionEventListener... listeners) {
delegate.eventListeners( listeners );
return this;
return getThis();
}
@Override
public SessionBuilder clearEventListeners() {
public T clearEventListeners() {
delegate.clearEventListeners();
return this;
return getThis();
}
@Override
public SessionBuilder jdbcTimeZone(TimeZone timeZone) {
public T jdbcTimeZone(TimeZone timeZone) {
delegate.jdbcTimeZone(timeZone);
return this;
return getThis();
}
@Override
public SessionBuilder setQueryParameterValidation(boolean enabled) {
public T setQueryParameterValidation(boolean enabled) {
delegate.setQueryParameterValidation( enabled );
return this;
return getThis();
}
@Override
public T connectionHandlingMode(PhysicalConnectionHandlingMode mode) {
delegate.connectionHandlingMode( mode );
return getThis();
}
@Override
public T autoClear(boolean autoClear) {
delegate.autoClear( autoClear );
return getThis();
}
@Override
public T flushMode(FlushMode flushMode) {
delegate.flushMode( flushMode );
return getThis();
}
}

View File

@ -6,29 +6,28 @@
*/
package org.hibernate.engine.spi;
import org.hibernate.SessionBuilder;
/**
* Base class for {@link SessionBuilderImplementor} implementations that wish to implement only parts of that contract
* themselves while forwarding other method invocations to a delegate instance.
*
* @author Gunnar Morling
*/
@SuppressWarnings("unused")
public abstract class AbstractDelegatingSessionBuilderImplementor
extends AbstractDelegatingSessionBuilder
implements SessionBuilderImplementor {
private final SessionBuilderImplementor delegate;
public abstract class AbstractDelegatingSessionBuilderImplementor<T extends SessionBuilderImplementor>
extends AbstractDelegatingSessionBuilder<T>
implements SessionBuilderImplementor<T> {
public AbstractDelegatingSessionBuilderImplementor(SessionBuilderImplementor delegate) {
super( delegate );
this.delegate = delegate;
}
protected SessionBuilderImplementor getDelegate() {
return (SessionBuilderImplementor) super.getDelegate();
}
@SuppressWarnings({ "unchecked", "deprecation" })
@Override
public SessionBuilder owner(SessionOwner sessionOwner) {
delegate.owner( sessionOwner );
return this;
public T owner(SessionOwner sessionOwner) {
getDelegate().owner( sessionOwner );
return (T) this;
}
}

View File

@ -7,13 +7,16 @@
package org.hibernate.engine.spi;
import java.sql.Connection;
import java.util.TimeZone;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.FlushMode;
import org.hibernate.Interceptor;
import org.hibernate.Session;
import org.hibernate.SessionBuilder;
import org.hibernate.SessionEventListener;
import org.hibernate.SharedSessionBuilder;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
/**
@ -21,9 +24,10 @@ import org.hibernate.resource.jdbc.spi.StatementInspector;
* themselves while forwarding other method invocations to a delegate instance.
*
* @author Gunnar Morling
* @author Guillaume Smet
*/
@SuppressWarnings("unused")
public abstract class AbstractDelegatingSharedSessionBuilder implements SharedSessionBuilder {
public abstract class AbstractDelegatingSharedSessionBuilder<T extends SharedSessionBuilder> implements SharedSessionBuilder<T> {
private final SharedSessionBuilder delegate;
@ -31,116 +35,159 @@ public abstract class AbstractDelegatingSharedSessionBuilder implements SharedSe
this.delegate = delegate;
}
@SuppressWarnings("unchecked")
protected T getThis() {
return (T) this;
}
public SharedSessionBuilder getDelegate() {
return delegate;
}
@Override
public Session openSession() {
return delegate.openSession();
}
@Override
public SharedSessionBuilder interceptor() {
public T interceptor() {
delegate.interceptor();
return this;
return getThis();
}
@Override
public SharedSessionBuilder connection() {
public T connection() {
delegate.connection();
return this;
return getThis();
}
@SuppressWarnings("deprecation")
@Override
public SharedSessionBuilder connectionReleaseMode() {
public T connectionReleaseMode() {
delegate.connectionReleaseMode();
return this;
return getThis();
}
@Override
public SharedSessionBuilder connectionHandlingMode() {
public T connectionHandlingMode() {
delegate.connectionHandlingMode();
return this;
return getThis();
}
@Override
public SharedSessionBuilder autoJoinTransactions() {
public T autoJoinTransactions() {
delegate.autoJoinTransactions();
return this;
return getThis();
}
@Override
public SharedSessionBuilder autoClose() {
public T autoClose() {
delegate.autoClose();
return this;
return getThis();
}
@SuppressWarnings("deprecation")
@Override
public SharedSessionBuilder flushBeforeCompletion() {
public T flushBeforeCompletion() {
delegate.flushBeforeCompletion();
return this;
return getThis();
}
@Override
public SharedSessionBuilder interceptor(Interceptor interceptor) {
public T interceptor(Interceptor interceptor) {
delegate.interceptor( interceptor );
return this;
return getThis();
}
@Override
public SharedSessionBuilder noInterceptor() {
public T noInterceptor() {
delegate.noInterceptor();
return this;
return getThis();
}
@Override
public SessionBuilder statementInspector(StatementInspector statementInspector) {
public T statementInspector(StatementInspector statementInspector) {
delegate.statementInspector( statementInspector );
return this;
return getThis();
}
@Override
public SharedSessionBuilder connection(Connection connection) {
public T connection(Connection connection) {
delegate.connection( connection );
return this;
return getThis();
}
@SuppressWarnings("deprecation")
@Override
public SharedSessionBuilder connectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
public T connectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
delegate.connectionReleaseMode( connectionReleaseMode );
return this;
return getThis();
}
@Override
public SharedSessionBuilder autoJoinTransactions(boolean autoJoinTransactions) {
public T autoJoinTransactions(boolean autoJoinTransactions) {
delegate.autoJoinTransactions( autoJoinTransactions );
return this;
return getThis();
}
@Override
public SharedSessionBuilder autoClose(boolean autoClose) {
public T autoClose(boolean autoClose) {
delegate.autoClose( autoClose );
return this;
return getThis();
}
@SuppressWarnings("deprecation")
@Override
public SharedSessionBuilder flushBeforeCompletion(boolean flushBeforeCompletion) {
public T flushBeforeCompletion(boolean flushBeforeCompletion) {
delegate.flushBeforeCompletion( flushBeforeCompletion );
return this;
return getThis();
}
@Override
public SessionBuilder tenantIdentifier(String tenantIdentifier) {
public T tenantIdentifier(String tenantIdentifier) {
delegate.tenantIdentifier( tenantIdentifier );
return this;
return getThis();
}
@Override
public SessionBuilder eventListeners(SessionEventListener... listeners) {
public T eventListeners(SessionEventListener... listeners) {
delegate.eventListeners( listeners );
return this;
return getThis();
}
@Override
public SessionBuilder clearEventListeners() {
public T clearEventListeners() {
delegate.clearEventListeners();
return this;
return getThis();
}
@Override
public T connectionHandlingMode(PhysicalConnectionHandlingMode mode) {
delegate.connectionHandlingMode( mode );
return getThis();
}
@Override
public T autoClear(boolean autoClear) {
delegate.autoClear( autoClear );
return getThis();
}
@Override
public T flushMode(FlushMode flushMode) {
delegate.flushMode( flushMode );
return getThis();
}
@Override
public T flushMode() {
delegate.flushMode();
return getThis();
}
@Override
public T jdbcTimeZone(TimeZone timeZone) {
delegate.jdbcTimeZone( timeZone );
return getThis();
}
}