Rename SAPDBDialect to MaxDBDialect

(Leaving a stub SAPDBDialect class for backward compatibility.)
This commit is contained in:
gavinking 2020-02-01 13:21:20 +01:00 committed by Steve Ebersole
parent e43c5a3166
commit 7267b418c5
7 changed files with 235 additions and 219 deletions

View File

@ -136,9 +136,9 @@ hibernate.connection.url jdbc:hsqldb:./build/db/hsqldb/hibernate
#hibernate.connection.url jdbc:sybase:Tds:co3061835-a:5000/tempdb
## SAP DB
## SAP MaxDB
#hibernate.dialect org.hibernate.dialect.SAPDBDialect
#hibernate.dialect org.hibernate.dialect.MaxDBDialect
#hibernate.connection.driver_class com.sap.dbtech.jdbc.DriverSapDB
#hibernate.connection.url jdbc:sapdb://localhost/TST
#hibernate.connection.username TEST

View File

@ -119,9 +119,9 @@ hibernate.connection.url @DB_URL@
#hibernate.connection.url jdbc:sybase:Tds:co3061835-a:5000/tempdb
## SAP DB
## SAP MaxDB
#hibernate.dialect org.hibernate.dialect.SAPDBDialect
#hibernate.dialect org.hibernate.dialect.MaxDBDialect
#hibernate.connection.driver_class com.sap.dbtech.jdbc.DriverSapDB
#hibernate.connection.url jdbc:sapdb://localhost/TST
#hibernate.connection.username TEST

View File

@ -55,7 +55,7 @@ import org.hibernate.dialect.PostgreSQL81Dialect;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.dialect.PostgreSQL9Dialect;
import org.hibernate.dialect.PostgresPlusDialect;
import org.hibernate.dialect.SAPDBDialect;
import org.hibernate.dialect.MaxDBDialect;
import org.hibernate.dialect.SQLServer2005Dialect;
import org.hibernate.dialect.SQLServer2008Dialect;
import org.hibernate.dialect.SQLServerDialect;
@ -218,7 +218,7 @@ public class StrategySelectorBuilder {
addDialect( strategySelector, PostgreSQL81Dialect.class );
addDialect( strategySelector, PostgreSQL82Dialect.class );
addDialect( strategySelector, PostgreSQL9Dialect.class );
addDialect( strategySelector, SAPDBDialect.class );
addDialect( strategySelector, MaxDBDialect.class );
addDialect( strategySelector, SQLServerDialect.class );
addDialect( strategySelector, SQLServer2005Dialect.class );
addDialect( strategySelector, SQLServer2008Dialect.class );

View File

@ -272,7 +272,7 @@ public enum Database {
MAXDB {
@Override
public Dialect createDialect(DialectResolutionInfo info) {
return new SAPDBDialect();
return new MaxDBDialect();
}
@Override
public boolean productNameMatches(String databaseName) {

View File

@ -0,0 +1,220 @@
/*
* 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.dialect;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.sequence.MaxDBSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
import org.hibernate.query.TrimSpec;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.sql.CaseFragment;
import org.hibernate.sql.DecodeCaseFragment;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorSAPDBDatabaseImpl;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
import org.hibernate.type.StandardBasicTypes;
import java.sql.DatabaseMetaData;
import java.sql.Types;
/**
* A SQL dialect compatible with SAP MaxDB.
*
* @author Brad Clow
*/
public class MaxDBDialect extends Dialect {
public MaxDBDialect() {
super();
registerColumnType( Types.BIT, 1, "boolean" ); //no BIT type
registerColumnType( Types.TINYINT, "smallint" );
registerColumnType( Types.BIGINT, "fixed(19,0)" );
registerColumnType( Types.NUMERIC, "fixed($p,$s)" );
registerColumnType( Types.DECIMAL, "fixed($p,$s)" );
//no explicit precision
registerColumnType(Types.TIMESTAMP, "timestamp");
registerColumnType(Types.TIMESTAMP_WITH_TIMEZONE, "timestamp");
registerColumnType( Types.VARBINARY, "long byte" );
registerColumnType( Types.CLOB, "long varchar" );
registerColumnType( Types.BLOB, "long byte" );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
}
@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry( queryEngine );
CommonFunctionFactory.log( queryEngine );
CommonFunctionFactory.pi( queryEngine );
CommonFunctionFactory.cot( queryEngine );
CommonFunctionFactory.cosh( queryEngine );
CommonFunctionFactory.sinh( queryEngine );
CommonFunctionFactory.tanh( queryEngine );
CommonFunctionFactory.radians( queryEngine );
CommonFunctionFactory.degrees( queryEngine );
CommonFunctionFactory.trunc( queryEngine );
CommonFunctionFactory.trim2( queryEngine );
CommonFunctionFactory.substr( queryEngine );
CommonFunctionFactory.substring_substr( queryEngine );
CommonFunctionFactory.translate( queryEngine );
CommonFunctionFactory.initcap( queryEngine );
CommonFunctionFactory.soundex( queryEngine );
CommonFunctionFactory.yearMonthDay( queryEngine );
CommonFunctionFactory.hourMinuteSecond( queryEngine );
CommonFunctionFactory.dayofweekmonthyear( queryEngine );
CommonFunctionFactory.daynameMonthname( queryEngine );
CommonFunctionFactory.dateTimeTimestamp( queryEngine );
CommonFunctionFactory.ceiling_ceil( queryEngine );
CommonFunctionFactory.week_weekofyear( queryEngine );
CommonFunctionFactory.concat_pipeOperator( queryEngine );
CommonFunctionFactory.coalesce_value( queryEngine );
//since lpad/rpad are not actually useful padding
//functions, map them to lfill/rfill
CommonFunctionFactory.pad_fill( queryEngine );
CommonFunctionFactory.datediff( queryEngine );
CommonFunctionFactory.adddateSubdateAddtimeSubtime( queryEngine );
CommonFunctionFactory.addMonths( queryEngine );
queryEngine.getSqmFunctionRegistry().registerPattern( "extract", "?1(?2)", StandardBasicTypes.INTEGER );
queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "nullif", "case ?1 when ?2 then null else ?1 end" )
.setExactArgumentCount(2)
.register();
queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "index" )
.setInvariantType( StandardBasicTypes.INTEGER )
.setArgumentCountBetween( 2, 4 )
.register();
queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern(
"locate",
StandardBasicTypes.INTEGER, "index(?2, ?1)", "index(?2, ?1, ?3)"
).setArgumentListSignature("(pattern, string[, start])");
}
@Override
public String trimPattern(TrimSpec specification, char character) {
return AbstractTransactSQLDialect.replaceLtrimRtrim(specification, character);
}
@Override
public boolean dropConstraints() {
return false;
}
@Override
public String getAddColumnString() {
return "add";
}
@Override
public String getAddForeignKeyConstraintString(
String constraintName,
String[] foreignKey,
String referencedTable,
String[] primaryKey,
boolean referencesPrimaryKey) {
final StringBuilder res = new StringBuilder( 30 )
.append( " foreign key " )
.append( constraintName )
.append( " (" )
.append( String.join( ", ", foreignKey ) )
.append( ") references " )
.append( referencedTable );
if ( !referencesPrimaryKey ) {
res.append( " (" )
.append( String.join( ", ", primaryKey ) )
.append( ')' );
}
return res.toString();
}
public String getAddForeignKeyConstraintString(
String constraintName,
String foreignKeyDefinition) {
return foreignKeyDefinition;
}
@Override
public String getAddPrimaryKeyConstraintString(String constraintName) {
return " primary key ";
}
@Override
public String getNullColumnString() {
return " null";
}
@Override
public SequenceSupport getSequenceSupport() {
return MaxDBSequenceSupport.INSTANCE;
}
@Override
public String getQuerySequencesString() {
return "select * from domain.sequences";
}
@Override
public SequenceInformationExtractor getSequenceInformationExtractor() {
return SequenceInformationExtractorSAPDBDatabaseImpl.INSTANCE;
}
@Override
public String getFromDual() {
return "from dual";
}
@Override
@SuppressWarnings("deprecation")
public CaseFragment createCaseFragment() {
return new DecodeCaseFragment();
}
@Override
public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(
EntityMappingType rootEntityDescriptor,
RuntimeModelCreationContext runtimeModelCreationContext) {
throw new NotYetImplementedFor6Exception( getClass() );
// return new LocalTemporaryTableBulkIdStrategy(
// new IdTableSupportStandardImpl() {
// @Override
// public String generateIdTableName(String baseName) {
// return "temp." + super.generateIdTableName( baseName );
// }
//
// @Override
// public String getCreateIdTableStatementOptions() {
// return "ignore rollback";
// }
// },
// AfterUseAction.DROP,
// null
// );
}
@Override
public boolean supportsJdbcConnectionLobCreation(DatabaseMetaData databaseMetaData) {
return false;
}
}

View File

@ -6,214 +6,8 @@
*/
package org.hibernate.dialect;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.sequence.SAPDBSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
import org.hibernate.query.TrimSpec;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.mutation.internal.idtable.AfterUseAction;
import org.hibernate.query.sqm.mutation.internal.idtable.IdTable;
import org.hibernate.query.sqm.mutation.internal.idtable.LocalTemporaryTableStrategy;
import org.hibernate.query.sqm.mutation.internal.idtable.TempIdTableExporter;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.sql.CaseFragment;
import org.hibernate.sql.DecodeCaseFragment;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorSAPDBDatabaseImpl;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
import org.hibernate.type.StandardBasicTypes;
import java.sql.DatabaseMetaData;
import java.sql.Types;
/**
* An SQL dialect compatible with SAP DB.
*
* @author Brad Clow
* @deprecated use {@link MaxDBDialect}
*/
public class SAPDBDialect extends Dialect {
/**
* Constructs a SAPDBDialect
*/
public SAPDBDialect() {
super();
registerColumnType( Types.BIT, 1, "boolean" ); //no BIT type
registerColumnType( Types.TINYINT, "smallint" );
registerColumnType( Types.BIGINT, "fixed(19,0)" );
registerColumnType( Types.NUMERIC, "fixed($p,$s)" );
registerColumnType( Types.DECIMAL, "fixed($p,$s)" );
//no explicit precision
registerColumnType(Types.TIMESTAMP, "timestamp");
registerColumnType(Types.TIMESTAMP_WITH_TIMEZONE, "timestamp");
registerColumnType( Types.VARBINARY, "long byte" );
registerColumnType( Types.CLOB, "long varchar" );
registerColumnType( Types.BLOB, "long byte" );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
}
@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry( queryEngine );
CommonFunctionFactory.log( queryEngine );
CommonFunctionFactory.pi( queryEngine );
CommonFunctionFactory.cot( queryEngine );
CommonFunctionFactory.cosh( queryEngine );
CommonFunctionFactory.sinh( queryEngine );
CommonFunctionFactory.tanh( queryEngine );
CommonFunctionFactory.radians( queryEngine );
CommonFunctionFactory.degrees( queryEngine );
CommonFunctionFactory.trunc( queryEngine );
CommonFunctionFactory.trim2( queryEngine );
CommonFunctionFactory.substr( queryEngine );
CommonFunctionFactory.substring_substr( queryEngine );
CommonFunctionFactory.translate( queryEngine );
CommonFunctionFactory.initcap( queryEngine );
CommonFunctionFactory.soundex( queryEngine );
CommonFunctionFactory.yearMonthDay( queryEngine );
CommonFunctionFactory.hourMinuteSecond( queryEngine );
CommonFunctionFactory.dayofweekmonthyear( queryEngine );
CommonFunctionFactory.daynameMonthname( queryEngine );
CommonFunctionFactory.dateTimeTimestamp( queryEngine );
CommonFunctionFactory.ceiling_ceil( queryEngine );
CommonFunctionFactory.week_weekofyear( queryEngine );
CommonFunctionFactory.concat_pipeOperator( queryEngine );
CommonFunctionFactory.coalesce_value( queryEngine );
//since lpad/rpad are not actually useful padding
//functions, map them to lfill/rfill
CommonFunctionFactory.pad_fill( queryEngine );
CommonFunctionFactory.datediff( queryEngine );
CommonFunctionFactory.adddateSubdateAddtimeSubtime( queryEngine );
CommonFunctionFactory.addMonths( queryEngine );
queryEngine.getSqmFunctionRegistry().registerPattern( "extract", "?1(?2)", StandardBasicTypes.INTEGER );
queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "nullif", "case ?1 when ?2 then null else ?1 end" )
.setExactArgumentCount(2)
.register();
queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "index" )
.setInvariantType( StandardBasicTypes.INTEGER )
.setArgumentCountBetween( 2, 4 )
.register();
queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern(
"locate",
StandardBasicTypes.INTEGER, "index(?2, ?1)", "index(?2, ?1, ?3)"
).setArgumentListSignature("(pattern, string[, start])");
}
@Override
public String trimPattern(TrimSpec specification, char character) {
return AbstractTransactSQLDialect.replaceLtrimRtrim(specification, character);
}
@Override
public boolean dropConstraints() {
return false;
}
@Override
public String getAddColumnString() {
return "add";
}
@Override
public String getAddForeignKeyConstraintString(
String constraintName,
String[] foreignKey,
String referencedTable,
String[] primaryKey,
boolean referencesPrimaryKey) {
final StringBuilder res = new StringBuilder( 30 )
.append( " foreign key " )
.append( constraintName )
.append( " (" )
.append( String.join( ", ", foreignKey ) )
.append( ") references " )
.append( referencedTable );
if ( !referencesPrimaryKey ) {
res.append( " (" )
.append( String.join( ", ", primaryKey ) )
.append( ')' );
}
return res.toString();
}
public String getAddForeignKeyConstraintString(
String constraintName,
String foreignKeyDefinition) {
return foreignKeyDefinition;
}
@Override
public String getAddPrimaryKeyConstraintString(String constraintName) {
return " primary key ";
}
@Override
public String getNullColumnString() {
return " null";
}
@Override
public SequenceSupport getSequenceSupport() {
return SAPDBSequenceSupport.INSTANCE;
}
@Override
public String getQuerySequencesString() {
return "select * from domain.sequences";
}
@Override
public SequenceInformationExtractor getSequenceInformationExtractor() {
return SequenceInformationExtractorSAPDBDatabaseImpl.INSTANCE;
}
@Override
public String getFromDual() {
return "from dual";
}
@Override
@SuppressWarnings("deprecation")
public CaseFragment createCaseFragment() {
return new DecodeCaseFragment();
}
@Override
public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(
EntityMappingType rootEntityDescriptor,
RuntimeModelCreationContext runtimeModelCreationContext) {
return new LocalTemporaryTableStrategy(
new IdTable( rootEntityDescriptor, name -> "temp." + name ),
() -> new TempIdTableExporter( true, this::getTypeName ) {
@Override
protected String getCreateOptions() {
return "ignore rollback";
}
},
AfterUseAction.DROP,
null,
runtimeModelCreationContext.getSessionFactory()
);
}
@Override
public boolean supportsJdbcConnectionLobCreation(DatabaseMetaData databaseMetaData) {
return false;
}
}
@Deprecated
public class SAPDBDialect extends MaxDBDialect {}

View File

@ -6,14 +6,16 @@
*/
package org.hibernate.dialect.sequence;
import org.hibernate.dialect.MaxDBDialect;
/**
* Sequence support for {@link org.hibernate.dialect.SAPDBDialect}.
* Sequence support for {@link MaxDBDialect}.
*
* @author Gavin King
*/
public final class SAPDBSequenceSupport extends NextvalSequenceSupport {
public final class MaxDBSequenceSupport extends NextvalSequenceSupport {
public static final SequenceSupport INSTANCE = new SAPDBSequenceSupport();
public static final SequenceSupport INSTANCE = new MaxDBSequenceSupport();
@Override
public String getFromDual() {