KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > admin > components > DBTools


1 // $Id: DBTools.java 3567 2003-06-30 22:32:03Z shuber $
2
//
3
// ____.
4
// __/\ ______| |__/\. _______
5
// __ .____| | \ | +----+ \
6
// _______| /--| | | - \ _ | : - \_________
7
// \\______: :---| : : | : | \________>
8
// |__\---\_____________:______: :____|____:_____\
9
// /_____|
10
//
11
// . . . i n j a h i a w e t r u s t . . .
12
//
13
//
14
// DBTools
15
//
16
// 02.04.2001 MJ added in jahia.
17
//
18

19
20 package org.jahia.admin.components;
21
22 import java.sql.Connection JavaDoc;
23 import java.sql.SQLException JavaDoc;
24 import java.sql.Statement JavaDoc;
25
26 import org.jahia.exceptions.JahiaException;
27 import org.jahia.registries.ServicesRegistry;
28
29 public class DBTools {
30
31     /**
32      * write a log entry to the database
33      *
34      * this method belongs in org.jahia.services.audit.JahiaDBAuditLogManager
35          * it is here for want of a convenient way to pass a JahiaEvent, with reference
36      * to ParamBean, to the manager from the Application Manager Service.
37      *
38      * @author Mikhael Janson
39      * @param entryID
40      * @param time
41      * @param userNameStr
42      * @param objectTypeStr
43      * @param objectIDStr
44      * @param operationStr
45      * @param contentStr
46      */

47     protected static boolean insertAuditLogEntry (int entryID,
48                                                   String JavaDoc timeStr,
49                                                   String JavaDoc userNameStr,
50                                                   String JavaDoc objectTypeStr,
51                                                   String JavaDoc objectIDStr,
52                                                   String JavaDoc parentObjIDStr,
53                                                   String JavaDoc parentTypeStr,
54                                                   String JavaDoc operationStr,
55                                                   String JavaDoc contentStr) throws
56         JahiaException {
57         String JavaDoc MSG_INTERNAL_ERROR = new String JavaDoc(
58             "Jahia Administration internal error");
59
60         // Try to get the DB Pool Service
61
ServicesRegistry registry = ServicesRegistry.getInstance();
62         if (registry == null) {
63             throw new JahiaException(MSG_INTERNAL_ERROR,
64                 "JahiaAdministration could not get the Service Registry instance.",
65                                      JahiaException.REGISTRY_ERROR,
66                                      JahiaException.CRITICAL_SEVERITY);
67         }
68
69         Connection JavaDoc dbConn = null;
70
71         try {
72             dbConn = org.jahia.services.database.ConnectionDispenser.
73                 getConnection();
74         } catch (NullPointerException JavaDoc npe) {
75             //System.out.println ("Null Pointer Exception, DB Pool Service instance might be null!");
76
}
77
78         if (dbConn == null) {
79             return false;
80         }
81
82         // Get a database connection
83
boolean result = true;
84         Statement JavaDoc statement = null;
85
86         try {
87             statement = dbConn.createStatement();
88
89             String JavaDoc query = "INSERT INTO jahia_audit_log (id_jahia_audit_log, time_jahia_audit_log, username_jahia_audit_log, objecttype_jahia_audit_log, operation_jahia_audit_log, objectid_jahia_audit_log, parentid_jahia_audit_log, parenttype_jahia_audit_log, content_jahia_audit_log ) VALUES ("
90                 + Integer.toString(entryID)
91                 + ",'" + timeStr
92                 + "','" + userNameStr
93                 + "'," + objectTypeStr
94                 + ",'" + operationStr
95                 + "'," + objectIDStr
96                 + "," + parentObjIDStr
97                 + "," + parentTypeStr
98                 + ",'" + contentStr + "')";
99             statement.executeUpdate(query);
100
101         } catch (SQLException JavaDoc sqlEx) {
102             //System.out.println ("SQL Exception occured!" + sqlEx.getMessage());
103
result = false;
104         } finally {
105             // Close the opened statement
106
try {
107                 if (statement != null) {
108                     statement.close();
109                 }
110             } catch (SQLException JavaDoc se) {
111                 // FIXME -MJ- : Don't know yet what to do with this exception.
112
// It should be logged somewhere !
113
}
114         }
115         return result;
116     }
117
118 }
Popular Tags