diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/HSMessageLogger.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/HSMessageLogger.java index 551f899c9d..1338e6fa28 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/HSMessageLogger.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/HSMessageLogger.java @@ -41,7 +41,10 @@ public interface HSMessageLogger extends BasicLogger { void connectionFinder(String className); @LogMessage(level = INFO) //maybe should be DEBUG? - @Message(value = "hibernate-spatial using type contributions from : %s", id = 80000003) + @Message(value = "hibernate-spatial adding type contributions from : %s", id = 80000003) void typeContributions(String source); + @LogMessage(level = INFO) //maybe should be DEBUG? + @Message(value = "hibernate-spatial adding function contributions from : %s", id = 80000004) + void functionContributions(String source); } diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/type/SpatialTypeContributorImplementor.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/ContributorImplementor.java similarity index 59% rename from hibernate-spatial/src/main/java/org/hibernate/spatial/type/SpatialTypeContributorImplementor.java rename to hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/ContributorImplementor.java index 0543de09f7..36b4d445b2 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/type/SpatialTypeContributorImplementor.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/ContributorImplementor.java @@ -5,23 +5,26 @@ * See the lgpl.txt file in the root directory or . */ -package org.hibernate.spatial.type; +package org.hibernate.spatial.contributor; +import org.hibernate.boot.model.FunctionContributions; import org.hibernate.boot.model.TypeContributions; +import org.hibernate.boot.model.TypeContributor; import org.hibernate.service.ServiceRegistry; /** * Internal contract for TypeContributor */ -abstract class SpatialTypeContributorImplementor { +abstract class ContributorImplementor { private final ServiceRegistry serviceRegistryegistry; - SpatialTypeContributorImplementor(ServiceRegistry serviceRegistry) { + ContributorImplementor(ServiceRegistry serviceRegistry) { this.serviceRegistryegistry = serviceRegistry; } - abstract void contribute(TypeContributions typeContributions); + abstract void contributeTypes(TypeContributions typeContributions); + abstract void contributeFunctions(FunctionContributions functionContributions); ServiceRegistry getServiceRegistryegistry() { return serviceRegistryegistry; diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/ContributorResolver.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/ContributorResolver.java new file mode 100644 index 0000000000..3155937a0e --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/ContributorResolver.java @@ -0,0 +1,44 @@ +/* + * 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 . + */ + +package org.hibernate.spatial.contributor; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.PostgreSQLDialect; +import org.hibernate.engine.jdbc.spi.JdbcServices; +import org.hibernate.service.ServiceRegistry; + +class ContributorResolver { + + private final static Map, + Function> ContributorMap = new HashMap<>(); + + + static { + //TypeContributorImplementor + ContributorMap.put( PostgreSQLDialect.class, PostgreSQLDialectContributor::new ); + } + + private ContributorResolver() { + } + + static ContributorImplementor resolveSpatialtypeContributorImplementor(ServiceRegistry serviceRegistry) { + JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); + Dialect dialect = jdbcServices.getDialect(); + for ( Class dialectClass : ContributorMap.keySet() ) { + if ( dialectClass.isAssignableFrom( dialect.getClass() ) ) { + return ContributorMap.get( dialectClass ).apply( serviceRegistry ); + } + } + return null; + } + +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/type/PostgreSQLDialectTypeContributor.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/PostgreSQLDialectContributor.java similarity index 63% rename from hibernate-spatial/src/main/java/org/hibernate/spatial/type/PostgreSQLDialectTypeContributor.java rename to hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/PostgreSQLDialectContributor.java index 7f4ddffe26..7711998b46 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/type/PostgreSQLDialectTypeContributor.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/PostgreSQLDialectContributor.java @@ -12,9 +12,13 @@ * See the lgpl.txt file in the root directory or . */ -package org.hibernate.spatial.type; +package org.hibernate.spatial.contributor; +import java.util.Map; + +import org.hibernate.boot.model.FunctionContributions; import org.hibernate.boot.model.TypeContributions; +import org.hibernate.query.sqm.function.SqmFunctionDescriptor; import org.hibernate.service.ServiceRegistry; import org.hibernate.spatial.GeolatteGeometryJavaTypeDescriptor; import org.hibernate.spatial.GeolatteGeometryType; @@ -22,14 +26,15 @@ import org.hibernate.spatial.HSMessageLogger; import org.hibernate.spatial.JTSGeometryJavaTypeDescriptor; import org.hibernate.spatial.JTSGeometryType; import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor; +import org.hibernate.spatial.dialect.postgis.PostgisFunctions; -public class PostgreSQLDialectTypeContributor extends SpatialTypeContributorImplementor{ +public class PostgreSQLDialectContributor extends ContributorImplementor { - PostgreSQLDialectTypeContributor(ServiceRegistry serviceRegistry) { + PostgreSQLDialectContributor(ServiceRegistry serviceRegistry) { super( serviceRegistry ); } - public void contribute(TypeContributions typeContributions) { + public void contributeTypes(TypeContributions typeContributions) { HSMessageLogger.LOGGER.typeContributions( this.getClass().getCanonicalName() ); typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_1 ) ); typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_1 ) ); @@ -38,4 +43,13 @@ public class PostgreSQLDialectTypeContributor extends SpatialTypeContributorImpl typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE ); typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE ); } + + @Override + void contributeFunctions(FunctionContributions functionContributions) { + HSMessageLogger.LOGGER.functionContributions( this.getClass().getCanonicalName() ); + PostgisFunctions functions = new PostgisFunctions(); + for( Map.Entry kv: functions) { + functionContributions.contributeFunction( kv.getKey(), kv.getValue() ); + } + } } diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/SpatialFunctionContributor.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/SpatialFunctionContributor.java new file mode 100644 index 0000000000..d18f9a5de1 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/SpatialFunctionContributor.java @@ -0,0 +1,26 @@ +/* + * 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 . + */ + +package org.hibernate.spatial.contributor; + +import org.hibernate.boot.model.FunctionContributions; +import org.hibernate.boot.model.FunctionContributor; +import org.hibernate.service.ServiceRegistry; + +public class SpatialFunctionContributor implements FunctionContributor { + + @Override + public void contributeTypes( + FunctionContributions functionContributions, ServiceRegistry serviceRegistry) { + ContributorImplementor contributorImplementor = ContributorResolver.resolveSpatialtypeContributorImplementor( + serviceRegistry ); + + if ( contributorImplementor != null ) { + contributorImplementor.contributeFunctions( functionContributions ); + } + } +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/type/SpatialTypeContributor.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/SpatialTypeContributor.java similarity index 72% rename from hibernate-spatial/src/main/java/org/hibernate/spatial/type/SpatialTypeContributor.java rename to hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/SpatialTypeContributor.java index 6e356a035b..6a41885e36 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/type/SpatialTypeContributor.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/contributor/SpatialTypeContributor.java @@ -5,7 +5,7 @@ * See the lgpl.txt file in the root directory or . */ -package org.hibernate.spatial.type; +package org.hibernate.spatial.contributor; import org.hibernate.boot.model.TypeContributions; import org.hibernate.boot.model.TypeContributor; @@ -15,10 +15,10 @@ public class SpatialTypeContributor implements TypeContributor { @Override public void contribute( TypeContributions typeContributions, ServiceRegistry serviceRegistry) { - SpatialTypeContributorImplementor contributorImplementor = TypeContributorResolver.resolve( serviceRegistry ); + ContributorImplementor contributorImplementor = ContributorResolver.resolveSpatialtypeContributorImplementor( serviceRegistry ); if (contributorImplementor != null) { - contributorImplementor.contribute( typeContributions ); + contributorImplementor.contributeTypes( typeContributions ); } } diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PGGeometryTypeDescriptor.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PGGeometryTypeDescriptor.java index 706543f6d2..5693a3af41 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PGGeometryTypeDescriptor.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PGGeometryTypeDescriptor.java @@ -11,6 +11,7 @@ import java.sql.CallableStatement; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Types; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueExtractor; @@ -76,6 +77,8 @@ public class PGGeometryTypeDescriptor implements JdbcTypeDescriptor { return decoder.decode( pgValue ); } + + @Override public int getJdbcType() { return 5432; @@ -103,9 +106,20 @@ public class PGGeometryTypeDescriptor implements JdbcTypeDescriptor { st.setObject( name, obj ); } + //this and the next override is ONLY necessary as long as the distinction between SQLType and JDBC Type is not resolved + @Override + protected void doBindNull(PreparedStatement st, int index, WrapperOptions options) throws SQLException { + st.setNull( index, Types.OTHER ); + } + + @Override + protected void doBindNull(CallableStatement st, String name, WrapperOptions options) throws SQLException { + st.setNull( name, Types.OTHER ); + } + private PGobject toPGobject(X value, WrapperOptions options) throws SQLException { final WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.POSTGIS_EWKB_1 ); - final Geometry geometry = getJavaTypeDescriptor().unwrap( value, Geometry.class, options ); + final Geometry geometry = getJavaTypeDescriptor().unwrap( value, Geometry.class, options ); final String hexString = encoder.encode( geometry, ByteOrder.NDR ).toString(); final PGobject obj = new PGobject(); obj.setType( "geometry" ); diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/type/TypeContributorResolver.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/type/TypeContributorResolver.java deleted file mode 100644 index b1c09b707e..0000000000 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/type/TypeContributorResolver.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 . - */ - -package org.hibernate.spatial.type; - -import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.PostgreSQLDialect; -import org.hibernate.engine.jdbc.spi.JdbcServices; -import org.hibernate.service.ServiceRegistry; - -class TypeContributorResolver { - - private TypeContributorResolver() { - } - - static SpatialTypeContributorImplementor resolve(ServiceRegistry serviceRegistry) { - JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); - Dialect dialect = jdbcServices.getDialect(); - if ( dialect.getClass().isAssignableFrom( PostgreSQLDialect.class ) ) { - return new PostgreSQLDialectTypeContributor( serviceRegistry ); - } - return null; - } - -} diff --git a/hibernate-spatial/src/main/resources/META-INF/services/org.hibernate.boot.model.FunctionContributor b/hibernate-spatial/src/main/resources/META-INF/services/org.hibernate.boot.model.FunctionContributor new file mode 100644 index 0000000000..4707b1bba4 --- /dev/null +++ b/hibernate-spatial/src/main/resources/META-INF/services/org.hibernate.boot.model.FunctionContributor @@ -0,0 +1,8 @@ +# +# 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 . +# + +org.hibernate.spatial.contributor.SpatialFunctionContributor \ No newline at end of file diff --git a/hibernate-spatial/src/main/resources/META-INF/services/org.hibernate.boot.model.TypeContributor b/hibernate-spatial/src/main/resources/META-INF/services/org.hibernate.boot.model.TypeContributor index 1204a5fefb..9d2d1d209a 100644 --- a/hibernate-spatial/src/main/resources/META-INF/services/org.hibernate.boot.model.TypeContributor +++ b/hibernate-spatial/src/main/resources/META-INF/services/org.hibernate.boot.model.TypeContributor @@ -5,4 +5,4 @@ # See the lgpl.txt file in the root directory or . # -org.hibernate.spatial.type.SpatialTypeContributor \ No newline at end of file +org.hibernate.spatial.contributor.SpatialTypeContributor \ No newline at end of file diff --git a/hibernate-spatial/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/hibernate-spatial/src/main/resources/OSGI-INF/blueprint/blueprint.xml index ac51b6addc..8e49886b56 100644 --- a/hibernate-spatial/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/hibernate-spatial/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -12,5 +12,9 @@ + + + + diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestGeolatteSpatialPredicates.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestGeolatteSpatialPredicates.java index 388cd7eca9..d6929e62ac 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestGeolatteSpatialPredicates.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestGeolatteSpatialPredicates.java @@ -40,6 +40,7 @@ import static org.junit.Assert.fail; */ @Skip(condition = SpatialDialectMatcher.class, message = "No Spatial Dialect") @SkipForDialect(value = HANASpatialDialect.class, comment = "The HANA dialect is tested via org.hibernate.spatial.dialect.hana.TestHANASpatialFunctions", jiraKey = "HHH-12426") +@Deprecated public class TestGeolatteSpatialPredicates extends SpatialFunctionalTestCase { private static final HSMessageLogger LOG = Logger.getMessageLogger( diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestJTSSpatialPredicates.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestJTSSpatialPredicates.java index c2b78ba7eb..dbed973f11 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestJTSSpatialPredicates.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestJTSSpatialPredicates.java @@ -36,6 +36,7 @@ import static org.junit.Assert.fail; @Skip(condition = SpatialDialectMatcher.class, message = "No Spatial Dialect") @SkipForDialect(value = HANASpatialDialect.class, comment = "The HANA dialect is tested via org.hibernate.spatial.dialect.hana.TestHANASpatialFunctions", jiraKey = "HHH-12426") +@Deprecated public class TestJTSSpatialPredicates extends SpatialFunctionalTestCase { private static final HSMessageLogger LOG = Logger.getMessageLogger( diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestSpatialFunctions.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestSpatialFunctions.java index fa83adf5b0..3c0b6a79e6 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestSpatialFunctions.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestSpatialFunctions.java @@ -36,7 +36,7 @@ import static java.lang.String.format; /** * @author Karel Maesen, Geovise BVBA */ -@Skip(condition = SpatialDialectMatcher.class, message = "No Spatial Dialect") +@Deprecated public class TestSpatialFunctions extends SpatialFunctionalTestCase { private static final HSMessageLogger LOG = Logger.getMessageLogger( diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/jts/hhh14523/DirtyCheckingTest.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/jts/hhh14523/DirtyCheckingTest.java index 0516ecb738..98380747b4 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/jts/hhh14523/DirtyCheckingTest.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/jts/hhh14523/DirtyCheckingTest.java @@ -19,6 +19,7 @@ import javax.persistence.Query; import javax.persistence.SequenceGenerator; import javax.persistence.Table; +import org.hibernate.dialect.PostgreSQLDialect; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect; @@ -34,7 +35,7 @@ import org.locationtech.jts.geom.Point; import static org.junit.Assert.assertEquals; @TestForIssue(jiraKey = "HHH-14523") -@RequiresDialect(PostgisPG95Dialect.class) +@RequiresDialect(PostgreSQLDialect.class) public class DirtyCheckingTest extends BaseEntityManagerFunctionalTestCase { private GeometryFactory gfact = new GeometryFactory(); diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/SpatialDialectMatcher.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/SpatialDialectMatcher.java index 9628d71fc8..0e5c91e328 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/SpatialDialectMatcher.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/SpatialDialectMatcher.java @@ -15,7 +15,10 @@ import org.hibernate.testing.Skip; /** * @author Karel Maesen, Geovise BVBA * creation-date: 1/13/12 + * + * @deprecated Since we no longer require SpatialDialects */ +@Deprecated public class SpatialDialectMatcher implements Skip.Matcher { @Override public boolean isMatch() { diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/SpatialFunctionalTestCase.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/SpatialFunctionalTestCase.java index ce4528b7e4..7a6bd25c97 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/SpatialFunctionalTestCase.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/SpatialFunctionalTestCase.java @@ -165,7 +165,7 @@ public abstract class SpatialFunctionalTestCase extends BaseCoreFunctionalTestCa */ public boolean isSupportedByDialect(SpatialFunction spatialFunction) { Dialect dialect = getDialect(); - throw new NotYetImplementedException(); + return true; } diff --git a/hibernate-spatial/src/test/resources/hibernate.properties b/hibernate-spatial/src/test/resources/hibernate.properties index 5233faa4fb..aeb9782231 100644 --- a/hibernate-spatial/src/test/resources/hibernate.properties +++ b/hibernate-spatial/src/test/resources/hibernate.properties @@ -6,17 +6,21 @@ # See the lgpl.txt file in the root directory or . # # Default unit/integration test config. +hibernate.dialect @db.dialect@ +hibernate.connection.driver_class @jdbc.driver@ +hibernate.connection.url @jdbc.url@ +hibernate.connection.username @jdbc.user@ +hibernate.connection.password @jdbc.pass@ -hibernate.show_sql=true -hibernate.max_fetch_depth=5 -hibernate.dialect=@db.dialect@ -hibernate.connection.driver_class=@jdbc.driver@ -hibernate.connection.url=@jdbc.url@ -hibernate.connection.username=@jdbc.user@ -hibernate.connection.password=@jdbc.pass@ -hibernate.connection.init_sql @connection.init_sql@ -#hibernate.cache.region_prefix hibernate.test -#hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory +hibernate.connection.pool_size 5 + +hibernate.show_sql false +hibernate.format_sql true + +hibernate.max_fetch_depth 5 + +hibernate.cache.region_prefix hibernate.test +hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory # ## NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle #hibernate.jdbc.batch_versioned_data true