HHH-6509 Removes obsolete code

This removes the HBSpatial static bootstrap class and the old SPI
mechanism. Both had become obsolete because of how spatial now
integrates with core.

Also reorganizes the packages to have all JTS extensions and utilities
in a jts package.
This commit is contained in:
Karel Maesen 2012-01-14 17:55:27 +01:00 committed by Steve Ebersole
parent 50a648ed32
commit ee96098ead
45 changed files with 127 additions and 598 deletions

View File

@ -1,259 +0,0 @@
/**
* $Id: HBSpatialExtension.java 253 2010-10-02 15:14:52Z maesenka $
*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for geographic data.
*
* Copyright © 2007 Geovise BVBA
* Copyright © 2007 K.U. Leuven LRD, Spatial Applications Division, Belgium
*
* This work was partially supported by the European Commission,
* under the 6th Framework Programme, contract IST-2-004688-STP.
*
* 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
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.spatial.cfg.HSConfiguration;
import org.hibernate.spatial.helper.GeometryFactoryHelper;
import org.hibernate.spatial.helper.PropertyFileReader;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.spi.SpatialDialectProvider;
/**
* This is the bootstrap class that is used to get an
* <code>SpatialDialect</code>.
* <p/>
* It also provides a default <code>SpatialDialect</code>.
* <code>GeometryType</code>s that do not have a <code>dialect</code>
* parameter use this default.
* <p/>
* The default <code>SpatialDialect</code> will be the first one that is
* returned by the <code>getDefaultDialect</code> method of the provider at
* least if it is non null.
*
* @author Karel Maesen
*/
//TODO -- this should be moved to the
public class HBSpatialExtension {
protected static List<SpatialDialectProvider> providers = new ArrayList<SpatialDialectProvider>();
private static final Logger log = LoggerFactory.getLogger( HBSpatialExtension.class );
private static SpatialDialect defaultSpatialDialect = null;
private static final String DIALECT_PROP_NAME = "hibernate.spatial.dialect";
private static HSConfiguration configuration = null;
private static MGeometryFactory defaultGeomFactory = new MGeometryFactory();
private static boolean configured = false;
static {
log.info( "Initializing HBSpatialExtension" );
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Enumeration<URL> resources = null;
try {
resources = loader.getResources(
"META-INF/services/"
+ SpatialDialectProvider.class.getName()
);
Set<String> names = new HashSet<String>();
while ( resources.hasMoreElements() ) {
URL url = resources.nextElement();
InputStream is = url.openStream();
try {
names.addAll( providerNamesFromReader( is ) );
}
finally {
is.close();
}
}
for ( String s : names ) {
try {
log.info(
"Attempting to load Hibernate Spatial Provider "
+ s
);
SpatialDialectProvider provider = (SpatialDialectProvider) loader
.loadClass( s ).newInstance();
providers.add( provider );
}
catch ( Exception e ) {
throw new HibernateSpatialException(
"Problem loading provider class", e
);
}
}
}
catch ( IOException e ) {
throw new HibernateSpatialException(
"No "
+ SpatialDialectProvider.class.getName()
+ " found in META-INF/services", e
);
}
// configuration - check if there is a system property
String dialectProp = System.getProperty( DIALECT_PROP_NAME );
if ( dialectProp != null ) {
HSConfiguration hsConfig = new HSConfiguration();
hsConfig.setDefaultDialect( dialectProp );
setConfiguration( hsConfig );
}
// configuration - load the config file
log.info( "Checking for default configuration file." );
HSConfiguration hsConfig = new HSConfiguration();
if ( hsConfig.configure() ) {
configuration = hsConfig;
}
}
/**
* Make sure nobody can instantiate this class
*/
private HBSpatialExtension() {
}
public static void setConfiguration(HSConfiguration c) {
log.info( "Setting configuration object:" + c );
configuration = c;
//if the HSExtension has already been initialized,
//then it should be reconfigured.
if ( configured == true ) {
forceConfigure();
}
}
private static synchronized void configure() {
// // do nothing if already configured
if ( configured ) {
return;
}
configured = true;
forceConfigure();
}
private static void forceConfigure() {
// if no configuration object, take the first dialect that is available.
if ( configuration == null ) {
return;
}
else {
log.info(
"Configuring HBSpatialExtension from "
+ configuration.getSource()
);
String dialectName = configuration.getDefaultDialect();
if ( dialectName != null ) {
SpatialDialect dialect = createSpatialDialect( dialectName );
if ( dialect != null ) {
log.info( "Setting Spatial Dialect to : " + dialectName );
setDefaultSpatialDialect( dialect );
}
}
// trying to create a defaultGeometryFactory
log.info( "Creating default Geometry Factory" );
defaultGeomFactory = GeometryFactoryHelper
.createGeometryFactory( configuration );
}
if ( defaultSpatialDialect == null ) {
log.warn( "Hibernate Spatial Configured but no spatial dialect" );
}
else {
log.info(
"Hibernate Spatial configured. Using dialect: "
+ defaultSpatialDialect.getClass().getCanonicalName()
);
}
}
public static HSConfiguration getConfiguration() {
return configuration;
}
/**
* @param dialect
*/
private static void setDefaultSpatialDialect(SpatialDialect dialect) {
defaultSpatialDialect = dialect;
}
public static SpatialDialect getDefaultSpatialDialect() {
configure();
return defaultSpatialDialect;
}
public static SpatialDialect createSpatialDialect(String dialectName) {
SpatialDialect dialect = null;
for ( SpatialDialectProvider provider : providers ) {
dialect = provider.createSpatialDialect( dialectName );
if ( dialect != null ) {
break;
}
}
if ( dialect == null ) {
throw new HibernateSpatialException(
"No SpatialDialect provider for persistenceUnit "
+ dialectName
);
}
return dialect;
}
//TODO -- this is not thread-safe!
//find another way to initialize
public static MGeometryFactory getDefaultGeomFactory() {
configure();
return defaultGeomFactory;
}
// Helper methods
private static Set<String> providerNamesFromReader(InputStream is)
throws IOException {
PropertyFileReader reader = new PropertyFileReader( is );
return reader.getNonCommentLines();
}
}

