pluggable SQL AST translators
This commit is contained in:
parent
35860baad6
commit
4149350222
|
@ -61,7 +61,7 @@ import org.hibernate.query.criteria.LiteralHandlingMode;
|
|||
import org.hibernate.query.hql.HqlTranslator;
|
||||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
||||
import org.hibernate.query.sqm.produce.function.SqmFunctionRegistry;
|
||||
import org.hibernate.query.sqm.sql.SqmToSqlAstConverterFactory;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
|
||||
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
|
||||
import org.hibernate.resource.jdbc.spi.StatementInspector;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
|
||||
|
@ -214,7 +214,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
private HqlTranslator hqlTranslator;
|
||||
private SqmMultiTableMutationStrategy sqmMultiTableMutationStrategy;
|
||||
private SqmFunctionRegistry sqmFunctionRegistry;
|
||||
private SqmToSqlAstConverterFactory sqmTranslatorFactory;
|
||||
private SqmTranslatorFactory sqmTranslatorFactory;
|
||||
private Boolean useOfJdbcNamedParametersEnabled;
|
||||
private Map querySubstitutions;
|
||||
private boolean namedQueryStartupCheckingEnabled;
|
||||
|
@ -622,7 +622,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
);
|
||||
}
|
||||
|
||||
private SqmToSqlAstConverterFactory resolveSqmTranslator(
|
||||
private SqmTranslatorFactory resolveSqmTranslator(
|
||||
String translatorImplFqn,
|
||||
StandardServiceRegistry serviceRegistry,
|
||||
StrategySelector strategySelector) {
|
||||
|
@ -631,7 +631,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
}
|
||||
|
||||
return strategySelector.resolveStrategy(
|
||||
SqmToSqlAstConverterFactory.class,
|
||||
SqmTranslatorFactory.class,
|
||||
translatorImplFqn
|
||||
);
|
||||
}
|
||||
|
@ -863,7 +863,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SqmToSqlAstConverterFactory getSqmTranslatorFactory() {
|
||||
public SqmTranslatorFactory getSqmTranslatorFactory() {
|
||||
return sqmTranslatorFactory;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.hibernate.query.criteria.LiteralHandlingMode;
|
|||
import org.hibernate.query.hql.HqlTranslator;
|
||||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
||||
import org.hibernate.query.sqm.produce.function.SqmFunctionRegistry;
|
||||
import org.hibernate.query.sqm.sql.SqmToSqlAstConverterFactory;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
|
||||
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
|
||||
import org.hibernate.resource.jdbc.spi.StatementInspector;
|
||||
import org.hibernate.tuple.entity.EntityTuplizerFactory;
|
||||
|
@ -400,7 +400,7 @@ public class AbstractDelegatingSessionFactoryOptions implements SessionFactoryOp
|
|||
}
|
||||
|
||||
@Override
|
||||
public SqmToSqlAstConverterFactory getSqmTranslatorFactory() {
|
||||
public SqmTranslatorFactory getSqmTranslatorFactory() {
|
||||
return delegate.getSqmTranslatorFactory();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.hibernate.query.criteria.LiteralHandlingMode;
|
|||
import org.hibernate.query.hql.HqlTranslator;
|
||||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
||||
import org.hibernate.query.sqm.produce.function.SqmFunctionRegistry;
|
||||
import org.hibernate.query.sqm.sql.SqmToSqlAstConverterFactory;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
|
||||
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
|
||||
import org.hibernate.resource.jdbc.spi.StatementInspector;
|
||||
import org.hibernate.stat.Statistics;
|
||||
|
@ -146,7 +146,7 @@ public interface SessionFactoryOptions {
|
|||
|
||||
HqlTranslator getHqlTranslator();
|
||||
|
||||
SqmToSqlAstConverterFactory getSqmTranslatorFactory();
|
||||
SqmTranslatorFactory getSqmTranslatorFactory();
|
||||
|
||||
SqmMultiTableMutationStrategy getSqmMultiTableMutationStrategy();
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.hibernate.query.hql.HqlTranslator;
|
|||
import org.hibernate.query.internal.ParameterMetadataImpl;
|
||||
import org.hibernate.query.spi.QueryInterpretationCache;
|
||||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
||||
import org.hibernate.query.sqm.sql.SqmToSqlAstConverterFactory;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
|
||||
import org.hibernate.resource.beans.container.spi.ExtendedBeanManager;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
|
||||
|
@ -931,7 +931,7 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
|
|||
String SEMANTIC_QUERY_PRODUCER = "hibernate.query.hql.translator";
|
||||
|
||||
/**
|
||||
* Names the {@link SqmToSqlAstConverterFactory} class to use.
|
||||
* Names the {@link SqmTranslatorFactory} class to use.
|
||||
*/
|
||||
String SEMANTIC_QUERY_TRANSLATOR = "hibernate.query.sqm.translator";
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ import org.hibernate.engine.jdbc.env.internal.DefaultSchemaNameResolver;
|
|||
import org.hibernate.engine.jdbc.env.spi.AnsiSqlKeywords;
|
||||
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
|
||||
import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
|
||||
import org.hibernate.engine.jdbc.env.spi.SchemaNameResolver;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
|
@ -83,7 +84,6 @@ import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
|||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.internal.util.io.StreamCopier;
|
||||
import org.hibernate.loader.BatchLoadSizingStrategy;
|
||||
|
@ -100,13 +100,15 @@ import org.hibernate.query.hql.HqlTranslator;
|
|||
import org.hibernate.query.spi.QueryEngine;
|
||||
import org.hibernate.query.spi.QueryOptions;
|
||||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
||||
import org.hibernate.query.sqm.sql.SqmToSqlAstConverterFactory;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.sql.ANSICaseFragment;
|
||||
import org.hibernate.sql.ANSIJoinFragment;
|
||||
import org.hibernate.sql.CaseFragment;
|
||||
import org.hibernate.sql.ForUpdateFragment;
|
||||
import org.hibernate.sql.JoinFragment;
|
||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
||||
import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
|
||||
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl;
|
||||
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl;
|
||||
|
@ -3097,9 +3099,20 @@ public abstract class Dialect implements ConversionContext {
|
|||
* precedence as it comes directly from the user config
|
||||
*
|
||||
* @see org.hibernate.query.sqm.sql.internal.StandardSqmSelectToSqlAstConverter
|
||||
* @see QueryEngine#getSqmTranslator()
|
||||
* @see QueryEngine#getSqmTranslatorFactory()
|
||||
*/
|
||||
public SqmToSqlAstConverterFactory getSqmTranslatorFactory() {
|
||||
public SqmTranslatorFactory getSqmTranslatorFactory() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an SqlAstTranslatorFactory specific for the Dialect. Return {@code null}
|
||||
* to use Hibernate's standard translator.
|
||||
*
|
||||
* @see StandardSqlAstTranslatorFactory
|
||||
* @see JdbcEnvironment#getSqlAstTranslatorFactory()
|
||||
*/
|
||||
public SqlAstTranslatorFactory getSqlAstTranslatorFactory() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ import org.hibernate.exception.internal.SQLStateConversionDelegate;
|
|||
import org.hibernate.exception.internal.StandardSQLExceptionConverter;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
||||
import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
|
||||
import org.hibernate.tool.schema.extract.spi.ExtractionContext;
|
||||
import org.hibernate.tool.schema.extract.spi.SequenceInformation;
|
||||
|
||||
|
@ -52,6 +54,8 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment {
|
|||
|
||||
private final Dialect dialect;
|
||||
|
||||
private final SqlAstTranslatorFactory sqlAstTranslatorFactory;
|
||||
|
||||
private final SqlExceptionHelper sqlExceptionHelper;
|
||||
private final ExtractedDatabaseMetaData extractedMetaDataSupport;
|
||||
private final Identifier currentCatalog;
|
||||
|
@ -72,6 +76,8 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment {
|
|||
public JdbcEnvironmentImpl(final ServiceRegistryImplementor serviceRegistry, Dialect dialect) {
|
||||
this.dialect = dialect;
|
||||
|
||||
this.sqlAstTranslatorFactory = resolveSqlAstTranslatorFactory( dialect );
|
||||
|
||||
final ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class );
|
||||
|
||||
NameQualifierSupport nameQualifierSupport = dialect.getNameQualifierSupport();
|
||||
|
@ -119,6 +125,14 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment {
|
|||
this.lobCreatorBuilder = LobCreatorBuilderImpl.makeLobCreatorBuilder();
|
||||
}
|
||||
|
||||
private static SqlAstTranslatorFactory resolveSqlAstTranslatorFactory(Dialect dialect) {
|
||||
if ( dialect.getSqlAstTranslatorFactory() != null ) {
|
||||
return dialect.getSqlAstTranslatorFactory();
|
||||
}
|
||||
|
||||
return new StandardSqlAstTranslatorFactory();
|
||||
}
|
||||
|
||||
private static boolean logWarnings(ConfigurationService cfgService, Dialect dialect) {
|
||||
return cfgService.getSetting(
|
||||
AvailableSettings.LOG_JDBC_WARNINGS,
|
||||
|
@ -159,6 +173,8 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment {
|
|||
public JdbcEnvironmentImpl(DatabaseMetaData databaseMetaData, Dialect dialect) throws SQLException {
|
||||
this.dialect = dialect;
|
||||
|
||||
this.sqlAstTranslatorFactory = resolveSqlAstTranslatorFactory( dialect );
|
||||
|
||||
this.sqlExceptionHelper = buildSqlExceptionHelper( dialect, false );
|
||||
|
||||
NameQualifierSupport nameQualifierSupport = dialect.getNameQualifierSupport();
|
||||
|
@ -232,6 +248,8 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment {
|
|||
DatabaseMetaData databaseMetaData) throws SQLException {
|
||||
this.dialect = dialect;
|
||||
|
||||
this.sqlAstTranslatorFactory = resolveSqlAstTranslatorFactory( dialect );
|
||||
|
||||
final ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class );
|
||||
|
||||
this.sqlExceptionHelper = buildSqlExceptionHelper( dialect, logWarnings( cfgService, dialect ) );
|
||||
|
@ -339,6 +357,11 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment {
|
|||
return dialect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlAstTranslatorFactory getSqlAstTranslatorFactory() {
|
||||
return sqlAstTranslatorFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtractedDatabaseMetaData getExtractedDatabaseMetaData() {
|
||||
return extractedMetaDataSupport;
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.hibernate.dialect.Dialect;
|
|||
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
|
||||
import org.hibernate.engine.jdbc.spi.TypeInfo;
|
||||
import org.hibernate.service.Service;
|
||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
||||
|
||||
/**
|
||||
* Initial look at this concept we keep talking about with merging information from {@link java.sql.DatabaseMetaData}
|
||||
|
@ -26,6 +27,8 @@ public interface JdbcEnvironment extends Service {
|
|||
*/
|
||||
Dialect getDialect();
|
||||
|
||||
SqlAstTranslatorFactory getSqlAstTranslatorFactory();
|
||||
|
||||
/**
|
||||
* Access to the bits of information we pulled off the JDBC {@link java.sql.DatabaseMetaData} (that did not get
|
||||
* "interpreted" into the helpers/delegates available here).
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.hibernate.query.hql.spi.SqmCreationOptions;
|
|||
import org.hibernate.query.internal.QueryInterpretationCacheDisabledImpl;
|
||||
import org.hibernate.query.internal.QueryInterpretationCacheStandardImpl;
|
||||
import org.hibernate.query.named.NamedQueryRepository;
|
||||
import org.hibernate.query.sqm.sql.SqmToSqlAstConverterFactory;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
|
||||
import org.hibernate.query.sqm.internal.DomainParameterXref;
|
||||
import org.hibernate.query.sqm.internal.SqmCreationOptionsStandard;
|
||||
import org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder;
|
||||
|
@ -63,7 +63,7 @@ public class QueryEngine {
|
|||
private final NamedQueryRepository namedQueryRepository;
|
||||
private final SqmCriteriaNodeBuilder criteriaBuilder;
|
||||
private final HqlTranslator hqlTranslator;
|
||||
private final SqmToSqlAstConverterFactory sqmToSqlAstConverterFactory;
|
||||
private final SqmTranslatorFactory sqmTranslatorFactory;
|
||||
private final QueryInterpretationCache interpretationCache;
|
||||
private final SqmFunctionRegistry sqmFunctionRegistry;
|
||||
|
||||
|
@ -88,7 +88,7 @@ public class QueryEngine {
|
|||
sqmCreationOptions
|
||||
);
|
||||
|
||||
this.sqmToSqlAstConverterFactory = resolveSqmToSqlAstConverterFactory(
|
||||
this.sqmTranslatorFactory = resolveSqmTranslatorFactory(
|
||||
runtimeOptions,
|
||||
dialect,
|
||||
sqmCreationContext,
|
||||
|
@ -126,7 +126,7 @@ public class QueryEngine {
|
|||
return new StandardHqlTranslator( sqmCreationContext, sqmCreationOptions );
|
||||
}
|
||||
|
||||
private SqmToSqlAstConverterFactory resolveSqmToSqlAstConverterFactory(
|
||||
private SqmTranslatorFactory resolveSqmTranslatorFactory(
|
||||
SessionFactoryOptions runtimeOptions,
|
||||
Dialect dialect,
|
||||
SqmCreationContext sqmCreationContext,
|
||||
|
@ -140,7 +140,7 @@ public class QueryEngine {
|
|||
}
|
||||
|
||||
//noinspection Convert2Lambda
|
||||
return new SqmToSqlAstConverterFactory() {
|
||||
return new SqmTranslatorFactory() {
|
||||
@Override
|
||||
public SqmSelectToSqlAstConverter createSelectConverter(
|
||||
QueryOptions queryOptions,
|
||||
|
@ -214,8 +214,8 @@ public class QueryEngine {
|
|||
return hqlTranslator;
|
||||
}
|
||||
|
||||
public SqmToSqlAstConverterFactory getSqmTranslatorFactory() {
|
||||
return sqmToSqlAstConverterFactory;
|
||||
public SqmTranslatorFactory getSqmTranslatorFactory() {
|
||||
return sqmTranslatorFactory;
|
||||
}
|
||||
|
||||
public QueryInterpretationCache getInterpretationCache() {
|
||||
|
|
|
@ -14,22 +14,25 @@ import javax.persistence.TupleElement;
|
|||
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.ScrollMode;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.util.streams.StingArrayCollector;
|
||||
import org.hibernate.query.IllegalQueryOperationException;
|
||||
import org.hibernate.query.spi.QueryEngine;
|
||||
import org.hibernate.query.spi.QueryOptions;
|
||||
import org.hibernate.query.spi.QueryParameterImplementor;
|
||||
import org.hibernate.query.spi.ScrollableResultsImplementor;
|
||||
import org.hibernate.query.spi.SelectQueryPlan;
|
||||
import org.hibernate.query.sqm.sql.SqmSelectToSqlAstConverter;
|
||||
import org.hibernate.query.sqm.sql.SqmToSqlAstConverterFactory;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
|
||||
import org.hibernate.query.sqm.sql.internal.SqmSelectInterpretation;
|
||||
import org.hibernate.query.sqm.tree.SqmStatement;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
|
||||
import org.hibernate.query.sqm.tree.select.SqmSelection;
|
||||
import org.hibernate.sql.ast.spi.SqlAstSelectToJdbcSelectConverter;
|
||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
||||
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameter;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
|
@ -157,8 +160,9 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
|
|||
// - this is similar to the plan for loaders
|
||||
|
||||
final SessionFactoryImplementor sessionFactory = session.getFactory();
|
||||
final QueryEngine queryEngine = sessionFactory.getQueryEngine();
|
||||
|
||||
final SqmToSqlAstConverterFactory sqmTranslatorFactory = sessionFactory.getQueryEngine().getSqmTranslatorFactory();
|
||||
final SqmTranslatorFactory sqmTranslatorFactory = queryEngine.getSqmTranslatorFactory();
|
||||
|
||||
final SqmSelectToSqlAstConverter sqmConverter = sqmTranslatorFactory.createSelectConverter(
|
||||
executionContext.getQueryOptions(),
|
||||
|
@ -170,11 +174,12 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
|
|||
|
||||
final SqmSelectInterpretation interpretation = sqmConverter.interpret( sqm );
|
||||
|
||||
// todo (6.0) : allow Dialect to specify SQL -> JdbcCall converter to use
|
||||
jdbcSelect = SqlAstSelectToJdbcSelectConverter.interpret(
|
||||
interpretation.getSqlAst(),
|
||||
sessionFactory
|
||||
);
|
||||
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
|
||||
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
|
||||
final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory();
|
||||
|
||||
jdbcSelect = sqlAstTranslatorFactory.buildSelectConverter( sessionFactory )
|
||||
.interpret( interpretation.getSqlAst() );
|
||||
|
||||
this.jdbcParamsXref = SqmUtil.generateJdbcParamsXref(
|
||||
domainParameterXref,
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
|||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface SqmToSqlAstConverterFactory {
|
||||
public interface SqmTranslatorFactory {
|
||||
SqmSelectToSqlAstConverter createSelectConverter(
|
||||
QueryOptions queryOptions,
|
||||
DomainParameterXref domainParameterXref,
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.sql.ast;
|
||||
|
||||
import org.hibernate.sql.ast.spi.SqlAstToJdbcOperationConverter;
|
||||
import org.hibernate.sql.ast.spi.SqlSelectAstWalker;
|
||||
import org.hibernate.sql.ast.tree.select.QuerySpec;
|
||||
import org.hibernate.sql.ast.tree.select.SelectStatement;
|
||||
import org.hibernate.sql.exec.spi.JdbcSelect;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface SqlAstSelectTranslator extends SqlSelectAstWalker, SqlAstToJdbcOperationConverter {
|
||||
|
||||
/**
|
||||
* Translate the SelectStatement into the executable JdbcSelect
|
||||
*/
|
||||
JdbcSelect interpret(SelectStatement selectStatement);
|
||||
|
||||
/**
|
||||
* Translate the QuerySpec into the executable JdbcSelect
|
||||
*/
|
||||
JdbcSelect interpret(QuerySpec querySpec);
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.sql.ast;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface SqlAstTranslatorFactory {
|
||||
SqlAstSelectTranslator buildSelectConverter(SessionFactoryImplementor sessionFactory);
|
||||
|
||||
// todo (6.0) : update, delete, etc
|
||||
}
|
|
@ -9,6 +9,7 @@ package org.hibernate.sql.ast.spi;
|
|||
import java.util.Collections;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.sql.ast.SqlAstSelectTranslator;
|
||||
import org.hibernate.sql.ast.SqlTreePrinter;
|
||||
import org.hibernate.sql.ast.tree.SqlAstTreeLogger;
|
||||
import org.hibernate.sql.ast.tree.select.QuerySpec;
|
||||
|
@ -23,49 +24,49 @@ import org.hibernate.sql.results.internal.JdbcValuesMappingProducerStandard;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SqlAstSelectToJdbcSelectConverter extends AbstractSqlAstToJdbcOperationConverter implements SqlSelectAstWalker {
|
||||
/**
|
||||
* Perform interpretation of a SQL AST QuerySpec
|
||||
*
|
||||
* @return The interpretation result
|
||||
*/
|
||||
public static JdbcSelect interpret(QuerySpec querySpec, SessionFactoryImplementor sessionFactory) {
|
||||
final SqlAstSelectToJdbcSelectConverter walker = new SqlAstSelectToJdbcSelectConverter( sessionFactory );
|
||||
walker.visitQuerySpec( querySpec );
|
||||
public class StandardSqlAstSelectTranslator
|
||||
extends AbstractSqlAstToJdbcOperationConverter
|
||||
implements SqlAstSelectTranslator {
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public StandardSqlAstSelectTranslator(SessionFactoryImplementor sessionFactory) {
|
||||
super( sessionFactory );
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcSelect interpret(QuerySpec querySpec) {
|
||||
visitQuerySpec( querySpec );
|
||||
|
||||
return new JdbcSelect(
|
||||
walker.getSql(),
|
||||
walker.getParameterBinders(),
|
||||
getSql(),
|
||||
getParameterBinders(),
|
||||
new JdbcValuesMappingProducerStandard(
|
||||
querySpec.getSelectClause().getSqlSelections(),
|
||||
Collections.emptyList()
|
||||
),
|
||||
walker.getAffectedTableNames()
|
||||
getAffectedTableNames()
|
||||
);
|
||||
}
|
||||
|
||||
public static JdbcSelect interpret(SelectStatement sqlSelectPlan, SessionFactoryImplementor sessionFactory) {
|
||||
@Override
|
||||
public JdbcSelect interpret(SelectStatement sqlAstSelect) {
|
||||
if ( SqlAstTreeLogger.DEBUG_ENABLED ) {
|
||||
SqlTreePrinter.print( sqlSelectPlan );
|
||||
SqlTreePrinter.print( sqlAstSelect );
|
||||
}
|
||||
|
||||
final SqlAstSelectToJdbcSelectConverter walker = new SqlAstSelectToJdbcSelectConverter( sessionFactory );
|
||||
visitQuerySpec( sqlAstSelect.getQuerySpec() );
|
||||
|
||||
walker.visitSelectQuery( sqlSelectPlan );
|
||||
return new JdbcSelect(
|
||||
walker.getSql(),
|
||||
walker.getParameterBinders(),
|
||||
getSql(),
|
||||
getParameterBinders(),
|
||||
new JdbcValuesMappingProducerStandard(
|
||||
sqlSelectPlan.getQuerySpec().getSelectClause().getSqlSelections(),
|
||||
sqlSelectPlan.getDomainResultDescriptors()
|
||||
sqlAstSelect.getQuerySpec().getSelectClause().getSqlSelections(),
|
||||
sqlAstSelect.getDomainResultDescriptors()
|
||||
),
|
||||
sqlSelectPlan.getAffectedTableExpressions()
|
||||
sqlAstSelect.getAffectedTableExpressions()
|
||||
);
|
||||
}
|
||||
|
||||
private SqlAstSelectToJdbcSelectConverter(SessionFactoryImplementor sessionFactory) {
|
||||
super( sessionFactory );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSelectQuery(SelectStatement selectQuery) {
|
||||
visitQuerySpec( selectQuery.getQuerySpec() );
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.sql.ast.spi;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
||||
import org.hibernate.sql.ast.SqlAstSelectTranslator;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class StandardSqlAstTranslatorFactory implements SqlAstTranslatorFactory {
|
||||
@Override
|
||||
public SqlAstSelectTranslator buildSelectConverter(SessionFactoryImplementor sessionFactory) {
|
||||
return new StandardSqlAstSelectTranslator( sessionFactory);
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ import org.hibernate.query.sqm.internal.QuerySqmImpl;
|
|||
import org.hibernate.query.sqm.sql.internal.SqmSelectInterpretation;
|
||||
import org.hibernate.query.sqm.sql.internal.StandardSqmSelectToSqlAstConverter;
|
||||
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
|
||||
import org.hibernate.sql.ast.spi.SqlAstSelectToJdbcSelectConverter;
|
||||
import org.hibernate.sql.ast.spi.StandardSqlAstSelectTranslator;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
|
@ -111,10 +111,8 @@ public class SmokeTests {
|
|||
assertThat( sqlSelection.getValuesArrayPosition(), is( 0 ) );
|
||||
assertThat( sqlSelection.getJdbcValueExtractor(), notNullValue() );
|
||||
|
||||
final JdbcSelect jdbcSelectOperation = SqlAstSelectToJdbcSelectConverter.interpret(
|
||||
sqlAst,
|
||||
session.getSessionFactory()
|
||||
);
|
||||
final JdbcSelect jdbcSelectOperation = new StandardSqlAstSelectTranslator( session.getSessionFactory() )
|
||||
.interpret( sqlAst );
|
||||
|
||||
assertThat(
|
||||
jdbcSelectOperation.getSql(),
|
||||
|
@ -208,11 +206,8 @@ public class SmokeTests {
|
|||
assertThat( valueConverter, notNullValue() );
|
||||
assertThat( valueConverter, instanceOf( OrdinalEnumValueConverter.class ) );
|
||||
|
||||
|
||||
final JdbcSelect jdbcSelectOperation = SqlAstSelectToJdbcSelectConverter.interpret(
|
||||
sqlAst,
|
||||
session.getSessionFactory()
|
||||
);
|
||||
final JdbcSelect jdbcSelectOperation = new StandardSqlAstSelectTranslator( session.getSessionFactory() )
|
||||
.interpret( sqlAst );
|
||||
|
||||
assertThat(
|
||||
jdbcSelectOperation.getSql(),
|
||||
|
|
Loading…
Reference in New Issue