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.SQLException;
22 import java.sql.Statement;
23 import java.util.Set;
24
25 import org.apache.log4j.spi.LoggingEvent;
26
27 /**
28 * @author Ceki Gülcü
29 *
30 */
31 public class DBHelper {
32
33 public final static short PROPERTIES_EXIST = 0x01;
34 public final static short EXCEPTION_EXISTS = 0x02;
35
36 public static short computeReferenceMask(LoggingEvent event) {
37 short mask = 0;
38 Set propertiesKeys = event.getPropertyKeySet();
39 if(propertiesKeys.size() > 0) {
40 mask = PROPERTIES_EXIST;
41 }
42 String[] strRep = event.getThrowableStrRep();
43 if(strRep != null) {
44 mask |= EXCEPTION_EXISTS;
45 }
46 return mask;
47 }
48
49 static public void closeConnection(Connection connection) {
50 if(connection != null) {
51 try {
52 connection.close();
53 } catch(SQLException sqle) {
54 // static utility classes should not log without an explicit repository
55 // reference
56 }
57 }
58 }
59
60 public static void closeStatement(Statement statement) {
61 if(statement != null) {
62 try {
63 statement.close();
64 } catch(SQLException sqle) {
65 }
66 }
67 }
68 }