HHH-6971 Migrates logging to JBoss logging.

This commit is contained in:
Karel Maesen 2012-01-14 18:48:24 +01:00 committed by Steve Ebersole
parent ee96098ead
commit 619c9ed515
18 changed files with 116 additions and 105 deletions

View File

@ -14,9 +14,6 @@ dependencies {
transitive = false
}
compile( libraries.slf4j_log4j12) {
transitive = true
}
testCompile( libraries.junit )
testCompile( project(':hibernate-testing') )

View File

@ -0,0 +1,13 @@
package org.hibernate.spatial;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.MessageLogger;
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: 1/14/12
*/
@MessageLogger(projectCode = "HS")
public interface Log extends BasicLogger {
}

View File

@ -0,0 +1,22 @@
package org.hibernate.spatial;
import org.jboss.logging.Logger;
/**
* A static factory for <code>Log</code>s.
*
* <p>This class is based on hibernate-ogm LoggerFactory class.</p>
*
* @author Karel Maesen, Geovise BVBA
* creation-date: 1/14/12
*/
public class LogFactory {
public static Log make() {
Throwable t = new Throwable();
StackTraceElement directCaller = t.getStackTrace()[1];
return Logger.getMessageLogger(Log.class, directCaller.getClassName());
}
}

View File

@ -27,6 +27,14 @@
*/
package org.hibernate.spatial.cfg;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.hibernate.cfg.Configuration;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -34,15 +42,6 @@ import java.io.InputStream;
import java.net.URL;
import java.util.Properties;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.cfg.Configuration;
/**
* Configuration information for the Hibernate Spatial Extension.
*
@ -55,7 +54,7 @@ public class HSConfiguration extends Properties {
*/
private static final long serialVersionUID = 1L;
private static Logger logger = LoggerFactory.getLogger( HSConfiguration.class );
private static Log logger = LogFactory.make();
private String source = "runtime configuration object";

View File

