HHH-11473 - Refactor MySQL Dialects

- Simplify InnoDB deprecated Dialects by just overriding the default storage engine method
This commit is contained in:
Vlad Mihalcea 2017-02-21 07:57:56 +02:00
parent 652aa43427
commit 91d1f38d95
5 changed files with 119 additions and 114 deletions

View File

@ -14,18 +14,9 @@ package org.hibernate.dialect;
*/
@SuppressWarnings("deprecation")
public class MySQL5InnoDBDialect extends MySQL5Dialect {
@Override
public boolean supportsCascadeDelete() {
return true;
}
@Override
public String getTableTypeString() {
return " ENGINE=InnoDB";
}
@Override
public boolean hasSelfReferentialForeignKeyBug() {
return true;
protected MySQLStorageEngine getDefaultMySQLStorageEngine() {
return InnoDBStorageEngine.INSTANCE;
}
}

View File

@ -14,18 +14,9 @@ package org.hibernate.dialect;
*/
@SuppressWarnings("deprecation")
public class MySQLInnoDBDialect extends MySQLDialect {
@Override
public boolean supportsCascadeDelete() {
return true;
}
@Override
public String getTableTypeString() {
return " type=InnoDB";
}
@Override
public boolean hasSelfReferentialForeignKeyBug() {
return true;
protected MySQLStorageEngine getDefaultMySQLStorageEngine() {
return InnoDBStorageEngine.INSTANCE;
}
}

View File

@ -7,6 +7,9 @@
package org.hibernate.spatial.dialect.mysql;
import org.hibernate.dialect.InnoDBStorageEngine;
import org.hibernate.dialect.MySQLStorageEngine;
/**
* Spatial Dialect for MySQL 5.6 with InnoDB engine.
*
@ -18,18 +21,8 @@ package org.hibernate.spatial.dialect.mysql;
public class MySQL56InnoDBSpatialDialect extends MySQL56SpatialDialect {
@Override
public boolean supportsCascadeDelete() {
return true;
}
@Override
public String getTableTypeString() {
return " ENGINE=InnoDB";
}
@Override
public boolean hasSelfReferentialForeignKeyBug() {
return true;
protected MySQLStorageEngine getDefaultMySQLStorageEngine() {
return InnoDBStorageEngine.INSTANCE;
}
}

View File

@ -6,16 +6,8 @@
*/
package org.hibernate.spatial.dialect.mysql;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.MySQL5InnoDBDialect;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
import org.hibernate.dialect.InnoDBStorageEngine;
import org.hibernate.dialect.MySQLStorageEngine;
/**
* A Dialect for MySQL 5 using InnoDB engine, with support for its spatial features
@ -24,76 +16,10 @@ import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
* @deprecated Use "hibernate.dialect.storage_engine=innodb" environment variable or JVM system property instead.
*/
@SuppressWarnings("deprecation")
public class MySQL5InnoDBSpatialDialect extends MySQL5InnoDBDialect implements SpatialDialect {
private MySQLSpatialDialect dialectDelegate = new MySQLSpatialDialect();
/**
* Constructs an instance
*/
public MySQL5InnoDBSpatialDialect() {
super();
registerColumnType(
MySQLGeometryTypeDescriptor.INSTANCE.getSqlType(),
"GEOMETRY"
);
for ( Map.Entry<String, SQLFunction> entry : new MySQLSpatialFunctions() ) {
registerFunction( entry.getKey(), entry.getValue() );
}
}
public class MySQL5InnoDBSpatialDialect extends MySQL5SpatialDialect {
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
dialectDelegate.contributeTypes( typeContributions, serviceRegistry );
}
@Override
public String getTypeName(int code, long length, int precision, int scale) throws HibernateException {
return dialectDelegate.getTypeName( code, length, precision, scale );
}
@Override
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
return dialectDelegate.remapSqlTypeDescriptor( sqlTypeDescriptor );
}
@Override
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
return dialectDelegate.getSpatialRelateSQL( columnName, spatialRelation );
}
@Override
public String getSpatialFilterExpression(String columnName) {
return dialectDelegate.getSpatialFilterExpression( columnName );
}
@Override
public String getSpatialAggregateSQL(String columnName, int aggregation) {
return dialectDelegate.getSpatialAggregateSQL( columnName, aggregation );
}
@Override
public String getDWithinSQL(String columnName) {
return dialectDelegate.getDWithinSQL( columnName );
}
@Override
public String getHavingSridSQL(String columnName) {
return dialectDelegate.getHavingSridSQL( columnName );
}
@Override
public String getIsEmptySQL(String columnName, boolean isEmpty) {
return dialectDelegate.getIsEmptySQL( columnName, isEmpty );
}
@Override
public boolean supportsFiltering() {
return dialectDelegate.supportsFiltering();
}
@Override
public boolean supports(SpatialFunction function) {
return dialectDelegate.supports( function );
protected MySQLStorageEngine getDefaultMySQLStorageEngine() {
return InnoDBStorageEngine.INSTANCE;
}
}

View File

@ -0,0 +1,104 @@
/*
* 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.spatial.dialect.mysql;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.InnoDBStorageEngine;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.MySQLStorageEngine;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* A Dialect for MySQL 5 using InnoDB engine, with support for its spatial features
*
* @author Karel Maesen, Geovise BVBA
*/
public class MySQL5SpatialDialect extends MySQL5Dialect implements SpatialDialect {
private MySQLSpatialDialect dialectDelegate = new MySQLSpatialDialect();
/**
* Constructs an instance
*/
public MySQL5SpatialDialect() {
super();
registerColumnType(
MySQLGeometryTypeDescriptor.INSTANCE.getSqlType(),
"GEOMETRY"
);
for ( Map.Entry<String, SQLFunction> entry : new MySQLSpatialFunctions() ) {
registerFunction( entry.getKey(), entry.getValue() );
}
}
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
dialectDelegate.contributeTypes( typeContributions, serviceRegistry );
}
@Override
public String getTypeName(int code, long length, int precision, int scale) throws HibernateException {
return dialectDelegate.getTypeName( code, length, precision, scale );
}
@Override
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
return dialectDelegate.remapSqlTypeDescriptor( sqlTypeDescriptor );
}
@Override
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
return dialectDelegate.getSpatialRelateSQL( columnName, spatialRelation );
}
@Override
public String getSpatialFilterExpression(String columnName) {
return dialectDelegate.getSpatialFilterExpression( columnName );
}
@Override
public String getSpatialAggregateSQL(String columnName, int aggregation) {
return dialectDelegate.getSpatialAggregateSQL( columnName, aggregation );
}
@Override
public String getDWithinSQL(String columnName) {
return dialectDelegate.getDWithinSQL( columnName );
}
@Override
public String getHavingSridSQL(String columnName) {
return dialectDelegate.getHavingSridSQL( columnName );
}
@Override
public String getIsEmptySQL(String columnName, boolean isEmpty) {
return dialectDelegate.getIsEmptySQL( columnName, isEmpty );
}
@Override
public boolean supportsFiltering() {
return dialectDelegate.supportsFiltering();
}
@Override
public boolean supports(SpatialFunction function) {
return dialectDelegate.supports( function );
}
@Override
protected MySQLStorageEngine getDefaultMySQLStorageEngine() {
return InnoDBStorageEngine.INSTANCE;
}
}