You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ce...@apache.org on 2005/01/04 13:51:21 UTC
cvs commit: logging-log4j/src/java/org/apache/log4j/db/dialect Util.java
ceki 2005/01/04 04:51:20
Modified: src/java/org/apache/log4j/db ConnectionSource.java
DBAppender2.java ConnectionSourceSkeleton.java
src/java/org/apache/log4j/db/dialect Util.java
Log:
For methods in utility classes wishing to log the easiest path is to change the class so that it extends ComponentBase and to convert the method to an instance method.
Revision Changes Path
1.9 +2 -1 logging-log4j/src/java/org/apache/log4j/db/ConnectionSource.java
Index: ConnectionSource.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/ConnectionSource.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ConnectionSource.java 3 Jun 2004 22:48:17 -0000 1.8
+++ ConnectionSource.java 4 Jan 2005 12:51:15 -0000 1.9
@@ -16,6 +16,7 @@
package org.apache.log4j.db;
+import org.apache.log4j.spi.Component;
import org.apache.log4j.spi.ErrorHandler;
import org.apache.log4j.spi.OptionHandler;
@@ -30,7 +31,7 @@
*
* @author <a href="mailto:rdecampo@twcny.rr.com">Ray DeCampo</a>
*/
-public interface ConnectionSource extends OptionHandler {
+public interface ConnectionSource extends Component, OptionHandler {
final int UNKNOWN_DIALECT = 0;
final int POSTGRES_DIALECT = 1;
1.5 +2 -1 logging-log4j/src/java/org/apache/log4j/db/DBAppender2.java
Index: DBAppender2.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DBAppender2.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DBAppender2.java 20 Nov 2004 11:34:00 -0000 1.4
+++ DBAppender2.java 4 Jan 2005 12:51:15 -0000 1.5
@@ -89,7 +89,8 @@
// if getGeneratedKeys method is not supported, we fallback to batch size
// of one.
batchSize = 1;
- Util.getDialectFromCode(connectionSource.getSQLDialectCode());
+
+ sqlDialect = Util.getDialectFromCode(connectionSource.getSQLDialectCode());
if (sqlDialect == null) {
throw new IllegalStateException(
1.9 +7 -22 logging-log4j/src/java/org/apache/log4j/db/ConnectionSourceSkeleton.java
Index: ConnectionSourceSkeleton.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/ConnectionSourceSkeleton.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ConnectionSourceSkeleton.java 18 Nov 2004 22:48:03 -0000 1.8
+++ ConnectionSourceSkeleton.java 4 Jan 2005 12:51:15 -0000 1.9
@@ -16,9 +16,8 @@
package org.apache.log4j.db;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
import org.apache.log4j.db.dialect.Util;
+import org.apache.log4j.spi.ComponentBase;
import org.apache.log4j.spi.ErrorHandler;
import java.sql.Connection;
@@ -29,7 +28,7 @@
/**
* @author Ceki Gülcü
*/
-public abstract class ConnectionSourceSkeleton implements ConnectionSource {
+public abstract class ConnectionSourceSkeleton extends ComponentBase implements ConnectionSource {
protected String user = null;
protected String password = null;
protected ErrorHandler errorHandler = null;
@@ -39,22 +38,6 @@
protected boolean supportsGetGeneratedKeys = false;
protected boolean supportsBatchUpdates = false;
- // Per instance logger
- private Logger logger;
-
- /**
- * Return an instance specific logger to be used by the ConnectionSource
- * itself. This logger is not intended to be used by Mrs. Piggy, hence the
- * protected keyword.
- *
- * @return instance specific logger
- */
- protected Logger getLogger() {
- if (logger == null) {
- logger = LogManager.getLogger(this.getClass().getName());
- }
- return logger;
- }
/**
* Learn relevant information about this connection source.
@@ -64,12 +47,14 @@
try {
Connection connection = getConnection();
if (connection == null) {
- logger.warn("Could not get a conneciton");
+ getLogger().warn("Could not get a conneciton");
return;
}
DatabaseMetaData meta = connection.getMetaData();
- supportsGetGeneratedKeys = Util.supportsGetGeneratedKeys(meta);
- supportsBatchUpdates = Util.supportsBatchUpdates(meta);
+ Util util = new Util();
+ util.setLoggerRepository(repository);
+ supportsGetGeneratedKeys = util.supportsGetGeneratedKeys(meta);
+ supportsBatchUpdates = util.supportsBatchUpdates(meta);
dialectCode = Util.discoverSQLDialect(meta);
} catch (SQLException se) {
getLogger().warn("Could not discover the dialect to use.", se);
1.9 +4 -8 logging-log4j/src/java/org/apache/log4j/db/dialect/Util.java
Index: Util.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/dialect/Util.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Util.java 18 Nov 2004 22:48:03 -0000 1.8
+++ Util.java 4 Jan 2005 12:51:20 -0000 1.9
@@ -16,9 +16,8 @@
package org.apache.log4j.db.dialect;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
import org.apache.log4j.db.ConnectionSource;
+import org.apache.log4j.spi.ComponentBase;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
@@ -29,7 +28,7 @@
* @author Ceki Gulcu
*
*/
-public class Util {
+public class Util extends ComponentBase {
private static final String POSTGRES_PART = "postgresql";
private static final String MYSQL_PART = "mysql";
private static final String ORACLE_PART = "oracle";
@@ -37,9 +36,6 @@
private static final String MSSQL_PART = "microsoft";
private static final String HSQL_PART = "hsql";
- static Logger getLogger() {
- return LogManager.getLogger(Util.class);
- }
public static int discoverSQLDialect(DatabaseMetaData meta) {
int dialectCode = 0;
@@ -100,7 +96,7 @@
* {@link DatabaseMetaData#supportsGetGeneratedKeys} method is missing in the
* JDBC driver implementation.
*/
- static public boolean supportsGetGeneratedKeys(DatabaseMetaData meta) {
+ public boolean supportsGetGeneratedKeys(DatabaseMetaData meta) {
try {
return meta.supportsGetGeneratedKeys();
} catch(Throwable e) {
@@ -115,7 +111,7 @@
* {@link DatabaseMetaData#supportsBatchUpdates} method is missing in the
* JDBC driver implementation.
*/
- static public boolean supportsBatchUpdates(DatabaseMetaData meta) {
+ public boolean supportsBatchUpdates(DatabaseMetaData meta) {
try {
return meta.supportsBatchUpdates();
} catch(Throwable e) {
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org