@ -35,8 +35,6 @@ import org.hibernate.spatial.helper.PropertyFileReader;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
@ -148,8 +146,7 @@ public class OracleSpatial10gDialect extends Oracle10gDialect implements
private final static String CONNECTION_FINDER_PROPERTY = "CONNECTION-FINDER";
private final static Logger log = LoggerFactory
.getLogger(OracleSpatial10gDialect.class);
private final static Log LOG = LogFactory.make();
private String OGC_STRICT = "OGC_STRICT";
@ -271,7 +268,7 @@ public class OracleSpatial10gDialect extends Oracle10gDialect implements
@Override
public String getTypeName(int code, long length, int precision, int scale) throws HibernateException {
if (code == 3000) return "SDO_GEOMETRY";
return super.getTypeName(code, length, precision, scale); //To change body of overridden methods use File | Settings | File Templates.
return super.getTypeName(code, length, precision, scale);
}
@Override
@ -533,7 +530,7 @@ public class OracleSpatial10gDialect extends Oracle10gDialect implements
URL propfile = loader.getResource(propfileLoc);
if (propfile != null) {
InputStream is = null;
log.info("properties file found: " + propfile);
LOG.info("properties file found: " + propfile);
try {
loader.getResource(getClass().getCanonicalName());
is = propfile.openStream();
@ -549,15 +546,15 @@ public class OracleSpatial10gDialect extends Oracle10gDialect implements
ConnectionFinder cf = (ConnectionFinder) clazz
.newInstance();
OracleJDBCTypeFactory.setConnectionFinder(cf);
log.info("Setting ConnectionFinder to " + ccn);
LOG.info("Setting ConnectionFinder to " + ccn);
} catch (ClassNotFoundException e) {
log.warn("Tried to set ConnectionFinder to " + ccn
LOG.warn("Tried to set ConnectionFinder to " + ccn
+ ", but class not found.");
} catch (InstantiationException e) {
log.warn("Tried to set ConnectionFinder to " + ccn
LOG.warn("Tried to set ConnectionFinder to " + ccn
+ ", but couldn't instantiate.");
} catch (IllegalAccessException e) {
log
LOG
.warn("Tried to set ConnectionFinder to "
+ ccn
+ ", but got IllegalAcessException on instantiation.");
@ -565,7 +562,7 @@ public class OracleSpatial10gDialect extends Oracle10gDialect implements
}
} catch (IOException e) {
log.warn("Problem reading properties file " + e);
LOG.warn("Problem reading properties file " + e);
} finally {
try {
is.close();

View File

@ -28,6 +28,9 @@
*/
package org.hibernate.spatial.helper;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@ -38,9 +41,6 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Helper class to read settings and properties files.
*
@ -48,7 +48,7 @@ import org.slf4j.LoggerFactory;
*/
public class PropertyFileReader {
private static final Logger log = LoggerFactory.getLogger( PropertyFileReader.class );
private static final Log LOG = LogFactory.make();
/**
* pattern for comment lines. If it matches, it is a comment.
@ -97,7 +97,7 @@ public class PropertyFileReader {
this.is.close();
}
catch ( IOException e ) {
log.warn( "Exception when closing PropertyFileReader: " + e );
LOG.warn( "Exception when closing PropertyFileReader: " + e );
}
}

View File

@ -29,8 +29,6 @@
package org.hibernate.spatial.jts;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A static utility class
@ -39,8 +37,6 @@ import org.slf4j.LoggerFactory;
*/
public class JTS {
private static final Logger log = LoggerFactory.getLogger( JTS.class );
private static MGeometryFactory defaultGeomFactory = new MGeometryFactory();
/**

View File

@ -29,13 +29,13 @@ import com.vividsolutions.jts.geom.Geometry;
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.SpatialFunction;
import org.hibernate.spatial.testing.SpatialDialectMatcher;
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
import org.hibernate.testing.Skip;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.HashMap;
@ -47,10 +47,10 @@ import java.util.Map;
@Skip(condition = SpatialDialectMatcher.class,message = "No Spatial Dialect")
public class TestSpatialFunctions extends SpatialFunctionalTestCase {
private static Logger LOGGER = LoggerFactory.getLogger( TestSpatialFunctions.class );
private static Log LOG = LogFactory.make();
protected Logger getLogger() {
return LOGGER;
protected Log getLogger() {
return LOG;
}
@Test

View File

@ -29,14 +29,14 @@ 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.SpatialFunction;
import org.hibernate.spatial.criterion.SpatialRestrictions;
import org.hibernate.spatial.testing.SpatialDialectMatcher;
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
import org.hibernate.testing.Skip;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.List;
@ -48,10 +48,10 @@ import static org.junit.Assert.fail;
@Skip(condition = SpatialDialectMatcher.class,message = "No Spatial Dialect")
public class TestSpatialRestrictions extends SpatialFunctionalTestCase {
private static Logger LOGGER = LoggerFactory.getLogger( TestSpatialRestrictions.class );
private static Log LOG = LogFactory.make();
protected Logger getLogger() {
return LOGGER;
protected Log getLogger() {
return LOG;
}
@Test
@ -222,7 +222,7 @@ public class TestSpatialRestrictions extends SpatialFunctionalTestCase {
}
}
assertEquals( cnt, list.size() );
LOGGER.info( String.format( "Found %d objects within testsuite-suite polygon.", cnt ) );
LOG.info( String.format( "Found %d objects within testsuite-suite polygon.", cnt ) );
}
private boolean findInList(Integer id, List<GeomEntity> list) {

View File

@ -30,13 +30,13 @@ import com.vividsolutions.jts.io.ParseException;
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.testing.SpatialDialectMatcher;
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
import org.hibernate.spatial.testing.TestDataElement;
import org.hibernate.testing.Skip;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.List;
@ -53,10 +53,10 @@ import static org.junit.Assert.assertTrue;
@Skip(condition = SpatialDialectMatcher.class, message = "No Spatial Dialect")
public class TestStoreRetrieve extends SpatialFunctionalTestCase {
private static Logger LOGGER = LoggerFactory.getLogger(TestStoreRetrieve.class);
private static Log LOG = LogFactory.make();
protected Logger getLogger() {
return LOGGER;
protected Log getLogger() {
return LOG;
}
public void prepareTest(){

View File

@ -30,8 +30,8 @@ import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import java.sql.*;
import java.util.HashMap;
@ -48,7 +48,7 @@ import java.util.Map;
*/
public abstract class AbstractExpectationsFactory {
private static final Logger LOGGER = LoggerFactory.getLogger( AbstractExpectationsFactory.class );
private static final Log LOG = LogFactory.make();
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)";
@ -793,7 +793,7 @@ public abstract class AbstractExpectationsFactory {
try {
cn = createConnection();
preparedStatement = nativeSQLStatement.prepare( cn );
LOGGER.info( "Native SQL is: " + preparedStatement.toString() );
LOG.info( "Native SQL is: " + preparedStatement.toString() );
ResultSet results = preparedStatement.executeQuery();
while ( results.next() ) {
int id = results.getInt( 1 );

View File

@ -28,8 +28,8 @@ package org.hibernate.spatial.testing;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.ParseException;
import org.apache.commons.dbcp.BasicDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import javax.sql.DataSource;
import java.io.*;
@ -46,7 +46,7 @@ import java.util.Properties;
public class DataSourceUtils {
private static Logger LOGGER = LoggerFactory.getLogger( DataSourceUtils.class );
private static Log LOG = LogFactory.make();
private final SQLExpressionTemplate sqlExpressionTemplate;
@ -180,7 +180,7 @@ public class DataSourceUtils {
PreparedStatement pmt = cn.prepareStatement( "delete from GEOMTEST" );
if ( !pmt.execute() ) {
int updateCount = pmt.getUpdateCount();
LOGGER.info( "Removing " + updateCount + " rows." );
LOG.info( "Removing " + updateCount + " rows." );
}
cn.commit();
pmt.close();
@ -205,13 +205,13 @@ public class DataSourceUtils {
Statement stmt = cn.createStatement();
for ( TestDataElement testDataElement : testData ) {
String sql = sqlExpressionTemplate.toInsertSql( testDataElement );
LOGGER.debug( "adding stmt: " + sql );
LOG.debug( "adding stmt: " + sql );
stmt.addBatch( sql );
}
int[] insCounts = stmt.executeBatch();
cn.commit();
stmt.close();
LOGGER.info( "Loaded " + sum( insCounts ) + " rows." );
LOG.info( "Loaded " + sum( insCounts ) + " rows." );
}
finally {
try {
@ -277,7 +277,7 @@ public class DataSourceUtils {
cn = getDataSource().getConnection();
cn.setAutoCommit( false );
PreparedStatement statement = cn.prepareStatement( sql );
LOGGER.info( "Executing statement: " + sql );
LOG.info( "Executing statement: " + sql );
statement.execute();
cn.commit();
statement.close();

View File

@ -5,11 +5,11 @@ import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
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 org.slf4j.Logger;
import java.sql.SQLException;
import java.util.List;
@ -130,7 +130,7 @@ public abstract class SpatialFunctionalTestCase extends BaseCoreFunctionalTestCa
return dialect.supportsFiltering();
}
abstract protected Logger getLogger();
abstract protected Log getLogger();
/**
* Adds the query results to a Map.

View File

@ -30,16 +30,17 @@ package org.hibernate.spatial.testing.dialects.sqlserver.convertors;
*/
import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.spatial.Log;
import org.hibernate.spatial.LogFactory;
import org.hibernate.spatial.dialect.sqlserver.convertors.Decoders;
import org.hibernate.spatial.dialect.sqlserver.convertors.Encoders;
import org.hibernate.spatial.dialect.sqlserver.convertors.OpenGisType;
import org.hibernate.spatial.testing.DataSourceUtils;
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
import org.hibernate.spatial.testing.TestData;
import org.hibernate.spatial.testing.TestSupport;
import org.hibernate.spatial.testing.dialects.sqlserver.SQLServerExpressionTemplate;
import org.hibernate.spatial.testing.dialects.sqlserver.SQLServerTestSupport;
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
import org.hibernate.spatial.testing.TestSupport;
import org.slf4j.Logger;
import java.io.IOException;
import java.sql.SQLException;
@ -55,10 +56,12 @@ import static org.junit.Assert.assertTrue;
*/
public abstract class AbstractConvertorTest extends SpatialFunctionalTestCase {
private DataSourceUtils dataSourceUtils;
private final static Log LOG = LogFactory.make();
private final static TestSupport support = new SQLServerTestSupport();
private DataSourceUtils dataSourceUtils;
Map<Integer, Geometry> decodedGeoms;
Map<Integer, Object> rawResults;
Map<Integer, byte[]> encodedGeoms;
@ -131,9 +134,8 @@ public abstract class AbstractConvertorTest extends SpatialFunctionalTestCase {
}
}
//TODO -- add logger.
@Override
protected Logger getLogger() {
return null; //To change body of implemented methods use File | Settings | File Templates.
protected Log getLogger() {
return LOG;
}
}

View File

@ -82,7 +82,6 @@ public class MLineStringTest extends TestCase {
int l = (int) Math.round( Math.random() * 250.0 );
l = Math.max( 2, l );
System.out.println( "Size of arbitraryline ==" + l );
mcoar = new MCoordinate[l];
for ( int i = 0; i < mcoar.length; i++ ) {
double x = Math.random() * 100000.0;

View File

@ -30,14 +30,6 @@ import com.vividsolutions.jts.geom.PrecisionModel;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.spatial.jts.mgeom.EventLocator;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MCoordinateSequenceFactory;
import org.hibernate.spatial.jts.mgeom.MGeometryException;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MLineString;
import org.hibernate.spatial.jts.mgeom.MultiMLineString;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

View File

@ -31,12 +31,6 @@ import com.vividsolutions.jts.geom.PrecisionModel;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.spatial.jts.mgeom.MCoordinate;
import org.hibernate.spatial.jts.mgeom.MCoordinateSequenceFactory;
import org.hibernate.spatial.jts.mgeom.MGeometryException;
import org.hibernate.spatial.jts.mgeom.MGeometryFactory;
import org.hibernate.spatial.jts.mgeom.MLineString;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;

View File

@ -24,31 +24,31 @@
# Default unit/integration test config.
#hibernate.dialect org.hibernate.dialect.H2Dialect
#hibernate.connection.driver_class org.h2.Driver
#hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
#hibernate.connection.username sa
#
#hibernate.connection.pool_size 5
#
#hibernate.show_sql false
#
#hibernate.max_fetch_depth 5
#
#hibernate.cache.region_prefix hibernate.test
#hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
#
## NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle
#hibernate.jdbc.batch_versioned_data true
hibernate.dialect org.hibernate.dialect.H2Dialect
hibernate.connection.driver_class org.h2.Driver
hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
hibernate.connection.username sa
hibernate.connection.pool_size 5
hibernate.show_sql false
hibernate.max_fetch_depth 5
hibernate.cache.region_prefix hibernate.test
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
# NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle
hibernate.jdbc.batch_versioned_data true
## Configs for spatial databases (used during testing on local dev environment).
hibernate.dialect org.hibernate.spatial.dialect.postgis.PostgisDialect
hibernate.connection.driver_class org.postgresql.Driver
hibernate.connection.url jdbc:postgresql://localhost:5432:hibbrtru
hibernate.connection.username hibbrtru
hibernate.connection.password hibbrtru
#hibernate.dialect org.hibernate.spatial.dialect.postgis.PostgisDialect
#hibernate.connection.driver_class org.postgresql.Driver
#hibernate.connection.url jdbc:postgresql://localhost:5432:hibbrtru
#hibernate.connection.username hibbrtru
#hibernate.connection.password hibbrtru
#hibernate.dialect org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect
#hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver