HHH-6509 - Change type contribution: SpatialDialects now register types.

This is done so that in a later stage we can more easily customize the
type mapping to the dialect (e.g. in the case of Oracle Spatial).
This commit is contained in:
Karel Maesen 2013-04-19 18:04:40 +02:00 committed by Steve Ebersole
parent 290c8354b3
commit d226ef36f2
20 changed files with 151 additions and 435 deletions

View File

@ -1,7 +1,16 @@
package org.hibernate.spatial;
import org.geolatte.geom.*;
import org.geolatte.geom.Geometry;
import org.geolatte.geom.GeometryCollection;
import org.geolatte.geom.LineString;
import org.geolatte.geom.MultiLineString;
import org.geolatte.geom.MultiPoint;
import org.geolatte.geom.MultiPolygon;
import org.geolatte.geom.Point;
import org.geolatte.geom.Polygon;
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* @author Karel Maesen, Geovise BVBA
@ -9,8 +18,6 @@ import org.hibernate.type.AbstractSingleColumnStandardBasicType;
*/
public class GeolatteGeometryType extends AbstractSingleColumnStandardBasicType<Geometry> implements Spatial {
public static final GeolatteGeometryType INSTANCE = new GeolatteGeometryType();
@Override
public String[] getRegistrationKeys() {
return new String[] {
@ -26,8 +33,8 @@ public class GeolatteGeometryType extends AbstractSingleColumnStandardBasicType<
};
}
public GeolatteGeometryType() {
super( GeometrySqlTypeDescriptor.INSTANCE, GeolatteGeometryJavaTypeDescriptor.INSTANCE );
public GeolatteGeometryType(SqlTypeDescriptor sqlTypeDescriptor) {
super( sqlTypeDescriptor, GeolatteGeometryJavaTypeDescriptor.INSTANCE );
}
@Override

View File

@ -1,67 +0,0 @@
/*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for spatial (geographic) data.
*
* Copyright © 2007-2012 Geovise BVBA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.hibernate.spatial;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* A generic <code>SqlTypeDescriptor</code>, intended to be remapped
* by the spatial dialect.
*
* @author Karel Maesen, Geovise BVBA
* creation-date: 7/27/11
*/
public class GeometrySqlTypeDescriptor implements SqlTypeDescriptor {
public static final GeometrySqlTypeDescriptor INSTANCE = new GeometrySqlTypeDescriptor();
@Override
public int getSqlType() {
return 3000; //this value doesn't conflict with presently defined java.sql.Types values.
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
throw new UnsupportedOperationException();
}
@Override
public <X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor) {
throw new UnsupportedOperationException();
}
/**
* Returns the fully-qualified database specific type name for the spatial user-defined type.
* @return
*/
public String getTypeName() {
return "GEOMETRY";
}
}

View File

@ -23,6 +23,7 @@ package org.hibernate.spatial;
import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* A {@link org.hibernate.type.BasicType BasicType} for JTS <code>Geometry</code>s.
@ -31,8 +32,6 @@ import org.hibernate.type.AbstractSingleColumnStandardBasicType;
*/
public class JTSGeometryType extends AbstractSingleColumnStandardBasicType<Geometry> implements Spatial {
public static final JTSGeometryType INSTANCE = new JTSGeometryType();
@Override
public String[] getRegistrationKeys() {
return new String[] {
@ -48,8 +47,8 @@ public class JTSGeometryType extends AbstractSingleColumnStandardBasicType<Geome
};
}
public JTSGeometryType() {
super( GeometrySqlTypeDescriptor.INSTANCE, JTSGeometryJavaTypeDescriptor.INSTANCE );
public JTSGeometryType(SqlTypeDescriptor sqlTypeDescriptor) {
super( sqlTypeDescriptor, JTSGeometryJavaTypeDescriptor.INSTANCE );
}
@Override

View File

@ -1,59 +0,0 @@
/*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for spatial (geographic) data.
*
* Copyright © 2007-2012 Geovise BVBA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.hibernate.spatial.dialect;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.BasicBinder;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: 1/19/12
*/
public abstract class AbstractGeometryValueBinder<X> extends BasicBinder<X> {
private static GeometryFactory geometryFactory = new GeometryFactory();
public AbstractGeometryValueBinder(JavaTypeDescriptor<X> javaDescriptor, SqlTypeDescriptor sqlDescriptor) {
super( javaDescriptor, sqlDescriptor );
}
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
Geometry jtsGeom = getJavaDescriptor().unwrap( value, Geometry.class, options );
Object dbGeom = toNative( jtsGeom, st.getConnection() );
st.setObject( index, dbGeom );
}
protected GeometryFactory getGeometryFactory() {
return geometryFactory;
}
protected abstract Object toNative(Geometry jtsGeom, Connection connection);
}

View File

@ -1,75 +0,0 @@
/*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for spatial (geographic) data.
*
* Copyright © 2007-2012 Geovise BVBA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.hibernate.spatial.dialect;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import org.hibernate.spatial.GeometrySqlTypeDescriptor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.BasicExtractor;
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: 1/19/12
*/
public abstract class AbstractGeometryValueExtractor<X> extends BasicExtractor<X> {
// later this will need to be configurable. So define this only once for both
// extractor and binder.
private static GeometryFactory geometryFactory = new GeometryFactory();
public AbstractGeometryValueExtractor(JavaTypeDescriptor<X> javaDescriptor, GeometrySqlTypeDescriptor typeDescriptor) {
super( javaDescriptor, typeDescriptor );
}
protected GeometryFactory getGeometryFactory() {
return geometryFactory;
}
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
Object geomObj = rs.getObject( name );
return (X) toJTS( geomObj );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
Object geomObj = statement.getObject( index );
return (X) toJTS( geomObj );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
Object geomObj = statement.getObject( name );
return (X) toJTS( geomObj );
}
abstract public Geometry toJTS(Object object);
}

View File

@ -21,15 +21,16 @@
package org.hibernate.spatial.dialect.h2geodb;
import org.hibernate.HibernateException;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.spatial.GeometrySqlTypeDescriptor;
import org.hibernate.metamodel.spi.TypeContributions;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.GeolatteGeometryType;
import org.hibernate.spatial.JTSGeometryType;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.SpatialRelation;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* Extends the H2Dialect by also including information on spatial functions.
@ -83,6 +84,7 @@ public class GeoDBDialect extends H2Dialect implements SpatialDialect {
CREATE ALIAS Version FOR "geodb.GeoDB.Version"
*/
/**
* Constructor. Registers OGC simple feature functions (see
* http://portal.opengeospatial.org/files/?artifact_id=829 for details).
@ -97,7 +99,7 @@ public class GeoDBDialect extends H2Dialect implements SpatialDialect {
// Register Geometry column type
registerColumnType(
GeoDBGeometryTypeDescriptor.INSTANCE.getSqlType(),
GeoDBGeometryTypeDescriptor.INSTANCE.getTypeName()
"GEOMETRY"
);
// Register functions that operate on spatial types
@ -240,37 +242,14 @@ public class GeoDBDialect extends H2Dialect implements SpatialDialect {
}
//TODO the getTypeName() override is necessary in the absence of HHH-6074
/**
* Get the name of the database type associated with the given
* {@link java.sql.Types} typecode with the given storage specification
* parameters. In the case of typecode == 3000, it returns this dialect's spatial type which is
* <code>GEOMETRY</code>.
*
* @param code The {@link java.sql.Types} typecode
* @param length The datatype length
* @param precision The datatype precision
* @param scale The datatype scale
*
* @return
*
* @throws org.hibernate.HibernateException
*/
@Override
public String getTypeName(int code, long length, int precision, int scale) throws HibernateException {
if ( code == 3000 ) {
return GeoDBGeometryTypeDescriptor.INSTANCE.getTypeName();
}
return super.getTypeName( code, length, precision, scale );
}
@Override
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
if ( sqlTypeDescriptor instanceof GeometrySqlTypeDescriptor ) {
return GeoDBGeometryTypeDescriptor.INSTANCE;
}
return super.remapSqlTypeDescriptor( sqlTypeDescriptor );
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(
typeContributions,
serviceRegistry
);
typeContributions.contributeType( new GeolatteGeometryType( GeoDBGeometryTypeDescriptor.INSTANCE ) );
typeContributions.contributeType( new JTSGeometryType( GeoDBGeometryTypeDescriptor.INSTANCE ) );
}
public String getSpatialAggregateSQL(String columnName, int aggregation) {

View File

@ -29,19 +29,19 @@ import java.sql.Types;
import org.geolatte.geom.Geometry;
import org.hibernate.spatial.GeometrySqlTypeDescriptor;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.BasicBinder;
import org.hibernate.type.descriptor.sql.BasicExtractor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: 2/29/12
*/
public class GeoDBGeometryTypeDescriptor extends GeometrySqlTypeDescriptor {
public class GeoDBGeometryTypeDescriptor implements SqlTypeDescriptor {
public static final GeoDBGeometryTypeDescriptor INSTANCE = new GeoDBGeometryTypeDescriptor();
@ -50,10 +50,6 @@ public class GeoDBGeometryTypeDescriptor extends GeometrySqlTypeDescriptor {
return Types.ARRAY;
}
@Override
public String getTypeName() {
return "GEOMETRY";
}
@Override
public boolean canBeRemapped() {

View File

@ -5,6 +5,8 @@ import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.dialect.MySQL5InnoDBDialect;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.metamodel.spi.TypeContributions;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
@ -22,13 +24,18 @@ public class MySQL5SpatialInnoDBDialect extends MySQL5InnoDBDialect implements S
super();
registerColumnType(
MySQLGeometryTypeDescriptor.INSTANCE.getSqlType(),
MySQLGeometryTypeDescriptor.INSTANCE.getTypeName()
"GEOMETRY"
);
for ( Map.Entry<String, StandardSQLFunction> 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 );

View File

@ -34,19 +34,19 @@ import org.geolatte.geom.codec.Wkb;
import org.geolatte.geom.codec.WkbDecoder;
import org.geolatte.geom.codec.WkbEncoder;
import org.hibernate.spatial.GeometrySqlTypeDescriptor;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.BasicBinder;
import org.hibernate.type.descriptor.sql.BasicExtractor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: 1/17/12
*/
public class MySQLGeometryTypeDescriptor extends GeometrySqlTypeDescriptor {
public class MySQLGeometryTypeDescriptor implements SqlTypeDescriptor {
public static final MySQLGeometryTypeDescriptor INSTANCE = new MySQLGeometryTypeDescriptor();
@ -54,18 +54,17 @@ public class MySQLGeometryTypeDescriptor extends GeometrySqlTypeDescriptor {
public int getSqlType() {
return Types.ARRAY;
}
@Override
public String getTypeName() {
return "GEOMETRY";
}
//
// @Override
// public String getTypeName() {
// return "GEOMETRY";
// }
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {

View File

@ -22,14 +22,15 @@ package org.hibernate.spatial.dialect.mysql;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.spatial.GeometrySqlTypeDescriptor;
import org.hibernate.metamodel.spi.TypeContributions;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.GeolatteGeometryType;
import org.hibernate.spatial.JTSGeometryType;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.SpatialRelation;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* Extends the MySQLDialect by also including information on spatial operators,
@ -44,29 +45,21 @@ public class MySQLSpatialDialect extends MySQLDialect implements SpatialDialect
super();
registerColumnType(
MySQLGeometryTypeDescriptor.INSTANCE.getSqlType(),
MySQLGeometryTypeDescriptor.INSTANCE.getTypeName()
"GEOMETRY"
);
for ( Map.Entry<String, StandardSQLFunction> entry : new MySQLSpatialFunctions() ) {
registerFunction( entry.getKey(), entry.getValue() );
}
}
//TODO the getTypeName() override is necessary in the absence of HHH-6074
@Override
public String getTypeName(int code, long length, int precision, int scale) throws HibernateException {
if ( code == 3000 ) {
return "GEOMETRY";
}
return super.getTypeName( code, length, precision, scale );
}
@Override
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
if ( sqlTypeDescriptor instanceof GeometrySqlTypeDescriptor ) {
return MySQLGeometryTypeDescriptor.INSTANCE;
}
return super.remapSqlTypeDescriptor( sqlTypeDescriptor );
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(
typeContributions,
serviceRegistry
);
typeContributions.contributeType( new GeolatteGeometryType( MySQLGeometryTypeDescriptor.INSTANCE ) );
typeContributions.contributeType( new JTSGeometryType( MySQLGeometryTypeDescriptor.INSTANCE ) );
}
/**

View File

@ -29,15 +29,16 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.QueryException;
import org.hibernate.dialect.Oracle10gDialect;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.spatial.GeometrySqlTypeDescriptor;
import org.hibernate.metamodel.spi.TypeContributions;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.GeolatteGeometryType;
import org.hibernate.spatial.JTSGeometryType;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import org.hibernate.spatial.Spatial;
import org.hibernate.spatial.SpatialAnalysis;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
@ -46,7 +47,6 @@ import org.hibernate.spatial.dialect.oracle.criterion.OracleSpatialAggregate;
import org.hibernate.spatial.helper.PropertyFileReader;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* Spatial Dialect for Oracle10g databases.
@ -163,19 +163,13 @@ public class OracleSpatial10gDialect extends Oracle10gDialect implements
}
@Override
public String getTypeName(int code, long length, int precision, int scale) throws HibernateException {
if ( code == 3000 ) {
return "SDO_GEOMETRY";
}
return super.getTypeName( code, length, precision, scale );
}
@Override
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
if ( sqlTypeDescriptor instanceof GeometrySqlTypeDescriptor ) {
return SDOGeometryTypeDescriptor.INSTANCE;
}
return super.remapSqlTypeDescriptor( sqlTypeDescriptor );
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(
typeContributions,
serviceRegistry
);
typeContributions.contributeType( new GeolatteGeometryType( SDOGeometryTypeDescriptor.INSTANCE ) );
typeContributions.contributeType( new JTSGeometryType( SDOGeometryTypeDescriptor.INSTANCE ) );
}
public String getNativeSpatialRelateSQL(String arg1, String arg2,
@ -503,10 +497,6 @@ public class OracleSpatial10gDialect extends Oracle10gDialect implements
}
}
public boolean isTwoPhaseFiltering() {
return false;
}
public boolean supportsFiltering() {
return true;
}
@ -583,9 +573,6 @@ public class OracleSpatial10gDialect extends Oracle10gDialect implements
private SpatialAnalysisFunction(String name, Type returnType, int analysis) {
super( name, returnType );
if (Spatial.class.isAssignableFrom( returnType.getClass() )) {
throw new IllegalArgumentException("This constructor is only valid for functions returning non-spatial values.");
}
this.analysis = analysis;
}

View File

@ -23,16 +23,16 @@ package org.hibernate.spatial.dialect.oracle;
import java.sql.Types;
import org.hibernate.spatial.GeometrySqlTypeDescriptor;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: 8/22/11
*/
public class SDOGeometryTypeDescriptor extends GeometrySqlTypeDescriptor {
public class SDOGeometryTypeDescriptor implements SqlTypeDescriptor {
public static SDOGeometryTypeDescriptor INSTANCE = new SDOGeometryTypeDescriptor();
@ -48,16 +48,15 @@ public class SDOGeometryTypeDescriptor extends GeometrySqlTypeDescriptor {
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return (ValueBinder<X>) new SDOGeometryValueBinder(javaTypeDescriptor);
return new SDOGeometryValueBinder<X>( javaTypeDescriptor );
}
@Override
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return (ValueExtractor<X>) new SDOGeometryValueExtractor(javaTypeDescriptor);
return (ValueExtractor<X>) new SDOGeometryValueExtractor( javaTypeDescriptor );
}
@Override
public String getTypeName(){
public String getTypeName() {
return "MDSYS.SDO_GEOMETRY";
}

View File

@ -21,6 +21,9 @@
package org.hibernate.spatial.dialect.oracle;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Struct;
import java.util.ArrayList;
import java.util.List;
@ -28,6 +31,7 @@ import java.util.List;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateSequence;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.MultiLineString;
@ -36,20 +40,48 @@ import com.vividsolutions.jts.geom.MultiPolygon;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
import org.hibernate.spatial.dialect.AbstractGeometryValueExtractor;
import org.hibernate.spatial.jts.Circle;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.BasicExtractor;
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: 8/22/11
*/
public class SDOGeometryValueExtractor<X> extends AbstractGeometryValueExtractor<X> {
public class SDOGeometryValueExtractor<X> extends BasicExtractor<X> {
private static GeometryFactory geometryFactory = new GeometryFactory();
public SDOGeometryValueExtractor(JavaTypeDescriptor<X> javaDescriptor) {
super( javaDescriptor, SDOGeometryTypeDescriptor.INSTANCE );
}
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
Object geomObj = rs.getObject( name );
return getJavaDescriptor().wrap( toJTS( geomObj ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
Object geomObj = statement.getObject( index );
return getJavaDescriptor().wrap( toJTS( geomObj ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
Object geomObj = statement.getObject( name );
return getJavaDescriptor().wrap( toJTS( geomObj ), options );
}
//TODO Clean up below this point
protected GeometryFactory getGeometryFactory() {
return geometryFactory;
}
public Geometry toJTS(Object struct) {
if ( struct == null ) {
return null;
@ -155,17 +187,19 @@ public class SDOGeometryValueExtractor<X> extends AbstractGeometryValueExtractor
}
if (lrs)
if ( lrs ) {
throw new UnsupportedOperationException();
else
}
else {
return getGeometryFactory().createLineString( cs );
}
}
private MultiLineString convertSDOMultiLine(int dim, int lrsDim,
SDOGeometry SDOGeom) {
boolean lrs = SDOGeom.isLRSGeometry();
if (lrs) {
if ( lrs ) {
throw new UnsupportedOperationException();
}
ElemInfo info = SDOGeom.getInfo();
@ -438,7 +472,6 @@ public class SDOGeometryValueExtractor<X> extends AbstractGeometryValueExtractor
);
}
/**
* Linearizes arcs and circles.
*
@ -481,7 +514,7 @@ public class SDOGeometryValueExtractor<X> extends AbstractGeometryValueExtractor
coords = Circle.linearizeCircle( x1, y1, x2, y2, x3, y3 );
}
else {
coords = Circle.linearizeArc(x1, y1, x2, y2, x3, y3);
coords = Circle.linearizeArc( x1, y1, x2, y2, x3, y3 );
}
// if this is an LRS geometry, fill the measure values into
@ -528,4 +561,5 @@ public class SDOGeometryValueExtractor<X> extends AbstractGeometryValueExtractor
}
return linearizedCoords;
}
}

View File

@ -35,19 +35,19 @@ import org.geolatte.geom.codec.WkbDecoder;
import org.geolatte.geom.codec.WkbEncoder;
import org.postgresql.util.PGobject;
import org.hibernate.spatial.GeometrySqlTypeDescriptor;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.BasicBinder;
import org.hibernate.type.descriptor.sql.BasicExtractor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: 7/27/11
*/
public class PGGeometryTypeDescriptor extends GeometrySqlTypeDescriptor {
public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
public static final PGGeometryTypeDescriptor INSTANCE = new PGGeometryTypeDescriptor();
@ -57,11 +57,6 @@ public class PGGeometryTypeDescriptor extends GeometrySqlTypeDescriptor {
return Types.OTHER;
}
@Override
public String getTypeName() {
return "GEOMETRY";
}
@Override
public boolean canBeRemapped() {
return false;

View File

@ -21,16 +21,17 @@
package org.hibernate.spatial.dialect.postgis;
import org.hibernate.HibernateException;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.spatial.GeometrySqlTypeDescriptor;
import org.hibernate.metamodel.spi.TypeContributions;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.GeolatteGeometryType;
import org.hibernate.spatial.JTSGeometryType;
import org.hibernate.spatial.SpatialAggregate;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.SpatialRelation;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* Extends the PostgreSQLDialect by also including information on spatial
@ -43,14 +44,26 @@ public class PostgisDialect extends PostgreSQL82Dialect implements SpatialDialec
public PostgisDialect() {
super();
registerTypesAndFunctions();
}
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(
typeContributions,
serviceRegistry
);
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE ) );
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE ) );
}
protected void registerTypesAndFunctions() {
registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
PGGeometryTypeDescriptor.INSTANCE.getTypeName()
"GEOMETRY"
);
// registering OGC functions
@ -192,11 +205,12 @@ public class PostgisDialect extends PostgreSQL82Dialect implements SpatialDialec
);
registerFunction(
"intersection", new StandardSQLFunction(
"st_intersection")
"st_intersection"
)
);
registerFunction(
"symdifference",
new StandardSQLFunction( "st_symdifference")
new StandardSQLFunction( "st_symdifference" )
);
registerFunction(
"geomunion", new StandardSQLFunction(
@ -225,39 +239,6 @@ public class PostgisDialect extends PostgreSQL82Dialect implements SpatialDialec
);
}
//TODO the getTypeName() override is necessary in the absence of HHH-6074
/**
* Get the name of the database type associated with the given
* {@link java.sql.Types} typecode with the given storage specification
* parameters. In the case of typecode == 3000, it returns this dialect's spatial type which is
* <code>GEOMETRY</code>.
*
* @param code The {@link java.sql.Types} typecode
* @param length The datatype length
* @param precision The datatype precision
* @param scale The datatype scale
*
* @return
*
* @throws HibernateException
*/
@Override
public String getTypeName(int code, long length, int precision, int scale) throws HibernateException {
if ( code == 3000 ) {
return "GEOMETRY";
}
return super.getTypeName( code, length, precision, scale );
}
@Override
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
if ( sqlTypeDescriptor instanceof GeometrySqlTypeDescriptor ) {
return PGGeometryTypeDescriptor.INSTANCE;
}
return super.remapSqlTypeDescriptor( sqlTypeDescriptor );
}
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
switch ( spatialRelation ) {
case SpatialRelation.WITHIN:

View File

@ -36,7 +36,7 @@ public class PostgisNoSQLMM extends PostgisDialect {
registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
PGGeometryTypeDescriptor.INSTANCE.getTypeName()
"GEOMETRY"
);
// registering OGC functions

View File

@ -32,19 +32,19 @@ import org.geolatte.geom.Geometry;
import org.geolatte.geom.codec.sqlserver.Decoders;
import org.geolatte.geom.codec.sqlserver.Encoders;
import org.hibernate.spatial.GeometrySqlTypeDescriptor;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.BasicBinder;
import org.hibernate.type.descriptor.sql.BasicExtractor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: 8/23/11
*/
public class SqlServer2008GeometryTypeDescriptor extends GeometrySqlTypeDescriptor {
public class SqlServer2008GeometryTypeDescriptor implements SqlTypeDescriptor {
public static final SqlServer2008GeometryTypeDescriptor INSTANCE = new SqlServer2008GeometryTypeDescriptor();
@ -53,11 +53,6 @@ public class SqlServer2008GeometryTypeDescriptor extends GeometrySqlTypeDescript
return Types.ARRAY;
}
@Override
public String getTypeName() {
return "GEOMETRY";
}
@Override
public boolean canBeRemapped() {
return false;

View File

@ -22,15 +22,16 @@
package org.hibernate.spatial.dialect.sqlserver;
import org.hibernate.HibernateException;
import org.hibernate.dialect.SQLServer2008Dialect;
import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.spatial.GeometrySqlTypeDescriptor;
import org.hibernate.metamodel.spi.TypeContributions;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.GeolatteGeometryType;
import org.hibernate.spatial.JTSGeometryType;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.SpatialRelation;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* The <code>SpatialDialect</code> for Microsoft SQL Server (2008).
@ -46,7 +47,7 @@ public class SqlServer2008SpatialDialect extends SQLServer2008Dialect implements
registerColumnType(
SqlServer2008GeometryTypeDescriptor.INSTANCE.getSqlType(),
SqlServer2008GeometryTypeDescriptor.INSTANCE.getTypeName()
"GEOMETRY"
);
// registering OGC functions
@ -103,21 +104,14 @@ public class SqlServer2008SpatialDialect extends SQLServer2008Dialect implements
);
}
//Temporary Fix for HHH-6074
@Override
public String getTypeName(int code, long length, int precision, int scale) throws HibernateException {
if ( code == 3000 ) {
return SqlServer2008GeometryTypeDescriptor.INSTANCE.getTypeName();
}
return super.getTypeName( code, length, precision, scale );
}
@Override
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
if ( sqlTypeDescriptor instanceof GeometrySqlTypeDescriptor ) {
return SqlServer2008GeometryTypeDescriptor.INSTANCE;
}
return super.remapSqlTypeDescriptor( sqlTypeDescriptor );
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(
typeContributions,
serviceRegistry
);
typeContributions.contributeType( new GeolatteGeometryType( SqlServer2008GeometryTypeDescriptor.INSTANCE ) );
typeContributions.contributeType( new JTSGeometryType( SqlServer2008GeometryTypeDescriptor.INSTANCE ) );
}
public String getSpatialRelateSQL(String columnName, int spatialRelation) {

View File

@ -1,47 +0,0 @@
/*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for spatial (geographic) data.
*
* Copyright © 2007-2012 Geovise BVBA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.hibernate.spatial.integration;
import org.hibernate.metamodel.spi.TypeContributions;
import org.hibernate.metamodel.spi.TypeContributor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.GeolatteGeometryType;
import org.hibernate.spatial.JTSGeometryType;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: 7/27/11
*/
public class SpatialTypeContributor implements TypeContributor {
private static final Log LOG = LogFactory.make();
@Override
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
LOG.info( "Registering JTSGeometryType" );
typeContributions.contributeType( JTSGeometryType.INSTANCE );
LOG.info( "Registering GeolatteGeometryType" );
typeContributions.contributeType( GeolatteGeometryType.INSTANCE );
}
}

View File

@ -1 +0,0 @@
org.hibernate.spatial.integration.SpatialTypeContributor