ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/server/DBInterface/DBLastInsertTest.java
(Generate patch)

Comparing experimental/server/DBInterface/DBLastInsertTest.java (file contents):
Revision 1.1 by pjm2, Tue Dec 5 08:25:33 2000 UTC vs.
Revision 1.2 by pjm2, Tue Dec 5 12:12:03 2000 UTC

# Line 9 | Line 9 | import java.sql.*;
9   * with the same connection.
10   *
11   * CONCLUSION: This works on raptor.  It is probably the method
12 < * we shall use in the final database logging system.
12 > * we shall use in the final database logging system.
13   *
14   * IMPORTANT: This method obtains the database user and database
15   * connection password from the Password class.  As such, this
# Line 37 | Line 37 | class DBLastInsertTest {
37              // Create a statement object.
38              Statement stmt = conn.createStatement();
39              
40 <            // Lock all three test tables.  (Waits until it can)
41 <            stmt.executeUpdate("LOCK TABLES packet WRITE, cpu WRITE, disk WRITE;");
40 >            // Lock all two test tables.  (Waits until it can)
41 >            // No other process will be able to use these tables
42 >            // until they are unlocked.
43 >            stmt.executeUpdate("LOCK TABLES packet_test WRITE, parameter_test WRITE;");
44              
45              // Execute an insert statement.
46 <            stmt.executeUpdate("INSERT INTO packet (ip, seq_no, date, machine_name) VALUES ('0.0.0.0', 4543, 1423123, 'raptor');");
46 >            stmt.executeUpdate("INSERT INTO packet_test (ip, machine_name, seq_no, sent_date, receipt_date) VALUES ('0.0.0.0', 'raptor', 1234, 12343, 12343);");
47  
48 <            // Wait 30 seconds.  No other process should be able to use the
49 <            // tables in this time period.
50 <            Thread.sleep(30000);
48 >            // Get the last used insertion id for THIS connection ;-)
49 >            ResultSet rs = stmt.executeQuery("SELECT LAST_INSERT_ID();");
50 >            rs.next();
51 >            String packet_id = rs.getString("LAST_INSERT_ID()");
52  
53 <            // insert another one with the same id as above, but in the seq_no field.
54 <            stmt.executeUpdate("INSERT INTO packet (ip, seq_no, date, machine_name) VALUES ('0.0.0.0', LAST_INSERT_ID(), 1423123, 'raptor');");            
53 >            // insert some entries into the parameter_test table using
54 >            // the id number from the packet_test insertion.
55 >            stmt.executeUpdate("INSERT INTO parameter_test (packet_id, name, value) VALUES ("+packet_id+", 'packet.attributes.machine_name', 'raptor!');");
56 >            stmt.executeUpdate("INSERT INTO parameter_test (packet_id, name, value) VALUES ("+packet_id+", 'packet.attributes.machine_name', 'raptor!');");
57 >            stmt.executeUpdate("INSERT INTO parameter_test (packet_id, name, value) VALUES ("+packet_id+", 'packet.attributes.machine_name', 'raptor!');");
58 >            stmt.executeUpdate("INSERT INTO parameter_test (packet_id, name, value) VALUES ("+packet_id+", 'packet.attributes.machine_name', 'raptor!');");
59              
60 +            // Remove the locks.
61              stmt.executeUpdate("UNLOCK TABLES;");
62              
63              // Close the statement and database connection.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines