You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by jg...@apache.org on 2009/03/25 18:18:17 UTC
svn commit: r758350 - in /ibatis/trunk/java/tools/ibator/core: build/
htmldoc/reference/ src/org/apache/ibatis/ibator/api/
src/org/apache/ibatis/ibator/internal/util/messages/
src/org/apache/ibatis/ibator/logging/
Author: jgbutler
Date: Wed Mar 25 17:18:04 2009
New Revision: 758350
URL: http://svn.apache.org/viewvc?rev=758350&view=rev
Log:
[Ibator] Some improvements to the logging API
Added:
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/AbstractLogFactory.java
Modified:
ibatis/trunk/java/tools/ibator/core/build/version.properties
ibatis/trunk/java/tools/ibator/core/htmldoc/reference/logging.html
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/CommentGenerator.java
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/util/messages/messages.properties
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/LogFactory.java
Modified: ibatis/trunk/java/tools/ibator/core/build/version.properties
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/build/version.properties?rev=758350&r1=758349&r2=758350&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/build/version.properties (original)
+++ ibatis/trunk/java/tools/ibator/core/build/version.properties Wed Mar 25 17:18:04 2009
@@ -1,4 +1,4 @@
#Ibator build version info
-#Wed Mar 25 10:30:37 CDT 2009
+#Wed Mar 25 11:41:10 CDT 2009
version=1.2.2
-buildNum=724
+buildNum=725
Modified: ibatis/trunk/java/tools/ibator/core/htmldoc/reference/logging.html
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/htmldoc/reference/logging.html?rev=758350&r1=758349&r2=758350&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/htmldoc/reference/logging.html (original)
+++ ibatis/trunk/java/tools/ibator/core/htmldoc/reference/logging.html Wed Mar 25 17:18:04 2009
@@ -49,6 +49,21 @@
<p><code>org.apache.ibatis.ibator.logging.LogFactory.forceJavaLogging();</code></p>
<p><b>Important:</b> You should specify the above line of code <i>before</i> any other Ibator code.</p>
+<h2>Supplying an Alternate Implementation</h2>
+<p>If you prefer to use a different logging implementation than Log4J or
+standard Java logging, you may supply an alternate implementation of the key logging
+interfaces as follows:</p>
+<ol>
+ <li>Create an implementation of the <code>org.apache.ibatis.ibator.logging.Log</code>
+ interface that implements the key logging methods for you logging implementation
+ of choice.</li>
+ <li>Create an implementation of the <code>org.apache.ibatis.ibator.logging.AbstractLogFactory</code>
+ interface that will return instances of your <code>Log</code> implementation.</li>
+ <li>Configure Ibator to use your new LogFactory by calling the method
+ <code>org.apache.ibatis.ibator.logging.LogFactory.setLogFactory(AbstractLogFactory)</code>
+ and supplying an instance of your <code>AbstractLogFactory</code> implementation.</li>
+</ol>
+
<h2>Configuring Log4J Logging</h2>
<p>The following is a sample Log4J configuration file:</p>
<pre>
Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/CommentGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/CommentGenerator.java?rev=758350&r1=758349&r2=758350&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/CommentGenerator.java (original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/CommentGenerator.java Wed Mar 25 17:18:04 2009
@@ -54,7 +54,7 @@
*
* @param field
* @param introspectedTable
- * @param columnName
+ * @param introspectedColumn
*/
public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn);
@@ -88,6 +88,8 @@
* This method should add a suitable comment as a child element of the
* specified xmlElement to warn users that the element was generated and
* is subject to regeneration.
+ *
+ * @param xmlElement
*/
public void addComment(XmlElement xmlElement);
Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/util/messages/messages.properties
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/util/messages/messages.properties?rev=758350&r1=758349&r2=758350&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/util/messages/messages.properties (original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/util/messages/messages.properties Wed Mar 25 17:18:04 2009
@@ -87,23 +87,30 @@
Tracing.3=Removing column "{0}" in table "{1}" because it is ignored by configuration
Tracing.4=Found override for column "{0}" in table "{1}"
-Usage.Lines=19
+Usage.Lines=26
Usage.0=Apache iBATIS Ibator - a code generator for iBATIS. Usage:
Usage.1=\ java -jar ibator.jar -configfile file_name [-overwrite]
-Usage.2=\ [-contextids ids] [-tables tableName]
-Usage.3=
-Usage.4=Where:
-Usage.5=\ -configfile: Specifies the the Ibator XML configuration file (required)
-Usage.6=
-Usage.7=\ -overwrite: If specified then exsting Java files will be overwritten.
-Usage.8=\ If not specified, then Ibator will not overwrite existing
-Usage.9=\ Java files (will save results in uniqely named files)
-Usage.10=
-Usage.11=\ -contextids: Used to specify a comma delimited list of contexts to use in
-Usage.12=\ this run of Ibator. If not specified, all contexts will be
-Usage.13=\ used.
-Usage.14=
-Usage.15=\ -tables: Used to specify a comma delimited list of tables to use in this
-Usage.16=\ run of Ibator. If not specified, all tables will be used. Table
-Usage.17=\ names must be fully qualified (e.g. schema.tablename). Table names
-Usage.18=\ must exactly match the case specified in the configuration file.
+Usage.2=\ [-contextids ids] [-tables tableNames]
+Usage.3=\ [-forceJavaLogging] [-verbose]
+Usage.4=
+Usage.5=Where:
+Usage.6=\ -configfile: Specifies the the Ibator XML configuration file (required)
+Usage.7=
+Usage.8=\ -overwrite: If specified then existing Java files will be overwritten.
+Usage.9=\ If not specified, then Ibator will not overwrite existing
+Usage.10=\ Java files (will save results in uniquely named files)
+Usage.11=
+Usage.12=\ -contextids: Used to specify a comma delimited list of contexts to use in
+Usage.13=\ this run of Ibator. If not specified, all contexts will be
+Usage.14=\ used.
+Usage.15=
+Usage.16=\ -tables: Used to specify a comma delimited list of tables to use in this
+Usage.17=\ run of Ibator. If not specified, all tables will be used. Table
+Usage.18=\ names must be fully qualified (e.g. schema.tablename). Table names
+Usage.19=\ must exactly match the case specified in the configuration file.
+Usage.20=
+Usage.21=\ -forceJavaLogging: Used to force Ibator to use standard Java logging even if
+Usage.22=\ Log4J is available in the runtime classpath. Ibator normally
+Usage.23=\ will use Log4J if it is available at runtime.
+Usage.24=
+Usage.25=\ -verbose: If specified, Ibator will write progress messages to the console.
Added: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/AbstractLogFactory.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/AbstractLogFactory.java?rev=758350&view=auto
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/AbstractLogFactory.java (added)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/AbstractLogFactory.java Wed Mar 25 17:18:04 2009
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2009 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ibatis.ibator.logging;
+
+
+/**
+ * Defines the interface for creating Log implementations.
+ *
+ * @author Jeff Butler
+ *
+ */
+public interface AbstractLogFactory {
+ Log getLog(Class<?> aClass);
+}
Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/LogFactory.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/LogFactory.java?rev=758350&r1=758349&r2=758350&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/LogFactory.java (original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/LogFactory.java Wed Mar 25 17:18:04 2009
@@ -15,47 +15,35 @@
*/
package org.apache.ibatis.ibator.logging;
-import java.lang.reflect.Constructor;
-
import org.apache.ibatis.ibator.internal.IbatorObjectFactory;
import org.apache.ibatis.ibator.internal.util.messages.Messages;
+
/**
+ * Factory for creating loggers. Uses runtime introspection
+ * to determine the AbstractLogFactory implementation.
*
- * @author Clinton Begin
* @author Jeff Butler
*
*/
public class LogFactory {
-
- private static Constructor<?> logConstructor;
-
+ private static AbstractLogFactory logFactory;
+
static {
- tryImplementation("org.apache.log4j.Logger", //$NON-NLS-1$
- "org.apache.ibatis.ibator.logging.Log4jImpl"); //$NON-NLS-1$
- tryImplementation("java.util.logging.Logger", //$NON-NLS-1$
- "org.apache.ibatis.ibator.logging.JdkLoggingImpl"); //$NON-NLS-1$
- }
-
- private static void tryImplementation(String testClassName,
- String implClassName) {
- if (logConstructor == null) {
- try {
- IbatorObjectFactory.internalClassForName(testClassName);
- Class<?> implClass = IbatorObjectFactory.internalClassForName(implClassName);
- logConstructor = implClass
- .getConstructor(new Class[] { Class.class });
- } catch (Throwable t) {
- }
+ try {
+ IbatorObjectFactory.internalClassForName("org.apache.log4j.Logger"); //$NON-NLS-1$
+ logFactory = new Log4jLoggingLogFactory();
+ } catch (Exception e) {
+ logFactory = new JdkLoggingLogFactory();
}
}
- public static Log getLog(Class<?> aClass) {
+ public static Log getLog(Class<?> clazz) {
try {
- return (Log) logConstructor.newInstance(new Object[] { aClass });
+ return logFactory.getLog(clazz);
} catch (Throwable t) {
throw new RuntimeException(Messages.getString("RuntimeError.21", //$NON-NLS-1$
- aClass.getName(), t.getMessage()), t);
+ clazz.getName(), t.getMessage()), t);
}
}
@@ -69,13 +57,22 @@
* Ibator method.
*/
public static synchronized void forceJavaLogging() {
- try {
- IbatorObjectFactory.internalClassForName("java.util.logging.Logger"); //$NON-NLS-1$
- Class<?> implClass = IbatorObjectFactory.internalClassForName(
- "org.apache.ibatis.ibator.logging.JdkLoggingImpl"); //$NON-NLS-1$
- logConstructor = implClass
- .getConstructor(new Class[] { Class.class });
- } catch (Throwable t) {
+ logFactory = new JdkLoggingLogFactory();
+ }
+
+ private static class JdkLoggingLogFactory implements AbstractLogFactory {
+ public Log getLog(Class<?> clazz) {
+ return new JdkLoggingImpl(clazz);
}
}
+
+ private static class Log4jLoggingLogFactory implements AbstractLogFactory {
+ public Log getLog(Class<?> clazz) {
+ return new Log4jImpl(clazz);
+ }
+ }
+
+ public static void setLogFactory(AbstractLogFactory logFactory) {
+ LogFactory.logFactory = logFactory;
+ }
}