Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JdbcUtils |
|
| 2.25;2.25 |
1 | /* | |
2 | * $Id: JdbcUtils.java 19191 2010-08-25 21:05:23Z tcarlson $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com | |
5 | * | |
6 | * The software in this package is published under the terms of the CPAL v1.0 | |
7 | * license, a copy of which has been included with this distribution in the | |
8 | * LICENSE.txt file. | |
9 | */ | |
10 | ||
11 | package org.mule.transport.jdbc; | |
12 | ||
13 | import java.sql.Connection; | |
14 | import java.sql.SQLException; | |
15 | ||
16 | /** | |
17 | * Utility methods for working with various parts of JDBC. | |
18 | */ | |
19 | public final class JdbcUtils | |
20 | { | |
21 | ||
22 | private JdbcUtils() | |
23 | 0 | { |
24 | // empty, just to restrict instanciation | |
25 | 0 | } |
26 | ||
27 | public static void close(Connection con) throws SQLException | |
28 | { | |
29 | 0 | if (con != null && !con.isClosed()) |
30 | { | |
31 | 0 | con.close(); |
32 | } | |
33 | 0 | } |
34 | ||
35 | public static void commitAndClose(Connection con) throws SQLException | |
36 | { | |
37 | 0 | if (con != null) |
38 | { | |
39 | 0 | if (!con.getAutoCommit()) |
40 | { | |
41 | 0 | con.commit(); |
42 | } | |
43 | 0 | con.close(); |
44 | } | |
45 | 0 | } |
46 | ||
47 | public static void rollbackAndClose(Connection con) throws SQLException | |
48 | { | |
49 | 0 | if (con != null) |
50 | { | |
51 | 0 | if (!con.getAutoCommit()) |
52 | { | |
53 | 0 | con.rollback(); |
54 | } | |
55 | 0 | con.close(); |
56 | } | |
57 | 0 | } |
58 | ||
59 | } |