From ed98698aa416012ad15540b360d87d849b7f942c Mon Sep 17 00:00:00 2001 From: Karel Maesen Date: Tue, 29 Apr 2014 23:59:20 +0200 Subject: [PATCH] HHH-6509 - Cleans up findBug warnings. --- .../spatial/HibernateSpatialConfiguration.java | 4 +++- .../dialect/oracle/OracleJDBCTypeFactory.java | 15 +++++---------- .../dialect/oracle/SDOGeometryValueBinder.java | 1 - .../dialect/oracle/SDOGeometryValueExtractor.java | 2 +- .../spatial/integration/TestSpatialFunctions.java | 5 ++--- .../integration/TestSpatialRestrictions.java | 10 +++++----- .../spatial/integration/geolatte/GeomEntity.java | 2 +- .../geolatte/TestStoreRetrieveUsingGeolatte.java | 9 +++++---- .../spatial/integration/jts/GeomEntity.java | 2 +- .../jts/TestStoreRetrieveUsingJTS.java | 5 +++-- .../spatial/testing/DataSourceUtils.java | 14 ++++++++------ .../testing/SpatialFunctionalTestCase.java | 12 ++++++------ .../org/hibernate/spatial/testing/TestData.java | 2 -- .../dialects/h2geodb/GeoDBExpressionTemplate.java | 2 +- .../dialects/mysql/MySQLExpressionTemplate.java | 2 +- .../oracle/SDOGeometryExpressionTemplate.java | 3 ++- .../postgis/PostgisExpressionTemplate.java | 2 +- .../sqlserver/SQLServerExpressionTemplate.java | 2 +- 18 files changed, 46 insertions(+), 48 deletions(-) diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/HibernateSpatialConfiguration.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/HibernateSpatialConfiguration.java index 9c67430c02..0a2a7bc7af 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/HibernateSpatialConfiguration.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/HibernateSpatialConfiguration.java @@ -1,5 +1,7 @@ package org.hibernate.spatial; +import java.io.Serializable; + import org.hibernate.spatial.dialect.oracle.ConnectionFinder; /** @@ -9,7 +11,7 @@ import org.hibernate.spatial.dialect.oracle.ConnectionFinder; * @author Karel Maesen, Geovise BVBA * creation-date: 8/16/13 */ -public class HibernateSpatialConfiguration { +public class HibernateSpatialConfiguration implements Serializable { private static final Log LOG = LogFactory.make(); private Boolean isOgcStrict = Boolean.TRUE; diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/OracleJDBCTypeFactory.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/OracleJDBCTypeFactory.java index 2ce13c69a0..3d21842f65 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/OracleJDBCTypeFactory.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/OracleJDBCTypeFactory.java @@ -45,11 +45,6 @@ import org.hibernate.spatial.helper.FinderException; public class OracleJDBCTypeFactory implements SQLTypeFactory { private final Class datumClass; - private final Class numberClass; - private final Class arrayClass; - private final Class structClass; - private final Class arrayDescriptorClass; - private final Class structDescriptorClass; private final Method structDescriptorCreator; private final Method arrayDescriptorCreator; private final Constructor numberConstructor; @@ -68,15 +63,15 @@ public class OracleJDBCTypeFactory implements SQLTypeFactory { } this.connectionFinder = connectionFinder; Object[] obj = findDescriptorCreator( "oracle.sql.StructDescriptor" ); - structDescriptorClass = (Class) obj[0]; + Class structDescriptorClass = (Class) obj[0]; structDescriptorCreator = (Method) obj[1]; obj = findDescriptorCreator( "oracle.sql.ArrayDescriptor" ); - arrayDescriptorClass = (Class) obj[0]; + Class arrayDescriptorClass = (Class) obj[0]; arrayDescriptorCreator = (Method) obj[1]; datumClass = findClass( "oracle.sql.Datum" ); - numberClass = findClass( "oracle.sql.NUMBER" ); - arrayClass = findClass( "oracle.sql.ARRAY" ); - structClass = findClass( "oracle.sql.STRUCT" ); + Class numberClass = findClass( "oracle.sql.NUMBER" ); + Class arrayClass = findClass( "oracle.sql.ARRAY" ); + Class structClass = findClass( "oracle.sql.STRUCT" ); numberConstructor = findConstructor( numberClass, java.lang.Integer.TYPE ); arrayConstructor = findConstructor( arrayClass, arrayDescriptorClass, Connection.class, Object.class ); diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/SDOGeometryValueBinder.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/SDOGeometryValueBinder.java index 361fa0ddf3..6440062577 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/SDOGeometryValueBinder.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/SDOGeometryValueBinder.java @@ -398,7 +398,6 @@ class SDOGeometryValueBinder implements ValueBinder { * @return the lrs position for the SDOGeometry.SDOGType */ private int getCoordinateLrsPosition(Geometry geom) { - final Coordinate c = geom.getCoordinate(); final int measurePos = 0; // if ( c != null && !Double.isNaN( c.m ) ) { // measurePos = ( Double.isNaN( c.z ) ) ? 3 : 4; diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/SDOGeometryValueExtractor.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/SDOGeometryValueExtractor.java index 124955d13a..fd71321647 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/SDOGeometryValueExtractor.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/SDOGeometryValueExtractor.java @@ -422,7 +422,7 @@ public class SDOGeometryValueExtractor extends BasicExtractor { final int dim = sdoGeom.getDimension(); final Coordinate[] coordinates = new Coordinate[oordinates.length / dim]; final int zDim = sdoGeom.getZDimension() - 1; - final int lrsDim = sdoGeom.getLRSDimension() - 1; +// final int lrsDim = sdoGeom.getLRSDimension() - 1; for ( int i = 0; i < coordinates.length; i++ ) { if ( dim == 2 ) { coordinates[i] = new Coordinate( 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 6f9332426e..71a636cfaf 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 @@ -681,9 +681,8 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase { if ( params == null ) { return; } - for ( String param : params.keySet() ) { - Object value = params.get( param ); - query.setParameter( param, value ); + for ( Map.Entry entry: params.entrySet() ) { + query.setParameter( entry.getKey(), entry.getValue() ); } } diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestSpatialRestrictions.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestSpatialRestrictions.java index c310178a15..cda2ffc03f 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestSpatialRestrictions.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestSpatialRestrictions.java @@ -211,11 +211,11 @@ public class TestSpatialRestrictions extends SpatialFunctionalTestCase { private void compare(Map dbexpected, List list) { int cnt = 0; - for ( Integer id : dbexpected.keySet() ) { - if ( dbexpected.get( id ) ) { + for ( Map.Entry entry : dbexpected.entrySet() ) { + if ( entry.getValue() ) { cnt++; - if ( !findInList( id, (List) list ) ) { - fail( String.format( "Expected object with id= %d, but not found in result", id ) ); + if ( !findInList( entry.getKey(), (List) list ) ) { + fail( String.format( "Expected object with id= %d, but not found in result", entry.getKey() ) ); } } } @@ -225,7 +225,7 @@ public class TestSpatialRestrictions extends SpatialFunctionalTestCase { private boolean findInList(Integer id, List list) { for ( GeomEntity entity : list ) { - if ( entity.getId() == id ) { + if ( entity.getId().equals( id ) ) { return true; } } diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/geolatte/GeomEntity.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/geolatte/GeomEntity.java index c558b068c9..856b69c64b 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/geolatte/GeomEntity.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/geolatte/GeomEntity.java @@ -92,7 +92,7 @@ public class GeomEntity { GeomEntity geomEntity = (GeomEntity) o; - if ( id != geomEntity.id ) { + if ( ! id.equals(geomEntity.id) ) { return false; } diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/geolatte/TestStoreRetrieveUsingGeolatte.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/geolatte/TestStoreRetrieveUsingGeolatte.java index c218b54900..9e7bf276e3 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/geolatte/TestStoreRetrieveUsingGeolatte.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/geolatte/TestStoreRetrieveUsingGeolatte.java @@ -43,7 +43,7 @@ public class TestStoreRetrieveUsingGeolatte extends SpatialFunctionalTestCase { @Test public void testAfterStoreRetrievingEqualObject() throws WktDecodeException { - Map stored = new HashMap(); + Map stored = new HashMap(); //check whether we retrieve exactly what we store storeTestObjects( stored ); retrieveAndCompare( stored ); @@ -90,14 +90,14 @@ public class TestStoreRetrieveUsingGeolatte extends SpatialFunctionalTestCase { String expectedText = ( storedGeometry != null ? storedGeometry.asText() : "NULL" ); String retrievedText = ( retrievedGeometry != null ? retrievedGeometry.asText() : "NULL" ); return String.format( - "Equality testsuite-suite failed for %d.\nExpected: %s\nReceived:%s", + "Equality testsuite-suite failed for %d.%nExpected: %s%nReceived:%s", id, expectedText, retrievedText ); } - private void storeTestObjects(Map stored) { + private void storeTestObjects(Map stored) { Session session = null; Transaction tx = null; int id = -1; @@ -144,7 +144,8 @@ public class TestStoreRetrieveUsingGeolatte extends SpatialFunctionalTestCase { if ( tx != null ) { tx.rollback(); } - throw new RuntimeException( "Failed storing testsuite-suite object with id:" + entity.getId(), e ); + Integer id = entity != null ? entity.getId() : -1; + throw new RuntimeException( "Failed storing testsuite-suite object with id:" + id, e ); } finally { if ( session != null ) { diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/jts/GeomEntity.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/jts/GeomEntity.java index 8cc40cf97c..0ea0e2138d 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/jts/GeomEntity.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/jts/GeomEntity.java @@ -93,7 +93,7 @@ public class GeomEntity { GeomEntity geomEntity = (GeomEntity) o; - if ( id != geomEntity.id ) { + if ( !id.equals( geomEntity.id ) ) { return false; } diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/jts/TestStoreRetrieveUsingJTS.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/jts/TestStoreRetrieveUsingJTS.java index eb42a54480..daf1d9e5a1 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/jts/TestStoreRetrieveUsingJTS.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/jts/TestStoreRetrieveUsingJTS.java @@ -87,7 +87,7 @@ public class TestStoreRetrieveUsingJTS extends SpatialFunctionalTestCase { String expectedText = ( storedGeometry != null ? storedGeometry.toText() : "NULL" ); String retrievedText = ( retrievedGeometry != null ? retrievedGeometry.toText() : "NULL" ); return String.format( - "Equality testsuite-suite failed for %d.\nExpected: %s\nReceived:%s", + "Equality testsuite-suite failed for %d.%nExpected: %s%nReceived:%s", id, expectedText, retrievedText @@ -141,7 +141,8 @@ public class TestStoreRetrieveUsingJTS extends SpatialFunctionalTestCase { if ( tx != null ) { tx.rollback(); } - throw new RuntimeException( "Failed storing testsuite-suite object with id:" + entity.getId(), e ); + Integer id = entity != null ? entity.getId() : -1; + throw new RuntimeException( "Failed storing testsuite-suite object with id:" + id, e ); } finally { if ( session != null ) { diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/DataSourceUtils.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/DataSourceUtils.java index 7d6b918552..435e38bc86 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/DataSourceUtils.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/DataSourceUtils.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringWriter; +import java.nio.charset.Charset; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -220,7 +221,8 @@ public class DataSourceUtils { cn.commit(); stmt.close(); LOG.info( "Loaded " + sum( insCounts ) + " rows." ); - }finally { + } + finally { try { if ( cn != null ) { cn.close(); @@ -247,9 +249,10 @@ public class DataSourceUtils { if ( is == null ) { throw new RuntimeException( "File " + fileName + " not found on Classpath." ); } + BufferedReader reader = null; try { - BufferedReader reader = new BufferedReader( - new InputStreamReader( is ) + reader = new BufferedReader( + new InputStreamReader( is, Charset.forName( "UTF-8" ) ) ); StringWriter sw = new StringWriter(); @@ -262,9 +265,8 @@ public class DataSourceUtils { return sw.toString(); } finally { - if ( is != null ) { - is.close(); - } + if (reader != null) reader.close(); + is.close(); } } 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 7da6380919..5209ededc1 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 @@ -49,8 +49,8 @@ import static org.junit.Assert.fail; */ public abstract class SpatialFunctionalTestCase extends BaseCoreFunctionalTestCase { - protected static String JTS = "jts"; - protected static String GEOLATTE = "geolatte"; + protected final static String JTS = "jts"; + protected final static String GEOLATTE = "geolatte"; protected TestData testData; protected DataSourceUtils dataSourceUtils; @@ -210,22 +210,22 @@ public abstract class SpatialFunctionalTestCase extends BaseCoreFunctionalTestCa } protected void compare(Map expected, Map received, String geometryType) { - for ( Integer id : expected.keySet() ) { + for ( Map.Entry entry: expected.entrySet()) { + Integer id = entry.getKey(); getLogger().debug( "Case :" + id ); getLogger().debug( "expected: " + expected.get( id ) ); getLogger().debug( "received: " + received.get( id ) ); - compare( id, expected.get( id ), received.get( id ), geometryType ); + compare( id, entry.getValue(), received.get( id ), geometryType ); } } - protected void compare(Integer id, Object expected, Object received, String geometryType) { assertTrue( expected != null || ( expected == null && received == null ) ); if ( expected instanceof byte[] ) { assertArrayEquals( "Failure on testsuite-suite for case " + id, (byte[]) expected, (byte[]) received ); } else if ( expected instanceof Geometry ) { - if ( geometryType == JTS ) { + if ( JTS.equals(geometryType) ) { if ( !( received instanceof Geometry ) ) { fail( "Expected a JTS Geometry, but received an object of type " + received.getClass() diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/TestData.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/TestData.java index fdda3953f7..98dc69d45d 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/TestData.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/TestData.java @@ -21,7 +21,6 @@ package org.hibernate.spatial.testing; -import java.io.InputStream; import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -37,7 +36,6 @@ import java.util.ListIterator; public class TestData implements List { private List testDataElements; - private InputStream in; protected TestData() { } diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/h2geodb/GeoDBExpressionTemplate.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/h2geodb/GeoDBExpressionTemplate.java index 694cac728f..b5a889cf5e 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/h2geodb/GeoDBExpressionTemplate.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/h2geodb/GeoDBExpressionTemplate.java @@ -33,7 +33,7 @@ import org.hibernate.spatial.testing.WktUtility; */ public class GeoDBExpressionTemplate implements SQLExpressionTemplate { - final String SQL_TEMPLATE = "insert into GEOMTEST (id, type, geom) values (%d, '%s', ST_GeomFromText('%s', %d))"; + static final String SQL_TEMPLATE = "insert into GEOMTEST (id, type, geom) values (%d, '%s', ST_GeomFromText('%s', %d))"; /* * (non-Javadoc) diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQLExpressionTemplate.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQLExpressionTemplate.java index df4eb66766..ea1c680dd5 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQLExpressionTemplate.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQLExpressionTemplate.java @@ -33,7 +33,7 @@ import org.hibernate.spatial.testing.WktUtility; */ public class MySQLExpressionTemplate implements SQLExpressionTemplate { - final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', GeomFromText('%s', %d))"; + static final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', GeomFromText('%s', %d))"; public String toInsertSql(TestDataElement testDataElement) { String wkt = WktUtility.getWkt( testDataElement.wkt ); diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/oracle/SDOGeometryExpressionTemplate.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/oracle/SDOGeometryExpressionTemplate.java index 383a940b43..f4a68ae3b6 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/oracle/SDOGeometryExpressionTemplate.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/oracle/SDOGeometryExpressionTemplate.java @@ -26,8 +26,9 @@ import org.hibernate.spatial.testing.TestDataElement; public class SDOGeometryExpressionTemplate implements SQLExpressionTemplate { - final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', %s)"; + static final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', %s)"; + @SuppressWarnings( "unchecked" ) public String toInsertSql(TestDataElement testDataElement) { SDOTestDataElement sdoTestDataElement = (SDOTestDataElement) testDataElement; return String.format( SQL_TEMPLATE, sdoTestDataElement.id, sdoTestDataElement.type, sdoTestDataElement.sdo ); diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/postgis/PostgisExpressionTemplate.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/postgis/PostgisExpressionTemplate.java index 2779dfdf37..cbb0a35e11 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/postgis/PostgisExpressionTemplate.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/postgis/PostgisExpressionTemplate.java @@ -31,7 +31,7 @@ import org.hibernate.spatial.testing.TestDataElement; */ public class PostgisExpressionTemplate implements SQLExpressionTemplate { - final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', GeomFromText('%s'))"; + static final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', GeomFromText('%s'))"; public String toInsertSql(TestDataElement testDataElement) { return String.format( diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/sqlserver/SQLServerExpressionTemplate.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/sqlserver/SQLServerExpressionTemplate.java index 4f452825e4..77e8ef8e62 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/sqlserver/SQLServerExpressionTemplate.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/sqlserver/SQLServerExpressionTemplate.java @@ -30,7 +30,7 @@ import org.hibernate.spatial.testing.WktUtility; */ public class SQLServerExpressionTemplate implements SQLExpressionTemplate { - final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', Geometry::STGeomFromText('%s', %d))"; + static final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', Geometry::STGeomFromText('%s', %d))"; public String toInsertSql(TestDataElement testDataElement) { int srid = WktUtility.getSRID( testDataElement.wkt );