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 ca...@apache.org on 2006/01/27 00:18:01 UTC
svn commit: r372655 - in /logging/log4j/trunk/src/java/org/apache/log4j:
db/DBAppender.java db/dialect/Util.java pattern/NameAbbreviator.java
rolling/helper/GZCompressAction.java
Author: carnold
Date: Thu Jan 26 15:17:48 2006
New Revision: 372655
URL: http://svn.apache.org/viewcvs?rev=372655&view=rev
Log:
Bug 38406: Remove JDK 1.4 dependencies
Modified:
logging/log4j/trunk/src/java/org/apache/log4j/db/DBAppender.java
logging/log4j/trunk/src/java/org/apache/log4j/db/dialect/Util.java
logging/log4j/trunk/src/java/org/apache/log4j/pattern/NameAbbreviator.java
logging/log4j/trunk/src/java/org/apache/log4j/rolling/helper/GZCompressAction.java
Modified: logging/log4j/trunk/src/java/org/apache/log4j/db/DBAppender.java
URL: http://svn.apache.org/viewcvs/logging/log4j/trunk/src/java/org/apache/log4j/db/DBAppender.java?rev=372655&r1=372654&r2=372655&view=diff
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/db/DBAppender.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/db/DBAppender.java Thu Jan 26 15:17:48 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 1999,2004-2005 The Apache Software Foundation.
+ * Copyright 1999,2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@
import java.util.Iterator;
import java.util.Set;
+import java.lang.reflect.*;
/**
@@ -116,6 +117,8 @@
static final String insertExceptionSQL =
"INSERT INTO logging_event_exception (event_id, i, trace_line) VALUES (?, ?, ?)";
static final String insertSQL;
+ private static final Method GET_GENERATED_KEYS_METHOD;
+
static {
StringBuffer sql = new StringBuffer();
@@ -134,6 +137,16 @@
sql.append("caller_line) ");
sql.append(" VALUES (?, ?, ? ,?, ?, ?, ?, ?, ?, ?, ?, ?)");
insertSQL = sql.toString();
+ //
+ // PreparedStatement.getGeneratedKeys added in JDK 1.4
+ //
+ Method getGeneratedKeysMethod;
+ try {
+ getGeneratedKeysMethod = PreparedStatement.class.getMethod("getGeneratedKeys", null);
+ } catch(Exception ex) {
+ getGeneratedKeysMethod = null;
+ }
+ GET_GENERATED_KEYS_METHOD = getGeneratedKeysMethod;
}
ConnectionSource connectionSource;
@@ -141,6 +154,7 @@
boolean cnxSupportsBatchUpdates = false;
SQLDialect sqlDialect;
boolean locationInfo = false;
+
public DBAppender() {
super(false);
@@ -155,7 +169,11 @@
}
sqlDialect = Util.getDialectFromCode(connectionSource.getSQLDialectCode());
- cnxSupportsGetGeneratedKeys = connectionSource.supportsGetGeneratedKeys();
+ if (GET_GENERATED_KEYS_METHOD != null) {
+ cnxSupportsGetGeneratedKeys = connectionSource.supportsGetGeneratedKeys();
+ } else {
+ cnxSupportsGetGeneratedKeys = false;
+ }
cnxSupportsBatchUpdates = connectionSource.supportsBatchUpdates();
if (!cnxSupportsGetGeneratedKeys && (sqlDialect == null)) {
throw new IllegalStateException(
@@ -219,9 +237,23 @@
ResultSet rs = null;
Statement idStatement = null;
+ boolean gotGeneratedKeys = false;
if (cnxSupportsGetGeneratedKeys) {
- rs = insertStatement.getGeneratedKeys();
- } else {
+ try {
+ rs = (ResultSet) GET_GENERATED_KEYS_METHOD.invoke(insertStatement, null);
+ gotGeneratedKeys = true;
+ } catch(InvocationTargetException ex) {
+ Throwable target = ex.getTargetException();
+ if (target instanceof SQLException) {
+ throw (SQLException) target;
+ }
+ throw ex;
+ } catch(IllegalAccessException ex) {
+ getLogger().warn("IllegalAccessException invoking PreparedStatement.getGeneratedKeys", ex);
+ }
+ }
+
+ if (!gotGeneratedKeys) {
insertStatement.close();
insertStatement = null;
@@ -295,7 +327,7 @@
} else {
insertExceptionStatement.execute();
}
- }
+ }
if (cnxSupportsBatchUpdates) {
insertExceptionStatement.executeBatch();
}
@@ -304,7 +336,7 @@
}
connection.commit();
- } catch (SQLException sqle) {
+ } catch (Throwable sqle) {
getLogger().error("problem appending event", sqle);
} finally {
DBHelper.closeConnection(connection);
Modified: logging/log4j/trunk/src/java/org/apache/log4j/db/dialect/Util.java
URL: http://svn.apache.org/viewcvs/logging/log4j/trunk/src/java/org/apache/log4j/db/dialect/Util.java?rev=372655&r1=372654&r2=372655&view=diff
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/db/dialect/Util.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/db/dialect/Util.java Thu Jan 26 15:17:48 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -98,10 +98,12 @@
*/
public boolean supportsGetGeneratedKeys(DatabaseMetaData meta) {
try {
- return meta.supportsGetGeneratedKeys();
+ //
+ // invoking JDK 1.4 method by reflection
+ //
+ return ((Boolean) DatabaseMetaData.class.getMethod("supportsGetGeneratedKeys", null).invoke(meta, null)).booleanValue();
} catch(Throwable e) {
- getLogger().warn("The following warning is only informative.");
- getLogger().warn("Could not call supportsGetGeneratedKeys method. This may be recoverable");
+ getLogger().info("Could not call supportsGetGeneratedKeys method. This may be recoverable");
return false;
}
}
@@ -115,7 +117,7 @@
try {
return meta.supportsBatchUpdates();
} catch(Throwable e) {
- getLogger().warn("Missing DatabaseMetaData.supportsBatchUpdates method.");
+ getLogger().info("Missing DatabaseMetaData.supportsBatchUpdates method.");
return false;
}
}
Modified: logging/log4j/trunk/src/java/org/apache/log4j/pattern/NameAbbreviator.java
URL: http://svn.apache.org/viewcvs/logging/log4j/trunk/src/java/org/apache/log4j/pattern/NameAbbreviator.java?rev=372655&r1=372654&r2=372655&view=diff
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/pattern/NameAbbreviator.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/pattern/NameAbbreviator.java Thu Jan 26 15:17:48 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 1999,2005 The Apache Software Foundation.
+ * Copyright 1999,2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -181,8 +181,9 @@
// precision is 1 and the category name ends with a dot.
int end = buf.length() - 1;
+ String bufString = buf.toString();
for (int i = count; i > 0; i--) {
- end = buf.lastIndexOf(".", end - 1);
+ end = bufString.lastIndexOf(".", end - 1);
if ((end == -1) || (end < nameStart)) {
return;
@@ -228,7 +229,7 @@
* @return starting index of next element.
*/
public int abbreviate(final StringBuffer buf, final int startPos) {
- int nextDot = buf.indexOf(".", startPos);
+ int nextDot = buf.toString().indexOf(".", startPos);
if (nextDot != -1) {
if ((nextDot - startPos) > charCount) {
Modified: logging/log4j/trunk/src/java/org/apache/log4j/rolling/helper/GZCompressAction.java
URL: http://svn.apache.org/viewcvs/logging/log4j/trunk/src/java/org/apache/log4j/rolling/helper/GZCompressAction.java?rev=372655&r1=372654&r2=372655&view=diff
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/rolling/helper/GZCompressAction.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/rolling/helper/GZCompressAction.java Thu Jan 26 15:17:48 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 1999,2005 The Apache Software Foundation.
+ * Copyright 1999,2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -104,7 +104,7 @@
final ULogger logger) throws IOException {
if (source.exists()) {
FileInputStream fis = new FileInputStream(source);
- FileOutputStream fos = new FileOutputStream(destination, false);
+ FileOutputStream fos = new FileOutputStream(destination);
GZIPOutputStream gzos = new GZIPOutputStream(fos);
byte[] inbuf = new byte[8102];
int n;
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org