HHH-14800 Introduce SpatialTypeContributor

See discussion #4111
This commit is contained in:
Karel Maesen 2021-07-19 21:57:45 +02:00
parent dcf2a85d20
commit 04491e6775
31 changed files with 356 additions and 184 deletions

View File

@ -19,7 +19,7 @@ dependencies {
compile( libraries.postgresql )
testCompile(libraries.junit)
testCompile(project(':hibernate-testing'))
testCompile( project( path: ':hibernate-core', configuration: 'tests' ) )
testCompile(libraries.validation)

View File

@ -0,0 +1,34 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.type;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.spatial.GeolatteGeometryJavaTypeDescriptor;
import org.hibernate.spatial.GeolatteGeometryType;
import org.hibernate.spatial.JTSGeometryJavaTypeDescriptor;
import org.hibernate.spatial.JTSGeometryType;
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor;
public class PostgisTypeContributor implements SpatialTypeContributorImplementor{
public void contribute(TypeContributions typeContributions) {
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_1 ) );
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_1 ) );
//Isn't this redundant?
typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE );
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE );
}
}

View File

@ -0,0 +1,33 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.type;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.boot.model.TypeContributor;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.GeolatteGeometryJavaTypeDescriptor;
import org.hibernate.spatial.GeolatteGeometryType;
import org.hibernate.spatial.JTSGeometryJavaTypeDescriptor;
import org.hibernate.spatial.JTSGeometryType;
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor;
public class SpatialTypeContributor implements TypeContributor {
@Override
public void contribute(
TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_1 ) );
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_1 ) );
typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE );
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE );
}
}

View File

@ -0,0 +1,11 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.type;
public interface SpatialTypeContributorImplementor {
}

View File

@ -0,0 +1,11 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.type;
public class TypeContributorResolver {
}

View File

