Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: lib/postgresql-jdbc-9.1-902.src/org/postgresql/jdbc2/AbstractJdbc2Connection.java
- ===================================================================
- --- lib/postgresql-jdbc-9.1-902.src/org/postgresql/jdbc2/AbstractJdbc2Connection.java (revision 29586)
- +++ lib/postgresql-jdbc-9.1-902.src/org/postgresql/jdbc2/AbstractJdbc2Connection.java (working copy)
- @@ -16,6 +16,7 @@
- import org.postgresql.core.Encoding;
- import org.postgresql.core.Field;
- import org.postgresql.core.Logger;
- +import org.postgresql.core.NotificationReceiver;
- import org.postgresql.core.ProtocolConnection;
- import org.postgresql.core.Query;
- import org.postgresql.core.QueryExecutor;
- @@ -39,9 +40,12 @@
- import java.sql.SQLException;
- import java.sql.SQLWarning;
- import java.util.Enumeration;
- +import java.util.HashSet;
- +import java.util.Iterator;
- import java.util.Locale;
- import java.util.NoSuchElementException;
- import java.util.Properties;
- +import java.util.Set;
- import java.util.StringTokenizer;
- import java.util.Vector;
- @@ -49,7 +53,7 @@
- * This class defines methods of the jdbc2 specification.
- * The real Connection class (for jdbc2) is org.postgresql.jdbc2.Jdbc2Connection
- */
- -public abstract class AbstractJdbc2Connection implements BaseConnection
- +public abstract class AbstractJdbc2Connection implements BaseConnection, NotificationReceiver
- {
- //
- // Driver-wide connection ID counter, used for logging
- @@ -97,6 +101,8 @@
- public abstract DatabaseMetaData getMetaData() throws SQLException;
- + public Set notificationListeners = new HashSet();
- +
- //
- // Ctor.
- //
- @@ -143,7 +149,7 @@
- logger.info(Driver.getVersion());
- // Now make the initial connection and set up local state
- - this.protoConnection = ConnectionFactory.openConnection(host, port, user, database, info, logger);
- + this.protoConnection = ConnectionFactory.openConnection(host, port, user, database, info, logger, this);
- this.dbVersionNumber = protoConnection.getServerVersion();
- this.compatible = info.getProperty("compatible", Driver.MAJORVERSION + "." + Driver.MINORVERSION);
- @@ -250,7 +256,7 @@
- firstWarning.setNextWarning(warn);
- else
- firstWarning = warn;
- -
- + warningReady();
- }
- public ResultSet execSQLQuery(String s) throws SQLException {
- @@ -1133,4 +1139,31 @@
- copyManager = new CopyManager(this);
- return copyManager;
- }
- +
- + @Override
- + public void removeNotificationListener(NotificationReceiver n) {
- + notificationListeners.remove(n);
- + }
- +
- + @Override
- + public void addNotificationListener(NotificationReceiver n) {
- + if (n == null) { throw new NullPointerException(); }
- + notificationListeners.add(n);
- + }
- +
- + @Override
- + public void notificationReady() {
- + Iterator i = notificationListeners.iterator();
- + while (i.hasNext()) {
- + ((NotificationReceiver)i.next()).notificationReady();
- + }
- + }
- +
- + @Override
- + public void warningReady() {
- + Iterator i = notificationListeners.iterator();
- + while (i.hasNext()) {
- + ((NotificationReceiver)i.next()).warningReady();
- + }
- + }
- }
- Index: lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v2/ProtocolConnectionImpl.java
- ===================================================================
- --- lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v2/ProtocolConnectionImpl.java (revision 29586)
- +++ lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v2/ProtocolConnectionImpl.java (working copy)
- @@ -21,12 +21,13 @@
- * @author Oliver Jowett (oliver@opencloud.com)
- */
- class ProtocolConnectionImpl implements ProtocolConnection {
- - ProtocolConnectionImpl(PGStream pgStream, String user, String database, Logger logger) {
- + ProtocolConnectionImpl(PGStream pgStream, String user, String database, Logger logger, NotificationReceiver nr) {
- this.pgStream = pgStream;
- this.user = user;
- this.database = database;
- this.logger = logger;
- this.executor = new QueryExecutorImpl(this, pgStream, logger);
- + notificationReceiver = nr;
- }
- public String getHost() {
- @@ -182,11 +183,17 @@
- warnings = newWarning;
- else
- warnings.setNextWarning(newWarning);
- + if (notificationReceiver != null) {
- + notificationReceiver.warningReady();
- + }
- }
- synchronized void addNotification(PGNotification notification)
- {
- notifications.add(notification);
- + if (notificationReceiver != null) {
- + notificationReceiver.notificationReady();
- + }
- }
- synchronized void setTransactionState(int state)
- @@ -216,4 +223,5 @@
- private final String database;
- private final QueryExecutorImpl executor;
- private final Logger logger;
- + private final NotificationReceiver notificationReceiver;
- }
- Index: lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v2/QueryExecutorImpl.java
- ===================================================================
- --- lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v2/QueryExecutorImpl.java (revision 29586)
- +++ lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v2/QueryExecutorImpl.java (working copy)
- @@ -18,6 +18,7 @@
- import org.postgresql.util.PSQLState;
- import org.postgresql.util.GT;
- import org.postgresql.copy.CopyOperation;
- +import org.postgresql.util.PSQLWarning;
- /**
- * QueryExecutor implementation for the V2 protocol.
- @@ -493,7 +494,9 @@
- break;
- case 'N': // Error Notification
- - handler.handleWarning(receiveNotification());
- + SQLWarning w = receiveNotification();
- + handler.handleWarning(w);
- + protoConnection.addWarning(new SQLWarning(w.getMessage()));
- break;
- case 'P': // Portal Name
- Index: lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v2/ConnectionFactoryImpl.java
- ===================================================================
- --- lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v2/ConnectionFactoryImpl.java (revision 29586)
- +++ lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v2/ConnectionFactoryImpl.java (working copy)
- @@ -37,7 +37,7 @@
- private static final int AUTH_REQ_MD5 = 5;
- private static final int AUTH_REQ_SCM = 6;
- - public ProtocolConnection openConnectionImpl(String host, int port, String user, String database, Properties info, Logger logger) throws SQLException {
- + public ProtocolConnection openConnectionImpl(String host, int port, String user, String database, Properties info, Logger logger, NotificationReceiver nr) throws SQLException {
- // Extract interesting values from the info properties:
- // - the SSL setting
- boolean requireSSL = (info.getProperty("ssl") != null);
- @@ -85,7 +85,7 @@
- doAuthentication(newStream, user, info.getProperty("password"), logger);
- // Do final startup.
- - ProtocolConnectionImpl protoConnection = new ProtocolConnectionImpl(newStream, user, database, logger);
- + ProtocolConnectionImpl protoConnection = new ProtocolConnectionImpl(newStream, user, database, logger, nr);
- readStartupMessages(newStream, protoConnection, logger);
- // Run some initial queries
- Index: lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v3/ProtocolConnectionImpl.java
- ===================================================================
- --- lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v3/ProtocolConnectionImpl.java (revision 29586)
- +++ lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v3/ProtocolConnectionImpl.java (working copy)
- @@ -22,7 +22,7 @@
- * @author Oliver Jowett (oliver@opencloud.com)
- */
- class ProtocolConnectionImpl implements ProtocolConnection {
- - ProtocolConnectionImpl(PGStream pgStream, String user, String database, Properties info, Logger logger) {
- + ProtocolConnectionImpl(PGStream pgStream, String user, String database, Properties info, Logger logger, NotificationReceiver nr) {
- this.pgStream = pgStream;
- this.user = user;
- this.database = database;
- @@ -30,6 +30,7 @@
- this.executor = new QueryExecutorImpl(this, pgStream, info, logger);
- // default value for server versions that don't report standard_conforming_strings
- this.standardConformingStrings = false;
- + notificationReceiver = nr;
- }
- public String getHost() {
- @@ -176,11 +177,18 @@
- warnings = newWarning;
- else
- warnings.setNextWarning(newWarning);
- +
- + if (notificationReceiver != null) {
- + notificationReceiver.warningReady();
- + }
- }
- synchronized void addNotification(PGNotification notification)
- {
- notifications.add(notification);
- + if (notificationReceiver != null) {
- + notificationReceiver.notificationReady();
- + }
- }
- synchronized void setTransactionState(int state)
- @@ -215,4 +223,6 @@
- private final String database;
- private final QueryExecutorImpl executor;
- private final Logger logger;
- + private final NotificationReceiver notificationReceiver;
- +
- }
- Index: lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v3/QueryExecutorImpl.java
- ===================================================================
- --- lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v3/QueryExecutorImpl.java (revision 29586)
- +++ lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v3/QueryExecutorImpl.java (working copy)
- @@ -1855,8 +1855,9 @@
- break;
- case 'N': // Notice Response
- - SQLWarning warning = receiveNoticeResponse();
- + PSQLWarning warning = receiveNoticeResponse();
- handler.handleWarning(warning);
- + protoConnection.addWarning(warning.copy());
- break;
- case 'S': // Parameter Status
- @@ -2101,7 +2102,7 @@
- return new PSQLException(errorMsg);
- }
- - private SQLWarning receiveNoticeResponse() throws IOException {
- + private PSQLWarning receiveNoticeResponse() throws IOException {
- int nlen = pgStream.ReceiveInteger4();
- ServerErrorMessage warnMsg = new ServerErrorMessage(pgStream.ReceiveString(nlen - 4), logger.getLogLevel());
- Index: lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v3/ConnectionFactoryImpl.java
- ===================================================================
- --- lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v3/ConnectionFactoryImpl.java (revision 29586)
- +++ lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/v3/ConnectionFactoryImpl.java (working copy)
- @@ -45,7 +45,7 @@
- private static class UnsupportedProtocolException extends IOException {
- }
- - public ProtocolConnection openConnectionImpl(String host, int port, String user, String database, Properties info, Logger logger) throws SQLException {
- + public ProtocolConnection openConnectionImpl(String host, int port, String user, String database, Properties info, Logger logger, NotificationReceiver nr) throws SQLException {
- // Extract interesting values from the info properties:
- // - the SSL setting
- boolean requireSSL = (info.getProperty("ssl") != null);
- @@ -106,7 +106,7 @@
- doAuthentication(newStream, host, user, info, logger);
- // Do final startup.
- - ProtocolConnectionImpl protoConnection = new ProtocolConnectionImpl(newStream, user, database, info, logger);
- + ProtocolConnectionImpl protoConnection = new ProtocolConnectionImpl(newStream, user, database, info, logger, nr);
- readStartupMessages(newStream, protoConnection, logger);
- runInitialQueries(protoConnection, info, logger);
- Index: lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/NotificationReceiver.java
- ===================================================================
- --- lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/NotificationReceiver.java (revision 0)
- +++ lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/NotificationReceiver.java (revision 0)
- @@ -0,0 +1,8 @@
- +package org.postgresql.core;
- +
- +public interface NotificationReceiver {
- +
- + void notificationReady();
- + void warningReady();
- +
- +}
- Index: lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/ConnectionFactory.java
- ===================================================================
- --- lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/ConnectionFactory.java (revision 29586)
- +++ lib/postgresql-jdbc-9.1-902.src/org/postgresql/core/ConnectionFactory.java (working copy)
- @@ -51,7 +51,7 @@
- * @return the new, initialized, connection
- * @throws SQLException if the connection could not be established.
- */
- - public static ProtocolConnection openConnection(String host, int port, String user, String database, Properties info, Logger logger) throws SQLException {
- + public static ProtocolConnection openConnection(String host, int port, String user, String database, Properties info, Logger logger, NotificationReceiver nr) throws SQLException {
- String protoName = info.getProperty("protocolVersion");
- for (int i = 0; i < versions.length; ++i)
- @@ -61,7 +61,7 @@
- continue;
- ConnectionFactory factory = (ConnectionFactory) versions[i][1];
- - ProtocolConnection connection = factory.openConnectionImpl(host, port, user, database, info, logger);
- + ProtocolConnection connection = factory.openConnectionImpl(host, port, user, database, info, logger, nr);
- if (connection != null)
- return connection;
- }
- @@ -86,5 +86,5 @@
- * @throws SQLException if the connection could not be established for a reason other
- * than protocol version incompatibility.
- */
- - public abstract ProtocolConnection openConnectionImpl(String host, int port, String user, String database, Properties info, Logger logger) throws SQLException;
- + public abstract ProtocolConnection openConnectionImpl(String host, int port, String user, String database, Properties info, Logger logger, NotificationReceiver nr) throws SQLException;
- }
- Index: lib/postgresql-jdbc-9.1-902.src/org/postgresql/PGConnection.java
- ===================================================================
- --- lib/postgresql-jdbc-9.1-902.src/org/postgresql/PGConnection.java (revision 29586)
- +++ lib/postgresql-jdbc-9.1-902.src/org/postgresql/PGConnection.java (working copy)
- @@ -9,6 +9,7 @@
- import java.sql.*;
- import org.postgresql.copy.CopyManager;
- +import org.postgresql.core.NotificationReceiver;
- import org.postgresql.fastpath.Fastpath;
- import org.postgresql.largeobject.LargeObjectManager;
- @@ -110,5 +111,8 @@
- */
- public int getPrepareThreshold();
- + void addNotificationListener(NotificationReceiver n);
- + void removeNotificationListener(NotificationReceiver n);
- +
- }
- Index: lib/postgresql-jdbc-9.1-902.src/org/postgresql/util/PSQLWarning.java
- ===================================================================
- --- lib/postgresql-jdbc-9.1-902.src/org/postgresql/util/PSQLWarning.java (revision 29586)
- +++ lib/postgresql-jdbc-9.1-902.src/org/postgresql/util/PSQLWarning.java (working copy)
- @@ -38,4 +38,9 @@
- {
- return serverError;
- }
- +
- + public PSQLWarning copy() {
- + return new PSQLWarning(serverError);
- + }
- +
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement