logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carn...@apache.org
Subject svn commit: r558362 [24/33] - in /logging/site/trunk/docs/log4j/companions/receivers: ./ apidocs/ apidocs/org/ apidocs/org/apache/ apidocs/org/apache/log4j/ apidocs/org/apache/log4j/db/ apidocs/org/apache/log4j/db/class-use/ apidocs/org/apache/log4j/db...
Date Sat, 21 Jul 2007 17:50:44 GMT
Added: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/CustomSQLDBReceiver.html
URL: http://svn.apache.org/viewvc/logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/CustomSQLDBReceiver.html?view=auto&rev=558362
==============================================================================
--- logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/CustomSQLDBReceiver.html (added)
+++ logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/CustomSQLDBReceiver.html Sat Jul 21 10:50:33 2007
@@ -0,0 +1,483 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /><title>CustomSQLDBReceiver xref</title>
+<link type="text/css" rel="stylesheet" href="../../../../stylesheet.css" />
+</head>
+<body>
+<div id="overview"><a href="../../../../../../../../../../apidocs/org/apache/log4j/db/CustomSQLDBReceiver.html">View Javadoc</a></div><pre>
+
+<a name="1" href="#1">1</a>   <em class="comment">/*</em>
+<a name="2" href="#2">2</a>   <em class="comment"> * Licensed to the Apache Software Foundation (ASF) under one or more</em>
+<a name="3" href="#3">3</a>   <em class="comment"> * contributor license agreements.  See the NOTICE file distributed with</em>
+<a name="4" href="#4">4</a>   <em class="comment"> * this work for additional information regarding copyright ownership.</em>
+<a name="5" href="#5">5</a>   <em class="comment"> * The ASF licenses this file to You under the Apache License, Version 2.0</em>
+<a name="6" href="#6">6</a>   <em class="comment"> * (the "License"); you may not use this file except in compliance with</em>
+<a name="7" href="#7">7</a>   <em class="comment"> * the License.  You may obtain a copy of the License at</em>
+<a name="8" href="#8">8</a>   <em class="comment"> * </em>
+<a name="9" href="#9">9</a>   <em class="comment"> *      <a href="http://www.apache.org/licenses/LICENSE-2.0" target="alexandria_uri">http://www.apache.org/licenses/LICENSE-2.0</a></em>
+<a name="10" href="#10">10</a>  <em class="comment"> * </em>
+<a name="11" href="#11">11</a>  <em class="comment"> * Unless required by applicable law or agreed to in writing, software</em>
+<a name="12" href="#12">12</a>  <em class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</em>
+<a name="13" href="#13">13</a>  <em class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</em>
+<a name="14" href="#14">14</a>  <em class="comment"> * See the License for the specific language governing permissions and</em>
+<a name="15" href="#15">15</a>  <em class="comment"> * limitations under the License.</em>
+<a name="16" href="#16">16</a>  <em class="comment"> */</em>
+<a name="17" href="#17">17</a>  
+<a name="18" href="#18">18</a>  <strong>package</strong> org.apache.log4j.db;
+<a name="19" href="#19">19</a>  
+<a name="20" href="#20">20</a>  <strong>import</strong> java.sql.Connection;
+<a name="21" href="#21">21</a>  <strong>import</strong> java.sql.ResultSet;
+<a name="22" href="#22">22</a>  <strong>import</strong> java.sql.SQLException;
+<a name="23" href="#23">23</a>  <strong>import</strong> java.sql.Statement;
+<a name="24" href="#24">24</a>  <strong>import</strong> java.util.Hashtable;
+<a name="25" href="#25">25</a>  <strong>import</strong> java.util.StringTokenizer;
+<a name="26" href="#26">26</a>  <strong>import</strong> java.util.Properties;
+<a name="27" href="#27">27</a>  
+<a name="28" href="#28">28</a>  <strong>import</strong> org.apache.log4j.Level;
+<a name="29" href="#29">29</a>  <strong>import</strong> org.apache.log4j.Logger;
+<a name="30" href="#30">30</a>  <strong>import</strong> org.apache.log4j.xml.UnrecognizedElementHandler;
+<a name="31" href="#31">31</a>  <strong>import</strong> org.apache.log4j.xml.DOMConfigurator;
+<a name="32" href="#32">32</a>  <strong>import</strong> org.apache.log4j.plugins.Pauseable;
+<a name="33" href="#33">33</a>  <strong>import</strong> org.apache.log4j.plugins.Receiver;
+<a name="34" href="#34">34</a>  <strong>import</strong> org.apache.log4j.scheduler.Job;
+<a name="35" href="#35">35</a>  <strong>import</strong> org.apache.log4j.scheduler.Scheduler;
+<a name="36" href="#36">36</a>  <strong>import</strong> org.apache.log4j.spi.LoggingEvent;
+<a name="37" href="#37">37</a>  <strong>import</strong> org.apache.log4j.spi.LoggerRepositoryEx;
+<a name="38" href="#38">38</a>  <strong>import</strong> org.apache.log4j.spi.ThrowableInformation;
+<a name="39" href="#39">39</a>  <strong>import</strong> org.apache.log4j.spi.LocationInfo;
+<a name="40" href="#40">40</a>  <strong>import</strong> org.apache.log4j.spi.OptionHandler;
+<a name="41" href="#41">41</a>  <strong>import</strong> org.w3c.dom.Element;
+<a name="42" href="#42">42</a>  
+<a name="43" href="#43">43</a>  <em>/**<em>*</em></em>
+<a name="44" href="#44">44</a>  <em> * Converts log data stored in a database into LoggingEvents.</em>
+<a name="45" href="#45">45</a>  <em> * &lt;p></em>
+<a name="46" href="#46">46</a>  <em> * &lt;b>NOTE:&lt;/b> This receiver cannot yet be created through Chainsaw's receiver panel.  </em>
+<a name="47" href="#47">47</a>  <em> * It must be created through an XML configuration file.</em>
+<a name="48" href="#48">48</a>  <em> * &lt;p></em>
+<a name="49" href="#49">49</a>  <em> * This receiver supports database configuration via ConnectionSource, in the</em>
+<a name="50" href="#50">50</a>  <em> * org.apache.log4j.db package: DriverManagerConnectionSource,</em>
+<a name="51" href="#51">51</a>  <em> * DataSourceConnectionSource, JNDIConnectionSource</em>
+<a name="52" href="#52">52</a>  <em> * &lt;p></em>
+<a name="53" href="#53">53</a>  <em> * This database receiver differs from DBReceiver in that this receiver relies</em>
+<a name="54" href="#54">54</a>  <em> * on custom SQL to retrieve logging event data, where DBReceiver requires the</em>
+<a name="55" href="#55">55</a>  <em> * use of a log4j-defined schema.</em>
+<a name="56" href="#56">56</a>  <em> * &lt;p></em>
+<a name="57" href="#57">57</a>  <em> * A 'refreshMillis' int parameter controls SQL execution. If 'refreshMillis' is</em>
+<a name="58" href="#58">58</a>  <em> * zero (the default), the receiver will run only one time. If it is set to any</em>
+<a name="59" href="#59">59</a>  <em> * other numeric value, the SQL will be executed on a recurring basis every</em>
+<a name="60" href="#60">60</a>  <em> * 'refreshMillis' milliseconds.</em>
+<a name="61" href="#61">61</a>  <em> * &lt;p></em>
+<a name="62" href="#62">62</a>  <em> * The receiver closes the connection and acquires a new connection on each </em>
+<a name="63" href="#63">63</a>  <em> * execution of the SQL (use pooled connections if possible).</em>
+<a name="64" href="#64">64</a>  <em> * &lt;p></em>
+<a name="65" href="#65">65</a>  <em> * If the SQL will be executing on a recurring basis, specify the IDField param -</em>
+<a name="66" href="#66">66</a>  <em> * the column name holding the unique identifier (int) representing the logging</em>
+<a name="67" href="#67">67</a>  <em> * event.</em>
+<a name="68" href="#68">68</a>  <em> * &lt;p></em>
+<a name="69" href="#69">69</a>  <em> * As events are retrieved, the column represented by IDField is examined and</em>
+<a name="70" href="#70">70</a>  <em> * the largest value is held and used by the next execution of the SQL statement</em>
+<a name="71" href="#71">71</a>  <em> * to avoid retrieving previously processed events.</em>
+<a name="72" href="#72">72</a>  <em> * &lt;p></em>
+<a name="73" href="#73">73</a>  <em> * As an example, the IDField references a 'COUNTER' (int, auto-increment,</em>
+<a name="74" href="#74">74</a>  <em> * unique) column. The first execution of the SQL statement returns 500 rows,</em>
+<a name="75" href="#75">75</a>  <em> * with a final value in the COUNTER field of 500.</em>
+<a name="76" href="#76">76</a>  <em> * &lt;p></em>
+<a name="77" href="#77">77</a>  <em> * The SQL statement is manipulated prior to the next execution, adding ' WHERE</em>
+<a name="78" href="#78">78</a>  <em> * COUNTER > 500' to the statement to avoid retrieval of previously processed</em>
+<a name="79" href="#79">79</a>  <em> * events.</em>
+<a name="80" href="#80">80</a>  <em> * &lt;p></em>
+<a name="81" href="#81">81</a>  <em> * The select statement must provide ALL fields which define a LoggingEvent.</em>
+<a name="82" href="#82">82</a>  <em> * &lt;p></em>
+<a name="83" href="#83">83</a>  <em> * The SQL statement MUST include the columns: LOGGER, TIMESTAMP, LEVEL, THREAD,</em>
+<a name="84" href="#84">84</a>  <em> * MESSAGE, NDC, MDC, CLASS, METHOD, FILE, LINE, PROPERTIES, EXCEPTION</em>
+<a name="85" href="#85">85</a>  <em> * &lt;p></em>
+<a name="86" href="#86">86</a>  <em> * Use ' AS ' in the SQL statement to alias the SQL's column names to match your</em>
+<a name="87" href="#87">87</a>  <em> * database schema. (see example below).</em>
+<a name="88" href="#88">88</a>  <em> * &lt;p></em>
+<a name="89" href="#89">89</a>  <em> * Include all fields in the SQL statement, even if you don't have data for the</em>
+<a name="90" href="#90">90</a>  <em> * field (specify an empty string as the value for columns which you don't have</em>
+<a name="91" href="#91">91</a>  <em> * data).</em>
+<a name="92" href="#92">92</a>  <em> * &lt;p></em>
+<a name="93" href="#93">93</a>  <em> * The TIMESTAMP column must be a datetime.</em>
+<a name="94" href="#94">94</a>  <em> * &lt;p></em>
+<a name="95" href="#95">95</a>  <em> * Both a PROPERTIES column and an MDC column are supported. These fields</em>
+<a name="96" href="#96">96</a>  <em> * represent Maps on the logging event, but require the use of string</em>
+<a name="97" href="#97">97</a>  <em> * concatenation database functions to hold the (possibly multiple) name/value</em>
+<a name="98" href="#98">98</a>  <em> * pairs in the column.</em>
+<a name="99" href="#99">99</a>  <em> * &lt;p></em>
+<a name="100" href="#100">100</a> <em> * For example, to include both 'userid' and 'lastname' properties in the</em>
+<a name="101" href="#101">101</a> <em> * logging event (from either the PROPERTIES or MDC columns), the name/value</em>
+<a name="102" href="#102">102</a> <em> * pairs must be concatenated together by your database.</em>
+<a name="103" href="#103">103</a> <em> * &lt;p></em>
+<a name="104" href="#104">104</a> <em> * The resulting PROPERTIES or MDC column must have data in this format: {{name,</em>
+<a name="105" href="#105">105</a> <em> * value, name2, value2}}</em>
+<a name="106" href="#106">106</a> <em> * &lt;p></em>
+<a name="107" href="#107">107</a> <em> * The resulting PROPERTIES column would contain this text: {{userid, someone,</em>
+<a name="108" href="#108">108</a> <em> * lastname, mylastname}}</em>
+<a name="109" href="#109">109</a> <em> * &lt;p></em>
+<a name="110" href="#110">110</a> <em> * Here is an example of concatenating a PROPERTIES or MDC column using MySQL's</em>
+<a name="111" href="#111">111</a> <em> * concat function, where the 'application' and 'hostname' parameters were fixed</em>
+<a name="112" href="#112">112</a> <em> * text, but the 'log4jid' key's value is the value of the COUNTER column:</em>
+<a name="113" href="#113">113</a> <em> * &lt;p></em>
+<a name="114" href="#114">114</a> <em> * concat("{{application,databaselogs,hostname,mymachine,log4jid,", COUNTER,</em>
+<a name="115" href="#115">115</a> <em> * "}}") as PROPERTIES</em>
+<a name="116" href="#116">116</a> <em> * &lt;p></em>
+<a name="117" href="#117">117</a> <em> * log4jid is a special property that is used by Chainsaw to represent an 'ID'</em>
+<a name="118" href="#118">118</a> <em> * field. Specify this property to ensure you can map events in Chainsaw to</em>
+<a name="119" href="#119">119</a> <em> * events in the database if you need to go back and view events at a later time</em>
+<a name="120" href="#120">120</a> <em> * or save the events to XML for later analysis.</em>
+<a name="121" href="#121">121</a> <em> * &lt;p></em>
+<a name="122" href="#122">122</a> <em> * Here is a complete MySQL SQL statement which can be used to provide events to</em>
+<a name="123" href="#123">123</a> <em> * Chainsaw:</em>
+<a name="124" href="#124">124</a> <em> * &lt;p></em>
+<a name="125" href="#125">125</a> <em> * select logger as LOGGER, timestamp as TIMESTAMP, level as LEVEL, thread as</em>
+<a name="126" href="#126">126</a> <em> * THREAD, message as MESSAGE, ndc as NDC, mdc as MDC, class as CLASS, method as</em>
+<a name="127" href="#127">127</a> <em> * METHOD, file as FILE, line as LINE,</em>
+<a name="128" href="#128">128</a> <em> * concat("{{application,databaselogs,hostname,mymachine, log4jid,",</em>
+<a name="129" href="#129">129</a> <em> * COUNTER,"}}") as PROPERTIES, "" as EXCEPTION from logtable</em>
+<a name="130" href="#130">130</a> <em> * &lt;p></em>
+<a name="131" href="#131">131</a> <em> * @author Scott Deboy &lt;sdeboy@apache.org></em>
+<a name="132" href="#132">132</a> <em> * &lt;p></em>
+<a name="133" href="#133">133</a> <em> */</em>
+<a name="134" href="#134">134</a> <strong>public</strong> <strong>class</strong> <a href="../../../../org/apache/log4j/db/CustomSQLDBReceiver.html">CustomSQLDBReceiver</a> <strong>extends</strong> Receiver implements Pauseable, UnrecognizedElementHandler {
+<a name="135" href="#135">135</a> 
+<a name="136" href="#136">136</a>     <strong>protected</strong> <strong>volatile</strong> Connection connection = <strong>null</strong>;
+<a name="137" href="#137">137</a> 
+<a name="138" href="#138">138</a>     <strong>protected</strong> String sqlStatement = <span class="string">""</span>;
+<a name="139" href="#139">139</a> 
+<a name="140" href="#140">140</a>     <em>/**<em>*</em></em>
+<a name="141" href="#141">141</a> <em>     * By default we refresh data every 1000 milliseconds.</em>
+<a name="142" href="#142">142</a> <em>     * </em>
+<a name="143" href="#143">143</a> <em>     * @see #setRefreshMillis</em>
+<a name="144" href="#144">144</a> <em>     */</em>
+<a name="145" href="#145">145</a>     <strong>static</strong> <strong>int</strong> DEFAULT_REFRESH_MILLIS = 1000;
+<a name="146" href="#146">146</a> 
+<a name="147" href="#147">147</a>     <strong>int</strong> refreshMillis = DEFAULT_REFRESH_MILLIS;
+<a name="148" href="#148">148</a> 
+<a name="149" href="#149">149</a>     <strong>protected</strong> String idField = <strong>null</strong>;
+<a name="150" href="#150">150</a> 
+<a name="151" href="#151">151</a>     <strong>int</strong> lastID = -1;
+<a name="152" href="#152">152</a> 
+<a name="153" href="#153">153</a>     <strong>private</strong> <strong>static</strong> <strong>final</strong> String WHERE_CLAUSE = <span class="string">" WHERE "</span>;
+<a name="154" href="#154">154</a> 
+<a name="155" href="#155">155</a>     <strong>private</strong> <strong>static</strong> <strong>final</strong> String AND_CLAUSE = <span class="string">" AND "</span>;
+<a name="156" href="#156">156</a> 
+<a name="157" href="#157">157</a>     <strong>private</strong> <strong>boolean</strong> whereExists = false;
+<a name="158" href="#158">158</a> 
+<a name="159" href="#159">159</a>     <strong>private</strong> <strong>boolean</strong> paused = false;
+<a name="160" href="#160">160</a> 
+<a name="161" href="#161">161</a>     <strong>private</strong> <a href="../../../../org/apache/log4j/db/ConnectionSource.html">ConnectionSource</a> connectionSource;
+<a name="162" href="#162">162</a> 
+<a name="163" href="#163">163</a>     <strong>public</strong> <strong>static</strong> <strong>final</strong> String LOG4J_ID_KEY = <span class="string">"log4jid"</span>;
+<a name="164" href="#164">164</a> 
+<a name="165" href="#165">165</a>     <strong>private</strong> Job customReceiverJob;
+<a name="166" href="#166">166</a> 
+<a name="167" href="#167">167</a>     <strong>public</strong> <strong>void</strong> activateOptions() {
+<a name="168" href="#168">168</a>       
+<a name="169" href="#169">169</a>       <strong>if</strong>(connectionSource == <strong>null</strong>)  {
+<a name="170" href="#170">170</a>         <strong>throw</strong> <strong>new</strong> IllegalStateException(
+<a name="171" href="#171">171</a>           <span class="string">"CustomSQLDBReceiver cannot function without a connection source"</span>);
+<a name="172" href="#172">172</a>       }
+<a name="173" href="#173">173</a>       whereExists = (sqlStatement.toUpperCase().indexOf(WHERE_CLAUSE) > -1);
+<a name="174" href="#174">174</a>     
+<a name="175" href="#175">175</a>       customReceiverJob = <strong>new</strong> CustomReceiverJob();
+<a name="176" href="#176">176</a>         
+<a name="177" href="#177">177</a>       <strong>if</strong>(<strong>this</strong>.repository == <strong>null</strong>) {
+<a name="178" href="#178">178</a>         <strong>throw</strong> <strong>new</strong> IllegalStateException(
+<a name="179" href="#179">179</a>         <span class="string">"CustomSQLDBReceiver cannot function without a reference to its owning repository"</span>);
+<a name="180" href="#180">180</a>       }
+<a name="181" href="#181">181</a>      
+<a name="182" href="#182">182</a>     
+<a name="183" href="#183">183</a> 
+<a name="184" href="#184">184</a>       <strong>if</strong> (repository instanceof LoggerRepositoryEx) {
+<a name="185" href="#185">185</a>         Scheduler scheduler = ((LoggerRepositoryEx) repository).getScheduler();
+<a name="186" href="#186">186</a>       
+<a name="187" href="#187">187</a>         scheduler.schedule(
+<a name="188" href="#188">188</a>           customReceiverJob, System.currentTimeMillis() + 500, refreshMillis);
+<a name="189" href="#189">189</a>       }
+<a name="190" href="#190">190</a> 
+<a name="191" href="#191">191</a>     }
+<a name="192" href="#192">192</a> 
+<a name="193" href="#193">193</a>     <strong>void</strong> closeConnection(Connection connection) {
+<a name="194" href="#194">194</a>         <strong>if</strong> (connection != <strong>null</strong>) {
+<a name="195" href="#195">195</a>             <strong>try</strong> {
+<a name="196" href="#196">196</a>                 <em class="comment">// LogLog.warn("closing the connection. ", new Exception("x"));</em>
+<a name="197" href="#197">197</a>                 connection.close();
+<a name="198" href="#198">198</a>             } <strong>catch</strong> (SQLException sqle) {
+<a name="199" href="#199">199</a>                 <em class="comment">// nothing we can do here</em>
+<a name="200" href="#200">200</a>             }
+<a name="201" href="#201">201</a>         }
+<a name="202" href="#202">202</a>     }
+<a name="203" href="#203">203</a> 
+<a name="204" href="#204">204</a>     <strong>public</strong> <strong>void</strong> setRefreshMillis(<strong>int</strong> refreshMillis) {
+<a name="205" href="#205">205</a>         <strong>this</strong>.refreshMillis = refreshMillis;
+<a name="206" href="#206">206</a>     }
+<a name="207" href="#207">207</a> 
+<a name="208" href="#208">208</a>     <strong>public</strong> <strong>int</strong> getRefreshMillis() {
+<a name="209" href="#209">209</a>         <strong>return</strong> refreshMillis;
+<a name="210" href="#210">210</a>     }
+<a name="211" href="#211">211</a> 
+<a name="212" href="#212">212</a>     <em>/**<em>*</em></em>
+<a name="213" href="#213">213</a> <em>     * @return Returns the connectionSource.</em>
+<a name="214" href="#214">214</a> <em>     */</em>
+<a name="215" href="#215">215</a>     <strong>public</strong> <a href="../../../../org/apache/log4j/db/ConnectionSource.html">ConnectionSource</a> getConnectionSource() {
+<a name="216" href="#216">216</a>         <strong>return</strong> connectionSource;
+<a name="217" href="#217">217</a>     }
+<a name="218" href="#218">218</a> 
+<a name="219" href="#219">219</a>     <em>/**<em>*</em></em>
+<a name="220" href="#220">220</a> <em>     * @param connectionSource</em>
+<a name="221" href="#221">221</a> <em>     *            The connectionSource to set.</em>
+<a name="222" href="#222">222</a> <em>     */</em>
+<a name="223" href="#223">223</a>     <strong>public</strong> <strong>void</strong> setConnectionSource(<a href="../../../../org/apache/log4j/db/ConnectionSource.html">ConnectionSource</a> connectionSource) {
+<a name="224" href="#224">224</a>         <strong>this</strong>.connectionSource = connectionSource;
+<a name="225" href="#225">225</a>     }
+<a name="226" href="#226">226</a> 
+<a name="227" href="#227">227</a>     <strong>public</strong> <strong>void</strong> close() {
+<a name="228" href="#228">228</a>         <strong>try</strong> {
+<a name="229" href="#229">229</a>             <strong>if</strong> ((connection != <strong>null</strong>) &amp;&amp; !connection.isClosed()) {
+<a name="230" href="#230">230</a>                 connection.close();
+<a name="231" href="#231">231</a>             }
+<a name="232" href="#232">232</a>         } <strong>catch</strong> (SQLException e) {
+<a name="233" href="#233">233</a>             e.printStackTrace();
+<a name="234" href="#234">234</a>         } <strong>finally</strong> {
+<a name="235" href="#235">235</a>             connection = <strong>null</strong>;
+<a name="236" href="#236">236</a>         }
+<a name="237" href="#237">237</a>     }
+<a name="238" href="#238">238</a> 
+<a name="239" href="#239">239</a>     <strong>public</strong> <strong>void</strong> finalize() throws Throwable {
+<a name="240" href="#240">240</a>         <strong>super</strong>.finalize();
+<a name="241" href="#241">241</a>         close();
+<a name="242" href="#242">242</a>     }
+<a name="243" href="#243">243</a> 
+<a name="244" href="#244">244</a>     <em class="comment">/*</em>
+<a name="245" href="#245">245</a> <em class="comment">     * (non-Javadoc)</em>
+<a name="246" href="#246">246</a> <em class="comment">     * </em>
+<a name="247" href="#247">247</a> <em class="comment">     * @see org.apache.log4j.plugins.Plugin#shutdown()</em>
+<a name="248" href="#248">248</a> <em class="comment">     */</em>
+<a name="249" href="#249">249</a>     <strong>public</strong> <strong>void</strong> shutdown() {
+<a name="250" href="#250">250</a>         getLogger().info(<span class="string">"removing receiverJob from the Scheduler."</span>);
+<a name="251" href="#251">251</a> 
+<a name="252" href="#252">252</a>         <strong>if</strong>(<strong>this</strong>.repository instanceof LoggerRepositoryEx) {
+<a name="253" href="#253">253</a>           Scheduler scheduler = ((LoggerRepositoryEx) repository).getScheduler();
+<a name="254" href="#254">254</a>           scheduler.delete(customReceiverJob);
+<a name="255" href="#255">255</a>         }
+<a name="256" href="#256">256</a> 
+<a name="257" href="#257">257</a>         lastID = -1;
+<a name="258" href="#258">258</a>     }
+<a name="259" href="#259">259</a> 
+<a name="260" href="#260">260</a>     <strong>public</strong> <strong>void</strong> setSql(String s) {
+<a name="261" href="#261">261</a>         sqlStatement = s;
+<a name="262" href="#262">262</a>     }
+<a name="263" href="#263">263</a> 
+<a name="264" href="#264">264</a>     <strong>public</strong> String getSql() {
+<a name="265" href="#265">265</a>         <strong>return</strong> sqlStatement;
+<a name="266" href="#266">266</a>     }
+<a name="267" href="#267">267</a> 
+<a name="268" href="#268">268</a>     <strong>public</strong> <strong>void</strong> setIDField(String id) {
+<a name="269" href="#269">269</a>         idField = id;
+<a name="270" href="#270">270</a>     }
+<a name="271" href="#271">271</a> 
+<a name="272" href="#272">272</a>     <strong>public</strong> String getIDField() {
+<a name="273" href="#273">273</a>         <strong>return</strong> idField;
+<a name="274" href="#274">274</a>     }
+<a name="275" href="#275">275</a> 
+<a name="276" href="#276">276</a>     <strong>public</strong> <strong>synchronized</strong> <strong>void</strong> setPaused(<strong>boolean</strong> p) {
+<a name="277" href="#277">277</a>         paused = p;
+<a name="278" href="#278">278</a>     }
+<a name="279" href="#279">279</a> 
+<a name="280" href="#280">280</a>     <strong>public</strong> <strong>synchronized</strong> <strong>boolean</strong> isPaused() {
+<a name="281" href="#281">281</a>         <strong>return</strong> paused;
+<a name="282" href="#282">282</a>     }
+<a name="283" href="#283">283</a> 
+<a name="284" href="#284">284</a>     <strong>class</strong> CustomReceiverJob implements Job {
+<a name="285" href="#285">285</a>         <strong>public</strong> <strong>void</strong> execute() {
+<a name="286" href="#286">286</a>             Connection connection = <strong>null</strong>;
+<a name="287" href="#287">287</a> 
+<a name="288" href="#288">288</a>             <strong>int</strong> oldLastID = lastID;
+<a name="289" href="#289">289</a>             <strong>try</strong> {
+<a name="290" href="#290">290</a>                 connection = connectionSource.getConnection();
+<a name="291" href="#291">291</a>                 Statement statement = connection.createStatement();
+<a name="292" href="#292">292</a> 
+<a name="293" href="#293">293</a>                 Logger eventLogger = <strong>null</strong>;
+<a name="294" href="#294">294</a>                 <strong>long</strong> timeStamp = 0L;
+<a name="295" href="#295">295</a>                 String level = <strong>null</strong>;
+<a name="296" href="#296">296</a>                 String threadName = <strong>null</strong>;
+<a name="297" href="#297">297</a>                 Object message = <strong>null</strong>;
+<a name="298" href="#298">298</a>                 String ndc = <strong>null</strong>;
+<a name="299" href="#299">299</a>                 Hashtable mdc = <strong>null</strong>;
+<a name="300" href="#300">300</a>                 String[] exception = <strong>null</strong>;
+<a name="301" href="#301">301</a>                 String className = <strong>null</strong>;
+<a name="302" href="#302">302</a>                 String methodName = <strong>null</strong>;
+<a name="303" href="#303">303</a>                 String fileName = <strong>null</strong>;
+<a name="304" href="#304">304</a>                 String lineNumber = <strong>null</strong>;
+<a name="305" href="#305">305</a>                 Hashtable properties = <strong>null</strong>;
+<a name="306" href="#306">306</a> 
+<a name="307" href="#307">307</a>                 String currentSQLStatement = sqlStatement;
+<a name="308" href="#308">308</a>                 <strong>if</strong> (whereExists) {
+<a name="309" href="#309">309</a>                     currentSQLStatement = sqlStatement + AND_CLAUSE + idField
+<a name="310" href="#310">310</a>                             + <span class="string">" > "</span> + lastID;
+<a name="311" href="#311">311</a>                 } <strong>else</strong> {
+<a name="312" href="#312">312</a>                     currentSQLStatement = sqlStatement + WHERE_CLAUSE + idField
+<a name="313" href="#313">313</a>                             + <span class="string">" > "</span> + lastID;
+<a name="314" href="#314">314</a>                 }
+<a name="315" href="#315">315</a> 
+<a name="316" href="#316">316</a>                 ResultSet rs = statement.executeQuery(currentSQLStatement);
+<a name="317" href="#317">317</a> 
+<a name="318" href="#318">318</a>                 <strong>int</strong> i = 0;
+<a name="319" href="#319">319</a>                 <strong>while</strong> (rs.next()) {
+<a name="320" href="#320">320</a>                     <em class="comment">// add a small break every 1000 received events</em>
+<a name="321" href="#321">321</a>                     <strong>if</strong> (++i == 1000) {
+<a name="322" href="#322">322</a>                         <strong>synchronized</strong> (<strong>this</strong>) {
+<a name="323" href="#323">323</a>                             <strong>try</strong> {
+<a name="324" href="#324">324</a>                                 <em class="comment">// add a delay</em>
+<a name="325" href="#325">325</a>                                 wait(300);
+<a name="326" href="#326">326</a>                             } <strong>catch</strong> (InterruptedException ie) {
+<a name="327" href="#327">327</a>                             }
+<a name="328" href="#328">328</a>                             i = 0;
+<a name="329" href="#329">329</a>                         }
+<a name="330" href="#330">330</a>                     }
+<a name="331" href="#331">331</a>                     eventLogger = Logger.getLogger(rs.getString(<span class="string">"LOGGER"</span>));
+<a name="332" href="#332">332</a>                     timeStamp = rs.getTimestamp(<span class="string">"TIMESTAMP"</span>).getTime();
+<a name="333" href="#333">333</a> 
+<a name="334" href="#334">334</a>                     level = rs.getString(<span class="string">"LEVEL"</span>);
+<a name="335" href="#335">335</a>                     threadName = rs.getString(<span class="string">"THREAD"</span>);
+<a name="336" href="#336">336</a>                     message = rs.getString(<span class="string">"MESSAGE"</span>);
+<a name="337" href="#337">337</a>                     ndc = rs.getString(<span class="string">"NDC"</span>);
+<a name="338" href="#338">338</a> 
+<a name="339" href="#339">339</a>                     String mdcString = rs.getString(<span class="string">"MDC"</span>);
+<a name="340" href="#340">340</a>                     mdc = <strong>new</strong> Hashtable();
+<a name="341" href="#341">341</a> 
+<a name="342" href="#342">342</a>                     <strong>if</strong> (mdcString != <strong>null</strong>) {
+<a name="343" href="#343">343</a>                         <em class="comment">// support MDC being wrapped in {{name, value}}</em>
+<a name="344" href="#344">344</a>                         <em class="comment">// or</em>
+<a name="345" href="#345">345</a>                         <em class="comment">// just name, value</em>
+<a name="346" href="#346">346</a>                         <strong>if</strong> ((mdcString.indexOf(<span class="string">"{{"</span>) > -1)
+<a name="347" href="#347">347</a>                                 &amp;&amp; (mdcString.indexOf(<span class="string">"}}"</span>) > -1)) {
+<a name="348" href="#348">348</a>                             mdcString = mdcString
+<a name="349" href="#349">349</a>                                     .substring(mdcString.indexOf(<span class="string">"{{"</span>) + 2,
+<a name="350" href="#350">350</a>                                             mdcString.indexOf(<span class="string">"}}"</span>));
+<a name="351" href="#351">351</a>                         }
+<a name="352" href="#352">352</a> 
+<a name="353" href="#353">353</a>                         StringTokenizer tok = <strong>new</strong> StringTokenizer(mdcString,
+<a name="354" href="#354">354</a>                                 <span class="string">","</span>);
+<a name="355" href="#355">355</a> 
+<a name="356" href="#356">356</a>                         <strong>while</strong> (tok.countTokens() > 1) {
+<a name="357" href="#357">357</a>                             mdc.put(tok.nextToken(), tok.nextToken());
+<a name="358" href="#358">358</a>                         }
+<a name="359" href="#359">359</a>                     }
+<a name="360" href="#360">360</a> 
+<a name="361" href="#361">361</a>                     exception = <strong>new</strong> String[] { rs.getString(<span class="string">"EXCEPTION"</span>) };
+<a name="362" href="#362">362</a>                     className = rs.getString(<span class="string">"CLASS"</span>);
+<a name="363" href="#363">363</a>                     methodName = rs.getString(<span class="string">"METHOD"</span>);
+<a name="364" href="#364">364</a>                     fileName = rs.getString(<span class="string">"FILE"</span>);
+<a name="365" href="#365">365</a>                     lineNumber = rs.getString(<span class="string">"LINE"</span>);
+<a name="366" href="#366">366</a> 
+<a name="367" href="#367">367</a>                     <em class="comment">// if properties are provided in the</em>
+<a name="368" href="#368">368</a>                     <em class="comment">// SQL they can be used here (for example, to route</em>
+<a name="369" href="#369">369</a>                     <em class="comment">// events to a unique tab in</em>
+<a name="370" href="#370">370</a>                     <em class="comment">// Chainsaw if the machinename and/or appname</em>
+<a name="371" href="#371">371</a>                     <em class="comment">// property</em>
+<a name="372" href="#372">372</a>                     <em class="comment">// are set)</em>
+<a name="373" href="#373">373</a>                     String propertiesString = rs.getString(<span class="string">"PROPERTIES"</span>);
+<a name="374" href="#374">374</a>                     properties = <strong>new</strong> Hashtable();
+<a name="375" href="#375">375</a> 
+<a name="376" href="#376">376</a>                     <strong>if</strong> (propertiesString != <strong>null</strong>) {
+<a name="377" href="#377">377</a>                         <em class="comment">// support properties being wrapped in {{name,</em>
+<a name="378" href="#378">378</a>                         <em class="comment">// value}} or just name, value</em>
+<a name="379" href="#379">379</a>                         <strong>if</strong> ((propertiesString.indexOf(<span class="string">"{{"</span>) > -1)
+<a name="380" href="#380">380</a>                                 &amp;&amp; (propertiesString.indexOf(<span class="string">"}}"</span>) > -1)) {
+<a name="381" href="#381">381</a>                             propertiesString = propertiesString.substring(
+<a name="382" href="#382">382</a>                                     propertiesString.indexOf(<span class="string">"{{"</span>) + 2,
+<a name="383" href="#383">383</a>                                     propertiesString.indexOf(<span class="string">"}}"</span>));
+<a name="384" href="#384">384</a>                         }
+<a name="385" href="#385">385</a> 
+<a name="386" href="#386">386</a>                         StringTokenizer tok2 = <strong>new</strong> StringTokenizer(
+<a name="387" href="#387">387</a>                                 propertiesString, <span class="string">","</span>);
+<a name="388" href="#388">388</a>                         <strong>while</strong> (tok2.countTokens() > 1) {
+<a name="389" href="#389">389</a>                             String name = tok2.nextToken();
+<a name="390" href="#390">390</a>                             String value = tok2.nextToken();
+<a name="391" href="#391">391</a>                             <strong>if</strong> (name.equals(LOG4J_ID_KEY)) {
+<a name="392" href="#392">392</a>                                 <strong>try</strong> {
+<a name="393" href="#393">393</a>                                     <strong>int</strong> thisInt = Integer.parseInt(value);
+<a name="394" href="#394">394</a>                                     value = String.valueOf(thisInt);
+<a name="395" href="#395">395</a>                                     <strong>if</strong> (thisInt > lastID) {
+<a name="396" href="#396">396</a>                                         lastID = thisInt;
+<a name="397" href="#397">397</a>                                     }
+<a name="398" href="#398">398</a>                                 } <strong>catch</strong> (Exception e) {
+<a name="399" href="#399">399</a>                                 }
+<a name="400" href="#400">400</a>                             }
+<a name="401" href="#401">401</a>                             properties.put(name, value);
+<a name="402" href="#402">402</a>                         }
+<a name="403" href="#403">403</a>                     }
+<a name="404" href="#404">404</a> 
+<a name="405" href="#405">405</a>                     Level levelImpl = Level.toLevel(level);
+<a name="406" href="#406">406</a> 
+<a name="407" href="#407">407</a> 
+<a name="408" href="#408">408</a> 					LocationInfo locationInfo = <strong>new</strong> LocationInfo(fileName,
+<a name="409" href="#409">409</a> 	                            className, methodName, lineNumber);
+<a name="410" href="#410">410</a> 	
+<a name="411" href="#411">411</a> 					ThrowableInformation throwableInfo =  <strong>new</strong> ThrowableInformation(
+<a name="412" href="#412">412</a> 		                            exception);
+<a name="413" href="#413">413</a> 	
+<a name="414" href="#414">414</a> 					properties.putAll(mdc);
+<a name="415" href="#415">415</a> 		
+<a name="416" href="#416">416</a> 				    LoggingEvent event = <strong>new</strong> LoggingEvent(eventLogger.getName(),
+<a name="417" href="#417">417</a> 				            eventLogger, timeStamp, levelImpl, message,
+<a name="418" href="#418">418</a> 				            threadName,
+<a name="419" href="#419">419</a> 				            throwableInfo,
+<a name="420" href="#420">420</a> 				            ndc,
+<a name="421" href="#421">421</a> 				            locationInfo,
+<a name="422" href="#422">422</a> 				            properties);
+<a name="423" href="#423">423</a> 
+<a name="424" href="#424">424</a>                     doPost(event);
+<a name="425" href="#425">425</a>                 }
+<a name="426" href="#426">426</a>                 <em class="comment">//log when rows are retrieved</em>
+<a name="427" href="#427">427</a>                 <strong>if</strong> (lastID != oldLastID) {
+<a name="428" href="#428">428</a>                     getLogger().debug(<span class="string">"lastID: "</span> + lastID);
+<a name="429" href="#429">429</a>                     oldLastID = lastID;
+<a name="430" href="#430">430</a>                 }
+<a name="431" href="#431">431</a> 
+<a name="432" href="#432">432</a>                 statement.close();
+<a name="433" href="#433">433</a>                 statement = <strong>null</strong>;
+<a name="434" href="#434">434</a>             } <strong>catch</strong> (SQLException sqle) {
+<a name="435" href="#435">435</a>                 getLogger()
+<a name="436" href="#436">436</a>                         .error(<span class="string">"*************Problem receiving events"</span>, sqle);
+<a name="437" href="#437">437</a>             } <strong>finally</strong> {
+<a name="438" href="#438">438</a>                 closeConnection(connection);
+<a name="439" href="#439">439</a>             }
+<a name="440" href="#440">440</a> 
+<a name="441" href="#441">441</a>             <em class="comment">// if paused, loop prior to executing sql query</em>
+<a name="442" href="#442">442</a>             <strong>synchronized</strong> (<strong>this</strong>) {
+<a name="443" href="#443">443</a>                 <strong>while</strong> (isPaused()) {
+<a name="444" href="#444">444</a>                     <strong>try</strong> {
+<a name="445" href="#445">445</a>                         wait(1000);
+<a name="446" href="#446">446</a>                     } <strong>catch</strong> (InterruptedException ie) {
+<a name="447" href="#447">447</a>                     }
+<a name="448" href="#448">448</a>                 }
+<a name="449" href="#449">449</a>             }
+<a name="450" href="#450">450</a>         }
+<a name="451" href="#451">451</a>     }
+<a name="452" href="#452">452</a> 
+<a name="453" href="#453">453</a>     <em>/**<em>*</em></em>
+<a name="454" href="#454">454</a> <em>     * @{inheritDoc}</em>
+<a name="455" href="#455">455</a> <em>     */</em>
+<a name="456" href="#456">456</a>   <strong>public</strong> <strong>boolean</strong> parseUnrecognizedElement(Element element, Properties props) throws Exception {
+<a name="457" href="#457">457</a>         <strong>if</strong> (<span class="string">"connectionSource"</span>.equals(element.getNodeName())) {
+<a name="458" href="#458">458</a>             Object instance =
+<a name="459" href="#459">459</a>                     DOMConfigurator.parseElement(element, props, ConnectionSource.<strong>class</strong>);
+<a name="460" href="#460">460</a>             <strong>if</strong> (instance instanceof ConnectionSource) {
+<a name="461" href="#461">461</a>                <a href="../../../../org/apache/log4j/db/ConnectionSource.html">ConnectionSource</a> source = (ConnectionSource) instance;
+<a name="462" href="#462">462</a>                source.activateOptions();
+<a name="463" href="#463">463</a>                setConnectionSource(source);
+<a name="464" href="#464">464</a>             }
+<a name="465" href="#465">465</a>             <strong>return</strong> <strong>true</strong>;
+<a name="466" href="#466">466</a>         }
+<a name="467" href="#467">467</a>         <strong>return</strong> false;
+<a name="468" href="#468">468</a>   }
+<a name="469" href="#469">469</a>     
+<a name="470" href="#470">470</a> }
+</pre>
+<hr/><div id="footer">This page was automatically generated by <a href="http://maven.apache.org/">Maven</a></div></body>
+</html>
+

Propchange: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/CustomSQLDBReceiver.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBAppender.html
URL: http://svn.apache.org/viewvc/logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBAppender.html?view=auto&rev=558362
==============================================================================
--- logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBAppender.html (added)
+++ logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBAppender.html Sat Jul 21 10:50:33 2007
@@ -0,0 +1,413 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /><title>DBAppender xref</title>
+<link type="text/css" rel="stylesheet" href="../../../../stylesheet.css" />
+</head>
+<body>
+<div id="overview"><a href="../../../../../../../../../../apidocs/org/apache/log4j/db/DBAppender.html">View Javadoc</a></div><pre>
+
+<a name="1" href="#1">1</a>   <em class="comment">/*</em>
+<a name="2" href="#2">2</a>   <em class="comment"> * Licensed to the Apache Software Foundation (ASF) under one or more</em>
+<a name="3" href="#3">3</a>   <em class="comment"> * contributor license agreements.  See the NOTICE file distributed with</em>
+<a name="4" href="#4">4</a>   <em class="comment"> * this work for additional information regarding copyright ownership.</em>
+<a name="5" href="#5">5</a>   <em class="comment"> * The ASF licenses this file to You under the Apache License, Version 2.0</em>
+<a name="6" href="#6">6</a>   <em class="comment"> * (the "License"); you may not use this file except in compliance with</em>
+<a name="7" href="#7">7</a>   <em class="comment"> * the License.  You may obtain a copy of the License at</em>
+<a name="8" href="#8">8</a>   <em class="comment"> *</em>
+<a name="9" href="#9">9</a>   <em class="comment"> *      <a href="http://www.apache.org/licenses/LICENSE-2.0" target="alexandria_uri">http://www.apache.org/licenses/LICENSE-2.0</a></em>
+<a name="10" href="#10">10</a>  <em class="comment"> *</em>
+<a name="11" href="#11">11</a>  <em class="comment"> * Unless required by applicable law or agreed to in writing, software</em>
+<a name="12" href="#12">12</a>  <em class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</em>
+<a name="13" href="#13">13</a>  <em class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</em>
+<a name="14" href="#14">14</a>  <em class="comment"> * See the License for the specific language governing permissions and</em>
+<a name="15" href="#15">15</a>  <em class="comment"> * limitations under the License.</em>
+<a name="16" href="#16">16</a>  <em class="comment"> */</em>
+<a name="17" href="#17">17</a>  
+<a name="18" href="#18">18</a>  <strong>package</strong> org.apache.log4j.db;
+<a name="19" href="#19">19</a>  
+<a name="20" href="#20">20</a>  <strong>import</strong> org.apache.log4j.AppenderSkeleton;
+<a name="21" href="#21">21</a>  <strong>import</strong> org.apache.log4j.db.dialect.SQLDialect;
+<a name="22" href="#22">22</a>  <strong>import</strong> org.apache.log4j.db.dialect.Util;
+<a name="23" href="#23">23</a>  <strong>import</strong> org.apache.log4j.helpers.LogLog;
+<a name="24" href="#24">24</a>  <strong>import</strong> org.apache.log4j.spi.LocationInfo;
+<a name="25" href="#25">25</a>  <strong>import</strong> org.apache.log4j.spi.LoggingEvent;
+<a name="26" href="#26">26</a>  <strong>import</strong> org.apache.log4j.xml.DOMConfigurator;
+<a name="27" href="#27">27</a>  <strong>import</strong> org.apache.log4j.xml.UnrecognizedElementHandler;
+<a name="28" href="#28">28</a>  <strong>import</strong> org.w3c.dom.Element;
+<a name="29" href="#29">29</a>  
+<a name="30" href="#30">30</a>  <strong>import</strong> java.lang.reflect.InvocationTargetException;
+<a name="31" href="#31">31</a>  <strong>import</strong> java.lang.reflect.Method;
+<a name="32" href="#32">32</a>  <strong>import</strong> java.sql.Connection;
+<a name="33" href="#33">33</a>  <strong>import</strong> java.sql.PreparedStatement;
+<a name="34" href="#34">34</a>  <strong>import</strong> java.sql.ResultSet;
+<a name="35" href="#35">35</a>  <strong>import</strong> java.sql.SQLException;
+<a name="36" href="#36">36</a>  <strong>import</strong> java.sql.Statement;
+<a name="37" href="#37">37</a>  <strong>import</strong> java.util.Iterator;
+<a name="38" href="#38">38</a>  <strong>import</strong> java.util.Properties;
+<a name="39" href="#39">39</a>  <strong>import</strong> java.util.Set;
+<a name="40" href="#40">40</a>  
+<a name="41" href="#41">41</a>  
+<a name="42" href="#42">42</a>  <em>/**<em>*</em></em>
+<a name="43" href="#43">43</a>  <em> * The DBAppender inserts loggin events into three database tables in a format</em>
+<a name="44" href="#44">44</a>  <em> * independent of the Java programming language. The three tables that</em>
+<a name="45" href="#45">45</a>  <em> * DBAppender inserts to must exists before DBAppender can be used. These tables</em>
+<a name="46" href="#46">46</a>  <em> * may be created with the help of SQL scripts found in the</em>
+<a name="47" href="#47">47</a>  <em> * &lt;em>src/java/org/apache/log4j/db/dialect&lt;/em> directory. There is a</em>
+<a name="48" href="#48">48</a>  <em> * specific script for each of the most popular database systems. If the script</em>
+<a name="49" href="#49">49</a>  <em> * for your particular type of database system is missing, it should be quite</em>
+<a name="50" href="#50">50</a>  <em> * easy to write one, taking example on the already existing scripts. If you</em>
+<a name="51" href="#51">51</a>  <em> * send them to us, we will gladly include missing scripts in future releases.</em>
+<a name="52" href="#52">52</a>  <em> *</em>
+<a name="53" href="#53">53</a>  <em> * &lt;p></em>
+<a name="54" href="#54">54</a>  <em> * If the JDBC driver you are using supports the</em>
+<a name="55" href="#55">55</a>  <em> * {@link java.sql.Statement#getGeneratedKeys}method introduced in JDBC 3.0</em>
+<a name="56" href="#56">56</a>  <em> * specification, then you are all set. Otherwise, there must be an</em>
+<a name="57" href="#57">57</a>  <em> * {@link SQLDialect}appropriate for your database system. Currently, we have</em>
+<a name="58" href="#58">58</a>  <em> * dialects for PostgreSQL, MySQL, Oracle and MsSQL. As mentioed previously, an</em>
+<a name="59" href="#59">59</a>  <em> * SQLDialect is required only if the JDBC driver for your database system does</em>
+<a name="60" href="#60">60</a>  <em> * not support the {@link java.sql.Statement#getGeneratedKeys getGeneratedKeys}</em>
+<a name="61" href="#61">61</a>  <em> * method.</em>
+<a name="62" href="#62">62</a>  <em> * &lt;/p></em>
+<a name="63" href="#63">63</a>  <em> *</em>
+<a name="64" href="#64">64</a>  <em> * &lt;table border="1" cellpadding="4"></em>
+<a name="65" href="#65">65</a>  <em> * &lt;tr></em>
+<a name="66" href="#66">66</a>  <em> * &lt;th>RDBMS&lt;/th></em>
+<a name="67" href="#67">67</a>  <em> * &lt;th>supports &lt;br/>&lt;code>getGeneratedKeys()&lt;/code> method&lt;/th></em>
+<a name="68" href="#68">68</a>  <em> * &lt;th>specific &lt;br/>SQLDialect support&lt;/th></em>
+<a name="69" href="#69">69</a>  <em> * &lt;tr></em>
+<a name="70" href="#70">70</a>  <em> * &lt;tr></em>
+<a name="71" href="#71">71</a>  <em> * &lt;td>PostgreSQL&lt;/td></em>
+<a name="72" href="#72">72</a>  <em> * &lt;td align="center">NO&lt;/td></em>
+<a name="73" href="#73">73</a>  <em> * &lt;td>present and used&lt;/td></em>
+<a name="74" href="#74">74</a>  <em> * &lt;tr></em>
+<a name="75" href="#75">75</a>  <em> * &lt;tr></em>
+<a name="76" href="#76">76</a>  <em> * &lt;td>MySQL&lt;/td></em>
+<a name="77" href="#77">77</a>  <em> * &lt;td align="center">YES&lt;/td></em>
+<a name="78" href="#78">78</a>  <em> * &lt;td>present, but not actually needed or used&lt;/td></em>
+<a name="79" href="#79">79</a>  <em> * &lt;tr></em>
+<a name="80" href="#80">80</a>  <em> * &lt;tr></em>
+<a name="81" href="#81">81</a>  <em> * &lt;td>Oracle&lt;/td></em>
+<a name="82" href="#82">82</a>  <em> * &lt;td align="center">YES&lt;/td></em>
+<a name="83" href="#83">83</a>  <em> * &lt;td>present, but not actually needed or used&lt;/td></em>
+<a name="84" href="#84">84</a>  <em> * &lt;tr></em>
+<a name="85" href="#85">85</a>  <em> * &lt;tr></em>
+<a name="86" href="#86">86</a>  <em> * &lt;td>DB2&lt;/td></em>
+<a name="87" href="#87">87</a>  <em> * &lt;td align="center">YES&lt;/td></em>
+<a name="88" href="#88">88</a>  <em> * &lt;td>not present, and not needed or used&lt;/td></em>
+<a name="89" href="#89">89</a>  <em> * &lt;tr></em>
+<a name="90" href="#90">90</a>  <em> * &lt;tr></em>
+<a name="91" href="#91">91</a>  <em> * &lt;td>MsSQL&lt;/td></em>
+<a name="92" href="#92">92</a>  <em> * &lt;td align="center">YES&lt;/td></em>
+<a name="93" href="#93">93</a>  <em> * &lt;td>not present, and not needed or used&lt;/td></em>
+<a name="94" href="#94">94</a>  <em> * &lt;tr></em>
+<a name="95" href="#95">95</a>  <em> * &lt;tr></em>
+<a name="96" href="#96">96</a>  <em> *   &lt;td>HSQL&lt;/td></em>
+<a name="97" href="#97">97</a>  <em> *    &lt;td align="center">NO&lt;/td></em>
+<a name="98" href="#98">98</a>  <em> *    &lt;td>present and used&lt;/td></em>
+<a name="99" href="#99">99</a>  <em> * &lt;tr></em>
+<a name="100" href="#100">100</a> <em> *</em>
+<a name="101" href="#101">101</a> <em> * &lt;/table></em>
+<a name="102" href="#102">102</a> <em> * &lt;p></em>
+<a name="103" href="#103">103</a> <em> * &lt;b>Performance: &lt;/b> Experiments show that writing a single event into the</em>
+<a name="104" href="#104">104</a> <em> * database takes approximately 50 milliseconds, on a "standard" PC. If pooled</em>
+<a name="105" href="#105">105</a> <em> * connections are used, this figure drops to under 10 milliseconds. Note that</em>
+<a name="106" href="#106">106</a> <em> * most JDBC drivers already ship with connection pooling support.</em>
+<a name="107" href="#107">107</a> <em> * &lt;/p></em>
+<a name="108" href="#108">108</a> <em> *</em>
+<a name="109" href="#109">109</a> <em> *</em>
+<a name="110" href="#110">110</a> <em> *</em>
+<a name="111" href="#111">111</a> <em> * &lt;p></em>
+<a name="112" href="#112">112</a> <em> * &lt;b>Configuration &lt;/b> DBAppender can be configured programmatically, or using</em>
+<a name="113" href="#113">113</a> <em> * {@link org.apache.log4j.xml.DOMConfigurator JoranConfigurator}. Example</em>
+<a name="114" href="#114">114</a> <em> * scripts can be found in the &lt;em>tests/input/db&lt;/em> directory.</em>
+<a name="115" href="#115">115</a> <em> *</em>
+<a name="116" href="#116">116</a> <em> * @author Ceki G&amp;uuml;lc&amp;uuml;</em>
+<a name="117" href="#117">117</a> <em> * @author Ray DeCampo</em>
+<a name="118" href="#118">118</a> <em> * @since 1.3</em>
+<a name="119" href="#119">119</a> <em> */</em>
+<a name="120" href="#120">120</a> <strong>public</strong> <strong>class</strong> <a href="../../../../org/apache/log4j/db/DBAppender.html">DBAppender</a> <strong>extends</strong> AppenderSkeleton implements UnrecognizedElementHandler {
+<a name="121" href="#121">121</a>   <strong>static</strong> <strong>final</strong> String insertPropertiesSQL =
+<a name="122" href="#122">122</a>     <span class="string">"INSERT INTO  logging_event_property (event_id, mapped_key, mapped_value) VALUES (?, ?, ?)"</span>;
+<a name="123" href="#123">123</a>   <strong>static</strong> <strong>final</strong> String insertExceptionSQL =
+<a name="124" href="#124">124</a>     <span class="string">"INSERT INTO  logging_event_exception (event_id, i, trace_line) VALUES (?, ?, ?)"</span>;
+<a name="125" href="#125">125</a>   <strong>static</strong> <strong>final</strong> String insertSQL;
+<a name="126" href="#126">126</a>   <strong>private</strong> <strong>static</strong> <strong>final</strong> Method GET_GENERATED_KEYS_METHOD;
+<a name="127" href="#127">127</a> 
+<a name="128" href="#128">128</a> 
+<a name="129" href="#129">129</a>   <strong>static</strong> {
+<a name="130" href="#130">130</a>     StringBuffer sql = <strong>new</strong> StringBuffer();
+<a name="131" href="#131">131</a>     sql.append(<span class="string">"INSERT INTO logging_event ("</span>);
+<a name="132" href="#132">132</a>     sql.append(<span class="string">"sequence_number, "</span>);
+<a name="133" href="#133">133</a>     sql.append(<span class="string">"timestamp, "</span>);
+<a name="134" href="#134">134</a>     sql.append(<span class="string">"rendered_message, "</span>);
+<a name="135" href="#135">135</a>     sql.append(<span class="string">"logger_name, "</span>);
+<a name="136" href="#136">136</a>     sql.append(<span class="string">"level_string, "</span>);
+<a name="137" href="#137">137</a>     sql.append(<span class="string">"ndc, "</span>);
+<a name="138" href="#138">138</a>     sql.append(<span class="string">"thread_name, "</span>);
+<a name="139" href="#139">139</a>     sql.append(<span class="string">"reference_flag, "</span>);
+<a name="140" href="#140">140</a>     sql.append(<span class="string">"caller_filename, "</span>);
+<a name="141" href="#141">141</a>     sql.append(<span class="string">"caller_class, "</span>);
+<a name="142" href="#142">142</a>     sql.append(<span class="string">"caller_method, "</span>);
+<a name="143" href="#143">143</a>     sql.append(<span class="string">"caller_line) "</span>);
+<a name="144" href="#144">144</a>     sql.append(<span class="string">" VALUES (?, ?, ? ,?, ?, ?, ?, ?, ?, ?, ?, ?)"</span>);
+<a name="145" href="#145">145</a>     insertSQL = sql.toString();
+<a name="146" href="#146">146</a>     <em class="comment">//</em>
+<a name="147" href="#147">147</a>     <em class="comment">//   PreparedStatement.getGeneratedKeys added in JDK 1.4</em>
+<a name="148" href="#148">148</a>     <em class="comment">//</em>
+<a name="149" href="#149">149</a>     Method getGeneratedKeysMethod;
+<a name="150" href="#150">150</a>     <strong>try</strong> {
+<a name="151" href="#151">151</a>         getGeneratedKeysMethod = PreparedStatement.<strong>class</strong>.getMethod(<span class="string">"getGeneratedKeys"</span>, <strong>null</strong>);
+<a name="152" href="#152">152</a>     } <strong>catch</strong>(Exception ex) {
+<a name="153" href="#153">153</a>         getGeneratedKeysMethod = <strong>null</strong>;
+<a name="154" href="#154">154</a>     }
+<a name="155" href="#155">155</a>     GET_GENERATED_KEYS_METHOD = getGeneratedKeysMethod;
+<a name="156" href="#156">156</a>   }
+<a name="157" href="#157">157</a> 
+<a name="158" href="#158">158</a>   <a href="../../../../org/apache/log4j/db/ConnectionSource.html">ConnectionSource</a> connectionSource;
+<a name="159" href="#159">159</a>   <strong>boolean</strong> cnxSupportsGetGeneratedKeys = false;
+<a name="160" href="#160">160</a>   <strong>boolean</strong> cnxSupportsBatchUpdates = false;
+<a name="161" href="#161">161</a>   <a href="../../../../org/apache/log4j/db/dialect/SQLDialect.html">SQLDialect</a> sqlDialect;
+<a name="162" href="#162">162</a>   <strong>boolean</strong> locationInfo = false;
+<a name="163" href="#163">163</a>   
+<a name="164" href="#164">164</a> 
+<a name="165" href="#165">165</a>   <strong>public</strong> <a href="../../../../org/apache/log4j/db/DBAppender.html">DBAppender</a>() {
+<a name="166" href="#166">166</a>       <strong>super</strong>(false);
+<a name="167" href="#167">167</a>   }
+<a name="168" href="#168">168</a> 
+<a name="169" href="#169">169</a>   <strong>public</strong> <strong>void</strong> activateOptions() {
+<a name="170" href="#170">170</a>     LogLog.debug(<span class="string">"DBAppender.activateOptions called"</span>);
+<a name="171" href="#171">171</a> 
+<a name="172" href="#172">172</a>     <strong>if</strong> (connectionSource == <strong>null</strong>) {
+<a name="173" href="#173">173</a>       <strong>throw</strong> <strong>new</strong> IllegalStateException(
+<a name="174" href="#174">174</a>         <span class="string">"DBAppender cannot function without a connection source"</span>);
+<a name="175" href="#175">175</a>     }
+<a name="176" href="#176">176</a> 
+<a name="177" href="#177">177</a>     sqlDialect = Util.getDialectFromCode(connectionSource.getSQLDialectCode());
+<a name="178" href="#178">178</a>     <strong>if</strong> (GET_GENERATED_KEYS_METHOD != <strong>null</strong>) {
+<a name="179" href="#179">179</a>         cnxSupportsGetGeneratedKeys = connectionSource.supportsGetGeneratedKeys();
+<a name="180" href="#180">180</a>     } <strong>else</strong> {
+<a name="181" href="#181">181</a>         cnxSupportsGetGeneratedKeys = false;
+<a name="182" href="#182">182</a>     }
+<a name="183" href="#183">183</a>     cnxSupportsBatchUpdates = connectionSource.supportsBatchUpdates();
+<a name="184" href="#184">184</a>     <strong>if</strong> (!cnxSupportsGetGeneratedKeys &amp;&amp; (sqlDialect == <strong>null</strong>)) {
+<a name="185" href="#185">185</a>       <strong>throw</strong> <strong>new</strong> IllegalStateException(
+<a name="186" href="#186">186</a>         <span class="string">"DBAppender cannot function if the JDBC driver does not support getGeneratedKeys method *and* without a specific SQL dialect"</span>);
+<a name="187" href="#187">187</a>     }
+<a name="188" href="#188">188</a>     
+<a name="189" href="#189">189</a>     <em class="comment">// all nice and dandy on the eastern front</em>
+<a name="190" href="#190">190</a>     <strong>super</strong>.activateOptions();
+<a name="191" href="#191">191</a>   }
+<a name="192" href="#192">192</a> 
+<a name="193" href="#193">193</a>   <em>/**<em>*</em></em>
+<a name="194" href="#194">194</a> <em>   * @return Returns the connectionSource.</em>
+<a name="195" href="#195">195</a> <em>   */</em>
+<a name="196" href="#196">196</a>   <strong>public</strong> <a href="../../../../org/apache/log4j/db/ConnectionSource.html">ConnectionSource</a> getConnectionSource() {
+<a name="197" href="#197">197</a>     <strong>return</strong> connectionSource;
+<a name="198" href="#198">198</a>   }
+<a name="199" href="#199">199</a> 
+<a name="200" href="#200">200</a>   <em>/**<em>*</em></em>
+<a name="201" href="#201">201</a> <em>   * @param connectionSource</em>
+<a name="202" href="#202">202</a> <em>   *          The connectionSource to set.</em>
+<a name="203" href="#203">203</a> <em>   */</em>
+<a name="204" href="#204">204</a>   <strong>public</strong> <strong>void</strong> setConnectionSource(<a href="../../../../org/apache/log4j/db/ConnectionSource.html">ConnectionSource</a> connectionSource) {
+<a name="205" href="#205">205</a>     LogLog.debug(<span class="string">"setConnectionSource called for DBAppender"</span>);
+<a name="206" href="#206">206</a>     <strong>this</strong>.connectionSource = connectionSource;
+<a name="207" href="#207">207</a>   }
+<a name="208" href="#208">208</a> 
+<a name="209" href="#209">209</a>   <strong>protected</strong> <strong>void</strong> append(LoggingEvent event) {
+<a name="210" href="#210">210</a>       Connection connection = <strong>null</strong>;
+<a name="211" href="#211">211</a>       <strong>try</strong> {
+<a name="212" href="#212">212</a>           connection = connectionSource.getConnection();
+<a name="213" href="#213">213</a>           connection.setAutoCommit(false);
+<a name="214" href="#214">214</a>           
+<a name="215" href="#215">215</a>           PreparedStatement insertStatement =
+<a name="216" href="#216">216</a>               connection.prepareStatement(insertSQL);
+<a name="217" href="#217">217</a> 
+<a name="218" href="#218">218</a> <em class="comment">/*<em class="comment">          insertStatement.setLong(1, event.getSequenceNumber());*/</em></em>
+<a name="219" href="#219">219</a> 		  insertStatement.setLong(1, 0);
+<a name="220" href="#220">220</a> 		
+<a name="221" href="#221">221</a>           insertStatement.setLong(2, event.getTimeStamp());
+<a name="222" href="#222">222</a>           insertStatement.setString(3, event.getRenderedMessage());
+<a name="223" href="#223">223</a>           insertStatement.setString(4, event.getLoggerName());
+<a name="224" href="#224">224</a>           insertStatement.setString(5, event.getLevel().toString());
+<a name="225" href="#225">225</a>           insertStatement.setString(6, event.getNDC());
+<a name="226" href="#226">226</a>           insertStatement.setString(7, event.getThreadName());
+<a name="227" href="#227">227</a>           insertStatement.setShort(8, DBHelper.computeReferenceMask(event));
+<a name="228" href="#228">228</a>           
+<a name="229" href="#229">229</a>           LocationInfo li;
+<a name="230" href="#230">230</a>           
+<a name="231" href="#231">231</a>           <strong>if</strong> (event.locationInformationExists() || locationInfo) {
+<a name="232" href="#232">232</a>               li = event.getLocationInformation();
+<a name="233" href="#233">233</a>           } <strong>else</strong> {
+<a name="234" href="#234">234</a>               li = LocationInfo.NA_LOCATION_INFO;
+<a name="235" href="#235">235</a>           }
+<a name="236" href="#236">236</a>           
+<a name="237" href="#237">237</a>           insertStatement.setString(9, li.getFileName());
+<a name="238" href="#238">238</a>           insertStatement.setString(10, li.getClassName());
+<a name="239" href="#239">239</a>           insertStatement.setString(11, li.getMethodName());
+<a name="240" href="#240">240</a>           insertStatement.setString(12, li.getLineNumber());
+<a name="241" href="#241">241</a>           
+<a name="242" href="#242">242</a>           <strong>int</strong> updateCount = insertStatement.executeUpdate();
+<a name="243" href="#243">243</a>           <strong>if</strong> (updateCount != 1) {
+<a name="244" href="#244">244</a>               LogLog.warn(<span class="string">"Failed to insert loggingEvent"</span>);
+<a name="245" href="#245">245</a>           }
+<a name="246" href="#246">246</a>           
+<a name="247" href="#247">247</a>           ResultSet rs = <strong>null</strong>;
+<a name="248" href="#248">248</a>           Statement idStatement = <strong>null</strong>;
+<a name="249" href="#249">249</a>           <strong>boolean</strong> gotGeneratedKeys = false;
+<a name="250" href="#250">250</a>           <strong>if</strong> (cnxSupportsGetGeneratedKeys) {
+<a name="251" href="#251">251</a>               <strong>try</strong> {
+<a name="252" href="#252">252</a>                   rs = (ResultSet) GET_GENERATED_KEYS_METHOD.invoke(insertStatement, <strong>null</strong>);
+<a name="253" href="#253">253</a>                   gotGeneratedKeys = <strong>true</strong>;
+<a name="254" href="#254">254</a>               } <strong>catch</strong>(InvocationTargetException ex) {
+<a name="255" href="#255">255</a>                   Throwable target = ex.getTargetException();
+<a name="256" href="#256">256</a>                   <strong>if</strong> (target instanceof SQLException) {
+<a name="257" href="#257">257</a>                       <strong>throw</strong> (SQLException) target;
+<a name="258" href="#258">258</a>                   }
+<a name="259" href="#259">259</a>                   <strong>throw</strong> ex; 
+<a name="260" href="#260">260</a>               } <strong>catch</strong>(IllegalAccessException ex) {
+<a name="261" href="#261">261</a>                   LogLog.warn(<span class="string">"IllegalAccessException invoking PreparedStatement.getGeneratedKeys"</span>, ex);
+<a name="262" href="#262">262</a>               }
+<a name="263" href="#263">263</a>           }
+<a name="264" href="#264">264</a>           
+<a name="265" href="#265">265</a>           <strong>if</strong> (!gotGeneratedKeys) {
+<a name="266" href="#266">266</a>               insertStatement.close();
+<a name="267" href="#267">267</a>               insertStatement = <strong>null</strong>;
+<a name="268" href="#268">268</a>               
+<a name="269" href="#269">269</a>               idStatement = connection.createStatement();
+<a name="270" href="#270">270</a>               idStatement.setMaxRows(1);
+<a name="271" href="#271">271</a>               rs = idStatement.executeQuery(sqlDialect.getSelectInsertId());
+<a name="272" href="#272">272</a>           }
+<a name="273" href="#273">273</a>           
+<a name="274" href="#274">274</a>           <em class="comment">// A ResultSet cursor is initially positioned before the first row; the </em>
+<a name="275" href="#275">275</a>           <em class="comment">// first call to the method next makes the first row the current row</em>
+<a name="276" href="#276">276</a>           rs.next();
+<a name="277" href="#277">277</a>           <strong>int</strong> eventId = rs.getInt(1);
+<a name="278" href="#278">278</a>           
+<a name="279" href="#279">279</a>           rs.close();
+<a name="280" href="#280">280</a> 
+<a name="281" href="#281">281</a>           <em class="comment">// we no longer need the insertStatement</em>
+<a name="282" href="#282">282</a>           <strong>if</strong>(insertStatement != <strong>null</strong>) {
+<a name="283" href="#283">283</a>               insertStatement.close();
+<a name="284" href="#284">284</a>               insertStatement = <strong>null</strong>;
+<a name="285" href="#285">285</a>           }
+<a name="286" href="#286">286</a> 
+<a name="287" href="#287">287</a>           <strong>if</strong>(idStatement != <strong>null</strong>) {
+<a name="288" href="#288">288</a>               idStatement.close();
+<a name="289" href="#289">289</a>               idStatement = <strong>null</strong>;
+<a name="290" href="#290">290</a>           }
+<a name="291" href="#291">291</a> 
+<a name="292" href="#292">292</a>           Set propertiesKeys = event.getPropertyKeySet();
+<a name="293" href="#293">293</a>           
+<a name="294" href="#294">294</a>           <strong>if</strong> (propertiesKeys.size() > 0) {
+<a name="295" href="#295">295</a>               PreparedStatement insertPropertiesStatement =
+<a name="296" href="#296">296</a>                   connection.prepareStatement(insertPropertiesSQL);
+<a name="297" href="#297">297</a>               
+<a name="298" href="#298">298</a>               <strong>for</strong> (Iterator i = propertiesKeys.iterator(); i.hasNext();) {
+<a name="299" href="#299">299</a>                   String key = (String) i.next();
+<a name="300" href="#300">300</a>                   String value = (String) event.getProperty(key);
+<a name="301" href="#301">301</a>                   
+<a name="302" href="#302">302</a>                   <em class="comment">//LogLog.info("id " + eventId + ", key " + key + ", value " + value);</em>
+<a name="303" href="#303">303</a>                   insertPropertiesStatement.setInt(1, eventId);
+<a name="304" href="#304">304</a>                   insertPropertiesStatement.setString(2, key);
+<a name="305" href="#305">305</a>                   insertPropertiesStatement.setString(3, value);
+<a name="306" href="#306">306</a>                   
+<a name="307" href="#307">307</a>                   <strong>if</strong> (cnxSupportsBatchUpdates) {
+<a name="308" href="#308">308</a>                       insertPropertiesStatement.addBatch();
+<a name="309" href="#309">309</a>                   } <strong>else</strong> {
+<a name="310" href="#310">310</a>                       insertPropertiesStatement.execute();
+<a name="311" href="#311">311</a>                   }
+<a name="312" href="#312">312</a>               }
+<a name="313" href="#313">313</a>               
+<a name="314" href="#314">314</a>               <strong>if</strong> (cnxSupportsBatchUpdates) {
+<a name="315" href="#315">315</a>                   insertPropertiesStatement.executeBatch();
+<a name="316" href="#316">316</a>               }
+<a name="317" href="#317">317</a>               
+<a name="318" href="#318">318</a>               insertPropertiesStatement.close();
+<a name="319" href="#319">319</a>               insertPropertiesStatement = <strong>null</strong>;
+<a name="320" href="#320">320</a>           }
+<a name="321" href="#321">321</a>           
+<a name="322" href="#322">322</a>           String[] strRep = event.getThrowableStrRep();
+<a name="323" href="#323">323</a>           
+<a name="324" href="#324">324</a>           <strong>if</strong> (strRep != <strong>null</strong>) {
+<a name="325" href="#325">325</a>               LogLog.debug(<span class="string">"Logging an exception"</span>);
+<a name="326" href="#326">326</a>               
+<a name="327" href="#327">327</a>               PreparedStatement insertExceptionStatement =
+<a name="328" href="#328">328</a>                   connection.prepareStatement(insertExceptionSQL);
+<a name="329" href="#329">329</a>               
+<a name="330" href="#330">330</a>               <strong>for</strong> (<strong>short</strong> i = 0; i &lt; strRep.length; i++) {
+<a name="331" href="#331">331</a>                   insertExceptionStatement.setInt(1, eventId);
+<a name="332" href="#332">332</a>                   insertExceptionStatement.setShort(2, i);
+<a name="333" href="#333">333</a>                   insertExceptionStatement.setString(3, strRep[i]);
+<a name="334" href="#334">334</a>                   <strong>if</strong> (cnxSupportsBatchUpdates) {
+<a name="335" href="#335">335</a>                       insertExceptionStatement.addBatch();
+<a name="336" href="#336">336</a>                   } <strong>else</strong> {
+<a name="337" href="#337">337</a>                       insertExceptionStatement.execute();
+<a name="338" href="#338">338</a>                   }
+<a name="339" href="#339">339</a>               }
+<a name="340" href="#340">340</a>               <strong>if</strong> (cnxSupportsBatchUpdates) {
+<a name="341" href="#341">341</a>                   insertExceptionStatement.executeBatch();
+<a name="342" href="#342">342</a>               }
+<a name="343" href="#343">343</a>               insertExceptionStatement.close();
+<a name="344" href="#344">344</a>               insertExceptionStatement = <strong>null</strong>;
+<a name="345" href="#345">345</a>           }
+<a name="346" href="#346">346</a>           
+<a name="347" href="#347">347</a>           connection.commit();
+<a name="348" href="#348">348</a>       } <strong>catch</strong> (Throwable sqle) {
+<a name="349" href="#349">349</a>           LogLog.error(<span class="string">"problem appending event"</span>, sqle);
+<a name="350" href="#350">350</a>       } <strong>finally</strong> {
+<a name="351" href="#351">351</a>           DBHelper.closeConnection(connection);
+<a name="352" href="#352">352</a>       }
+<a name="353" href="#353">353</a>   }
+<a name="354" href="#354">354</a> 
+<a name="355" href="#355">355</a>   <strong>public</strong> <strong>void</strong> close() {
+<a name="356" href="#356">356</a>     closed = <strong>true</strong>;
+<a name="357" href="#357">357</a>   }
+<a name="358" href="#358">358</a> 
+<a name="359" href="#359">359</a>   <em>/**<em>*</em></em>
+<a name="360" href="#360">360</a> <em>   * Returns value of the &lt;b>LocationInfo &lt;/b> property which determines whether</em>
+<a name="361" href="#361">361</a> <em>   * caller's location info is written to the database.</em>
+<a name="362" href="#362">362</a> <em>   */</em>
+<a name="363" href="#363">363</a>   <strong>public</strong> <strong>boolean</strong> getLocationInfo() {
+<a name="364" href="#364">364</a>     <strong>return</strong> locationInfo;
+<a name="365" href="#365">365</a>   }
+<a name="366" href="#366">366</a> 
+<a name="367" href="#367">367</a>   <em>/**<em>*</em></em>
+<a name="368" href="#368">368</a> <em>   * If true, the information written to the database will include caller's</em>
+<a name="369" href="#369">369</a> <em>   * location information. Due to performance concerns, by default no location</em>
+<a name="370" href="#370">370</a> <em>   * information is written to the database.</em>
+<a name="371" href="#371">371</a> <em>   */</em>
+<a name="372" href="#372">372</a>   <strong>public</strong> <strong>void</strong> setLocationInfo(<strong>boolean</strong> locationInfo) {
+<a name="373" href="#373">373</a>     <strong>this</strong>.locationInfo = locationInfo;
+<a name="374" href="#374">374</a>   }
+<a name="375" href="#375">375</a> 
+<a name="376" href="#376">376</a>     <em>/**<em>*</em></em>
+<a name="377" href="#377">377</a> <em>     * Gets whether appender requires a layout.</em>
+<a name="378" href="#378">378</a> <em>     * @return false</em>
+<a name="379" href="#379">379</a> <em>     */</em>
+<a name="380" href="#380">380</a>   <strong>public</strong> <strong>boolean</strong> requiresLayout() {
+<a name="381" href="#381">381</a>       <strong>return</strong> false;
+<a name="382" href="#382">382</a>   }
+<a name="383" href="#383">383</a> 
+<a name="384" href="#384">384</a>     <em>/**<em>*</em></em>
+<a name="385" href="#385">385</a> <em>     * @{inheritDoc}</em>
+<a name="386" href="#386">386</a> <em>     */</em>
+<a name="387" href="#387">387</a>   <strong>public</strong> <strong>boolean</strong> parseUnrecognizedElement(Element element, Properties props) throws Exception {
+<a name="388" href="#388">388</a>         <strong>if</strong> (<span class="string">"connectionSource"</span>.equals(element.getNodeName())) {
+<a name="389" href="#389">389</a>             Object instance =
+<a name="390" href="#390">390</a>                     DOMConfigurator.parseElement(element, props, ConnectionSource.<strong>class</strong>);
+<a name="391" href="#391">391</a>             <strong>if</strong> (instance instanceof ConnectionSource) {
+<a name="392" href="#392">392</a>                <a href="../../../../org/apache/log4j/db/ConnectionSource.html">ConnectionSource</a> source = (ConnectionSource) instance;
+<a name="393" href="#393">393</a>                source.activateOptions();
+<a name="394" href="#394">394</a>                setConnectionSource(source);
+<a name="395" href="#395">395</a>             }
+<a name="396" href="#396">396</a>             <strong>return</strong> <strong>true</strong>;
+<a name="397" href="#397">397</a>         }
+<a name="398" href="#398">398</a>         <strong>return</strong> false;
+<a name="399" href="#399">399</a>   }
+<a name="400" href="#400">400</a> }
+</pre>
+<hr/><div id="footer">This page was automatically generated by <a href="http://maven.apache.org/">Maven</a></div></body>
+</html>
+

