HHH-6509 - Using jboss message logger for logging

This commit is contained in:
Karel Maesen 2015-04-12 13:29:46 +02:00 committed by Steve Ebersole
parent 97de410e8c
commit 9ccd331831
17 changed files with 210 additions and 369 deletions

View File

@ -21,15 +21,26 @@
package org.hibernate.spatial;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.hibernate.internal.CoreMessageLogger;
import static org.jboss.logging.Logger.Level.WARN;
/**
* The logger interface for the Hibernate Spatial module.
*
* @author Karel Maesen, Geovise BVBA
*/
@MessageLogger(projectCode = "HS")
public interface Log extends CoreMessageLogger {
@MessageLogger(projectCode = "HHH")
public interface HSMessageLogger extends BasicLogger {
/**
* Message indicating that user attempted to use the deprecated ValidTimeAuditStrategy
*/
// @LogMessage(level = WARN)
// @Message(value = "ValidTimeAuditStrategy is deprecated, please use ValidityAuditStrategy instead", id = 25001)
// void voidvalidTimeAuditStrategyDeprecated();
}

View File

@ -4,6 +4,8 @@ import org.geolatte.geom.codec.db.oracle.ConnectionFinder;
import java.io.Serializable;
import org.jboss.logging.Logger;
/**
* A global configuration object that is is used by
* some Dialects during construction.
@ -13,7 +15,10 @@ import java.io.Serializable;
*/
public class HibernateSpatialConfiguration implements Serializable {
private static final Log LOG = LogFactory.make();
private static final HSMessageLogger LOG = Logger.getMessageLogger(
HSMessageLogger.class,
HibernateSpatialConfiguration.class.getName()
);
private Boolean isOgcStrict = Boolean.TRUE;
private ConnectionFinder connectionFinder;

View File

@ -1,50 +0,0 @@
/*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for spatial (geographic) data.
*
* Copyright © 2007-2013 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.jboss.logging.Logger;
/**
* A static factory for <code>Log</code>s.
*
* The implementation is based on the hibernate-ogm LoggerFactory class.
*
* @author Karel Maesen, Geovise BVBA
* creation-date: 1/14/12
*/
public class LogFactory {
private LogFactory(){}
/**
* Creates a new logger for the class that invokes this method.
*
* @return A new logger for the invoking class.
*/
public static Log make() {
final Throwable t = new Throwable();
final StackTraceElement directCaller = t.getStackTrace()[1];
return Logger.getMessageLogger( Log.class, directCaller.getClassName() );
}
}

View File

@ -41,9 +41,10 @@ import org.geolatte.geom.codec.WkbEncoder;
import org.geolatte.geom.crs.CoordinateReferenceSystems;
import org.geolatte.geom.jts.JTS;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import org.hibernate.spatial.HSMessageLogger;
/**
* A utility class to serialize from/to GeoDB WKB's.
@ -55,7 +56,10 @@ import org.hibernate.spatial.LogFactory;
*/
public class GeoDbWkb {
private static final Log LOGGER = LogFactory.make();
private static final HSMessageLogger LOGGER = Logger.getMessageLogger(
HSMessageLogger.class,
GeoDbWkb.class.getName()
);
private GeoDbWkb() {
}

View File

@ -27,7 +27,6 @@ import org.geolatte.geom.codec.db.oracle.OracleJDBCTypeFactory;
import org.geolatte.geom.codec.db.oracle.SDOGeometry;
import org.hibernate.HibernateException;
import org.hibernate.spatial.helper.FinderException;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
@ -69,7 +68,7 @@ class SDOGeometryValueBinder<J> implements ValueBinder<J> {
}
}
public Object store(SDOGeometry geom, Connection conn) throws SQLException, FinderException {
public Object store(SDOGeometry geom, Connection conn) throws SQLException {
return typeFactory.createStruct( geom, conn );
}
@ -81,12 +80,6 @@ class SDOGeometryValueBinder<J> implements ValueBinder<J> {
catch (SQLException e) {
throw new HibernateException( "Problem during conversion from JTS to SDOGeometry", e );
}
catch (FinderException e) {
throw new HibernateException(
"OracleConnection could not be retrieved for creating SDOGeometry " +
"STRUCT", e
);
}
catch (IllegalArgumentException e) {
//we get here if the type of geometry is unsupported by geolatte encoders
throw new HibernateException( e.getMessage() );

View File

@ -1,42 +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.helper;
/**
* This exception is thrown when Hibernate Spatial fails to find a required
* resource.
*
* @author Karel Maesen, Geovise BVBA
*/
public class FinderException extends Exception {
private static final long serialVersionUID = 1L;
/**
* Creates an instance with the specified message
*
* @param msg the error message for this exception
*/
public FinderException(String msg) {
super( msg );
}
}

View File

@ -1,48 +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.helper;
import java.io.Serializable;
/**
* A <code>FinderStrategy</code> is used to find a specific feature. It is
* useful in cases where reflection is used to determine some property of a
* class.
*
* @param <T> the return type of the <code>find</code> method
* @param <S> the type of subject
*
* @author Karel Maesen
*/
public interface FinderStrategy<T, S> extends Serializable {
/**
* Find a feature or property of a subject
*
* @param subject the object that is being searched
*
* @return the object sought
*
* @throws FinderException thrown when the feature can be found;
*/
public T find(S subject) throws FinderException;
}

View File

@ -1,80 +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.helper;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.regex.Pattern;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
/**
* Helper class to read settings and properties files.
*
* @author Karel Maesen
*/
public class PropertyFileReader {
private static final Log LOG = LogFactory.make();
/**
* pattern for comment lines. If it matches, it is a comment.
*/
private static final Pattern NON_COMMENT_PATTERN = Pattern.compile( "^([^#]+)" );
private InputStream is;
/**
* Constructs an instance from the specified {@code InputStream}
* @param is The inputstream
*/
public PropertyFileReader(InputStream is) {
this.is = is;
}
/**
* Returns the properties
* @return {@code Properties}
* @throws IOException if an error occurs when reading from the {@code InputStream}
*/
public Properties getProperties() throws IOException {
if ( is == null ) {
return null;
}
final Properties props = new Properties();
props.load( is );
return props;
}
/**
* Closes this instance, and closes the underlying {@code InputStream}
*/
public void close() {
try {
this.is.close();
}
catch ( IOException e ) {
LOG.warn( "Exception when closing PropertyFileReader: " + e );
}
}
}

View File

@ -1,30 +0,0 @@
<!DOCTYPE html>
<!--
~ This file is part of Hibernate Spatial, an extension to the
~ hibernate ORM solution for spatial (geographic) data.
~
~ Copyright © 2007-2013 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
-->
<html>
<head></head>
<body>
<p>
This package contains general helper classes.
</p>
</body>
</html>

View File

@ -26,18 +26,21 @@ import java.util.HashMap;
import java.util.Map;
import com.vividsolutions.jts.geom.Geometry;
import org.junit.Test;
import org.jboss.logging.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import org.hibernate.spatial.HSMessageLogger;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.dialect.h2geodb.GeoDBDialect;
import org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect;
import org.hibernate.spatial.testing.SpatialDialectMatcher;
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
import org.junit.Test;
import org.hibernate.testing.Skip;
import org.hibernate.testing.SkipForDialect;
@ -49,10 +52,12 @@ import static java.lang.String.format;
@Skip(condition = SpatialDialectMatcher.class, message = "No Spatial Dialect")
public class TestSpatialFunctions extends SpatialFunctionalTestCase {
private static Log LOG = LogFactory.make();
private static final HSMessageLogger LOG = Logger.getMessageLogger(
HSMessageLogger.class,
TestSpatialFunctions.class.getName()
);
protected Log getLogger() {
protected HSMessageLogger getLogger() {
return LOG;
}
@ -91,7 +96,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
}
Map<Integer, String> dbexpected = expectationsFactory.getAsText();
String hql = format( "SELECT id, astext(geom) from org.hibernate.spatial.integration.%s.GeomEntity", pckg );
retrieveHQLResultsAndCompare( dbexpected, hql, pckg);
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
}
@Test
@ -227,7 +232,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getEnvelope();
String hql = format("SELECT id, envelope(geom) from org.hibernate.spatial.integration.%s.GeomEntity", pckg);
String hql = format( "SELECT id, envelope(geom) from org.hibernate.spatial.integration.%s.GeomEntity", pckg );
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
}
@ -246,8 +251,10 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getWithin( expectationsFactory.getTestPolygon() );
String hql = format("SELECT id, within(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where within(geom, :filter) = true and srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, within(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where within(geom, :filter) = true and srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
}
@ -267,8 +274,10 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getEquals( expectationsFactory.getTestPolygon() );
String hql = format("SELECT id, equals(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where equals(geom, :filter) = true and srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, equals(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where equals(geom, :filter) = true and srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
}
@ -288,8 +297,10 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getCrosses( expectationsFactory.getTestPolygon() );
String hql = format("SELECT id, crosses(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where crosses(geom, :filter) = true and srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, crosses(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where crosses(geom, :filter) = true and srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
@ -302,7 +313,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_contains_on_geolatte() throws SQLException {
contains( GEOLATTE);
contains( GEOLATTE );
}
public void contains(String pckg) throws SQLException {
@ -310,8 +321,10 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getContains( expectationsFactory.getTestPolygon() );
String hql = format("SELECT id, contains(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where contains(geom, :filter) = true and srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, contains(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where contains(geom, :filter) = true and srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
}
@ -323,7 +336,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_disjoint_on_geolatte() throws SQLException {
disjoint( GEOLATTE);
disjoint( GEOLATTE );
}
public void disjoint(String pckg) throws SQLException {
@ -331,8 +344,10 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getDisjoint( expectationsFactory.getTestPolygon() );
String hql = format("SELECT id, disjoint(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where disjoint(geom, :filter) = true and srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, disjoint(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where disjoint(geom, :filter) = true and srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
}
@ -344,7 +359,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_intersects_on_geolatte() throws SQLException {
intersects( GEOLATTE);
intersects( GEOLATTE );
}
public void intersects(String pckg) throws SQLException {
@ -352,8 +367,10 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getIntersects( expectationsFactory.getTestPolygon() );
String hql = format("SELECT id, intersects(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where intersects(geom, :filter) = true and srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, intersects(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where intersects(geom, :filter) = true and srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
}
@ -365,7 +382,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_overlaps_on_geolatte() throws SQLException {
overlaps( GEOLATTE);
overlaps( GEOLATTE );
}
public void overlaps(String pckg) throws SQLException {
@ -373,8 +390,10 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getOverlaps( expectationsFactory.getTestPolygon() );
String hql = format("SELECT id, overlaps(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where overlaps(geom, :filter) = true and srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, overlaps(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where overlaps(geom, :filter) = true and srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
}
@ -386,15 +405,17 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_touches_on_geolatte() throws SQLException {
touches( GEOLATTE);
touches( GEOLATTE );
}
public void touches(String pckg) throws SQLException {
if ( !isSupportedByDialect( SpatialFunction.touches ) ) {
return;
}
String hql = format("SELECT id, touches(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where touches(geom, :filter) = true and srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, touches(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where touches(geom, :filter) = true and srid(geom) = 4326", pckg
);
Map<Integer, Boolean> dbexpected = expectationsFactory.getTouches( expectationsFactory.getTestPolygon() );
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
@ -407,7 +428,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_relate_on_geolatte() throws SQLException {
relate( GEOLATTE);
relate( GEOLATTE );
}
public void relate(String pckg) throws SQLException {
@ -419,8 +440,10 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
expectationsFactory.getTestPolygon(),
matrix
);
String hql = format("SELECT id, relate(geom, :filter, :matrix) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where relate(geom, :filter, :matrix) = true and srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, relate(geom, :filter, :matrix) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where relate(geom, :filter, :matrix) = true and srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
params.put( "matrix", matrix );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
@ -439,7 +462,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_distance_on_geolatte() throws SQLException {
distance( GEOLATTE);
distance( GEOLATTE );
}
public void distance(String pckg) throws SQLException {
@ -447,8 +470,10 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Double> dbexpected = expectationsFactory.getDistance( expectationsFactory.getTestPolygon() );
String hql = format("SELECT id, distance(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, distance(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
}
@ -460,7 +485,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_buffer_on_geolatte() throws SQLException {
buffer( GEOLATTE);
buffer( GEOLATTE );
}
public void buffer(String pckg) throws SQLException {
@ -468,8 +493,10 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getBuffer( Double.valueOf( 1.0 ) );
String hql = format("SELECT id, buffer(geom, :distance) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, buffer(geom, :distance) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "distance", Double.valueOf( 1.0 ) );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
@ -482,7 +509,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_convexhull_on_geolatte() throws SQLException {
convexhull( GEOLATTE);
convexhull( GEOLATTE );
}
public void convexhull(String pckg) throws SQLException {
@ -490,21 +517,25 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getConvexHull( expectationsFactory.getTestPolygon() );
String hql = format("SELECT id, convexhull(geomunion(geom, :polygon)) from org.hibernate.spatial.integration" +
".%s.GeomEntity where srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, convexhull(geomunion(geom, :polygon)) from org.hibernate.spatial.integration" +
".%s.GeomEntity where srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
}
@Test @SkipForDialect( value = GeoDBDialect.class)
public void test_intersection_on_jts()throws SQLException {
@Test
@SkipForDialect(value = GeoDBDialect.class)
public void test_intersection_on_jts() throws SQLException {
intersection( JTS );
}
@Test @SkipForDialect( value = GeoDBDialect.class)
public void test_intersection_on_geolatte()throws SQLException {
intersection( GEOLATTE);
@Test
@SkipForDialect(value = GeoDBDialect.class)
public void test_intersection_on_geolatte() throws SQLException {
intersection( GEOLATTE );
}
//skipped for GeoDBDialect because GeoDB throws exceptions in case the intersection is empty.
@ -514,8 +545,10 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getIntersection( expectationsFactory.getTestPolygon() );
String hql = format("SELECT id, intersection(geom, :polygon) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, intersection(geom, :polygon) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
}
@ -527,7 +560,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_difference_on_geolatte() throws SQLException {
difference( GEOLATTE);
difference( GEOLATTE );
}
public void difference(String pckg) throws SQLException {
@ -535,8 +568,10 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getDifference( expectationsFactory.getTestPolygon() );
String hql = format("SELECT id, difference(geom, :polygon) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, difference(geom, :polygon) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
}
@ -548,7 +583,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_symdifference_on_geolatte() throws SQLException {
symdifference( GEOLATTE);
symdifference( GEOLATTE );
}
public void symdifference(String pckg) throws SQLException {
@ -556,8 +591,10 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getSymDifference( expectationsFactory.getTestPolygon() );
String hql = format("SELECT id, symdifference(geom, :polygon) from " +
"org.hibernate.spatial.integration.%s.GeomEntity where srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, symdifference(geom, :polygon) from " +
"org.hibernate.spatial.integration.%s.GeomEntity where srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
}
@ -569,7 +606,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_geomunion_on_geolatte() throws SQLException {
geomunion( GEOLATTE);
geomunion( GEOLATTE );
}
public void geomunion(String pckg) throws SQLException {
@ -577,10 +614,12 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
return;
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getGeomUnion( expectationsFactory.getTestPolygon() );
String hql = format("SELECT id, geomunion(geom, :polygon) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, geomunion(geom, :polygon) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg);
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
}
@Test
@ -590,7 +629,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_dwithin_on_geolatte() throws SQLException {
dwithin( GEOLATTE);
dwithin( GEOLATTE );
}
public void dwithin(String pckg) throws SQLException {
@ -602,9 +641,11 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
expectationsFactory.getTestPoint(),
distance
);
String hql = format("SELECT id, dwithin(geom, :filter, :distance) from " +
"org.hibernate.spatial.integration.%s.GeomEntity where dwithin(geom, :filter, :distance) = true " +
"and srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, dwithin(geom, :filter, :distance) from " +
"org.hibernate.spatial.integration.%s.GeomEntity where dwithin(geom, :filter, :distance) = true " +
"and srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPoint() );
if ( getDialect() instanceof OracleSpatial10gDialect ) {
//because this uses the weird syntax and conventions of SDO_WITHIN_DISTANCE which returns a string (really)
@ -625,7 +666,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
@Test
public void test_transform_on_geolatte() throws SQLException {
transform( GEOLATTE);
transform( GEOLATTE );
}
public void transform(String pckg) throws SQLException {
@ -634,18 +675,24 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
}
int epsg = 4324;
Map<Integer, Geometry> dbexpected = expectationsFactory.getTransform( epsg );
String hql = format("SELECT id, transform(geom, :epsg) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = 4326", pckg);
String hql = format(
"SELECT id, transform(geom, :epsg) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = 4326", pckg
);
Map<String, Object> params = createQueryParams( "epsg", Integer.valueOf( epsg ) );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
}
public <T> void retrieveHQLResultsAndCompare(Map<Integer, T> dbexpected, String hql, String geometryType) {
retrieveHQLResultsAndCompare( dbexpected, hql, null, geometryType);
retrieveHQLResultsAndCompare( dbexpected, hql, null, geometryType );
}
protected <T> void retrieveHQLResultsAndCompare(Map<Integer, T> dbexpected, String hql, Map<String, Object> params, String geometryType) {
protected <T> void retrieveHQLResultsAndCompare(
Map<Integer, T> dbexpected,
String hql,
Map<String, Object> params,
String geometryType) {
Map<Integer, T> hsreceived = new HashMap<Integer, T>();
doInSession( hql, hsreceived, params );
compare( dbexpected, hsreceived, geometryType );
@ -681,7 +728,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
if ( params == null ) {
return;
}
for ( Map.Entry<String, Object> entry: params.entrySet() ) {
for ( Map.Entry<String, Object> entry : params.entrySet() ) {
query.setParameter( entry.getKey(), entry.getValue() );
}
}

View File

@ -25,14 +25,15 @@ import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import org.jboss.logging.Logger;
import org.junit.Test;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Criterion;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import org.hibernate.spatial.HSMessageLogger;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.criterion.SpatialRestrictions;
import org.hibernate.spatial.integration.jts.GeomEntity;
@ -46,9 +47,12 @@ import static org.junit.Assert.fail;
@Skip(condition = SpatialDialectMatcher.class, message = "No Spatial Dialect")
public class TestSpatialRestrictions extends SpatialFunctionalTestCase {
private static Log LOG = LogFactory.make();
private static HSMessageLogger LOG = Logger.getMessageLogger(
HSMessageLogger.class,
TestSpatialRestrictions.class.getName()
);
protected Log getLogger() {
protected HSMessageLogger getLogger() {
return LOG;
}

View File

@ -9,13 +9,15 @@ import org.geolatte.geom.Geometry;
import org.geolatte.geom.GeometryEquality;
import org.geolatte.geom.GeometryPointEquality;
import org.geolatte.geom.codec.WktDecodeException;
import org.jboss.logging.Logger;
import org.junit.Test;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import org.hibernate.spatial.HSMessageLogger;
import org.hibernate.spatial.testing.SpatialDialectMatcher;
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
import org.hibernate.spatial.testing.TestDataElement;
@ -32,9 +34,12 @@ import static org.junit.Assert.assertTrue;
@Skip(condition = SpatialDialectMatcher.class, message = "No Spatial Dialect")
public class TestStoreRetrieveUsingGeolatte extends SpatialFunctionalTestCase {
private static Log LOG = LogFactory.make();
private static HSMessageLogger LOG = Logger.getMessageLogger(
HSMessageLogger.class,
TestStoreRetrieveUsingGeolatte.class.getName()
);
protected Log getLogger() {
protected HSMessageLogger getLogger() {
return LOG;
}

View File

@ -6,13 +6,15 @@ import java.util.Map;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.ParseException;
import org.jboss.logging.Logger;
import org.junit.Test;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import org.hibernate.spatial.HSMessageLogger;
import org.hibernate.spatial.testing.SpatialDialectMatcher;
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
import org.hibernate.spatial.testing.TestDataElement;
@ -29,9 +31,13 @@ import static org.junit.Assert.assertTrue;
@Skip(condition = SpatialDialectMatcher.class, message = "No Spatial Dialect")
public class TestStoreRetrieveUsingJTS extends SpatialFunctionalTestCase {
private static Log LOG = LogFactory.make();
private static final HSMessageLogger LOG = Logger.getMessageLogger(
HSMessageLogger.class,
TestStoreRetrieveUsingJTS.class.getName()
);
protected Log getLogger() {
protected HSMessageLogger getLogger() {
return LOG;
}

View File

@ -35,8 +35,9 @@ import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import org.jboss.logging.Logger;
import org.hibernate.spatial.HSMessageLogger;
/**
* An <code>AbstractExpectationsFactory</code> provides the expected
@ -49,7 +50,10 @@ import org.hibernate.spatial.LogFactory;
*/
public abstract class AbstractExpectationsFactory {
private static final Log LOG = LogFactory.make();
private static final HSMessageLogger LOG = Logger.getMessageLogger(
HSMessageLogger.class,
AbstractExpectationsFactory.class.getName()
);
public final static String TEST_POLYGON_WKT = "POLYGON((0 0, 50 0, 100 100, 0 100, 0 0))";
public final static String TEST_POINT_WKT = "POINT(0 0)";

View File

@ -44,8 +44,9 @@ import org.geolatte.geom.codec.Wkt;
import org.geolatte.geom.codec.WktDecodeException;
import org.geolatte.geom.codec.WktDecoder;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import org.jboss.logging.Logger;
import org.hibernate.spatial.HSMessageLogger;
/**
* <p>Unit testsuite-suite support class.</p>
@ -55,7 +56,10 @@ import org.hibernate.spatial.LogFactory;
public class DataSourceUtils {
private static Log LOG = LogFactory.make();
private static HSMessageLogger LOG = Logger.getMessageLogger(
HSMessageLogger.class,
DataSourceUtils.class.getName()
);
private final SQLExpressionTemplate sqlExpressionTemplate;

View File

@ -21,25 +21,29 @@
package org.hibernate.spatial.testing;
import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.testing.AfterClassOnce;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import java.sql.BatchUpdateException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.*;
import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.HSMessageLogger;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.testing.AfterClassOnce;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* @author Karel Maesen, Geovise BVBA
@ -182,7 +186,7 @@ public abstract class SpatialFunctionalTestCase extends BaseCoreFunctionalTestCa
return dialect.supportsFiltering();
}
abstract protected Log getLogger();
abstract protected HSMessageLogger getLogger();
/**
* Adds the query results to a Map.

View File

@ -29,8 +29,9 @@ import org.geolatte.geom.codec.WkbDecoder;
import org.geolatte.geom.jts.JTS;
import org.postgresql.util.PGobject;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import org.jboss.logging.Logger;
import org.hibernate.spatial.HSMessageLogger;
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
import org.hibernate.spatial.testing.DataSourceUtils;
import org.hibernate.spatial.testing.NativeSQLStatement;
@ -42,7 +43,10 @@ import org.hibernate.spatial.testing.NativeSQLStatement;
*/
public class PostgisExpectationsFactory extends AbstractExpectationsFactory {
private static final Log LOG = LogFactory.make();
private static final HSMessageLogger LOG = Logger.getMessageLogger(
HSMessageLogger.class,
PostgisExpectationsFactory.class.getName()
);
public PostgisExpectationsFactory(DataSourceUtils utils) {