Added: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBReceiver.html URL: http://svn.apache.org/viewvc/logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBReceiver.html?view=auto&rev=558362 ============================================================================== --- logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBReceiver.html (added) +++ logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBReceiver.html Sat Jul 21 10:50:33 2007 @@ -0,0 +1,153 @@ + + + +DBReceiver xref + + + +
View Javadoc
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one or more
+3    * contributor license agreements.  See the NOTICE file distributed with
+4    * this work for additional information regarding copyright ownership.
+5    * The ASF licenses this file to You under the Apache License, Version 2.0
+6    * (the "License"); you may not use this file except in compliance with
+7    * the License.  You may obtain a copy of the License at
+8    *
+9    *      http://www.apache.org/licenses/LICENSE-2.0
+10   *
+11   * Unless required by applicable law or agreed to in writing, software
+12   * distributed under the License is distributed on an "AS IS" BASIS,
+13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+14   * See the License for the specific language governing permissions and
+15   * limitations under the License.
+16   */
+17  
+18  package org.apache.log4j.db;
+19  
+20  import org.apache.log4j.plugins.Pauseable;
+21  import org.apache.log4j.plugins.Receiver;
+22  import org.apache.log4j.scheduler.Scheduler;
+23  import org.apache.log4j.spi.LoggerRepositoryEx;
+24  import org.apache.log4j.xml.DOMConfigurator;
+25  import org.apache.log4j.xml.UnrecognizedElementHandler;
+26  import org.w3c.dom.Element;
+27  
+28  import java.util.Properties;
+29  
+30  /***
+31   *
+32   * @author Scott Deboy <sdeboy@apache.org>
+33   * @author Ceki G&uuml;lc&uuml;
+34   *
+35   */
+36  public class DBReceiver extends Receiver implements Pauseable, UnrecognizedElementHandler {
+37    /***
+38     * By default we refresh data every 1000 milliseconds.
+39     * @see #setRefreshMillis
+40     */
+41    static int DEFAULT_REFRESH_MILLIS = 1000;
+42    ConnectionSource connectionSource;
+43    int refreshMillis = DEFAULT_REFRESH_MILLIS;
+44    DBReceiverJob receiverJob;
+45    boolean paused = false;
+46  
+47    public void activateOptions() {
+48      
+49      if(connectionSource == null)  {
+50        throw new IllegalStateException(
+51          "DBAppender cannot function without a connection source");
+52      }
+53    
+54      receiverJob = new DBReceiverJob(this);
+55      receiverJob.setLoggerRepository(repository);
+56        
+57      if(this.repository == null) {
+58        throw new IllegalStateException(
+59        "DBAppender cannot function without a reference to its owning repository");
+60      }
+61  
+62      if (repository instanceof LoggerRepositoryEx) {
+63          Scheduler scheduler = ((LoggerRepositoryEx) repository).getScheduler();
+64      
+65          scheduler.schedule(
+66              receiverJob, System.currentTimeMillis() + 500, refreshMillis);
+67      }
+68     
+69    }
+70  
+71    public void setRefreshMillis(int refreshMillis) {
+72      this.refreshMillis = refreshMillis;
+73    }
+74  
+75    public int getRefreshMillis() {
+76      return refreshMillis;
+77    }
+78  
+79  
+80    /***
+81     * @return Returns the connectionSource.
+82     */
+83    public ConnectionSource getConnectionSource() {
+84      return connectionSource;
+85    }
+86  
+87  
+88    /***
+89     * @param connectionSource The connectionSource to set.
+90     */
+91    public void setConnectionSource(ConnectionSource connectionSource) {
+92      this.connectionSource = connectionSource;
+93    }
+94  
+95  
+96    /* (non-Javadoc)
+97     * @see org.apache.log4j.plugins.Plugin#shutdown()
+98     */
+99    public void shutdown() {
+100     getLogger().info("removing receiverJob from the Scheduler.");
+101 
+102     if(this.repository instanceof LoggerRepositoryEx) {
+103       Scheduler scheduler = ((LoggerRepositoryEx) repository).getScheduler();
+104       scheduler.delete(receiverJob);
+105     }
+106   }
+107 
+108 
+109   /* (non-Javadoc)
+110    * @see org.apache.log4j.plugins.Pauseable#setPaused(boolean)
+111    */
+112   public void setPaused(boolean paused) {
+113     this.paused = paused;
+114   }
+115 
+116   /* (non-Javadoc)
+117    * @see org.apache.log4j.plugins.Pauseable#isPaused()
+118    */
+119   public boolean isPaused() {
+120     return paused;
+121   }
+122 
+123     /***
+124      * @{inheritDoc}
+125      */
+126   public boolean parseUnrecognizedElement(Element element, Properties props) throws Exception {
+127         if ("connectionSource".equals(element.getNodeName())) {
+128             Object instance =
+129                     DOMConfigurator.parseElement(element, props, ConnectionSource.class);
+130             if (instance instanceof ConnectionSource) {
+131                 ConnectionSource source = (ConnectionSource) instance;
+132                 source.activateOptions();
+133                 setConnectionSource(source);
+134             }
+135             return true;
+136         }
+137         return false;
+138   }
+139 
+140 }
+
+
+ + Propchange: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBReceiver.html ------------------------------------------------------------------------------ svn:mime-type = text/html Added: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBReceiverJob.html URL: http://svn.apache.org/viewvc/logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBReceiverJob.html?view=auto&rev=558362 ============================================================================== --- logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBReceiverJob.html (added) +++ logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBReceiverJob.html Sat Jul 21 10:50:33 2007 @@ -0,0 +1,243 @@ + + + +DBReceiverJob xref + + + +
View Javadoc
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one or more
+3    * contributor license agreements.  See the NOTICE file distributed with
+4    * this work for additional information regarding copyright ownership.
+5    * The ASF licenses this file to You under the Apache License, Version 2.0
+6    * (the "License"); you may not use this file except in compliance with
+7    * the License.  You may obtain a copy of the License at
+8    *
+9    *      http://www.apache.org/licenses/LICENSE-2.0
+10   *
+11   * Unless required by applicable law or agreed to in writing, software
+12   * distributed under the License is distributed on an "AS IS" BASIS,
+13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+14   * See the License for the specific language governing permissions and
+15   * limitations under the License.
+16   */
+17  
+18  package org.apache.log4j.db;
+19  
+20  import org.apache.log4j.Level;
+21  import org.apache.log4j.Logger;
+22  import org.apache.log4j.scheduler.Job;
+23  import org.apache.log4j.spi.ComponentBase;
+24  import org.apache.log4j.spi.LocationInfo;
+25  import org.apache.log4j.spi.LoggingEvent;
+26  import org.apache.log4j.spi.ThrowableInformation;
+27  
+28  import java.sql.Connection;
+29  import java.sql.PreparedStatement;
+30  import java.sql.ResultSet;
+31  import java.sql.SQLException;
+32  import java.util.Hashtable;
+33  import java.util.Vector;
+34  
+35  /***
+36   * Actual retrieval of data is made by the instance of DBReceiverJob associated
+37   * with DBReceiver.
+38   * 
+39   * @author Ceki G&uuml;lc&uuml;
+40   */
+41  class DBReceiverJob extends ComponentBase implements Job {
+42  
+43    String sqlException = "SELECT trace_line FROM logging_event_exception where event_id=? ORDER by i ASC";
+44    String sqlProperties = "SELECT mapped_key, mapped_value FROM logging_event_property WHERE event_id=?";
+45    String sqlSelect = 
+46      "SELECT " +
+47      "sequence_number, timestamp, rendered_message, logger_name, " +
+48      "level_string, ndc, thread_name, reference_flag, " +
+49      "caller_filename, caller_class, caller_method, caller_line, " +
+50      "event_id " +
+51      "FROM logging_event " +
+52      "WHERE event_id > ?  ORDER BY event_id ASC";
+53  
+54  
+55    long lastId = Short.MIN_VALUE;
+56  
+57    DBReceiver parentDBReceiver;
+58  
+59    DBReceiverJob(DBReceiver parent) {
+60      parentDBReceiver = parent;
+61    }
+62  
+63    public void execute() {
+64      getLogger().debug("DBReceiverJob.execute() called");
+65  
+66      Connection connection = null;
+67  
+68      try {
+69        connection = parentDBReceiver.connectionSource.getConnection();
+70        PreparedStatement statement = connection.prepareStatement(sqlSelect);
+71        statement.setLong(1, lastId);
+72        ResultSet rs = statement.executeQuery();
+73        //rs.beforeFirst();
+74  
+75        while (rs.next()) {
+76  	    Logger logger = null;
+77  	    long timeStamp = 0L;
+78  	    String level = null;
+79  	    String threadName = null;
+80  	    Object message = null;
+81  	    String ndc = null;
+82  	    String className = null;
+83  	    String methodName = null;
+84  	    String fileName = null;
+85  	    String lineNumber = null;
+86  	    Hashtable properties = new Hashtable();
+87  	
+88  
+89          //event.setSequenceNumber(rs.getLong(1));
+90          timeStamp = rs.getLong(2);
+91          message = rs.getString(3);
+92  		logger = Logger.getLogger(rs.getString(4));
+93          level = rs.getString(5);
+94  		Level levelImpl = Level.toLevel(level.trim());
+95  
+96          ndc = rs.getString(6);
+97          threadName = rs.getString(7);
+98  
+99          short mask = rs.getShort(8);
+100 
+101         fileName = rs.getString(9);
+102         className = rs.getString(10);
+103         methodName = rs.getString(11);
+104         lineNumber = rs.getString(12).trim();
+105 
+106 		LocationInfo locationInfo = null;
+107         if (fileName.equals(LocationInfo.NA)) {
+108           locationInfo = LocationInfo.NA_LOCATION_INFO;
+109         } else {
+110           locationInfo = new LocationInfo(fileName, className,
+111               methodName, lineNumber);
+112         }
+113 
+114         long id = rs.getLong(13);
+115         //LogLog.info("Received event with id=" + id);
+116         lastId = id;
+117 
+118 		ThrowableInformation throwableInfo = null;
+119         if ((mask & DBHelper.EXCEPTION_EXISTS) != 0) {
+120           throwableInfo = getException(connection, id);
+121         }
+122 
+123 	    LoggingEvent event = new LoggingEvent(logger.getName(),
+124 	            logger, timeStamp, levelImpl, message,
+125 	            threadName,
+126 	            throwableInfo,
+127 	            ndc,
+128 	            locationInfo,
+129 	            properties);
+130 
+131 
+132         // Scott asked for this info to be
+133         event.setProperty("log4jid", Long.toString(id));
+134 
+135         if ((mask & DBHelper.PROPERTIES_EXIST) != 0) {
+136           getProperties(connection, id, event);
+137         }
+138 
+139 
+140 
+141 
+142         if (!parentDBReceiver.isPaused()) {
+143           parentDBReceiver.doPost(event);
+144         }
+145       } // while
+146       statement.close();
+147       statement = null;
+148     } catch (SQLException sqle) {
+149       getLogger().error("Problem receiving events", sqle);
+150     } finally {
+151       closeConnection(connection);
+152     }
+153   }
+154 
+155   void closeConnection(Connection connection) {
+156     if (connection != null) {
+157       try {
+158         //LogLog.warn("closing the connection. ", new Exception("x"));
+159         connection.close();
+160       } catch (SQLException sqle) {
+161         // nothing we can do here
+162       }
+163     }
+164   }
+165 
+166   /***
+167    * Retrieve the event properties from the logging_event_property table.
+168    * 
+169    * @param connection
+170    * @param id
+171    * @param event
+172    * @throws SQLException
+173    */
+174   void getProperties(Connection connection, long id, LoggingEvent event)
+175       throws SQLException {
+176 
+177     PreparedStatement statement = connection.prepareStatement(sqlProperties);
+178     try {
+179       statement.setLong(1, id);
+180       ResultSet rs = statement.executeQuery();
+181 
+182       while (rs.next()) {
+183         String key = rs.getString(1);
+184         String value = rs.getString(2);
+185         event.setProperty(key, value);
+186       }
+187     } finally {
+188       statement.close();
+189     }
+190   }
+191 
+192   /***
+193    * Retrieve the exception string representation from the
+194    * logging_event_exception table.
+195    * 
+196    * @param connection
+197    * @param id
+198    * @throws SQLException
+199    */
+200   ThrowableInformation getException(Connection connection, long id)
+201       throws SQLException {
+202 
+203     PreparedStatement statement = null;
+204 
+205     try {
+206       statement = connection.prepareStatement(sqlException);
+207       statement.setLong(1, id);
+208       ResultSet rs = statement.executeQuery();
+209 
+210       Vector v = new Vector();
+211 
+212       while (rs.next()) {
+213         //int i = rs.getShort(1);
+214         v.add(rs.getString(1));
+215       }
+216 
+217       int len = v.size();
+218       String[] strRep = new String[len];
+219       for (int i = 0; i < len; i++) {
+220         strRep[i] = (String) v.get(i);
+221       }
+222       // we've filled strRep, we now attach it to the event
+223       return new ThrowableInformation(strRep);
+224     } finally {
+225       if (statement != null) {
+226         statement.close();
+227       }
+228     }
+229   }
+230 }
+
+
+ + Propchange: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBReceiverJob.html ------------------------------------------------------------------------------ svn:mime-type = text/html Added: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DataSourceConnectionSource.html URL: http://svn.apache.org/viewvc/logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DataSourceConnectionSource.html?view=auto&rev=558362 ============================================================================== --- logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DataSourceConnectionSource.html (added) +++ logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DataSourceConnectionSource.html Sat Jul 21 10:50:33 2007 @@ -0,0 +1,118 @@ + + + +DataSourceConnectionSource xref + + + +
View Javadoc
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one or more
+3    * contributor license agreements.  See the NOTICE file distributed with
+4    * this work for additional information regarding copyright ownership.
+5    * The ASF licenses this file to You under the Apache License, Version 2.0
+6    * (the "License"); you may not use this file except in compliance with
+7    * the License.  You may obtain a copy of the License at
+8    *
+9    *      http://www.apache.org/licenses/LICENSE-2.0
+10   *
+11   * Unless required by applicable law or agreed to in writing, software
+12   * distributed under the License is distributed on an "AS IS" BASIS,
+13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+14   * See the License for the specific language governing permissions and
+15   * limitations under the License.
+16   */
+17  
+18  package org.apache.log4j.db;
+19  
+20  
+21  import org.apache.log4j.xml.DOMConfigurator;
+22  import org.apache.log4j.xml.UnrecognizedElementHandler;
+23  import org.w3c.dom.Element;
+24  
+25  import javax.sql.DataSource;
+26  import java.sql.Connection;
+27  import java.sql.SQLException;
+28  import java.util.Properties;
+29  
+30  
+31  /***
+32   *  The DataSourceConnectionSource is an implementation of {@link ConnectionSource}
+33   *  that obtains the Connection in the recommended JDBC manner based on
+34   *  a {@link javax.sql.DataSource DataSource}.
+35   *  <p>
+36   *
+37   *  @author Ray DeCampo
+38   *  @author Ceki G&uuml;lc&uuml;
+39   */
+40  public class DataSourceConnectionSource extends ConnectionSourceSkeleton
+41          implements UnrecognizedElementHandler {
+42  
+43    private DataSource dataSource;
+44  
+45    
+46    public void activateOptions() {
+47      //LogLog.debug("**********DataSourceConnectionSource.activateOptions called");
+48      if (dataSource == null) {
+49        getLogger().warn("WARNING: No data source specified");
+50      } else {
+51        Connection connection = null;
+52        try {
+53          connection = getConnection();
+54        } catch(SQLException se) {
+55          getLogger().warn("Could not get a connection to discover the dialect to use.", se);
+56        }
+57        if(connection != null) {
+58          discoverConnnectionProperties();
+59        } 
+60        if(!supportsGetGeneratedKeys() && getSQLDialectCode() == ConnectionSource.UNKNOWN_DIALECT) {
+61          getLogger().warn("Connection does not support GetGeneratedKey method and could not discover the dialect.");
+62        }
+63      }
+64    }
+65  
+66    /***
+67     * @see org.apache.log4j.db.ConnectionSource#getConnection()
+68     */
+69    public Connection getConnection() throws SQLException {
+70      if (dataSource == null) {
+71        getLogger().error("WARNING: No data source specified");
+72        return null;
+73      }
+74  
+75      if (getUser() == null) {
+76        return dataSource.getConnection();
+77      } else {
+78        return dataSource.getConnection(getUser(), getPassword());
+79      }
+80    }
+81  
+82    public DataSource getDataSource() {
+83      return dataSource;
+84    }
+85  
+86    public void setDataSource(DataSource dataSource) {
+87      this.dataSource = dataSource;
+88    }
+89  
+90      /***
+91       * @{inheritDoc}
+92       */
+93    public boolean parseUnrecognizedElement(Element element, Properties props) throws Exception {
+94          if ("dataSource".equals(element.getNodeName())) {
+95              Object instance =
+96                      DOMConfigurator.parseElement(element, props, DataSource.class);
+97              if (instance instanceof DataSource) {
+98                 setDataSource((DataSource) instance);
+99              }
+100             return true;
+101         }
+102         return false;
+103   }
+104 
+105 }
+
+
+ + Propchange: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DataSourceConnectionSource.html ------------------------------------------------------------------------------ svn:mime-type = text/html Added: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DriverManagerConnectionSource.html URL: http://svn.apache.org/viewvc/logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DriverManagerConnectionSource.html?view=auto&rev=558362 ============================================================================== --- logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DriverManagerConnectionSource.html (added) +++ logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DriverManagerConnectionSource.html Sat Jul 21 10:50:33 2007 @@ -0,0 +1,146 @@ + + + +DriverManagerConnectionSource xref + + + +
View Javadoc
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one or more
+3    * contributor license agreements.  See the NOTICE file distributed with
+4    * this work for additional information regarding copyright ownership.
+5    * The ASF licenses this file to You under the Apache License, Version 2.0
+6    * (the "License"); you may not use this file except in compliance with
+7    * the License.  You may obtain a copy of the License at
+8    *
+9    *      http://www.apache.org/licenses/LICENSE-2.0
+10   *
+11   * Unless required by applicable law or agreed to in writing, software
+12   * distributed under the License is distributed on an "AS IS" BASIS,
+13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+14   * See the License for the specific language governing permissions and
+15   * limitations under the License.
+16   */
+17  
+18  package org.apache.log4j.db;
+19  
+20  import java.sql.Connection;
+21  import java.sql.DriverManager;
+22  import java.sql.SQLException;
+23  
+24  
+25  /***
+26   *  The DriverManagerConnectionSource is an implementation of {@link ConnectionSource}
+27   *  that obtains the Connection in the traditional JDBC manner based on the
+28   *  connection URL.
+29   *  <p>
+30   *  Note that this class will establish a new Connection for each call to
+31   *  {@link #getConnection()}.  It is recommended that you either use a JDBC
+32   *  driver that natively supported Connection pooling or that you create
+33   *  your own implementation of {@link ConnectionSource} that taps into whatever
+34   *  pooling mechanism you are already using.  (If you have access to a JNDI
+35   *  implementation that supports {@link javax.sql.DataSource}s, e.g. within
+36   *  a J2EE application server, see {@link JNDIConnectionSource}).  See
+37   *  <a href="#dbcp">below</a> for a configuration example that uses the
+38   *  <a href="http://jakarta.apache.org/commons/dbcp/index.html">commons-dbcp</a>
+39   *  package from Apache.
+40   *  <p>
+41   *  Sample configuration:<br>
+42   *  <pre>
+43   *     &lt;connectionSource class="org.apache.log4j.jdbc.DriverManagerConnectionSource"&gt;
+44   *        &lt;param name="driver" value="com.mysql.jdbc.Driver" /&gt;
+45   *        &lt;param name="url" value="jdbc:mysql://localhost:3306/mydb" /&gt;
+46   *        &lt;param name="username" value="myUser" /&gt;
+47   *        &lt;param name="password" value="myPassword" /&gt;
+48   *     &lt;/connectionSource&gt;
+49   *  </pre>
+50   *  <p>
+51   *  <a name="dbcp">If</a> you do not have another connection pooling mechanism
+52   *  built into your application, you can use  the
+53   *  <a href="http://jakarta.apache.org/commons/dbcp/index.html">commons-dbcp</a>
+54   *  package from Apache:<br>
+55   *  <pre>
+56   *     &lt;connectionSource class="org.apache.log4j.jdbc.DriverManagerConnectionSource"&gt;
+57   *        &lt;param name="driver" value="org.apache.commons.dbcp.PoolingDriver" /&gt;
+58   *        &lt;param name="url" value="jdbc:apache:commons:dbcp:/myPoolingDriver" /&gt;
+59   *     &lt;/connectionSource&gt;
+60   *  </pre>
+61   *  Then the configuration information for the commons-dbcp package goes into
+62   *  the file myPoolingDriver.jocl and is placed in the classpath.  See the
+63   *  <a href="http://jakarta.apache.org/commons/dbcp/index.html">commons-dbcp</a>
+64   *  documentation for details.
+65   *
+66   *  @author <a href="mailto:rdecampo@twcny.rr.com">Ray DeCampo</a>
+67   */
+68  public class DriverManagerConnectionSource extends ConnectionSourceSkeleton {
+69    private String driverClass = null;
+70    private String url = null;
+71  
+72    public void activateOptions() {
+73      try {
+74        if (driverClass != null) {
+75          Class.forName(driverClass);
+76          discoverConnnectionProperties();
+77        } else {
+78          getLogger().error(
+79            "WARNING: No JDBC driver specified for log4j DriverManagerConnectionSource.");
+80        }
+81      } catch (final ClassNotFoundException cnfe) {
+82       getLogger().error("Could not load JDBC driver class: " + driverClass, cnfe);
+83      }
+84    }
+85  
+86  
+87    /***
+88     * @see org.apache.log4j.db.ConnectionSource#getConnection()
+89     */
+90    public Connection getConnection() throws SQLException {
+91      if (getUser() == null) {
+92        return DriverManager.getConnection(url);
+93      } else {
+94        return DriverManager.getConnection(url, getUser(), getPassword());
+95      }
+96    }
+97  
+98  
+99    /***
+100    * Returns the url.
+101    * @return String
+102    */
+103   public String getUrl() {
+104     return url;
+105   }
+106 
+107 
+108   /***
+109    * Sets the url.
+110    * @param url The url to set
+111    */
+112   public void setUrl(String url) {
+113     this.url = url;
+114   }
+115 
+116 
+117   /***
+118    * Returns the name of the driver class.
+119    * @return String
+120    */
+121   public String getDriverClass() {
+122     return driverClass;
+123   }
+124 
+125 
+126   /***
+127    * Sets the driver class.
+128    * @param driverClass The driver class to set
+129    */
+130   public void setDriverClass(String driverClass) {
+131     this.driverClass = driverClass;
+132   }
+133 }
+
+
+ + Propchange: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DriverManagerConnectionSource.html ------------------------------------------------------------------------------ svn:mime-type = text/html Added: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/JNDIConnectionSource.html URL: http://svn.apache.org/viewvc/logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/JNDIConnectionSource.html?view=auto&rev=558362 ============================================================================== --- logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/JNDIConnectionSource.html (added) +++ logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/JNDIConnectionSource.html Sat Jul 21 10:50:33 2007 @@ -0,0 +1,156 @@ + + + +JNDIConnectionSource xref + + + +
View Javadoc
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one or more
+3    * contributor license agreements.  See the NOTICE file distributed with
+4    * this work for additional information regarding copyright ownership.
+5    * The ASF licenses this file to You under the Apache License, Version 2.0
+6    * (the "License"); you may not use this file except in compliance with
+7    * the License.  You may obtain a copy of the License at
+8    *
+9    *      http://www.apache.org/licenses/LICENSE-2.0
+10   *
+11   * Unless required by applicable law or agreed to in writing, software
+12   * distributed under the License is distributed on an "AS IS" BASIS,
+13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+14   * See the License for the specific language governing permissions and
+15   * limitations under the License.
+16   */
+17  package org.apache.log4j.db;
+18  
+19  import java.sql.Connection;
+20  import java.sql.SQLException;
+21  
+22  import javax.naming.Context;
+23  import javax.naming.InitialContext;
+24  import javax.naming.NamingException;
+25  
+26  // PortableRemoteObject was introduced in JDK 1.3. We won't use it.
+27  // import javax.rmi.PortableRemoteObject;
+28  import javax.sql.DataSource;
+29  
+30  
+31  /***
+32   *  The <id>JNDIConnectionSource</id> is an implementation of
+33   *  {@link ConnectionSource} that obtains a {@link javax.sql.DataSource} from a
+34   *  JNDI provider and uses it to obtain a {@link java.sql.Connection}.  It is
+35   *  primarily designed to be used inside of J2EE application servers or
+36   *  application server clients, assuming the application server supports remote
+37   *  access of {@link javax.sql.DataSource}s.  In this way one can take
+38   *  advantage of  connection pooling and whatever other goodies the application
+39   *  server provides.
+40   *  <p>
+41   *  Sample configuration:<br>
+42   *  <pre>
+43   *    &lt;connectionSource class="org.apache.log4j.jdbc.JNDIConnectionSource"&gt;
+44   *        &lt;param name="jndiLocation" value="jdbc/MySQLDS" /&gt;
+45   *    &lt;/connectionSource&gt;
+46   *  </pre>
+47   *  <p>
+48   *  Sample configuration (with username and password):<br>
+49   *  <pre>
+50   *    &lt;connectionSource class="org.apache.log4j.jdbc.JNDIConnectionSource"&gt;
+51   *        &lt;param name="jndiLocation" value="jdbc/MySQLDS" /&gt;
+52   *        &lt;param name="username" value="myUser" /&gt;
+53   *        &lt;param name="password" value="myPassword" /&gt;
+54   *    &lt;/connectionSource&gt;
+55   *  </pre>
+56   *  <p>
+57   *  Note that this class will obtain an {@link javax.naming.InitialContext}
+58   *  using the no-argument constructor.  This will usually work when executing
+59   *  within a J2EE environment.  When outside the J2EE environment, make sure
+60   *  that you provide a jndi.properties file as described by your JNDI
+61   *  provider's documentation.
+62   *
+63   *  @author <a href="mailto:rdecampo@twcny.rr.com">Ray DeCampo</a>
+64   */
+65  public class JNDIConnectionSource
+66         extends ConnectionSourceSkeleton {
+67    private String jndiLocation = null;
+68    private DataSource dataSource = null;
+69  
+70    /***
+71     * @see org.apache.log4j.spi.OptionHandler#activateOptions()
+72     */
+73    public void activateOptions() {
+74      if (jndiLocation == null) {
+75        getLogger().error("No JNDI location specified for JNDIConnectionSource.");
+76      }
+77      
+78      discoverConnnectionProperties();
+79  
+80    }
+81    
+82    /***
+83     * @see org.apache.log4j.db.ConnectionSource#getConnection()
+84     */
+85    public Connection getConnection()
+86           throws SQLException {
+87      Connection conn = null;
+88      try {
+89  
+90        if(dataSource == null) {
+91          dataSource = lookupDataSource();
+92        }
+93        if (getUser() == null) {
+94          conn = dataSource.getConnection();
+95        } else {
+96          conn = dataSource.getConnection(getUser(), getPassword());
+97        }
+98      } catch (final NamingException ne) {
+99           getLogger().error("Error while getting data source", ne);
+100       throw new SQLException("NamingException while looking up DataSource: " + ne.getMessage());
+101     } catch (final ClassCastException cce) {
+102       getLogger().error("ClassCastException while looking up DataSource.", cce);
+103       throw new SQLException("ClassCastException while looking up DataSource: " + cce.getMessage());
+104     }
+105 
+106     return conn;
+107   }
+108 
+109   /***
+110    * Returns the jndiLocation.
+111    * @return String
+112    */
+113   public String getJndiLocation() {
+114     return jndiLocation;
+115   }
+116 
+117 
+118   /***
+119    * Sets the jndiLocation.
+120    * @param jndiLocation The jndiLocation to set
+121    */
+122   public void setJndiLocation(String jndiLocation) {
+123     this.jndiLocation = jndiLocation;
+124   }
+125 
+126 
+127   private DataSource lookupDataSource()
+128          throws NamingException, SQLException {
+129     DataSource ds;
+130     Context ctx = new InitialContext();
+131     Object obj = ctx.lookup(jndiLocation);
+132 
+133     // PortableRemoteObject was introduced in JDK 1.3. We won't use it.
+134     //ds = (DataSource)PortableRemoteObject.narrow(obj, DataSource.class);
+135     ds = (DataSource) obj;
+136 
+137     if (ds == null) {
+138       throw new SQLException("Failed to obtain data source from JNDI location " + jndiLocation);
+139     } else {
+140       return ds;
+141     }
+142   }
+143 }
+
+
+ + Propchange: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/JNDIConnectionSource.html ------------------------------------------------------------------------------ svn:mime-type = text/html Added: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/HSQLDBDialect.html URL: http://svn.apache.org/viewvc/logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/HSQLDBDialect.html?view=auto&rev=558362 ============================================================================== --- logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/HSQLDBDialect.html (added) +++ logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/HSQLDBDialect.html Sat Jul 21 10:50:33 2007 @@ -0,0 +1,43 @@ + + + +HSQLDBDialect xref + + + +
View Javadoc
+
+1   /*
+2    * Copyright 1999,2004 The Apache Software Foundation.
+3    *
+4    * Licensed under the Apache License, Version 2.0 (the "License");
+5    * you may not use this file except in compliance with the License.
+6    * You may obtain a copy of the License at
+7    *
+8    *      http://www.apache.org/licenses/LICENSE-2.0
+9    *
+10   * Unless required by applicable law or agreed to in writing, software
+11   * distributed under the License is distributed on an "AS IS" BASIS,
+12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+13   * See the License for the specific language governing permissions and
+14   * limitations under the License.
+15   */
+16  
+17  package org.apache.log4j.db.dialect; 
+18  
+19  /*** 
+20   * The HSQLDB dialect. 
+21   * 
+22   * @author <a href="http://www.qos.ch/log4j/">Ceki G&uuml;lc&uuml;</a>
+23  */ 
+24  public class HSQLDBDialect implements SQLDialect { 
+25   public static final String SELECT_CURRVAL = "CALL IDENTITY()"; 
+26  
+27   public String getSelectInsertId() { 
+28     return SELECT_CURRVAL; 
+29   } 
+30  }
+
+
+ + Propchange: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/HSQLDBDialect.html ------------------------------------------------------------------------------ svn:mime-type = text/html Added: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/MsSQLDialect.html URL: http://svn.apache.org/viewvc/logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/MsSQLDialect.html?view=auto&rev=558362 ============================================================================== --- logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/MsSQLDialect.html (added) +++ logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/MsSQLDialect.html Sat Jul 21 10:50:33 2007 @@ -0,0 +1,46 @@ + + + +MsSQLDialect xref + + + +
View Javadoc
+
+1   /*
+2    * Copyright 1999,2004 The Apache Software Foundation.
+3    *
+4    * Licensed under the Apache License, Version 2.0 (the "License");
+5    * you may not use this file except in compliance with the License.
+6    * You may obtain a copy of the License at
+7    *
+8    *      http://www.apache.org/licenses/LICENSE-2.0
+9    *
+10   * Unless required by applicable law or agreed to in writing, software
+11   * distributed under the License is distributed on an "AS IS" BASIS,
+12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+13   * See the License for the specific language governing permissions and
+14   * limitations under the License.
+15   */
+16  
+17  package org.apache.log4j.db.dialect; 
+18  
+19  /*** 
+20  * The MS SQL Server dialect is untested. 
+21  * 
+22  * Note that the dialect is not needed if your JDBC driver supports 
+23  * the getGeneratedKeys method introduced in JDBC 3.0 specification.
+24  * 
+25  * @author James Stauffer 
+26  */ 
+27  public class MsSQLDialect implements SQLDialect { 
+28   public static final String SELECT_CURRVAL = "SELECT @@identity id"; 
+29  
+30   public String getSelectInsertId() { 
+31     return SELECT_CURRVAL; 
+32   } 
+33  }
+
+
+ + Propchange: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/MsSQLDialect.html ------------------------------------------------------------------------------ svn:mime-type = text/html Added: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/MySQLDialect.html URL: http://svn.apache.org/viewvc/logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/MySQLDialect.html?view=auto&rev=558362 ============================================================================== --- logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/MySQLDialect.html (added) +++ logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/MySQLDialect.html Sat Jul 21 10:50:33 2007 @@ -0,0 +1,44 @@ + + + +MySQLDialect xref + + + +
View Javadoc
+
+1   /*
+2    * Copyright 1999,2004 The Apache Software Foundation.
+3    *
+4    * Licensed under the Apache License, Version 2.0 (the "License");
+5    * you may not use this file except in compliance with the License.
+6    * You may obtain a copy of the License at
+7    *
+8    *      http://www.apache.org/licenses/LICENSE-2.0
+9    *
+10   * Unless required by applicable law or agreed to in writing, software
+11   * distributed under the License is distributed on an "AS IS" BASIS,
+12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+13   * See the License for the specific language governing permissions and
+14   * limitations under the License.
+15   */
+16  
+17  package org.apache.log4j.db.dialect;
+18  
+19  /***
+20   * 
+21   * 
+22   * @author Ceki
+23   *
+24   */
+25  public class MySQLDialect implements SQLDialect {
+26    public static final String SELECT_LAST_INSERT_ID = "SELECT LAST_INSERT_ID()";
+27    
+28    public String getSelectInsertId() {
+29      return SELECT_LAST_INSERT_ID;
+30    }
+31  }
+
+
+ + Propchange: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/MySQLDialect.html ------------------------------------------------------------------------------ svn:mime-type = text/html Added: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/OracleDialect.html URL: http://svn.apache.org/viewvc/logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/OracleDialect.html?view=auto&rev=558362 ============================================================================== --- logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/OracleDialect.html (added) +++ logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/OracleDialect.html Sat Jul 21 10:50:33 2007 @@ -0,0 +1,45 @@ + + + +OracleDialect xref + + + +
View Javadoc
+
+1   /*
+2    * Copyright 1999,2004 The Apache Software Foundation.
+3    *
+4    * Licensed under the Apache License, Version 2.0 (the "License");
+5    * you may not use this file except in compliance with the License.
+6    * You may obtain a copy of the License at
+7    *
+8    *      http://www.apache.org/licenses/LICENSE-2.0
+9    *
+10   * Unless required by applicable law or agreed to in writing, software
+11   * distributed under the License is distributed on an "AS IS" BASIS,
+12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+13   * See the License for the specific language governing permissions and
+14   * limitations under the License.
+15   */
+16  
+17  package org.apache.log4j.db.dialect;
+18  
+19  /***
+20   * The Oracle dialect. Tested successfully on Oracle9i Release 9.2.0.3.0 by 
+21   * James Stauffer.
+22   * 
+23   * @author Ceki G&uuml;lc&uuml;
+24   */
+25  public class OracleDialect implements SQLDialect {
+26    public static final String SELECT_CURRVAL = "SELECT logging_event_id_seq.currval from dual";
+27  
+28    public String getSelectInsertId() {
+29      return SELECT_CURRVAL;
+30    }
+31  
+32  }
+
+
+ + Propchange: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/dialect/OracleDialect.html ------------------------------------------------------------------------------ svn:mime-type = text/html