blob: 8c53ba56bc9a167c5ea0b65df4ecf152cc311999 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>JdbcUtils.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Shiro :: Core</a> &gt; <a href="index.source.html" class="el_package">org.apache.shiro.util</a> &gt; <span class="el_source">JdbcUtils.java</span></div><h1>JdbcUtils.java</h1><pre class="source lang-java linenums">/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* &quot;License&quot;); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.shiro.util;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A set of static helper methods for managing JDBC API objects.
* &lt;p/&gt;
* &lt;em&gt;Note:&lt;/em&gt; Some parts of this class were copied from the Spring Framework and then modified.
* They were copied here to prevent Spring dependencies in the Shiro core API. The original license conditions
* (Apache 2.0) have been maintained.
*
* @since 0.2
*/
public class JdbcUtils {
/** Private internal log instance. */
<span class="fc" id="L41"> private static final Logger log = LoggerFactory.getLogger(JdbcUtils.class);</span>
/**
* Private constructor to prevent instantiation.
*/
<span class="nc" id="L46"> private JdbcUtils() {</span>
<span class="nc" id="L47"> }</span>
/**
* Close the given JDBC Connection and ignore any thrown exception.
* This is useful for typical finally blocks in manual JDBC code.
*
* @param connection the JDBC Connection to close (may be &lt;tt&gt;null&lt;/tt&gt;)
*/
public static void closeConnection(Connection connection) {
<span class="fc bfc" id="L56" title="All 2 branches covered."> if (connection != null) {</span>
try {
<span class="fc" id="L58"> connection.close();</span>
<span class="nc" id="L59"> } catch (SQLException ex) {</span>
<span class="nc bnc" id="L60" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span>
<span class="nc" id="L61"> log.debug(&quot;Could not close JDBC Connection&quot;, ex);</span>
}
<span class="nc" id="L63"> } catch (Throwable ex) {</span>
<span class="nc bnc" id="L64" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span>
<span class="nc" id="L65"> log.debug(&quot;Unexpected exception on closing JDBC Connection&quot;, ex);</span>
}
<span class="pc" id="L67"> }</span>
}
<span class="fc" id="L69"> }</span>
/**
* Close the given JDBC Statement and ignore any thrown exception.
* This is useful for typical finally blocks in manual JDBC code.
*
* @param statement the JDBC Statement to close (may be &lt;tt&gt;null&lt;/tt&gt;)
*/
public static void closeStatement(Statement statement) {
<span class="fc bfc" id="L78" title="All 2 branches covered."> if (statement != null) {</span>
try {
<span class="fc" id="L80"> statement.close();</span>
<span class="nc" id="L81"> } catch (SQLException ex) {</span>
<span class="nc bnc" id="L82" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span>
<span class="nc" id="L83"> log.debug(&quot;Could not close JDBC Statement&quot;, ex);</span>
}
<span class="nc" id="L85"> } catch (Throwable ex) {</span>
<span class="nc bnc" id="L86" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span>
<span class="nc" id="L87"> log.debug(&quot;Unexpected exception on closing JDBC Statement&quot;, ex);</span>
}
<span class="pc" id="L89"> }</span>
}
<span class="fc" id="L91"> }</span>
/**
* Close the given JDBC ResultSet and ignore any thrown exception.
* This is useful for typical finally blocks in manual JDBC code.
*
* @param rs the JDBC ResultSet to close (may be &lt;tt&gt;null&lt;/tt&gt;)
*/
public static void closeResultSet(ResultSet rs) {
<span class="pc bpc" id="L100" title="1 of 2 branches missed."> if (rs != null) {</span>
try {
<span class="fc" id="L102"> rs.close();</span>
<span class="nc" id="L103"> } catch (SQLException ex) {</span>
<span class="nc bnc" id="L104" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span>
<span class="nc" id="L105"> log.debug(&quot;Could not close JDBC ResultSet&quot;, ex);</span>
}
<span class="nc" id="L107"> } catch (Throwable ex) {</span>
<span class="nc bnc" id="L108" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span>
<span class="nc" id="L109"> log.debug(&quot;Unexpected exception on closing JDBC ResultSet&quot;, ex);</span>
}
<span class="pc" id="L111"> }</span>
}
<span class="fc" id="L113"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.7.201606060606</span></div></body></html>