public PSQLException(String msg, PSQLState state, Throwable cause) { super(msg, state == null ? null : state.getState(), cause); }
public PSQLException(ServerErrorMessage serverError) { this(serverError.toString(), new PSQLState(serverError.getSQLState())); _serverError = serverError; }
} catch (SQLException ex) { int errorCode = XAException.XAER_RMERR; if (PSQLState.UNDEFINED_OBJECT.getState().equals(ex.getSQLState())) { if (committedOrRolledBack || !xid.equals(preparedXid)) { if (LOGGER.isLoggable(Level.FINEST)) { if (PSQLState.isConnectionError(ex.getSQLState())) { if (LOGGER.isLoggable(Level.FINEST)) { debug("rollback connection failure (sql error code " + ex.getSQLState() + "), reconnection could be expected");
} catch (SQLException ex) { int errorCode = XAException.XAER_RMERR; if (PSQLState.UNDEFINED_OBJECT.getState().equals(ex.getSQLState())) { if (committedOrRolledBack || !xid.equals(preparedXid)) { if (LOGGER.isLoggable(Level.FINEST)) { if (PSQLState.isConnectionError(ex.getSQLState())) { if (LOGGER.isLoggable(Level.FINEST)) { debug("commit connection failure (sql error code " + ex.getSQLState() + "), reconnection could be expected");
public PSQLException(String msg, PSQLState state) { super(msg, state == null ? null : state.getState()); }
public PSQLException(ServerErrorMessage serverError) { this(serverError.toString(), new PSQLState(serverError.getSQLState())); _serverError = serverError; }
public static boolean isConnectionError(String psqlState) { return PSQLState.CONNECTION_UNABLE_TO_CONNECT.getState().equals(psqlState) || PSQLState.CONNECTION_DOES_NOT_EXIST.getState().equals(psqlState) || PSQLState.CONNECTION_REJECTED.getState().equals(psqlState) || PSQLState.CONNECTION_FAILURE.getState().equals(psqlState) || PSQLState.CONNECTION_FAILURE_DURING_TRANSACTION.getState().equals(psqlState); }
public PSQLException(ServerErrorMessage serverError) { this(serverError.toString(), new PSQLState(serverError.getSQLState())); _serverError = serverError; }
public PSQLException(String msg, PSQLState state, Throwable cause) { super(msg, state == null ? null : state.getState()); initCause(cause); }
public static java.sql.SQLFeatureNotSupportedException notImplemented(Class callClass, String functionName) { return new java.sql.SQLFeatureNotSupportedException(GT.tr("Method {0} is not yet implemented.", callClass.getName() + "." + functionName), PSQLState.NOT_IMPLEMENTED.getState()); }
/** * This method was added in v6.5, and simply throws an SQLException for an unimplemented method. I * decided to do it this way while implementing the JDBC2 extensions to JDBC, as it should help * keep the overall driver size down. It now requires the call Class and the function name to help * when the driver is used with closed software that don't report the stack strace * * @param callClass the call Class * @param functionName the name of the unimplemented function with the type of its arguments * @return PSQLException with a localized message giving the complete description of the * unimplemeted function */ public static SQLFeatureNotSupportedException notImplemented(Class<?> callClass, String functionName) { return new SQLFeatureNotSupportedException( GT.tr("Method {0} is not yet implemented.", callClass.getName() + "." + functionName), PSQLState.NOT_IMPLEMENTED.getState()); }
/** * Drops a replication slot that was created on the DB * * @param slotName the name of the replication slot, may not be null * @return {@code true} if the slot was dropped, {@code false} otherwise */ public boolean dropReplicationSlot(String slotName) { try { execute("select pg_drop_replication_slot('" + slotName + "')"); return true; } catch (SQLException e) { // slot is active if (PSQLState.OBJECT_IN_USE.getState().equals(e.getSQLState())) { LOGGER.warn("Cannot drop replication slot '{}' because it's still in use", slotName); return false; } else if (PSQLState.UNDEFINED_OBJECT.getState().equals(e.getSQLState())) { LOGGER.debug("Replication slot {} has already been dropped", slotName); return false; } else { LOGGER.error("Unexpected error while attempting to drop replication slot", e); } return false; } }
protected boolean willHealViaReparse(SQLException e) { // "prepared statement \"S_2\" does not exist" if (PSQLState.INVALID_SQL_STATEMENT_NAME.getState().equals(e.getSQLState())) { return true; } if (!PSQLState.NOT_IMPLEMENTED.getState().equals(e.getSQLState())) { return false; } if (!(e instanceof PSQLException)) { return false; } PSQLException pe = (PSQLException) e; ServerErrorMessage serverErrorMessage = pe.getServerErrorMessage(); if (serverErrorMessage == null) { return false; } // "cached plan must not change result type" String routine = pe.getServerErrorMessage().getRoutine(); return "RevalidateCachedQuery".equals(routine) // 9.2+ || "RevalidateCachedPlan".equals(routine); // <= 9.1 }
public void setClientInfo(Properties properties) throws SQLClientInfoException { if (properties == null || properties.size() == 0) return; Map<String, ClientInfoStatus> failures = new HashMap<String, ClientInfoStatus>(); Iterator<String> i = properties.stringPropertyNames().iterator(); while (i.hasNext()) { String name = i.next(); if (haveMinimumServerVersion("9.0") && "ApplicationName".equals(name)) { String value = properties.getProperty(name); setClientInfo(name, value); } else { failures.put(i.next(), ClientInfoStatus.REASON_UNKNOWN_PROPERTY); } } if (!failures.isEmpty()) throw new SQLClientInfoException(GT.tr("ClientInfo property not supported."), PSQLState.NOT_IMPLEMENTED.getState(), failures); }
@Override public void setClientInfo(Properties properties) throws SQLClientInfoException { try { checkClosed(); } catch (final SQLException cause) { Map<String, ClientInfoStatus> failures = new HashMap<String, ClientInfoStatus>(); for (Map.Entry<Object, Object> e : properties.entrySet()) { failures.put((String) e.getKey(), ClientInfoStatus.REASON_UNKNOWN); } throw new SQLClientInfoException(GT.tr("This connection has been closed."), failures, cause); } Map<String, ClientInfoStatus> failures = new HashMap<String, ClientInfoStatus>(); for (String name : new String[]{"ApplicationName"}) { try { setClientInfo(name, properties.getProperty(name, null)); } catch (SQLClientInfoException e) { failures.putAll(e.getFailedProperties()); } } if (!failures.isEmpty()) { throw new SQLClientInfoException(GT.tr("One or more ClientInfo failed."), PSQLState.NOT_IMPLEMENTED.getState(), failures); } }
public void setClientInfo(String name, String value) throws SQLClientInfoException { if (haveMinimumServerVersion("9.0") && "ApplicationName".equals(name)) { if (value == null) value = ""; try { StringBuffer sql = new StringBuffer("SET application_name = '"); Utils.appendEscapedLiteral(sql, value, getStandardConformingStrings()); sql.append("'"); execSQLUpdate(sql.toString()); } catch (SQLException sqle) { Map<String, ClientInfoStatus> failures = new HashMap<String, ClientInfoStatus>(); failures.put(name, ClientInfoStatus.REASON_UNKNOWN); throw new SQLClientInfoException(GT.tr("Failed to set ClientInfo property: {0}", "ApplicationName"), sqle.getSQLState(), failures, sqle); } _clientInfo.put(name, value); return; } Map<String, ClientInfoStatus> failures = new HashMap<String, ClientInfoStatus>(); failures.put(name, ClientInfoStatus.REASON_UNKNOWN_PROPERTY); throw new SQLClientInfoException(GT.tr("ClientInfo property not supported."), PSQLState.NOT_IMPLEMENTED.getState(), failures); }
if (PSQLState.IN_FAILED_SQL_TRANSACTION.getState().equals(e.getSQLState())) {
PSQLState.NOT_IMPLEMENTED.getState()));
@Test public void shouldSupportSSLParameters() throws Exception { // the default docker image we're testing against doesn't use SSL, so check that the connector fails to start when // SSL is enabled Configuration config = TestHelper.defaultConfig().with(PostgresConnectorConfig.SSL_MODE, PostgresConnectorConfig.SecureConnectionMode.REQUIRED).build(); start(PostgresConnector.class, config, (success, msg, error) -> { if (TestHelper.shouldSSLConnectionFail()) { // we expect the task to fail at startup when we're printing the server info assertThat(success).isFalse(); assertThat(error).isInstanceOf(ConnectException.class); Throwable cause = error.getCause(); assertThat(cause).isInstanceOf(SQLException.class); assertThat(PSQLState.CONNECTION_REJECTED.getState().equals(((SQLException)cause).getSQLState())); } }); if (TestHelper.shouldSSLConnectionFail()) { assertConnectorNotRunning(); } else { assertConnectorIsRunning(); Thread.sleep(10000); stopConnector(); } }