Project

General

Profile

« Previous | Next » 

Revision 2099

Added by Matt Jones over 20 years ago

Modified SQL scripts to add the new access_log table. I've partially tested this under postgres but have not yet tested under oracle.

View differences:

src/xmltables_postgres.sql
1
/*
2
 * xmltables-postgres.sql
3
 *             : Create or replace tables for storing XML in PostgreSQL
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 Regents of the University of California and the
4
 *             National Center for Ecological Analysis and Synthesis
4 5
 *
5
 *      Purpose: creates tables needed for storing XML in PostgreSQL database
6
 * 
7
 *      Created: 08 May 2001 
8
 *       Author: John Harris
9
 * Organization: National Center for Ecological Analysis and Synthesis
10
 *    Copyright: 2000 Regents of the University of California and the
11
 *               National Center for Ecological Analysis and Synthesis
12
 *  For Details: http://www.nceas.ucsb.edu/
13
 *    File Info: '$Id$'
6
 *   '$Author$'
7
 *     '$Date$'
8
 * '$Revision$'
14 9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 */
24
 
25
/*
15 26
 *	this is sql script does the same as the sql script named 
16 27
 *	xmltables.sql except that this script is to be use to 
17 28
 *	create the database tables on a Postgresql backend rather
......
259 270
);
260 271

  
261 272
/*
262
 *Logging -- table to store metadata and data access log
273
 * Logging -- table to store metadata and data access log
263 274
 */
264 275
CREATE SEQUENCE access_log_id_seq;
265 276
CREATE TABLE access_log (
266
  entryid       INT8 default nextval ('access_log_id_seq'),
267
  ip_address    VARCHAR(512),
268
  principal     VARCHAR(512),
277
  entryid       INT8 default nextval ('access_log_id_seq'), -- the identifier for the log event
278
  ip_address    VARCHAR(512),   -- the ip address inititiating the event
279
  principal     VARCHAR(512),   -- the user initiiating the event
269 280
  docid         VARCHAR(250),	-- the document id #
270 281
  rev           INT8,           -- the revision number
271
  event         VARCHAR(512),
272
  date_logged   TIMESTAMP,
282
  event         VARCHAR(512),   -- the code symbolizing the event type
283
  date_logged   TIMESTAMP,      -- the datetime on which the event occurred
273 284
  CONSTRAINT access_log_pk PRIMARY KEY (entryid)
274 285
);
src/upgrade-db-to-1.4.sql
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 Regents of the University of California and the
4
 *             National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author$'
7
 *     '$Date$'
8
 * '$Revision$'
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 */
24
 
25
/*
26
 * Logging -- table to store metadata and data access log
27
 */
28
CREATE TABLE access_log (
29
  entryid       NUMBER(20),     -- the identifier for the log event
30
  ip_address    VARCHAR2(512),  -- the ip address inititiating the event
31
  principal     VARCHAR2(512),  -- the user initiiating the event
32
  docid         VARCHAR2(250),	-- the document id #
33
  rev           NUMBER(10),     -- the revision number
34
  event         VARCHAR2(512),  -- the code symbolizing the event type
35
  date_logged   DATE,           -- the datetime on which the event occurred
36
  CONSTRAINT access_log_pk PRIMARY KEY (entryid)
37
);  
38
 
39
CREATE SEQUENCE access_log_id_seq;
40
CREATE TRIGGER access_log_before_insert
41
BEFORE INSERT ON access_log FOR EACH ROW
42
BEGIN
43
  SELECT access_log_id_seq.nextval
44
    INTO :new.entryid
45
    FROM dual;
46
END;
47
/
0 48

  
src/xmltables.sql
1
/*
2
 * xmltables.sql -- Create or replace tables for storing XML in the db
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 Regents of the University of California and the
4
 *             National Center for Ecological Analysis and Synthesis
3 5
 *
4
 *      Purpose: creates tables needed for XML database
5
 * 
6
 *      Created: 12 September 1999
7
 *       Author: Matt Jones
8
 * Organization: National Center for Ecological Analysis and Synthesis
9
 *    Copyright: 2000 Regents of the University of California and the
10
 *               National Center for Ecological Analysis and Synthesis
11
 *  For Details: http://www.nceas.ucsb.edu/
12
 *    File Info: '$Id$'
6
 *   '$Author$'
7
 *     '$Date$'
8
 * '$Revision$'
13 9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14 23
 */
15 24

  
16 25
/*
......
26 35
DROP SEQUENCE accnum_uniqueid_seq;
27 36
DROP SEQUENCE xml_documents_id_seq;
28 37
DROP SEQUENCE accession_number_id_seq;
38
DROP SEQUENCE access_log_seq;
29 39
               
30 40
/* Drop triggers are not necessary */
31 41
DROP TRIGGER xml_nodes_before_insert;
......
34 44
DROP TRIGGER xml_relation_before_insert;
35 45
DROP TRIGGER xml_replication_before_insert;
36 46
DROP TRIGGER accession_number_before_insert;
47
DROP TRIGGER access_log_before_insert;
37 48

  
38 49
DROP TABLE xml_index;
39 50
DROP TABLE xml_access;
......
45 56
DROP TABLE xml_replication;
46 57
DROP TABLE xml_catalog;
47 58
DROP TABLE accession_number;
59
DROP TABLE access_log;
48 60

  
49 61
/*
50 62
 *Replication -- table to store servers that metacat is replicated to
......
310 322
		FOREIGN KEY (docid) REFERENCES xml_documents
311 323
);
312 324

  
325
/*
326
 * Logging -- table to store metadata and data access log
327
 */