Propchange: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBAppender.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBHelper.html
URL: http://svn.apache.org/viewvc/logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBHelper.html?view=auto&rev=558362
==============================================================================
--- logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBHelper.html (added)
+++ logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBHelper.html Sat Jul 21 10:50:33 2007
@@ -0,0 +1,81 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /><title>DBHelper xref</title>
+<link type="text/css" rel="stylesheet" href="../../../../stylesheet.css" />
+</head>
+<body>
+<div id="overview"><a href="../../../../../../../../../../apidocs/org/apache/log4j/db/DBHelper.html">View Javadoc</a></div><pre>
+
+<a name="1" href="#1">1</a>   <em class="comment">/*</em>
+<a name="2" href="#2">2</a>   <em class="comment"> * Licensed to the Apache Software Foundation (ASF) under one or more</em>
+<a name="3" href="#3">3</a>   <em class="comment"> * contributor license agreements.  See the NOTICE file distributed with</em>
+<a name="4" href="#4">4</a>   <em class="comment"> * this work for additional information regarding copyright ownership.</em>
+<a name="5" href="#5">5</a>   <em class="comment"> * The ASF licenses this file to You under the Apache License, Version 2.0</em>
+<a name="6" href="#6">6</a>   <em class="comment"> * (the "License"); you may not use this file except in compliance with</em>
+<a name="7" href="#7">7</a>   <em class="comment"> * the License.  You may obtain a copy of the License at</em>
+<a name="8" href="#8">8</a>   <em class="comment"> * </em>
+<a name="9" href="#9">9</a>   <em class="comment"> *      <a href="http://www.apache.org/licenses/LICENSE-2.0" target="alexandria_uri">http://www.apache.org/licenses/LICENSE-2.0</a></em>
+<a name="10" href="#10">10</a>  <em class="comment"> * </em>
+<a name="11" href="#11">11</a>  <em class="comment"> * Unless required by applicable law or agreed to in writing, software</em>
+<a name="12" href="#12">12</a>  <em class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</em>
+<a name="13" href="#13">13</a>  <em class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</em>
+<a name="14" href="#14">14</a>  <em class="comment"> * See the License for the specific language governing permissions and</em>
+<a name="15" href="#15">15</a>  <em class="comment"> * limitations under the License.</em>
+<a name="16" href="#16">16</a>  <em class="comment"> */</em>
+<a name="17" href="#17">17</a>  
+<a name="18" href="#18">18</a>  <strong>package</strong> org.apache.log4j.db;
+<a name="19" href="#19">19</a>  
+<a name="20" href="#20">20</a>  <strong>import</strong> java.sql.Connection;
+<a name="21" href="#21">21</a>  <strong>import</strong> java.sql.SQLException;
+<a name="22" href="#22">22</a>  <strong>import</strong> java.sql.Statement;
+<a name="23" href="#23">23</a>  <strong>import</strong> java.util.Set;
+<a name="24" href="#24">24</a>  
+<a name="25" href="#25">25</a>  <strong>import</strong> org.apache.log4j.spi.LoggingEvent;
+<a name="26" href="#26">26</a>  
+<a name="27" href="#27">27</a>  <em>/**<em>*</em></em>
+<a name="28" href="#28">28</a>  <em> * @author Ceki G&amp;uuml;lc&amp;uuml;</em>
+<a name="29" href="#29">29</a>  <em> *</em>
+<a name="30" href="#30">30</a>  <em> */</em>
+<a name="31" href="#31">31</a>  <strong>public</strong> <strong>class</strong> <a href="../../../../org/apache/log4j/db/DBHelper.html">DBHelper</a> {
+<a name="32" href="#32">32</a>    
+<a name="33" href="#33">33</a>    <strong>public</strong> <strong>final</strong> <strong>static</strong> <strong>short</strong> PROPERTIES_EXIST = 0x01;
+<a name="34" href="#34">34</a>    <strong>public</strong> <strong>final</strong> <strong>static</strong> <strong>short</strong> EXCEPTION_EXISTS = 0x02;
+<a name="35" href="#35">35</a>    
+<a name="36" href="#36">36</a>    <strong>public</strong>  <strong>static</strong> <strong>short</strong> computeReferenceMask(LoggingEvent event) {
+<a name="37" href="#37">37</a>      <strong>short</strong> mask = 0;
+<a name="38" href="#38">38</a>      Set propertiesKeys = event.getPropertyKeySet();
+<a name="39" href="#39">39</a>      <strong>if</strong>(propertiesKeys.size() > 0) {
+<a name="40" href="#40">40</a>        mask = PROPERTIES_EXIST;
+<a name="41" href="#41">41</a>      }
+<a name="42" href="#42">42</a>      String[] strRep = event.getThrowableStrRep();
+<a name="43" href="#43">43</a>      <strong>if</strong>(strRep != <strong>null</strong>) {
+<a name="44" href="#44">44</a>        mask |= EXCEPTION_EXISTS;
+<a name="45" href="#45">45</a>      }
+<a name="46" href="#46">46</a>      <strong>return</strong> mask;
+<a name="47" href="#47">47</a>    }
+<a name="48" href="#48">48</a>    
+<a name="49" href="#49">49</a>    <strong>static</strong> <strong>public</strong> <strong>void</strong> closeConnection(Connection connection) {
+<a name="50" href="#50">50</a>      <strong>if</strong>(connection != <strong>null</strong>) {
+<a name="51" href="#51">51</a>        <strong>try</strong> { 
+<a name="52" href="#52">52</a>          connection.close();
+<a name="53" href="#53">53</a>        } <strong>catch</strong>(SQLException sqle) {
+<a name="54" href="#54">54</a>          <em class="comment">// static utility classes should not log without an explicit repository</em>
+<a name="55" href="#55">55</a>          <em class="comment">// reference</em>
+<a name="56" href="#56">56</a>        }
+<a name="57" href="#57">57</a>      }
+<a name="58" href="#58">58</a>    }
+<a name="59" href="#59">59</a>    
+<a name="60" href="#60">60</a>    <strong>public</strong> <strong>static</strong> <strong>void</strong> closeStatement(Statement statement) {
+<a name="61" href="#61">61</a>      <strong>if</strong>(statement != <strong>null</strong>) {
+<a name="62" href="#62">62</a>        <strong>try</strong> {
+<a name="63" href="#63">63</a>          statement.close();
+<a name="64" href="#64">64</a>        } <strong>catch</strong>(SQLException sqle) {
+<a name="65" href="#65">65</a>        }
+<a name="66" href="#66">66</a>      }
+<a name="67" href="#67">67</a>    }
+<a name="68" href="#68">68</a>  }
+</pre>
+<hr/><div id="footer">This page was automatically generated by <a href="http://maven.apache.org/">Maven</a></div></body>
+</html>
+

Propchange: logging/site/trunk/docs/log4j/companions/receivers/xref/org/apache/log4j/db/DBHelper.html
------------------------------------------------------------------------------
    svn:mime-type = text/html



Mime
View raw message