HHH-6509 - Cleans up findBug warnings.

This commit is contained in:
Karel Maesen 2014-04-29 23:59:20 +02:00 committed by Steve Ebersole
parent e80a67307f
commit ed98698aa4
18 changed files with 46 additions and 48 deletions

View File

@ -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;

View File

@ -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 );

View File

@ -398,7 +398,6 @@ class SDOGeometryValueBinder<J> implements ValueBinder<J> {
* @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;

View File

@ -422,7 +422,7 @@ public class SDOGeometryValueExtractor<X> extends BasicExtractor<X> {
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(

View File

@ -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<String, Object> entry: params.entrySet() ) {
query.setParameter( entry.getKey(), entry.getValue() );
}
}

View File

@ -211,11 +211,11 @@ public class TestSpatialRestrictions extends SpatialFunctionalTestCase {
private void compare(Map<Integer, Boolean> dbexpected, List list) {
int cnt = 0;
for ( Integer id : dbexpected.keySet() ) {
if ( dbexpected.get( id ) ) {
for ( Map.Entry<Integer, Boolean> entry : dbexpected.entrySet() ) {
if ( entry.getValue() ) {
cnt++;
if ( !findInList( id, (List<GeomEntity>) list ) ) {
fail( String.format( "Expected object with id= %d, but not found in result", id ) );
if ( !findInList( entry.getKey(), (List<GeomEntity>) 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<GeomEntity> list) {
for ( GeomEntity entity : list ) {
if ( entity.getId() == id ) {
if ( entity.getId().equals( id ) ) {
return true;
}
}

View File

@ -92,7 +92,7 @@ public class GeomEntity {
GeomEntity geomEntity = (GeomEntity) o;
if ( id != geomEntity.id ) {
if ( ! id.equals(geomEntity.id) ) {
return false;
}

View File

@ -43,7 +43,7 @@ public class TestStoreRetrieveUsingGeolatte extends SpatialFunctionalTestCase {
@Test
public void testAfterStoreRetrievingEqualObject() throws WktDecodeException {
Map<Integer,GeomEntity> stored = new HashMap<Integer, GeomEntity>();
Map<Integer, GeomEntity> stored = new HashMap<Integer, GeomEntity>();
//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<Integer,GeomEntity> stored) {
private void storeTestObjects(Map<Integer, GeomEntity> 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 ) {

View File

@ -93,7 +93,7 @@ public class GeomEntity {
GeomEntity geomEntity = (GeomEntity) o;
if ( id != geomEntity.id ) {
if ( !id.equals( geomEntity.id ) ) {
return false;
}

View File

@ -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 ) {

View File

@ -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();
}
}

View File

@ -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 <T> void compare(Map<Integer, T> expected, Map<Integer, T> received, String geometryType) {
for ( Integer id : expected.keySet() ) {
for ( Map.Entry<Integer, T> 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()

View File

@ -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<TestDataElement> {
private List<TestDataElement> testDataElements;
private InputStream in;
protected TestData() {
}

View File

@ -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)

View File

@ -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 );

View File

@ -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 );

View File

@ -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(

View File

@ -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 );