diff -rcN -x CVS orig/pgjdbc/org/postgresql/PGNotification.java notif/pgjdbc/org/postgresql/PGNotification.java *** orig/pgjdbc/org/postgresql/PGNotification.java Sat Nov 29 11:52:09 2003 --- notif/pgjdbc/org/postgresql/PGNotification.java Wed Jan 28 03:42:54 2004 *************** *** 27,31 **** --- 27,38 ---- */ public int getPID(); + /** + * Returns additional information from the notifying process. + * Currently, this feature is unimplemented and always returns + * an empty String. + */ + public String getParameter(); + } diff -rcN -x CVS orig/pgjdbc/org/postgresql/core/Notification.java notif/pgjdbc/org/postgresql/core/Notification.java *** orig/pgjdbc/org/postgresql/core/Notification.java Sat Nov 29 11:52:09 2003 --- notif/pgjdbc/org/postgresql/core/Notification.java Wed Jan 28 03:43:31 2004 *************** *** 18,25 **** --- 18,31 ---- { public Notification(String p_name, int p_pid) { + this(p_name, p_pid, ""); + } + + public Notification(String p_name, int p_pid, String p_parameter) + { m_name = p_name; m_pid = p_pid; + m_parameter = p_parameter; } /* *************** *** 38,44 **** --- 44,56 ---- return m_pid; } + public String getParameter() + { + return m_parameter; + } + private String m_name; + private String m_parameter; private int m_pid; } diff -rcN -x CVS orig/pgjdbc/org/postgresql/core/PGStream.java notif/pgjdbc/org/postgresql/core/PGStream.java *** orig/pgjdbc/org/postgresql/core/PGStream.java Sat Nov 29 11:52:09 2003 --- notif/pgjdbc/org/postgresql/core/PGStream.java Wed Jan 28 03:31:56 2004 *************** *** 86,110 **** } /* - * Sends an integer to the back end - * - * @param val the integer to be sent - * @param siz the length of the integer in bytes (size of structure) - * @exception IOException if an I/O error occurs - */ - public void SendIntegerR(int val, int siz) throws IOException - { - byte[] buf = new byte[siz]; - - for (int i = 0; i < siz; i++) - { - buf[i] = (byte)(val & 0xff); - val >>= 8; - } - Send(buf); - } - - /* * Send an array of bytes to the backend * * @param buf The array of bytes to be sent --- 86,91 ---- *************** *** 181,215 **** * @return the integer received from the backend * @exception SQLException if an I/O error occurs */ - public int ReceiveInteger(int siz) throws SQLException - { - int n = 0; - - try - { - for (int i = 0 ; i < siz ; i++) - { - int b = pg_input.read(); - - if (b < 0) - throw new PSQLException("postgresql.stream.eof", PSQLState.COMMUNICATION_ERROR); - n = n | (b << (8 * i)) ; - } - } - catch (IOException e) - { - throw new PSQLException("postgresql.stream.ioerror", PSQLState.COMMUNICATION_ERROR, e); - } - return n; - } - - /* - * Receives an integer from the backend - * - * @param siz length of the integer in bytes - * @return the integer received from the backend - * @exception SQLException if an I/O error occurs - */ public int ReceiveIntegerR(int siz) throws SQLException { int n = 0; --- 162,167 ---- diff -rcN -x CVS orig/pgjdbc/org/postgresql/core/QueryExecutor.java notif/pgjdbc/org/postgresql/core/QueryExecutor.java *** orig/pgjdbc/org/postgresql/core/QueryExecutor.java Mon Jan 12 19:07:09 2004 --- notif/pgjdbc/org/postgresql/core/QueryExecutor.java Wed Jan 28 03:21:39 2004 *************** *** 129,137 **** switch (c) { case 'A': // Asynchronous Notify ! int pid = pgStream.ReceiveInteger(4); String msg = pgStream.ReceiveString(connection.getEncoding()); ! connection.addNotification(new org.postgresql.core.Notification(msg, pid)); break; case 'B': // Binary Data Transfer receiveTupleV3(true); --- 129,139 ---- switch (c) { case 'A': // Asynchronous Notify ! int msglen = pgStream.ReceiveIntegerR(4); ! int pid = pgStream.ReceiveIntegerR(4); String msg = pgStream.ReceiveString(connection.getEncoding()); ! String param = pgStream.ReceiveString(connection.getEncoding()); ! connection.addNotification(new org.postgresql.core.Notification(msg, pid, param)); break; case 'B': // Binary Data Transfer receiveTupleV3(true); *************** *** 237,243 **** switch (c) { case 'A': // Asynchronous Notify ! int pid = pgStream.ReceiveInteger(4); String msg = pgStream.ReceiveString(connection.getEncoding()); connection.addNotification(new org.postgresql.core.Notification(msg, pid)); break; --- 239,245 ---- switch (c) { case 'A': // Asynchronous Notify ! int pid = pgStream.ReceiveIntegerR(4); String msg = pgStream.ReceiveString(connection.getEncoding()); connection.addNotification(new org.postgresql.core.Notification(msg, pid)); break; diff -rcN -x CVS orig/pgjdbc/org/postgresql/fastpath/Fastpath.java notif/pgjdbc/org/postgresql/fastpath/Fastpath.java *** orig/pgjdbc/org/postgresql/fastpath/Fastpath.java Wed Dec 17 19:27:14 2003 --- notif/pgjdbc/org/postgresql/fastpath/Fastpath.java Wed Jan 28 03:22:22 2004 *************** *** 118,126 **** switch (c) { case 'A': // Asynchronous Notify ! int pid = stream.ReceiveInteger(4); String msg = stream.ReceiveString(conn.getEncoding()); ! conn.addNotification(new org.postgresql.core.Notification(msg, pid)); break; //------------------------------ // Error message returned --- 118,128 ---- switch (c) { case 'A': // Asynchronous Notify ! int msglen = stream.ReceiveIntegerR(4); ! int pid = stream.ReceiveIntegerR(4); String msg = stream.ReceiveString(conn.getEncoding()); ! String param = stream.ReceiveString(conn.getEncoding()); ! conn.addNotification(new org.postgresql.core.Notification(msg, pid, param)); break; //------------------------------ // Error message returned *************** *** 233,240 **** { case 'A': // Asynchronous Notify //TODO: do something with this ! int pid = stream.ReceiveInteger(4); String msg = stream.ReceiveString(conn.getEncoding()); break; //------------------------------ --- 235,243 ---- { case 'A': // Asynchronous Notify //TODO: do something with this ! int pid = stream.ReceiveIntegerR(4); String msg = stream.ReceiveString(conn.getEncoding()); + conn.addNotification(new org.postgresql.core.Notification(msg, pid)); break; //------------------------------ diff -rcN -x CVS orig/pgjdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java notif/pgjdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java *** orig/pgjdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java Thu Jan 15 02:33:37 2004 --- notif/pgjdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java Wed Jan 28 03:17:26 2004 *************** *** 56,61 **** --- 56,62 ---- // features some applications require. suite.addTestSuite(JBuilderTest.class); suite.addTestSuite(MiscTest.class); + suite.addTestSuite(NotifyTest.class); // Fastpath/LargeObject suite.addTestSuite(BlobTest.class); diff -rcN -x CVS orig/pgjdbc/org/postgresql/test/jdbc2/NotifyTest.java notif/pgjdbc/org/postgresql/test/jdbc2/NotifyTest.java *** orig/pgjdbc/org/postgresql/test/jdbc2/NotifyTest.java Wed Dec 31 16:00:00 1969 --- notif/pgjdbc/org/postgresql/test/jdbc2/NotifyTest.java Wed Jan 28 03:44:03 2004 *************** *** 0 **** --- 1,44 ---- + package org.postgresql.test.jdbc2; + + import org.postgresql.test.TestUtil; + import junit.framework.TestCase; + import java.sql.*; + + import org.postgresql.PGConnection; + import org.postgresql.PGNotification; + + public class NotifyTest extends TestCase + { + + private Connection conn; + + public NotifyTest(String name) + { + super(name); + } + + protected void setUp() throws SQLException + { + conn = TestUtil.openDB(); + } + + protected void tearDown() throws SQLException + { + TestUtil.closeDB(conn); + } + + public void testNotify() throws SQLException + { + Statement stmt = conn.createStatement(); + stmt.executeUpdate("LISTEN mynotification"); + stmt.executeUpdate("NOTIFY mynotification"); + + PGNotification notifications[] = ((org.postgresql.PGConnection)conn).getNotifications(); + assertNotNull(notifications); + assertEquals(notifications.length, 1); + assertEquals(notifications[0].getName(), "mynotification"); + assertEquals(notifications[0].getParameter(), ""); + + stmt.close(); + } + }