View File

@ -30,7 +30,6 @@ package org.hibernate.spatial.criterion;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.criterion.CriteriaQuery;
@ -39,7 +38,7 @@ import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.TypedValue;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.helper.EnvelopeAdapter;
import org.hibernate.spatial.jts.EnvelopeAdapter;
/**
* An implementation for a simple spatial filter. This <code>Criterion</code>
@ -63,7 +62,7 @@ public class SpatialFilter implements Criterion {
public SpatialFilter(String propertyName, Envelope envelope, int SRID) {
this.propertyName = propertyName;
this.filter = EnvelopeAdapter.toPolygon( envelope, SRID );
this.filter = EnvelopeAdapter.toPolygon(envelope, SRID);
}

View File

@ -1,29 +1,20 @@
package org.hibernate.spatial.dialect.oracle;
import com.vividsolutions.jts.algorithm.CGAlgorithms;
import com.vividsolutions.jts.geom.*;
import org.hibernate.HibernateException;
import org.hibernate.spatial.jts.JTS;
import org.hibernate.spatial.helper.FinderException;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.WrapperOptions;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import com.vividsolutions.jts.algorithm.CGAlgorithms;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryCollection;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.MultiLineString;
import com.vividsolutions.jts.geom.MultiPoint;
import com.vividsolutions.jts.geom.MultiPolygon;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
import org.hibernate.HibernateException;
import org.hibernate.spatial.HBSpatialExtension;
import org.hibernate.spatial.helper.FinderException;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.WrapperOptions;
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: 8/22/11
@ -43,7 +34,7 @@ public class SDOGeometryValueBinder implements ValueBinder<Geometry> {
}
public MGeometryFactory getGeometryFactory() {
return HBSpatialExtension.getDefaultGeomFactory();
return JTS.getDefaultGeomFactory();
}
private Object toNative(Geometry jtsGeom, Connection connection){
@ -335,7 +326,7 @@ public class SDOGeometryValueBinder implements ValueBinder<Geometry> {
* @return the lrs position for the SDOGeometry.SDOGType
*/
private int getCoordinateLrsPosition(Geometry geom) {
MCoordinate c = MCoordinate.convertCoordinate( geom.getCoordinate() );
MCoordinate c = MCoordinate.convertCoordinate(geom.getCoordinate());
int measurePos = 0;
if (c != null && !Double.isNaN(c.m)) {
measurePos = (Double.isNaN(c.z)) ? 3 : 4;

View File

@ -19,10 +19,10 @@ import com.vividsolutions.jts.geom.Polygon;
import org.hibernate.HibernateException;
import org.hibernate.spatial.Circle;
import org.hibernate.spatial.HBSpatialExtension;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.mgeom.MLineString;
import org.hibernate.spatial.jts.JTS;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MLineString;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
@ -40,7 +40,7 @@ public class SDOGeometryValueExtractor implements ValueExtractor<Geometry> {
}
public MGeometryFactory getGeometryFactory() {
return HBSpatialExtension.getDefaultGeomFactory();
return JTS.getDefaultGeomFactory();
}
public Geometry toJTS(Object struct) {
@ -485,7 +485,7 @@ public class SDOGeometryValueExtractor implements ValueExtractor<Geometry> {
mcoord[lastIndex] = MCoordinate.create2dWithMeasure( x3, y3, m3 );
// convert the middle coordinates to MCoordinate
for ( int i = 1; i < lastIndex; i++ ) {
mcoord[i] = MCoordinate.convertCoordinate( coords[i] );
mcoord[i] = MCoordinate.convertCoordinate(coords[i]);
// if we happen to split on the middle measure, then
// assign it
if ( Double.compare( mcoord[i].x, x2 ) == 0

View File

@ -8,6 +8,7 @@ import java.sql.Types;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import org.hibernate.spatial.jts.JTS;
import org.postgis.GeometryCollection;
import org.postgis.LineString;
import org.postgis.LinearRing;
@ -18,10 +19,9 @@ import org.postgis.PGgeometry;
import org.postgis.Point;
import org.postgis.Polygon;
import org.hibernate.spatial.HBSpatialExtension;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.mgeom.MGeometry;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MGeometry;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.WrapperOptions;
@ -45,7 +45,7 @@ public class PGGeometryValueBinder implements ValueBinder<Geometry> {
}
public MGeometryFactory getGeometryFactory() {
return HBSpatialExtension.getDefaultGeomFactory();
return JTS.getDefaultGeomFactory();
}
@ -101,7 +101,7 @@ public class PGGeometryValueBinder implements ValueBinder<Geometry> {
if ( forced.isEmpty() ) {
GeometryFactory factory = jtsGeom.getFactory();
if ( factory == null ) {
factory = HBSpatialExtension.getDefaultGeomFactory();
factory = JTS.getDefaultGeomFactory();
}
forced = factory.createGeometryCollection( null );
forced.setSRID( jtsGeom.getSRID() );
@ -197,7 +197,7 @@ public class PGGeometryValueBinder implements ValueBinder<Geometry> {
);
}
MultiLineString mls = new MultiLineString( lines );
if ( string instanceof MGeometry ) {
if ( string instanceof MGeometry) {
mls.haveMeasure = true;
}
mls.setSrid( string.getSRID() );

View File

@ -5,6 +5,7 @@ import java.sql.SQLException;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.spatial.jts.JTS;
import org.postgis.GeometryCollection;
import org.postgis.MultiLineString;
import org.postgis.MultiPoint;
@ -14,10 +15,9 @@ import org.postgis.PGgeometry;
import org.postgis.Point;
import org.postgis.Polygon;
import org.hibernate.spatial.HBSpatialExtension;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.mgeom.MLineString;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MLineString;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
@ -34,7 +34,7 @@ public class PGGeometryValueExtractor implements ValueExtractor<Geometry> {
}
public MGeometryFactory getGeometryFactory() {
return HBSpatialExtension.getDefaultGeomFactory();
return JTS.getDefaultGeomFactory();
}
public Geometry toJTS(Object object) {
@ -263,9 +263,9 @@ public class PGGeometryValueExtractor implements ValueExtractor<Geometry> {
pt.getX(), pt
.getY(), pt.getZ(), pt.getM()
) : MCoordinate.create3d(
pt
.getX(), pt.getY(), pt.getZ()
);
pt
.getX(), pt.getY(), pt.getZ()
);
}
return mc;
}

View File

@ -7,9 +7,9 @@ import java.sql.Types;
import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.spatial.HBSpatialExtension;
import org.hibernate.spatial.jts.JTS;
import org.hibernate.spatial.dialect.sqlserver.convertors.Encoders;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.WrapperOptions;
@ -33,7 +33,7 @@ public class SqlServer2008GeometryValueBinder implements ValueBinder<Geometry> {
}
public MGeometryFactory getGeometryFactory() {
return HBSpatialExtension.getDefaultGeomFactory();
return JTS.getDefaultGeomFactory();
}
public Object toNative(Geometry geom, Connection connection) {

View File

@ -6,9 +6,9 @@ import java.sql.SQLException;
import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.spatial.HBSpatialExtension;
import org.hibernate.spatial.jts.JTS;
import org.hibernate.spatial.dialect.sqlserver.convertors.Decoders;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
@ -25,7 +25,7 @@ public class SqlServer2008GeometryValueExtractor implements ValueExtractor<Geome
}
public MGeometryFactory getGeometryFactory() {
return HBSpatialExtension.getDefaultGeomFactory();
return JTS.getDefaultGeomFactory();
}
public Geometry toJTS(Object obj) {

View File

@ -27,7 +27,7 @@ package org.hibernate.spatial.dialect.sqlserver.convertors;
import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
abstract class AbstractDecoder<G extends Geometry> implements Decoder<G> {

View File

@ -31,7 +31,7 @@ import java.util.List;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.spatial.mgeom.MGeometry;
import org.hibernate.spatial.jts.mgeom.MGeometry;
abstract class AbstractEncoder<G extends Geometry> implements Encoder<G> {

View File

@ -31,7 +31,7 @@ import java.util.List;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryCollection;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
abstract class AbstractGeometryCollectionDecoder<T extends GeometryCollection> extends AbstractDecoder<T> {

View File

@ -30,8 +30,8 @@ import java.util.List;
import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.spatial.HBSpatialExtension;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.JTS;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
/**
* Decodes SQL Server Geometry objects to JTS <code>Geometry</code>s.
@ -43,7 +43,7 @@ public class Decoders {
final private static List<Decoder<? extends Geometry>> DECODERS = new ArrayList<Decoder<? extends Geometry>>();
static {
MGeometryFactory factory = HBSpatialExtension.getDefaultGeomFactory();
MGeometryFactory factory = JTS.getDefaultGeomFactory();
//Decoders
DECODERS.add( new PointDecoder( factory ) );

View File

@ -30,7 +30,7 @@ import java.util.List;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryCollection;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
/**
* <code>Decoder</code> for GeometryCollections.

View File

@ -29,8 +29,8 @@ import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateSequence;
import com.vividsolutions.jts.geom.LineString;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
class LineStringDecoder extends AbstractDecoder<LineString> {

View File

@ -31,8 +31,8 @@ import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.MultiLineString;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.mgeom.MLineString;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MLineString;
class MultiLineStringDecoder extends AbstractGeometryCollectionDecoder<MultiLineString> {

View File

@ -31,7 +31,7 @@ import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.MultiPoint;
import com.vividsolutions.jts.geom.Point;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
/**
* <code>Decoder</code> for GeometryCollections.

View File

@ -28,7 +28,7 @@ package org.hibernate.spatial.dialect.sqlserver.convertors;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.MultiPoint;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
class MultiPointEncoder extends GeometryCollectionEncoder<MultiPoint> {

View File

@ -31,7 +31,7 @@ import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.MultiPolygon;
import com.vividsolutions.jts.geom.Polygon;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
class MultiPolygonDecoder extends AbstractGeometryCollectionDecoder<MultiPolygon> {

View File

@ -28,7 +28,7 @@ package org.hibernate.spatial.dialect.sqlserver.convertors;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Point;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
/**
* @author Karel Maesen, Geovise BVBA.

View File

@ -31,7 +31,7 @@ import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Point;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
/**
* @author Karel Maesen, Geovise BVBA.

View File

@ -29,7 +29,7 @@ import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.Polygon;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
/**
* @author Karel Maesen, Geovise BVBA

View File

@ -30,7 +30,7 @@ import java.nio.ByteOrder;
import com.vividsolutions.jts.geom.Coordinate;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
/**
* A <code>SqlServerGeometry</code> represents the native SQL Server database object.

View File

@ -1,99 +0,0 @@
/*
* $Id: GeometryFactoryHelper.java 200 2010-03-31 19:52:12Z maesenka $
*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for geographic data.
*
* Copyright © 2007-2010 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
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.helper;
import java.util.Map;
import com.vividsolutions.jts.geom.PrecisionModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.spatial.cfg.HSProperty;
import org.hibernate.spatial.mgeom.MGeometryFactory;
/**
* Factory for creating a <code>GeometryFactory</code> given a map of
* configuration parameters.
*
* @author Karel Maesen, Geovise BVBA
*/
public class GeometryFactoryHelper {
private static Logger logger = LoggerFactory.getLogger( GeometryFactoryHelper.class );
public static MGeometryFactory createGeometryFactory(Map map) {
if ( map == null ) {
return new MGeometryFactory();
}
String precisionModelName = null;
Double scale = null;
if ( map.containsKey( HSProperty.PRECISION_MODEL.toString() ) ) {
precisionModelName = (String) map.get(
HSProperty.PRECISION_MODEL
.toString()
);
}
if ( map.containsKey( HSProperty.PRECISION_MODEL_SCALE.toString() ) ) {
scale = Double.parseDouble(
( (String) map
.get( HSProperty.PRECISION_MODEL_SCALE.toString() ) )
);
}
if ( scale != null && !scale.isNaN() && precisionModelName != null
&& precisionModelName.equalsIgnoreCase( "FIXED" ) ) {
return new MGeometryFactory( new PrecisionModel( scale ) );
}
if ( precisionModelName == null ) {
return new MGeometryFactory();
}
if ( precisionModelName.equalsIgnoreCase( "FIXED" ) ) {
return new MGeometryFactory(
new PrecisionModel( PrecisionModel.FIXED )
);
}
if ( precisionModelName.equalsIgnoreCase( "FLOATING" ) ) {
return new MGeometryFactory(
new PrecisionModel(
PrecisionModel.FLOATING
)
);
}
if ( precisionModelName.equalsIgnoreCase( "FLOATING_SINGLE" ) ) {
return new MGeometryFactory(
new PrecisionModel(
PrecisionModel.FLOATING_SINGLE
)
);
}
logger.warn(
"Configured for PrecisionModel: " + precisionModelName
+ " but don't know how to instantiate."
);
logger.warn( "Reverting to default GeometryModel" );
return new MGeometryFactory();
}
}

View File

@ -1,27 +0,0 @@
package org.hibernate.spatial.helper;
import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.type.Type;
/**
* This <code>FinderStrategy</code> implementation returns the first
* geometry-valued property.
*/
public class GeometryPropertyFinder implements FinderStrategy<String, ClassMetadata> {
public String find(ClassMetadata metadata) throws FinderException {
for ( String prop : metadata.getPropertyNames() ) {
Type type = metadata.getPropertyType( prop );
if ( Geometry.class.isAssignableFrom( type.getReturnedClass() ) ) {
return prop;
}
}
throw new FinderException(
"Could not find a Geometry-valued property in "
+ metadata.getEntityName()
);
}
}

View File

@ -26,7 +26,7 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.helper;
package org.hibernate.spatial.jts;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;

View File

@ -1,5 +1,5 @@
/**
* $Id: HibernateSpatialException.java 54 2007-11-12 21:16:42Z maesenka $
* $Id: JTS.java 253 2010-10-02 15:14:52Z maesenka $
*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for geographic data.
@ -26,30 +26,31 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial;
package org.hibernate.spatial.jts;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Exception for Hibernate Spatial
* A static utility class
*
* @author Karel Maesen
*/
public class HibernateSpatialException extends RuntimeException {
public class JTS {
private static final Logger log = LoggerFactory.getLogger( JTS.class );
private static MGeometryFactory defaultGeomFactory = new MGeometryFactory();
/**
* generated serialVersionUID
* Make sure nobody can instantiate this class
*/
private static final long serialVersionUID = -2153256823661407568L;
public HibernateSpatialException(String msg) {
super( msg );
private JTS() {
}
public HibernateSpatialException(Throwable cause) {
super( cause );
}
public HibernateSpatialException(String msg, Throwable cause) {
super( msg, cause );
public static MGeometryFactory getDefaultGeomFactory() {
return defaultGeomFactory;
}
}

View File

@ -22,7 +22,7 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
/**
* This utility class is used to testsuite-suite doubles for equality

View File

@ -22,7 +22,7 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
import java.util.ArrayList;
import java.util.List;

View File

@ -26,7 +26,7 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateSequence;

View File

@ -26,7 +26,7 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
import java.io.Serializable;

View File

@ -26,7 +26,7 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
import java.io.Serializable;

View File

@ -26,7 +26,7 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
import java.io.Serializable;

View File

@ -26,7 +26,7 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
/**
* @author Karel Maesen

View File

@ -26,7 +26,7 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
import com.vividsolutions.jts.geom.CoordinateSequence;
import com.vividsolutions.jts.geom.GeometryFactory;

View File

@ -26,19 +26,13 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
import com.vividsolutions.jts.geom.*;
import java.util.ArrayList;
import java.util.List;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateArrays;
import com.vividsolutions.jts.geom.CoordinateSequence;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineSegment;
import com.vividsolutions.jts.geom.LineString;
/**
* An implementation of the LineString class with the addition that the
* containing CoordinateSequence can carry measure. Note that this is not a
@ -256,11 +250,11 @@ public class MLineString extends LineString implements MGeometry {
else {
double[] measures = this.getMeasures();
if ( this.getMeasureDirection() == MGeometry.INCREASING ) {
if ( this.getMeasureDirection() == INCREASING) {
return measures[measures.length - 1];
}
else if ( this.getMeasureDirection() == MGeometry.DECREASING
|| this.getMeasureDirection() == MGeometry.CONSTANT ) {
else if ( this.getMeasureDirection() == DECREASING
|| this.getMeasureDirection() == CONSTANT) {
return measures[0];
}
else {
@ -306,7 +300,7 @@ public class MLineString extends LineString implements MGeometry {
sseq.firstIndex = i;
}
}
if ( direction == MGeometry.INCREASING ) {
if ( direction == INCREASING) {
if ( m > toM ) {
break;
}
@ -393,7 +387,7 @@ public class MLineString extends LineString implements MGeometry {
private void addInterpolatedEndPoints(double fromM, double toM, MCoordinate[] mcoordinates, CoordinateSubSequence subsequence) {
boolean increasing = this.getMeasureDirection() == MGeometry.INCREASING;
boolean increasing = this.getMeasureDirection() == INCREASING;
double fM, lM;
if ( increasing ) {
fM = fromM;
@ -465,20 +459,20 @@ public class MLineString extends LineString implements MGeometry {
*/
public int getMeasureDirection() {
if ( !this.monotone ) {
return MGeometry.NON_MONOTONE;
return NON_MONOTONE;
}
MCoordinate c1 = (MCoordinate) this.getCoordinateN( 0 );
MCoordinate c2 = (MCoordinate) this
.getCoordinateN( this.getNumPoints() - 1 );
if ( c1.m < c2.m ) {
return MGeometry.INCREASING;
return INCREASING;
}
else if ( c1.m > c2.m ) {
return MGeometry.DECREASING;
return DECREASING;
}
else {
return MGeometry.CONSTANT;
return CONSTANT;
}
}
@ -507,11 +501,11 @@ public class MLineString extends LineString implements MGeometry {
}
else {
double[] a = this.getMeasures();
if ( this.getMeasureDirection() == MGeometry.INCREASING ) {
if ( this.getMeasureDirection() == INCREASING) {
return a[0];
}
else if ( this.getMeasureDirection() == MGeometry.DECREASING
|| this.getMeasureDirection() == MGeometry.CONSTANT ) {
else if ( this.getMeasureDirection() == DECREASING
|| this.getMeasureDirection() == CONSTANT) {
return a[a.length - 1];
}
else {
@ -712,11 +706,11 @@ public class MLineString extends LineString implements MGeometry {
);
}
Coordinate[] linecoar = l.getCoordinates();
if ( l.getMeasureDirection() == MGeometry.DECREASING ) {
if ( l.getMeasureDirection() == DECREASING) {
CoordinateArrays.reverse( linecoar );
}
Coordinate[] thiscoar = this.getCoordinates();
if ( this.getMeasureDirection() == MGeometry.DECREASING ) {
if ( this.getMeasureDirection() == DECREASING) {
CoordinateArrays.reverse( thiscoar );
}

View File

@ -22,7 +22,7 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateSequence;
@ -65,7 +65,7 @@ public class MultiMLineString extends MultiLineString implements MGeometry {
if ( this.isEmpty() ) {
return;
}
int mdir = MGeometry.CONSTANT;
int mdir = CONSTANT;
for ( int i = 0; i < this.geometries.length; i++ ) {
MLineString ml = (MLineString) this.geometries[0];
if ( !ml.isEmpty() ) {
@ -83,7 +83,7 @@ public class MultiMLineString extends MultiLineString implements MGeometry {
// are monotone
if ( !ml.isMonotone( false )
|| ( ml.getMeasureDirection() != mdir && !( ml
.getMeasureDirection() == MGeometry.CONSTANT ) ) ) {
.getMeasureDirection() == CONSTANT) ) ) {
this.monotone = false;
break;
}
@ -97,7 +97,7 @@ public class MultiMLineString extends MultiLineString implements MGeometry {
// are inconsistent with previous parts
if ( i > 0 ) {
MLineString mlp = (MLineString) this.geometries[i - 1];
if ( mdir == MGeometry.INCREASING ) {
if ( mdir == INCREASING) {
if ( mlp.getMaxM() > ml.getMinM() ) {
monotone = false;
}

View File

@ -1,71 +0,0 @@
/*
* $Id: SpatialDialectProvider.java 200 2010-03-31 19:52:12Z maesenka $
*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for geographic data.
*
* Copyright © 2007-2010 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
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.spi;
import org.hibernate.spatial.SpatialDialect;
/**
* Interface that is implemented by a SpatialDialect Provider.
* <p/>
* A <class>SpatialDialectProvider</class> creates a SpatialDialect for one or
* more database systems. These databases are identified by a dialect string.
* Usually this is the fully qualified class name of a
* <code>org.hibernate.dialect.Dialect</code> or <code>SpatialDialect</code>
* implementation
*
* @author Karel Maesen, Geovise BVBA
*/
public interface SpatialDialectProvider {
/**
* create Spatial Dialect with the provided name.
*
* @param dialect Name of the dialect to create.
*
* @return a SpatialDialect
*/
public SpatialDialect createSpatialDialect(String dialect);
/**
* Returns the default dialect for this provider.
*
* @return The Default Dialect provided by the implementation.
* <p/>
* Implementations should never return null for this method.
*/
public SpatialDialect getDefaultDialect();
/**
* Returns the Dialect names
* <p/>
* This method must return the canonical class names of the Spatialdialect
* implementations that this provider provides.
*
* @return array of dialect names.
*/
public String[] getSupportedDialects();
}

View File

@ -61,9 +61,9 @@ import com.vividsolutions.jts.geom.PrecisionModel;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.util.Assert;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.mgeom.MLineString;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MLineString;
/**
* Converts a geometry in EWKT to a JTS-Geometry.

View File

@ -29,7 +29,7 @@ import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryCollection;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
/**
* This class tests for the equality between geometries.

View File

@ -29,7 +29,7 @@ import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.LineString;
import org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect;
import org.hibernate.spatial.dialect.sqlserver.convertors.OpenGisType;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
import org.hibernate.testing.BeforeClassOnce;
import org.hibernate.testing.RequiresDialect;
import org.junit.Test;

View File

@ -29,7 +29,7 @@ import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Point;
import org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect;
import org.hibernate.spatial.dialect.sqlserver.convertors.OpenGisType;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
import org.hibernate.testing.BeforeClassOnce;
import org.hibernate.testing.RequiresDialect;
import org.junit.Test;

View File

@ -26,7 +26,7 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateSequence;

View File

@ -26,7 +26,7 @@
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateSequence;

View File

@ -23,20 +23,20 @@
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.PrecisionModel;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.spatial.mgeom.EventLocator;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.mgeom.MCoordinateSequenceFactory;
import org.hibernate.spatial.mgeom.MGeometryException;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.mgeom.MLineString;
import org.hibernate.spatial.mgeom.MultiMLineString;
import org.hibernate.spatial.jts.mgeom.EventLocator;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MCoordinateSequenceFactory;
import org.hibernate.spatial.jts.mgeom.MGeometryException;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MLineString;
import org.hibernate.spatial.jts.mgeom.MultiMLineString;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

View File

@ -23,7 +23,7 @@
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernate.spatial.mgeom;
package org.hibernate.spatial.jts.mgeom;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateSequence;
@ -31,11 +31,11 @@ import com.vividsolutions.jts.geom.PrecisionModel;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.spatial.mgeom.MCoordinate;
import org.hibernate.spatial.mgeom.MCoordinateSequenceFactory;
import org.hibernate.spatial.mgeom.MGeometryException;
import org.hibernate.spatial.mgeom.MGeometryFactory;
import org.hibernate.spatial.mgeom.MLineString;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MCoordinateSequenceFactory;
import org.hibernate.spatial.jts.mgeom.MGeometryException;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MLineString;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;