1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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
55
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 }