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