Skip to content

Commit 052aad0

Browse files
committed
HHH-10313 - Make SessionImplementor extend WrapperOptions
1 parent 59a5a88 commit 052aad0

File tree

5 files changed

+106
-25
lines changed

5 files changed

+106
-25
lines changed

hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@
3939
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
4040
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
4141
import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification;
42+
import org.hibernate.internal.WrapperOptionsImpl;
4243
import org.hibernate.jdbc.ReturningWork;
4344
import org.hibernate.jdbc.Work;
4445
import org.hibernate.loader.custom.CustomQuery;
4546
import org.hibernate.persister.entity.EntityPersister;
4647
import org.hibernate.procedure.ProcedureCall;
4748
import org.hibernate.resource.transaction.TransactionCoordinator;
4849
import org.hibernate.stat.SessionStatistics;
50+
import org.hibernate.type.descriptor.WrapperOptions;
51+
import org.hibernate.type.descriptor.WrapperOptionsContext;
4952

5053
/**
5154
* This class is meant to be extended.
@@ -57,7 +60,7 @@
5760
*
5861
* @author Sanne Grinovero <[email protected]> (C) 2012 Red Hat Inc.
5962
*/
60-
public class SessionDelegatorBaseImpl implements SessionImplementor, Session {
63+
public class SessionDelegatorBaseImpl implements SessionImplementor, Session, WrapperOptionsContext {
6164

6265
protected final SessionImplementor sessionImplementor;
6366
protected final Session session;
@@ -766,4 +769,17 @@ public LobHelper getLobHelper() {
766769
public void addEventListeners(SessionEventListener... listeners) {
767770
session.addEventListeners( listeners );
768771
}
772+
773+
@Override
774+
public WrapperOptions getWrapperOptions() {
775+
if ( sessionImplementor instanceof WrapperOptionsContext ) {
776+
return ( (WrapperOptionsContext) sessionImplementor ).getWrapperOptions();
777+
}
778+
else if ( session instanceof WrapperOptionsContext ) {
779+
return ( (WrapperOptionsContext) session ).getWrapperOptions();
780+
}
781+
else {
782+
return new WrapperOptionsImpl( sessionImplementor );
783+
}
784+
}
769785
}

hibernate-core/src/main/java/org/hibernate/internal/AbstractSessionImpl.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,23 @@
5757
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder.TransactionCoordinatorOptions;
5858
import org.hibernate.resource.transaction.spi.TransactionStatus;
5959
import org.hibernate.service.ServiceRegistry;
60+
import org.hibernate.type.descriptor.WrapperOptions;
61+
import org.hibernate.type.descriptor.WrapperOptionsContext;
6062

6163
/**
6264
* Functionality common to stateless and stateful sessions
6365
*
6466
* @author Gavin King
6567
*/
6668
public abstract class AbstractSessionImpl
67-
implements Serializable, SharedSessionContract, SessionImplementor, JdbcSessionOwner, TransactionCoordinatorOptions {
69+
implements Serializable, SharedSessionContract, SessionImplementor, JdbcSessionOwner, TransactionCoordinatorOptions, WrapperOptionsContext {
70+
6871
protected transient SessionFactoryImpl factory;
6972
private final String tenantIdentifier;
7073
private boolean closed;
7174

7275
protected transient Transaction currentHibernateTransaction;
76+
protected transient WrapperOptionsImpl wrapperOptions;
7377

7478
protected AbstractSessionImpl(SessionFactoryImpl factory, String tenantIdentifier) {
7579
this.factory = factory;
@@ -589,4 +593,12 @@ public TransactionCoordinatorBuilder getTransactionCoordinatorBuilder() {
589593
return factory.getServiceRegistry().getService( TransactionCoordinatorBuilder.class );
590594
}
591595

596+
@Override
597+
public WrapperOptions getWrapperOptions() {
598+
if ( wrapperOptions == null ) {
599+
wrapperOptions = new WrapperOptionsImpl( this );
600+
}
601+
602+
return wrapperOptions;
603+
}
592604
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.internal;
8+
9+
import org.hibernate.Hibernate;
10+
import org.hibernate.cfg.Environment;
11+
import org.hibernate.engine.jdbc.LobCreator;
12+
import org.hibernate.engine.spi.SessionImplementor;
13+
import org.hibernate.type.descriptor.WrapperOptions;
14+
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
15+
16+
/**
17+
* @author Steve Ebersole
18+
*/
19+
public class WrapperOptionsImpl implements WrapperOptions {
20+
private final SessionImplementor session;
21+
22+
private final boolean useStreamForLobBinding;
23+
24+
public WrapperOptionsImpl(SessionImplementor session) {
25+
this.session = session;
26+
27+
this.useStreamForLobBinding = Environment.useStreamsForBinary()
28+
|| session.getFactory().getDialect().useInputStreamToInsertBlob();
29+
}
30+
31+
@Override
32+
public boolean useStreamForLobBinding() {
33+
return useStreamForLobBinding;
34+
}
35+
36+
@Override
37+
public LobCreator getLobCreator() {
38+
return Hibernate.getLobCreator( session );
39+
}
40+
41+
@Override
42+
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
43+
final SqlTypeDescriptor remapped = sqlTypeDescriptor.canBeRemapped()
44+
? session.getFactory().getDialect().remapSqlTypeDescriptor( sqlTypeDescriptor )
45+
: sqlTypeDescriptor;
46+
return remapped == null ? sqlTypeDescriptor : remapped;
47+
}
48+
}

hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,20 @@
1313
import java.sql.SQLException;
1414
import java.util.Map;
1515

16-
import org.hibernate.Hibernate;
1716
import org.hibernate.HibernateException;
1817
import org.hibernate.MappingException;
19-
import org.hibernate.cfg.Environment;
20-
import org.hibernate.engine.jdbc.LobCreator;
2118
import org.hibernate.engine.jdbc.Size;
2219
import org.hibernate.engine.spi.Mapping;
2320
import org.hibernate.engine.spi.SessionFactoryImplementor;
2421
import org.hibernate.engine.spi.SessionImplementor;
22+
import org.hibernate.internal.WrapperOptionsImpl;
2523
import org.hibernate.internal.util.collections.ArrayHelper;
2624
import org.hibernate.type.descriptor.WrapperOptions;
25+
import org.hibernate.type.descriptor.WrapperOptionsContext;
2726
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
2827
import org.hibernate.type.descriptor.java.MutabilityPlan;
2928
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
3029

31-
import org.dom4j.Node;
32-
3330
/**
3431
* Convenience base class for {@link BasicType} implementations
3532
*
@@ -354,24 +351,11 @@ public T extract(CallableStatement statement, String[] paramNames, final Session
354351
return remapSqlTypeDescriptor( options ).getExtractor( javaTypeDescriptor ).extract( statement, paramNames, options );
355352
}
356353

357-
// TODO : have SessionImplementor extend WrapperOptions
358354
private WrapperOptions getOptions(final SessionImplementor session) {
359-
return new WrapperOptions() {
360-
public boolean useStreamForLobBinding() {
361-
return Environment.useStreamsForBinary()
362-
|| session.getFactory().getDialect().useInputStreamToInsertBlob();
363-
}
364-
365-
public LobCreator getLobCreator() {
366-
return Hibernate.getLobCreator( session );
367-
}
368-
369-
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
370-
final SqlTypeDescriptor remapped = sqlTypeDescriptor.canBeRemapped()
371-
? session.getFactory().getDialect().remapSqlTypeDescriptor( sqlTypeDescriptor )
372-
: sqlTypeDescriptor;
373-
return remapped == null ? sqlTypeDescriptor : remapped;
374-
}
375-
};
355+
if ( session instanceof WrapperOptionsContext ) {
356+
return ( (WrapperOptionsContext) session ).getWrapperOptions();
357+
}
358+
359+
return new WrapperOptionsImpl( session );
376360
}
377361
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.type.descriptor;
8+
9+
/**
10+
* Defines the context for {@link WrapperOptions}
11+
*
12+
* @author Steve Ebersole
13+
*/
14+
public interface WrapperOptionsContext {
15+
/**
16+
* Obtain the WrapperOptions for this context.
17+
*
18+
* @return The WrapperOptions
19+
*/
20+
WrapperOptions getWrapperOptions();
21+
}

0 commit comments

Comments
 (0)