328
CREATE TABLE access_log (
329
  entryid       NUMBER(20),     -- the identifier for the log event
330
  ip_address    VARCHAR2(512),  -- the ip address inititiating the event
331
  principal     VARCHAR2(512),  -- the user initiiating the event
332
  docid         VARCHAR2(250),	-- the document id #
333
  rev           NUMBER(10),     -- the revision number
334
  event         VARCHAR2(512),  -- the code symbolizing the event type
335
  date_logged   DATE,           -- the datetime on which the event occurred
336
  CONSTRAINT access_log_pk PRIMARY KEY (entryid)
337
);
338

  
339
CREATE SEQUENCE access_log_id_seq;
340
CREATE TRIGGER access_log_before_insert
341
BEFORE INSERT ON access_log FOR EACH ROW
342
BEGIN
343
  SELECT access_log_id_seq.nextval
344
    INTO :new.entryid
345
    FROM dual;
346
END;
src/edu/ucsb/nceas/metacat/EventLog.java
86 86
     * include basic identification information about the principal or computer
87 87
     * that initiated the event.
88 88
     * 
89
     * @param logData the data to be logged when an event occurs
89
     * @param ipAddress the internet protocol address for the event
90
	 * @param principal the principal for the event (a username, etc)
91
	 * @param docid the identifier of the document to which the event applies
92
	 * @param revision the revision of the document to which the event applies
93
	 * @param event the string code for the event
90 94
     */
91
    public void log(EventLogData logData)
95
    public void log(String ipAddress, String principal, String docid,
96
			long revision, String event)
92 97
    {
98
        EventLogData logData = new EventLogData(ipAddress, principal, docid,
99
                revision, event);
93 100
        insertLogEntry(logData);
94 101
    }
95

  
102
    
96 103
    /**
97 104
     * Insert a single log event record to the database.
98 105
     * 
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
495 495
                    out.println("   Query: " + pquery);
496 496
                    out.println("  Params: ");
497 497
                    if (pquery != null) {
498
                        Hashtable qparams = util.parseQuery(u.getQuery());
498
                        Hashtable qparams = MetaCatUtil.parseQuery(u.getQuery());
499 499
                        for (Enumeration en = qparams.keys(); en
500 500
                                .hasMoreElements();) {
501 501
                            String pname = (String) en.nextElement();
......
974 974
                try {
975 975

  
976 976
                    URL murl = new URL(docs[i]);
977
                    Hashtable murlQueryStr = util.parseQuery(murl.getQuery());
977
                    Hashtable murlQueryStr = MetaCatUtil.parseQuery(
978
                            murl.getQuery());
978 979
                    // case docid="http://.../?docid=aaa"
979 980
                    // or docid="metacat://.../?docid=bbb"
980 981
                    if (murlQueryStr.containsKey("docid")) {
......
997 998
                            readFromURLConnection(response, docid);
998 999
                        }
999 1000
                    }
1000

  
1001
                    // case docid="ccc"
1001
                    
1002
                    // Log the event to the event table
1003
                    EventLog.getInstance().log("192.168.1.103", "public", 
1004
                            "test.1", 1, "read");
1002 1005
                } catch (MalformedURLException mue) {
1003 1006
                    docid = docs[i];
1004 1007
                    if (zip) {
......
1009 1012
                    }
1010 1013
                }
1011 1014

  
1012
            } /* end for */
1015
            }
1013 1016

  
1014 1017
            if (zip) {
1015 1018
                zout.finish(); //terminate the zip file
src/upgrade-db-to-1.4_postgres.sql
1
/*
2
 * logging.sql -- Create or replace tables for logging events
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 Regents of the University of California and the
4
 *             National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author$'
7
 *     '$Date$'
8
 * '$Revision$'
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
3 23
 */
4

  
24
 
5 25
/*
6 26
 *Logging -- table to store metadata and data access log
7 27
 */
8 28
CREATE SEQUENCE access_log_id_seq;
9 29
CREATE TABLE access_log (
10
  entryid       INT8 default nextval ('access_log_id_seq'),
11
  ip_address    VARCHAR(512),
12
  principal     VARCHAR(512),
30
  entryid       INT8 default nextval ('access_log_id_seq'), -- the identifier for the log event
31
  ip_address    VARCHAR(512),   -- the ip address inititiating the event
32
  principal     VARCHAR(512),   -- the user initiiating the event
13 33
  docid         VARCHAR(250),	-- the document id #
14 34
  rev           INT8,           -- the revision number
15
  event         VARCHAR(512),
16
  date_logged   TIMESTAMP,
35
  event         VARCHAR(512),   -- the code symbolizing the event type
36
  date_logged   TIMESTAMP,      -- the datetime on which the event occurred
17 37
  CONSTRAINT access_log_pk PRIMARY KEY (entryid)
18 38
);

Also available in: Unified diff