Project

General

Profile

« Previous | Next » 

Revision 2104

Added by Matt Jones about 20 years ago

Patched to make the date-time value insertion work under oracle. Now it
tests fine under both oracle and postgres. Still need to write an
access/query function.

View differences:

src/edu/ucsb/nceas/metacat/EventLog.java
23 23
 */
24 24
package edu.ucsb.nceas.metacat;
25 25

  
26
import java.sql.PreparedStatement;
26 27
import java.sql.SQLException;
27
import java.sql.Statement;
28
import java.text.SimpleDateFormat;
28
import java.sql.Timestamp;
29 29
import java.util.Date;
30 30

  
31 31
/**
......
44 44
 * external text file so that the log table doesn't get to big.  This 
45 45
 * function should be able to be called manually or on a schedule. 
46 46
 * 
47
 * TODO: Write oracle sql code for creating logging table
48
 * 
49 47
 * TODO: Write an access function that returns an XML report for a
50 48
 * specific subset of events.  Users should be able to query on
51 49
 * principal, docid/rev, date, event, and possibly other fields.
......
106 104
     */
107 105
    private void insertLogEntry(EventLogData logData)
108 106
    {
109
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
110
                "dd-MMM-yyyy HH:mm:ss");
111

  
112 107
        String insertString = "insert into access_log"
113 108
                + "(ip_address, principal, docid, "
114 109
                + "event, date_logged) "
......
117 112
                + "'" + logData.getPrincipal() + "', "
118 113
                + "'" + logData.getDocid() + "', "
119 114
                + "'" + logData.getEvent() + "', "
120
                + "'" + simpleDateFormat.format(new Date()) + "')"; 
115
                + " ? " + ")"; 
121 116

  
122 117
        DBConnection dbConn = null;
123 118
        int serialNumber = -1;
......
127 122
            serialNumber = dbConn.getCheckOutSerialNumber();
128 123
            
129 124
            // Execute the insert statement
130
            Statement stmt = dbConn.createStatement();
131
            stmt.executeUpdate(insertString);
125
            PreparedStatement stmt = dbConn.prepareStatement(insertString);
126
            stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
127
            stmt.executeUpdate();
132 128
            stmt.close();
133 129
        } catch (SQLException e) {
134 130
            MetaCatUtil.debugMessage("Error while logging event to database: " 

Also available in: Unified diff