@ -10,39 +10,29 @@ package org.hibernate.spatial.integration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.dialect.Dialect;
import org.hibernate.query.Query;
import org.hibernate.query.criteria.JpaCriteriaQuery;
import org.hibernate.spatial.integration.geolatte.GeomEntity;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.spatial.testing.GeometryEquality;
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
import org.hibernate.spatial.testing.datareader.TestDataElement;
import org.hibernate.spatial.testing.domain.SpatialDomainModel;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import org.geolatte.geom.codec.WktDecodeException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
//import org.geolatte.geom.C3DM;
//import org.geolatte.geom.Geometry;
//import org.geolatte.geom.GeometryEquality;
//import org.geolatte.geom.GeometryPointEquality;
/**
* Created by Karel Maesen, Geovise BVBA on 15/02/2018.
*/
public abstract class AbstractTestStoreRetrieve<G, E extends GeomEntityLike<G>> extends SpatialFunctionalTestCase {
public void prepareTest() {
}
@DomainModel(modelDescriptorClasses = SpatialDomainModel.class)
@SessionFactory
public abstract class AbstractTestStoreRetrieve<G, E extends GeomEntityLike<G>>
extends SpatialTestDataProvider {
protected abstract GeometryEquality<G> getGeometryEquality();
@ -50,12 +40,26 @@ public abstract class AbstractTestStoreRetrieve<G, E extends GeomEntityLike<G>>
protected abstract E createFrom(TestDataElement element, Dialect dialect);
private Map<Integer, E> stored = new HashMap<>();
@Test
public void testAfterStoreRetrievingEqualObject() throws WktDecodeException {
Map<Integer, E> stored = new HashMap<>();
public void testStoringGeomEntity(SessionFactoryScope scope) {
//check whether we retrieve exactly what we store
storeTestObjects( stored );
retrieveAndCompare( stored );
scope.inTransaction( this::storeTestObjects );
scope.inTransaction( this::retrieveAndCompare );
}
@SuppressWarnings("unchecked")
private void retrieveAndCompare(SessionImplementor session) {
Query query = session.createQuery( "from " + this.getGeomEntityClass().getCanonicalName() );
List<E> results = (List<E>) query.getResultList();
results.stream().forEach( this::isInStored );
}
private void isInStored(E entity) {
E input = stored.get( entity.getId() );
assertEquals( entity, input );
}
@Test
@ -64,36 +68,6 @@ public abstract class AbstractTestStoreRetrieve<G, E extends GeomEntityLike<G>>
retrieveNullGeometry();
}
private void retrieveAndCompare(Map<Integer, E> stored) {
int id = -1;
Transaction tx = null;
Session session = null;
GeometryEquality<G> geomEq = getGeometryEquality();
try {
session = openSession();
tx = session.beginTransaction();
for ( E storedEntity : stored.values() ) {
id = storedEntity.getId();
E retrievedEntity = session.get( getGeomEntityClass(), id );
G retrievedGeometry = retrievedEntity.getGeom();
G storedGeometry = storedEntity.getGeom();
String msg = createFailureMessage( storedEntity.getId(), storedGeometry, retrievedGeometry );
assertTrue( msg, geomEq.test( storedGeometry, retrievedGeometry ) );
}
tx.commit();
}
catch (Exception e) {
if ( tx != null ) {
tx.rollback();
}
throw new RuntimeException( String.format( "Failure on case: %d", id ), e );
}
finally {
if ( session != null ) {
session.close();
}
}
}
private String createFailureMessage(int id, G storedGeometry, G retrievedGeometry) {
String expectedText = ( storedGeometry != null ? storedGeometry.toString() : "NULL" );
@ -106,88 +80,21 @@ public abstract class AbstractTestStoreRetrieve<G, E extends GeomEntityLike<G>>
);
}
private void storeTestObjects(Map<Integer, E> stored) {
Session session = null;
Transaction tx = null;
int id = -1;
try {
session = openSession();
Dialect dialect = sessionFactory().getJdbcServices().getDialect();
// Every testsuite-suite instance is committed seperately
// to improve feedback in case of failure
for ( TestDataElement element : testData ) {
id = element.id;
tx = session.beginTransaction();
E entity = createFrom( element, dialect );
stored.put( entity.getId(), entity );
session.save( entity );
tx.commit();
}
}
catch (Exception e) {
if ( tx != null ) {
tx.rollback();
}
throw new RuntimeException( "Failed storing testsuite-suite object with id:" + id, e );
}
finally {
if ( session != null ) {
session.close();
}
private void storeTestObjects(SessionImplementor session) {
// Every testsuite-suite instance is committed seperately
// to improve feedback in case of failure
for ( TestDataElement element : testData ) {
E entity = createFrom( element, session.getJdbcServices().getDialect() );
stored.put( entity.getId(), entity );
session.save( entity );
}
}
private void storeNullGeometry() {
GeomEntity entity = null;
Session session = null;
Transaction tx = null;
try {
session = openSession();
tx = session.beginTransaction();
entity = new GeomEntity();
entity.setId( 1 );
entity.setType( "NULL OBJECT" );
session.save( entity );
tx.commit();
}
catch (Exception e) {
if ( tx != null ) {
tx.rollback();
}
Integer id = entity != null ? entity.getId() : -1;
throw new RuntimeException( "Failed storing testsuite-suite object with id:" + id, e );
}
finally {
if ( session != null ) {
session.close();
}
}
}
private void retrieveNullGeometry() {
Transaction tx = null;
Session session = null;
try {
session = openSession();
tx = session.beginTransaction();
JpaCriteriaQuery<GeomEntity> criteria = session.getCriteriaBuilder().createQuery( GeomEntity.class );
Query<GeomEntity> query = session.createQuery( criteria );
List<GeomEntity> retrieved = query.list();
assertEquals( "Expected exactly one result", 1, retrieved.size() );
GeomEntity entity = retrieved.get( 0 );
assertNull( entity.getGeom() );
tx.commit();
}
catch (Exception e) {
if ( tx != null ) {
tx.rollback();
}
throw new RuntimeException( e );
}
finally {
if ( session != null ) {
session.close();
}
}
}
}

View File

@ -8,6 +8,7 @@
package org.hibernate.spatial.integration;
import org.hibernate.dialect.AbstractHANADialect;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.spatial.dialect.db2.DB2SpatialDialect;
@ -24,7 +25,7 @@ public class DecodeUtil {
if ( dialect instanceof AbstractHANADialect ) {
decoder = Wkt.newDecoder( Wkt.Dialect.HANA_EWKT );
}
else if ( dialect instanceof DB2SpatialDialect ) {
else if ( dialect instanceof DB2Dialect ) {
decoder = Wkt.newDecoder( Wkt.Dialect.DB2_WKT );
}
else {

View File

@ -0,0 +1,63 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.integration;
import java.sql.BatchUpdateException;
import java.sql.SQLException;
import javax.persistence.Query;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
import org.hibernate.spatial.testing.DataSourceUtils;
import org.hibernate.spatial.testing.JTSGeometryEquality;
import org.hibernate.spatial.testing.TestSupportFactories;
import org.hibernate.spatial.testing.datareader.TestData;
import org.hibernate.spatial.testing.datareader.TestSupport;
import org.hibernate.testing.orm.junit.DialectContext;
public class SpatialTestDataProvider {
protected final static String JTS = "jts";
protected TestData testData;
protected JTSGeometryEquality geometryEquality;
protected AbstractExpectationsFactory expectationsFactory;
public SpatialTestDataProvider() {
try {
TestSupport support = TestSupportFactories.instance().getTestSupportFactory( DialectContext.getDialect() );
testData = support.createTestData( TestSupport.TestDataPurpose.StoreRetrieveData );
geometryEquality = support.createGeometryEquality();
}
catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException( e );
}
}
/**
* Inserts the test data via a direct route (JDBC).
*/
public void prepareTest(SessionImplementor session) {
throw new NotYetImplementedException();
}
protected String entityName(String pckg) {
if ( JTS.equalsIgnoreCase( pckg ) ) {
return "org.hibernate.spatial.testing.domain.JtsGeomEntity";
}
else {
return "org.hibernate.spatial.testing.domain.GeomEntity";
}
}
}

View File

@ -20,7 +20,7 @@ import org.hibernate.Transaction;
import org.hibernate.spatial.HSMessageLogger;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.dialect.hana.HANASpatialDialect;
import org.hibernate.spatial.integration.geolatte.GeomEntity;
import org.hibernate.spatial.testing.domain.GeomEntity;
import org.hibernate.spatial.predicate.GeolatteSpatialPredicates;
import org.hibernate.spatial.testing.SpatialDialectMatcher;
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;

View File

@ -20,7 +20,7 @@ import org.hibernate.Transaction;
import org.hibernate.spatial.HSMessageLogger;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.dialect.hana.HANASpatialDialect;
import org.hibernate.spatial.integration.jts.JtsGeomEntity;
import org.hibernate.spatial.testing.domain.JtsGeomEntity;
import org.hibernate.spatial.predicate.JTSSpatialPredicates;
import org.hibernate.spatial.testing.SpatialDialectMatcher;
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;

View File

@ -0,0 +1,60 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.integration;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.spatial.testing.domain.SpatialDomainModel;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.hibernate.tool.schema.TargetType;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.jupiter.api.Assertions.assertFalse;
@DomainModel(modelDescriptorClasses = SpatialDomainModel.class)
@SessionFactory
public class TestSpatialSchemaGeneration {
File output;
@BeforeEach
public void setup() throws IOException {
output = File.createTempFile( "update_script", ".sql" );
output.deleteOnExit();
}
@Test
public void testCreatedSchemaHasGeometryField(SessionFactoryScope scope) throws IOException {
MetadataImplementor metadata = scope.getMetadataImplementor();
new SchemaExport()
.setOverrideOutputFileContent()
.setOutputFile( output.getAbsolutePath() )
.setFormat( false )
.execute( EnumSet.of( TargetType.SCRIPT ), SchemaExport.Action.BOTH, metadata );
final List<String> sqlLines = Files.readAllLines( output.toPath(), Charset.defaultCharset() );
String result = sqlLines.stream().collect( Collectors.joining( " " ) ).toLowerCase( Locale.ROOT );
assertThat( result, stringContainsInOrder( List.of( "geometry", "geom" ) ) );
}
}

View File

@ -13,6 +13,7 @@ import org.hibernate.spatial.testing.GeolatteGeometryEquality;
import org.hibernate.spatial.testing.GeometryEquality;
import org.hibernate.spatial.testing.SpatialDialectMatcher;
import org.hibernate.spatial.testing.datareader.TestDataElement;
import org.hibernate.spatial.testing.domain.GeomEntity;
import org.hibernate.testing.Skip;
@ -25,7 +26,7 @@ import org.geolatte.geom.codec.WktDecodeException;
* This testsuite-suite class verifies whether the <code>Geometry</code>s retrieved
* are equal to the <code>Geometry</code>s stored.
*/
@Skip(condition = SpatialDialectMatcher.class, message = "No Spatial Dialect")
public class TestStoreRetrieveUsingGeolatte extends AbstractTestStoreRetrieve<Geometry, GeomEntity> {
private static final HSMessageLogger LOG = Logger.getMessageLogger(

View File

@ -13,6 +13,7 @@ import org.hibernate.spatial.testing.GeometryEquality;
import org.hibernate.spatial.testing.JTSGeometryEquality;
import org.hibernate.spatial.testing.SpatialDialectMatcher;
import org.hibernate.spatial.testing.datareader.TestDataElement;
import org.hibernate.spatial.testing.domain.JtsGeomEntity;
import org.hibernate.testing.Skip;

View File

@ -21,9 +21,9 @@ import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.dialect.Dialect;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.HSMessageLogger;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.integration.jts.JtsGeomEntity;
import org.hibernate.spatial.testing.domain.GeomEntity;
import org.hibernate.spatial.testing.domain.JtsGeomEntity;
import org.hibernate.spatial.testing.datareader.TestData;
import org.hibernate.spatial.testing.datareader.TestSupport;
@ -113,7 +113,7 @@ public abstract class SpatialFunctionalTestCase extends BaseCoreFunctionalTestCa
TestSupport support = TestSupportFactories.instance().getTestSupportFactory( getDialect() );
dataSourceUtils = support.createDataSourceUtil( serviceRegistry );
expectationsFactory = support.createExpectationsFactory( dataSourceUtils );
testData = support.createTestData( this );
testData = support.createTestData( TestSupport.TestDataPurpose.StoreRetrieveData );
geometryEquality = support.createGeometryEquality();
}
catch (Exception e) {
@ -151,7 +151,7 @@ public abstract class SpatialFunctionalTestCase extends BaseCoreFunctionalTestCa
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
org.hibernate.spatial.integration.geolatte.GeomEntity.class,
GeomEntity.class,
JtsGeomEntity.class
};
}
@ -252,10 +252,10 @@ public abstract class SpatialFunctionalTestCase extends BaseCoreFunctionalTestCa
protected String entityName(String pckg) {
if ( JTS.equalsIgnoreCase( pckg ) ) {
return "org.hibernate.spatial.integration.jts.JtsGeomEntity";
return "org.hibernate.spatial.testing.domain.JtsGeomEntity";
}
else {
return "org.hibernate.spatial.integration.geolatte.GeomEntity";
return "org.hibernate.spatial.testing.domain.GeomEntity";
}
}

View File

@ -11,6 +11,7 @@ import org.hibernate.dialect.CockroachDialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.MariaDBDialect;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.testing.datareader.TestSupport;
import org.hibernate.spatial.testing.dialects.cockroachdb.CockroachDBTestSupport;
@ -43,7 +44,7 @@ public class TestSupportFactories {
private static Class<? extends TestSupport> getSupportFactoryClass(Dialect dialect) {
String canonicalName = dialect.getClass().getCanonicalName();
if ( ( dialect instanceof SpatialDialect ) && PostgreSQL82Dialect.class.isAssignableFrom( dialect.getClass() ) ) {
if ( PostgreSQLDialect.class.isAssignableFrom( dialect.getClass() ) ) {
//this test works because all postgis dialects ultimately derive of the Postgresql82Dialect
return PostgisTestSupport.class;
}

View File

@ -23,14 +23,21 @@ import org.hibernate.spatial.testing.JTSGeometryEquality;
import org.hibernate.spatial.testing.SQLExpressionTemplate;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import junit.framework.TestCase;
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: Sep 30, 2010
*/
@Deprecated
public abstract class TestSupport {
public enum TestDataPurpose {
SpatialFunctionsData,
StoreRetrieveData
}
protected ConfigurationService configurationService;
public DataSourceUtils createDataSourceUtil(ServiceRegistry serviceRegistry) {
@ -42,7 +49,7 @@ public abstract class TestSupport {
return new JTSGeometryEquality();
}
public abstract TestData createTestData(BaseCoreFunctionalTestCase testcase);
public abstract TestData createTestData(TestDataPurpose purpose);
public abstract AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils);

View File

@ -18,17 +18,18 @@ import org.hibernate.spatial.testing.datareader.TestSupport;
import org.hibernate.spatial.testing.dialects.postgis.PostgisExpressionTemplate;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import junit.framework.TestCase;
public class CockroachDBTestSupport extends TestSupport {
@Override
public TestData createTestData(BaseCoreFunctionalTestCase testcase) {
Class<? extends BaseCoreFunctionalTestCase> testcaseClass = testcase.getClass();
if ( ( testcaseClass == TestSpatialFunctions.class ) ||
( testcaseClass == TestJTSSpatialPredicates.class ) ||
( testcaseClass == TestGeolatteSpatialPredicates.class ) ) {
return TestData.fromFile( "cockroachdb/functions-test.xml" );
public TestData createTestData(TestDataPurpose purpose) {
switch ( purpose ) {
case SpatialFunctionsData:
return TestData.fromFile( "cockroachdb/functions-test.xml" );
default:
return TestData.fromFile( "cockroachdb/test-data-set.xml" );
}
return TestData.fromFile( "cockroachdb/test-data-set.xml" );
}
@Override

View File

@ -20,14 +20,16 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
*/
public class DB2TestSupport extends TestSupport {
public TestData createTestData(BaseCoreFunctionalTestCase testcase) {
if ( "org.hibernate.spatial.integration.TestSpatialFunctions".equals(
testcase.getClass().getCanonicalName() ) ) {
return TestData.fromFile( "db2/test-db2nozm-only-polygon.xml" );
public TestData createTestData(TestDataPurpose purpose) {
switch ( purpose ) {
case SpatialFunctionsData:
return TestData.fromFile( "db2/test-db2nozm-only-polygon.xml" );
default:
return TestData.fromFile( "db2/test-db2nozm-data-set.xml" );
}
return TestData.fromFile( "db2/test-db2nozm-data-set.xml" );
}
public DB2ExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
return new DB2ExpectationsFactory( dataSourceUtils );
}

View File

@ -39,7 +39,8 @@ public class GeoDBTestSupport extends TestSupport {
}
}
public TestData createTestData(BaseCoreFunctionalTestCase testcase) {
@Override
public TestData createTestData(TestDataPurpose purpose) {
return TestData.fromFile( "h2geodb/test-geodb-data-set.xml" );
}

View File

@ -16,8 +16,9 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
public class HANATestSupport extends TestSupport {
@Override
public TestData createTestData(BaseCoreFunctionalTestCase testcase) {
public TestData createTestData(TestDataPurpose purpose) {
return TestData.fromFile( "hana/test-hana-data-set.xml" );
}

View File

@ -16,10 +16,10 @@ import org.hibernate.spatial.testing.datareader.TestSupport;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
public class MariaDBTestSupport extends TestSupport {
@Override
public TestData createTestData(BaseCoreFunctionalTestCase testcase) {
return TestData.fromFile( "mariadb/test-mariadb-functions-data-set.xml" );
@Override
public TestData createTestData(TestDataPurpose purpose) {
return TestData.fromFile( "mariadb/test-mariadb-functions-data-set.xml" );
}
@Override

View File

@ -19,10 +19,11 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
public class MySQL8TestSupport extends MySQLTestSupport {
@Override
public TestData createTestData(BaseCoreFunctionalTestCase testcase) {
public TestData createTestData(TestDataPurpose purpose) {
return TestData.fromFile( "mysql/test-mysql8-functions-data-set.xml" );
}
@Override
public SQLExpressionTemplate getSQLExpressionTemplate() {
return new MySQL8ExpressionTemplate();

View File

@ -16,6 +16,7 @@ import org.hibernate.spatial.testing.datareader.TestData;
import org.hibernate.spatial.testing.datareader.TestSupport;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import junit.framework.TestCase;
/**
* @author Karel Maesen, Geovise BVBA
@ -23,11 +24,7 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
*/
public class MySQLTestSupport extends TestSupport {
@Override
public TestData createTestData(BaseCoreFunctionalTestCase testcase) {
return TestData.fromFile( "mysql/test-mysql-functions-data-set.xml" );
}
@Override
public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
@ -39,6 +36,11 @@ public class MySQLTestSupport extends TestSupport {
return new MySQLGeometryEquality();
}
@Override
public TestData createTestData(TestDataPurpose purpose) {
return TestData.fromFile( "mysql/test-mysql-functions-data-set.xml" );
}
@Override
public SQLExpressionTemplate getSQLExpressionTemplate() {
return new MySQLExpressionTemplate();

View File

@ -24,7 +24,7 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
public class OracleSDOTestSupport extends TestSupport {
@Override
public TestData createTestData(BaseCoreFunctionalTestCase testcase) {
public TestData createTestData(TestDataPurpose purpose) {
return TestData.fromFile( "oracle10g/test-sdo-geometry-data-set-2D.xml", new SDOTestDataReader() );
}

View File

@ -26,14 +26,14 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
public class PostgisTestSupport extends TestSupport {
public TestData createTestData(BaseCoreFunctionalTestCase testcase) {
Class<? extends BaseCoreFunctionalTestCase> testcaseClass = testcase.getClass();
if ( testcaseClass == TestSpatialFunctions.class ||
testcaseClass == TestJTSSpatialPredicates.class ||
testcaseClass == TestGeolatteSpatialPredicates.class ) {
return TestData.fromFile( "postgis-functions-test.xml" );
@Override
public TestData createTestData(TestDataPurpose purpose) {
switch ( purpose ) {
case SpatialFunctionsData:
return TestData.fromFile( "postgis-functions-test.xml" );
default:
return TestData.fromFile( "test-data-set.xml" );
}
return TestData.fromFile( "test-data-set.xml" );
}
public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {

View File

@ -20,8 +20,8 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
*/
public class SQLServerTestSupport extends TestSupport {
public TestData createTestData(BaseCoreFunctionalTestCase testcase) {
@Override
public TestData createTestData(TestDataPurpose purpose) {
return TestData.fromFile( "test-data-set.xml" );
}

View File

@ -5,7 +5,14 @@
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.integration.geolatte;
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.testing.domain;
import javax.persistence.Entity;
import javax.persistence.Id;
@ -36,7 +43,7 @@ public class GeomEntity implements GeomEntityLike<Geometry> {
private String type;
private Geometry geom;
static GeomEntity createFrom(TestDataElement element, Dialect dialect) throws WktDecodeException {
public static GeomEntity createFrom(TestDataElement element, Dialect dialect) throws WktDecodeException {
WktDecoder decoder = getWktDecoder( dialect );
Geometry geom = decoder.decode( element.wkt );
GeomEntity result = new GeomEntity();

View File

@ -5,7 +5,14 @@
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.integration.jts;
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.testing.domain;
import javax.persistence.Entity;
import javax.persistence.Id;

View File

@ -0,0 +1,19 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.testing.domain;
import org.hibernate.testing.orm.domain.AbstractDomainModelDescriptor;
public class SpatialDomainModel extends AbstractDomainModelDescriptor {
public SpatialDomainModel() {
super(
GeomEntity.class,
JtsGeomEntity.class
);
}
}

View File

@ -1,3 +1,4 @@
#
# Hibernate, Relational Persistence for Idiomatic Java
#
@ -20,11 +21,11 @@ hibernate.connection.init_sql @connection.init_sql@
#hibernate.jdbc.batch_versioned_data true
## Configs for spatial databases (used during testing on local dev environment).
#
#hibernate.dialect org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect
#hibernate.dialect org.hibernate.dialect.PostgreSQLDialect
#hibernate.connection.driver_class org.postgresql.Driver
#hibernate.connection.url jdbc:postgresql://localhost:9432/
#hibernate.connection.username hibern8
#hibernate.connection.password hibern8
#hibernate.connection.url jdbc:postgresql://localhost:5432/hibernate_orm_test?preparedStatementCacheQueries=0
#hibernate.connection.username hibernate_orm_test
#hibernate.connection.password hibernate_orm_test
##
## GeoDb (H2 spatial extension)
##