remove unwrap() methods that aren't to do with proxying
it's better to do this stuff in a more typesafe way
This commit is contained in:
parent
2e2a544584
commit
cd7417e815
|
@ -402,24 +402,6 @@ public interface MetadataBuilder {
|
|||
|
||||
MetadataBuilder applyIdGenerationTypeInterpreter(IdGeneratorStrategyInterpreter interpreter);
|
||||
|
||||
|
||||
// /**
|
||||
// * Specify the resolve to be used in identifying the backing members of a
|
||||
// * persistent attributes.
|
||||
// *
|
||||
// * @param resolver The resolver to use
|
||||
// *
|
||||
// * @return {@code this}, for method chaining
|
||||
// */
|
||||
// public MetadataBuilder with(PersistentAttributeMemberResolver resolver);
|
||||
|
||||
/**
|
||||
* Allows unwrapping this builder as another, more specific type.
|
||||
*
|
||||
* @return The unwrapped builder.
|
||||
*/
|
||||
<T extends MetadataBuilder> T unwrap(Class<T> type);
|
||||
|
||||
/**
|
||||
* Actually build the metamodel
|
||||
*
|
||||
|
|
|
@ -697,13 +697,6 @@ public interface SessionFactoryBuilder {
|
|||
*/
|
||||
SessionFactoryBuilder enableJpaClosedCompliance(boolean enabled);
|
||||
|
||||
/**
|
||||
* Allows unwrapping this builder as another, more specific type.
|
||||
*
|
||||
* @return The unwrapped builder.
|
||||
*/
|
||||
<T extends SessionFactoryBuilder> T unwrap(Class<T> type);
|
||||
|
||||
/**
|
||||
* After all options have been set, build the SessionFactory.
|
||||
*
|
||||
|
|
|
@ -407,12 +407,6 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends MetadataBuilder> T unwrap(Class<T> type) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataImplementor build() {
|
||||
final CfgXmlAccessService cfgXmlAccessService = options.serviceRegistry.getService( CfgXmlAccessService.class );
|
||||
|
|
|
@ -407,12 +407,6 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
|
|||
this.optionsBuilder.disableJtaTransactionAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends SessionFactoryBuilder> T unwrap(Class<T> type) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionFactory build() {
|
||||
final StandardServiceRegistry serviceRegistry = metadata.getMetadataBuildingOptions().getServiceRegistry();
|
||||
|
|
|
@ -238,11 +238,6 @@ public abstract class AbstractDelegatingMetadataBuilderImplementor<T extends Met
|
|||
return getThis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <M extends MetadataBuilder> M unwrap(Class<M> type) {
|
||||
return delegate.unwrap( type );
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuildingOptions getMetadataBuildingOptions() {
|
||||
return delegate.getMetadataBuildingOptions();
|
||||
|
|
|
@ -371,12 +371,6 @@ public abstract class AbstractDelegatingSessionFactoryBuilder<T extends SessionF
|
|||
return getThis();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <S extends SessionFactoryBuilder> S unwrap(Class<S> type) {
|
||||
return (S) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T applyStatelessInterceptor(Supplier<? extends Interceptor> statelessInterceptorSupplier) {
|
||||
delegate.applyStatelessInterceptor(statelessInterceptorSupplier);
|
||||
|
|
|
@ -207,7 +207,7 @@ public enum Database {
|
|||
POSTGRESQL {
|
||||
@Override
|
||||
public Dialect createDialect(DialectResolutionInfo info) {
|
||||
final String version = getVersion( info.unwrap( DatabaseMetaData.class ) );
|
||||
final String version = getVersion( info.getDatabaseMetadata() );
|
||||
if ( version.startsWith( "Cockroach" ) ) {
|
||||
return new CockroachDialect( info );
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ public class MySQLDialect extends Dialect {
|
|||
// we need to remember the character set before calling getMaxVarcharLength()
|
||||
// we could not do this earlier because we get called from the constructor
|
||||
// of the superclass, before our own constructor has run
|
||||
int bytesPerCharacter = getCharacterSetBytesPerCharacter( info.unwrap(DatabaseMetaData.class) );
|
||||
int bytesPerCharacter = getCharacterSetBytesPerCharacter( info.getDatabaseMetadata() );
|
||||
maxVarcharLength = maxVarcharLength( getMySQLVersion(), bytesPerCharacter );
|
||||
maxVarbinaryLength = maxVarbinaryLength( getMySQLVersion() );
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public class SybaseASEDialect extends SybaseDialect {
|
|||
|
||||
public SybaseASEDialect(DialectResolutionInfo info) {
|
||||
super(info);
|
||||
ansiNull = isAnsiNull( info.unwrap( DatabaseMetaData.class ) );
|
||||
ansiNull = isAnsiNull( info.getDatabaseMetadata() );
|
||||
registerSybaseKeywords();
|
||||
}
|
||||
|
||||
|
|
|
@ -99,10 +99,7 @@ public class DatabaseMetaDataDialectResolutionInfoAdapter implements DialectReso
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> clazz) {
|
||||
if ( clazz.isInstance( databaseMetaData ) ) {
|
||||
return clazz.cast( databaseMetaData );
|
||||
}
|
||||
return null;
|
||||
public DatabaseMetaData getDatabaseMetadata() {
|
||||
return databaseMetaData;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ package org.hibernate.engine.jdbc.dialect.spi;
|
|||
|
||||
import org.hibernate.dialect.DatabaseVersion;
|
||||
|
||||
import java.sql.DatabaseMetaData;
|
||||
|
||||
/**
|
||||
* Exposes information about the database and JDBC driver that can be used in resolving the appropriate Dialect
|
||||
* to use.
|
||||
|
@ -78,13 +80,11 @@ public interface DialectResolutionInfo extends DatabaseVersion {
|
|||
String getSQLKeywords();
|
||||
|
||||
/**
|
||||
* Obtain access to the underlying object of the given type.
|
||||
* Obtain access to the {@link DatabaseMetaData} if it is available.
|
||||
*
|
||||
* Return <code>null</code> if the underlying object is not of the given type.
|
||||
*
|
||||
* @return The unwrapped object or <code>null</code>
|
||||
* @return The {@link DatabaseMetaData} or <code>null</code> if not available
|
||||
*/
|
||||
default <T> T unwrap(Class<T> clazz) {
|
||||
default DatabaseMetaData getDatabaseMetadata() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -269,7 +269,7 @@ public class EmbeddedAttributeMapping
|
|||
)
|
||||
);
|
||||
|
||||
columnReferences.add( columnReference.unwrap( ColumnReference.class ) );
|
||||
columnReferences.add( columnReference.getColumnReference() );
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -302,13 +302,7 @@ public class EmbeddedAttributeMapping
|
|||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
}
|
||||
else {
|
||||
joinType = requestedJoinType;
|
||||
}
|
||||
final SqlAstJoinType joinType = requestedJoinType == null ? SqlAstJoinType.INNER : requestedJoinType;
|
||||
final TableGroup tableGroup = createRootTableGroupJoin(
|
||||
navigablePath,
|
||||
lhs,
|
||||
|
|
|
@ -159,6 +159,11 @@ public class ColumnReference implements Expression, Assignable {
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColumnReference getColumnReference() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getQualifier() {
|
||||
return qualifier;
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ public interface Expression extends SqlAstNode, SqlSelectionProducer {
|
|||
*/
|
||||
JdbcMappingContainer getExpressionType();
|
||||
|
||||
default <T> T unwrap(Class<T> target) {
|
||||
return (T) this;
|
||||
default ColumnReference getColumnReference() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,25 +30,8 @@ public class SqlSelectionExpression implements Expression {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T unwrap(Class<T> target) {
|
||||
if ( target.isInstance( this ) ) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
if ( target.isInstance( theSelection ) ) {
|
||||
return (T) theSelection;
|
||||
}
|
||||
|
||||
if ( target.isInstance( theSelection.getExpression() ) ) {
|
||||
return (T) theSelection.getExpression();
|
||||
}
|
||||
|
||||
if ( target.isInstance( theSelection.getExpressionType() ) ) {
|
||||
return (T) theSelection.getExpressionType();
|
||||
}
|
||||
|
||||
return theSelection.getExpression().unwrap( target );
|
||||
public ColumnReference getColumnReference() {
|
||||
return theSelection.getExpression().getColumnReference();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.hibernate.metamodel.mapping.ModelPartContainer;
|
|||
import org.hibernate.query.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstWalker;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
import org.hibernate.sql.results.graph.DomainResult;
|
||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||
|
@ -38,8 +39,8 @@ public abstract class DelegatingTableGroup implements TableGroup {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> target) {
|
||||
return getTableGroup().unwrap( target );
|
||||
public ColumnReference getColumnReference() {
|
||||
return getTableGroup().getColumnReference();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -71,9 +71,10 @@ public class PostgreSQLMultipleTypesOtherContributorTest extends BaseEntityManag
|
|||
options.put(
|
||||
EntityManagerFactoryBuilderImpl.METADATA_BUILDER_CONTRIBUTOR,
|
||||
(MetadataBuilderContributor) metadataBuilder -> {
|
||||
final TypeConfiguration typeConfiguration = metadataBuilder.unwrap( MetadataBuilderImplementor.class )
|
||||
.getBootstrapContext()
|
||||
.getTypeConfiguration();
|
||||
final TypeConfiguration typeConfiguration =
|
||||
( (MetadataBuilderImplementor) metadataBuilder )
|
||||
.getBootstrapContext()
|
||||
.getTypeConfiguration();
|
||||
typeConfiguration.getJavaTypeRegistry().addDescriptor( InetJavaType.INSTANCE );
|
||||
typeConfiguration.getJdbcTypeRegistry().addDescriptor( InetJdbcType.INSTANCE );
|
||||
metadataBuilder.applyBasicType(
|
||||
|
|
|
@ -53,9 +53,10 @@ public class PostgreSQLInetTypesOtherContributorTest extends PostgreSQLInetTypes
|
|||
|
||||
@Override
|
||||
public void contribute(MetadataBuilder metadataBuilder) {
|
||||
final TypeConfiguration typeConfiguration = metadataBuilder.unwrap( MetadataBuilderImplementor.class )
|
||||
.getBootstrapContext()
|
||||
.getTypeConfiguration();
|
||||
final TypeConfiguration typeConfiguration =
|
||||
( (MetadataBuilderImplementor) metadataBuilder )
|
||||
.getBootstrapContext()
|
||||
.getTypeConfiguration();
|
||||
typeConfiguration.getJavaTypeRegistry().addDescriptor( InetJavaType.INSTANCE );
|
||||
typeConfiguration.getJdbcTypeRegistry().addDescriptor( InetJdbcType.INSTANCE );
|
||||
metadataBuilder.applyBasicType(
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.junit.Test;
|
|||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
|
@ -42,9 +41,10 @@ public class PostgreSQLInetTypesOtherTest extends BaseEntityManagerFunctionalTes
|
|||
options.put(
|
||||
EntityManagerFactoryBuilderImpl.METADATA_BUILDER_CONTRIBUTOR,
|
||||
(MetadataBuilderContributor) metadataBuilder -> {
|
||||
final TypeConfiguration typeConfiguration = metadataBuilder.unwrap( MetadataBuilderImplementor.class )
|
||||
.getBootstrapContext()
|
||||
.getTypeConfiguration();
|
||||
final TypeConfiguration typeConfiguration =
|
||||
( (MetadataBuilderImplementor) metadataBuilder )
|
||||
.getBootstrapContext()
|
||||
.getTypeConfiguration();
|
||||
typeConfiguration.getJavaTypeRegistry().addDescriptor( InetJavaType.INSTANCE );
|
||||
typeConfiguration.getJdbcTypeRegistry().addDescriptor( InetJdbcType.INSTANCE );
|
||||
metadataBuilder.applyBasicType(
|
||||
|
|
Loading…
Reference in New Issue