diff --git a/pgjdbc/src/main/java/org/postgresql/Driver.java b/pgjdbc/src/main/java/org/postgresql/Driver.java index 782e155157..1d372a599c 100644 --- a/pgjdbc/src/main/java/org/postgresql/Driver.java +++ b/pgjdbc/src/main/java/org/postgresql/Driver.java @@ -417,10 +417,7 @@ private static Connection makeConnection(String url, Properties props) throws SQ * @see java.sql.Driver#acceptsURL */ public boolean acceptsURL(String url) { - if (parseURL(url, null) == null) { - return false; - } - return true; + return parseURL(url, null) != null; } /** @@ -567,9 +564,8 @@ public static Properties parseURL(String url, Properties defaults) { // parse the args part of the url String[] args = l_urlArgs.split("&"); - for (int i = 0; i < args.length; ++i) { - String token = args[i]; - if (token.length() == 0) { + for (String token : args) { + if (token.isEmpty()) { continue; } int l_pos = token.indexOf('='); diff --git a/pgjdbc/src/main/java/org/postgresql/PGConnection.java b/pgjdbc/src/main/java/org/postgresql/PGConnection.java index f3289e376a..b83a0bcf5e 100644 --- a/pgjdbc/src/main/java/org/postgresql/PGConnection.java +++ b/pgjdbc/src/main/java/org/postgresql/PGConnection.java @@ -29,7 +29,7 @@ public interface PGConnection { * @throws SQLException if something wrong happens * @since 7.3 */ - public PGNotification[] getNotifications() throws SQLException; + PGNotification[] getNotifications() throws SQLException; /** * This returns the COPY API for the current connection. @@ -38,7 +38,7 @@ public interface PGConnection { * @throws SQLException if something wrong happens * @since 8.4 */ - public CopyManager getCopyAPI() throws SQLException; + CopyManager getCopyAPI() throws SQLException; /** * This returns the LargeObject API for the current connection. @@ -47,7 +47,7 @@ public interface PGConnection { * @throws SQLException if something wrong happens * @since 7.3 */ - public LargeObjectManager getLargeObjectAPI() throws SQLException; + LargeObjectManager getLargeObjectAPI() throws SQLException; /** * This returns the Fastpath API for the current connection. @@ -56,7 +56,7 @@ public interface PGConnection { * @throws SQLException if something wrong happens * @since 7.3 */ - public Fastpath getFastpathAPI() throws SQLException; + Fastpath getFastpathAPI() throws SQLException; /** * This allows client code to add a handler for one of org.postgresql's more unique data types. It @@ -69,7 +69,7 @@ public interface PGConnection { * does not work correctly for registering classes that cannot be directly loaded by * the JDBC driver's classloader. */ - public void addDataType(String type, String className); + void addDataType(String type, String className); /** * This allows client code to add a handler for one of org.postgresql's more unique data types. @@ -100,7 +100,7 @@ public interface PGConnection { * @see org.postgresql.util.PGobject * @since 8.0 */ - public void addDataType(String type, Class klass) throws SQLException; + void addDataType(String type, Class klass) throws SQLException; /** * Set the default statement reuse threshold before enabling server-side prepare. See @@ -109,7 +109,7 @@ public interface PGConnection { * @param threshold the new threshold * @since build 302 */ - public void setPrepareThreshold(int threshold); + void setPrepareThreshold(int threshold); /** * Get the default server-side prepare reuse threshold for statements created from this @@ -118,7 +118,7 @@ public interface PGConnection { * @return the current threshold * @since build 302 */ - public int getPrepareThreshold(); + int getPrepareThreshold(); /** * Set the default fetch size for statements created from this connection @@ -127,7 +127,7 @@ public interface PGConnection { * @throws SQLException if specified negative fetchSize parameter * @see Statement#setFetchSize(int) */ - public void setDefaultFetchSize(int fetchSize) throws SQLException; + void setDefaultFetchSize(int fetchSize) throws SQLException; /** @@ -137,14 +137,14 @@ public interface PGConnection { * @see PGProperty#DEFAULT_ROW_FETCH_SIZE * @see Statement#getFetchSize() */ - public int getDefaultFetchSize(); + int getDefaultFetchSize(); /** * Return the process ID (PID) of the backend server process handling this connection. * * @return PID of backend server process. */ - public int getBackendPID(); + int getBackendPID(); /** * Return the given string suitably quoted to be used as an identifier in an SQL statement string. @@ -155,7 +155,7 @@ public interface PGConnection { * @return the escaped identifier * @throws SQLException if something goes wrong */ - public String escapeIdentifier(String identifier) throws SQLException; + String escapeIdentifier(String identifier) throws SQLException; /** * Return the given string suitably quoted to be used as a string literal in an SQL statement @@ -166,5 +166,5 @@ public interface PGConnection { * @return the quoted literal * @throws SQLException if something goes wrong */ - public String escapeLiteral(String literal) throws SQLException; + String escapeLiteral(String literal) throws SQLException; } diff --git a/pgjdbc/src/main/java/org/postgresql/PGNotification.java b/pgjdbc/src/main/java/org/postgresql/PGNotification.java index f02e886ff1..ef31e4d038 100644 --- a/pgjdbc/src/main/java/org/postgresql/PGNotification.java +++ b/pgjdbc/src/main/java/org/postgresql/PGNotification.java @@ -18,7 +18,7 @@ public interface PGNotification { * @return name of this notification * @since 7.3 */ - public String getName(); + String getName(); /** * Returns the process id of the backend process making this notification @@ -26,7 +26,7 @@ public interface PGNotification { * @return process id of the backend process making this notification * @since 7.3 */ - public int getPID(); + int getPID(); /** * Returns additional information from the notifying process. This feature has only been @@ -36,5 +36,5 @@ public interface PGNotification { * @return additional information from the notifying process * @since 8.0 */ - public String getParameter(); + String getParameter(); } diff --git a/pgjdbc/src/main/java/org/postgresql/PGRefCursorResultSet.java b/pgjdbc/src/main/java/org/postgresql/PGRefCursorResultSet.java index 1ea9d86e64..0bd80282a0 100644 --- a/pgjdbc/src/main/java/org/postgresql/PGRefCursorResultSet.java +++ b/pgjdbc/src/main/java/org/postgresql/PGRefCursorResultSet.java @@ -22,5 +22,5 @@ public interface PGRefCursorResultSet { * @deprecated As of 8.0, replaced with calling getString() on the ResultSet that this ResultSet * was obtained from. */ - public String getRefCursor(); + String getRefCursor(); } diff --git a/pgjdbc/src/main/java/org/postgresql/PGResultSetMetaData.java b/pgjdbc/src/main/java/org/postgresql/PGResultSetMetaData.java index b3e94adbfd..54a9360cd2 100644 --- a/pgjdbc/src/main/java/org/postgresql/PGResultSetMetaData.java +++ b/pgjdbc/src/main/java/org/postgresql/PGResultSetMetaData.java @@ -22,7 +22,7 @@ public interface PGResultSetMetaData { * @throws SQLException if something wrong happens * @since 8.0 */ - public String getBaseColumnName(int column) throws SQLException; + String getBaseColumnName(int column) throws SQLException; /** * Returns the underlying table name of query result, or "" if it is unable to be determined. @@ -32,7 +32,7 @@ public interface PGResultSetMetaData { * @throws SQLException if something wrong happens * @since 8.0 */ - public String getBaseTableName(int column) throws SQLException; + String getBaseTableName(int column) throws SQLException; /** * Returns the underlying schema name of query result, or "" if it is unable to be determined. @@ -42,7 +42,7 @@ public interface PGResultSetMetaData { * @throws SQLException if something wrong happens * @since 8.0 */ - public String getBaseSchemaName(int column) throws SQLException; + String getBaseSchemaName(int column) throws SQLException; /** * Is a column Text or Binary? @@ -54,5 +54,5 @@ public interface PGResultSetMetaData { * @see Field#TEXT_FORMAT * @since 9.4 */ - public int getFormat(int column) throws SQLException; + int getFormat(int column) throws SQLException; } diff --git a/pgjdbc/src/main/java/org/postgresql/PGStatement.java b/pgjdbc/src/main/java/org/postgresql/PGStatement.java index d7f69cbc15..637840f111 100644 --- a/pgjdbc/src/main/java/org/postgresql/PGStatement.java +++ b/pgjdbc/src/main/java/org/postgresql/PGStatement.java @@ -21,10 +21,10 @@ public interface PGStatement { // The follow values are the nearest MAX/MIN values with hour, // minute, second, millisecond set to 0 - this is used for // -infinity / infinity representation in Java - public static final long DATE_POSITIVE_INFINITY = 9223372036825200000L; - public static final long DATE_NEGATIVE_INFINITY = -9223372036832400000L; - public static final long DATE_POSITIVE_SMALLER_INFINITY = 185543533774800000L; - public static final long DATE_NEGATIVE_SMALLER_INFINITY = -185543533774800000L; + long DATE_POSITIVE_INFINITY = 9223372036825200000L; + long DATE_NEGATIVE_INFINITY = -9223372036832400000L; + long DATE_POSITIVE_SMALLER_INFINITY = 185543533774800000L; + long DATE_NEGATIVE_SMALLER_INFINITY = -185543533774800000L; /** @@ -34,7 +34,7 @@ public interface PGStatement { * @throws SQLException if something goes wrong * @since 7.3 */ - public long getLastOID() throws SQLException; + long getLastOID() throws SQLException; /** * Turn on the use of prepared statements in the server (server side prepared statements are @@ -46,7 +46,7 @@ public interface PGStatement { * @since 7.3 * @deprecated As of build 302, replaced by {@link #setPrepareThreshold(int)} */ - public void setUseServerPrepare(boolean flag) throws SQLException; + void setUseServerPrepare(boolean flag) throws SQLException; /** * Checks if this statement will be executed as a server-prepared statement. A return value of @@ -55,7 +55,7 @@ public interface PGStatement { * * @return true if the next reuse of this statement will use a server-prepared statement */ - public boolean isUseServerPrepare(); + boolean isUseServerPrepare(); /** * Sets the reuse threshold for using server-prepared statements. @@ -72,7 +72,7 @@ public interface PGStatement { * @throws SQLException if an exception occurs while changing the threshold * @since build 302 */ - public void setPrepareThreshold(int threshold) throws SQLException; + void setPrepareThreshold(int threshold) throws SQLException; /** * Gets the server-side prepare reuse threshold in use for this statement. @@ -81,5 +81,5 @@ public interface PGStatement { * @see #setPrepareThreshold(int) * @since build 302 */ - public int getPrepareThreshold(); + int getPrepareThreshold(); } diff --git a/pgjdbc/src/main/java/org/postgresql/copy/CopyIn.java b/pgjdbc/src/main/java/org/postgresql/copy/CopyIn.java index e472ba0026..fd2dfcdb3f 100644 --- a/pgjdbc/src/main/java/org/postgresql/copy/CopyIn.java +++ b/pgjdbc/src/main/java/org/postgresql/copy/CopyIn.java @@ -41,5 +41,5 @@ public interface CopyIn extends CopyOperation { * @return number of updated rows for server 8.2 or newer (see getHandledRowCount()) * @throws SQLException if the operation fails. */ - public long endCopy() throws SQLException; + long endCopy() throws SQLException; } diff --git a/pgjdbc/src/main/java/org/postgresql/copy/CopyOperation.java b/pgjdbc/src/main/java/org/postgresql/copy/CopyOperation.java index 07a6e34a60..99dcc24d12 100644 --- a/pgjdbc/src/main/java/org/postgresql/copy/CopyOperation.java +++ b/pgjdbc/src/main/java/org/postgresql/copy/CopyOperation.java @@ -50,5 +50,5 @@ public interface CopyOperation { * * @return number of handled rows or -1 */ - public long getHandledRowCount(); + long getHandledRowCount(); } diff --git a/pgjdbc/src/main/java/org/postgresql/core/BaseConnection.java b/pgjdbc/src/main/java/org/postgresql/core/BaseConnection.java index d12ddcbbfa..fce4dbd648 100644 --- a/pgjdbc/src/main/java/org/postgresql/core/BaseConnection.java +++ b/pgjdbc/src/main/java/org/postgresql/core/BaseConnection.java @@ -27,7 +27,7 @@ public interface BaseConnection extends PGConnection, Connection { * * @throws SQLException if something goes wrong. */ - public void cancelQuery() throws SQLException; + void cancelQuery() throws SQLException; /** * Execute a SQL query that returns a single resultset. Never causes a new transaction to be @@ -37,9 +37,9 @@ public interface BaseConnection extends PGConnection, Connection { * @return the (non-null) returned resultset * @throws SQLException if something goes wrong. */ - public ResultSet execSQLQuery(String s) throws SQLException; + ResultSet execSQLQuery(String s) throws SQLException; - public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurrency) + ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurrency) throws SQLException; /** @@ -49,14 +49,14 @@ public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurre * @param s the query to execute * @throws SQLException if something goes wrong. */ - public void execSQLUpdate(String s) throws SQLException; + void execSQLUpdate(String s) throws SQLException; /** * Get the QueryExecutor implementation for this connection. * * @return the (non-null) executor */ - public QueryExecutor getQueryExecutor(); + QueryExecutor getQueryExecutor(); /** * Construct and return an appropriate object for the given type and value. This only considers @@ -72,11 +72,11 @@ public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurre * @return an appropriate object; never null. * @throws SQLException if something goes wrong */ - public Object getObject(String type, String value, byte[] byteValue) throws SQLException; + Object getObject(String type, String value, byte[] byteValue) throws SQLException; - public Encoding getEncoding() throws SQLException; + Encoding getEncoding() throws SQLException; - public TypeInfo getTypeInfo(); + TypeInfo getTypeInfo(); /** * Check if we should use driver behaviour introduced in a particular driver version. This @@ -91,7 +91,7 @@ public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurre * @deprecated Avoid using this in new code that can require PgJDBC 9.4. */ @Deprecated - public boolean haveMinimumCompatibleVersion(String ver); + boolean haveMinimumCompatibleVersion(String ver); /** * Check if we should use driver behaviour introduced in a particular driver version. @@ -111,7 +111,7 @@ public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurre * @param ver the driver version to check, eg 90401 for 9.4.1 * @return true if the driver's behavioural version is at least "ver". */ - public boolean haveMinimumCompatibleVersion(int ver); + boolean haveMinimumCompatibleVersion(int ver); /** * Check if we should use driver behaviour introduced in a particular driver version. @@ -122,7 +122,7 @@ public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurre * @param ver the driver version to check * @return true if the driver's behavioural version is at least "ver". */ - public boolean haveMinimumCompatibleVersion(Version ver); + boolean haveMinimumCompatibleVersion(Version ver); /** * Check if we have at least a particular server version. @@ -132,7 +132,7 @@ public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurre * @deprecated Use haveMinimumServerVersion(int) instead */ @Deprecated - public boolean haveMinimumServerVersion(String ver); + boolean haveMinimumServerVersion(String ver); /** * Check if we have at least a particular server version. @@ -143,7 +143,7 @@ public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurre * @param ver the server version to check, of the form xxyyzz eg 90401 * @return true if the server version is at least "ver". */ - public boolean haveMinimumServerVersion(int ver); + boolean haveMinimumServerVersion(int ver); /** * Check if we have at least a particular server version. @@ -154,7 +154,7 @@ public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurre * @param ver the server version to check * @return true if the server version is at least "ver". */ - public boolean haveMinimumServerVersion(Version ver); + boolean haveMinimumServerVersion(Version ver); /** * Encode a string using the database's client_encoding (usually UTF8, but can vary on older @@ -165,7 +165,7 @@ public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurre * @return an encoded representation of the string * @throws SQLException if something goes wrong. */ - public byte[] encodeString(String str) throws SQLException; + byte[] encodeString(String str) throws SQLException; /** * Escapes a string for use as string-literal within an SQL command. The method chooses the @@ -175,7 +175,7 @@ public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurre * @return the escaped representation of the string * @throws SQLException if the string contains a \0 character */ - public String escapeString(String str) throws SQLException; + String escapeString(String str) throws SQLException; /** * Returns whether the server treats string-literals according to the SQL standard or if it uses @@ -186,23 +186,23 @@ public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurre * @return true if the server treats string literals according to the SQL standard * @see ProtocolConnection#getStandardConformingStrings() */ - public boolean getStandardConformingStrings(); + boolean getStandardConformingStrings(); // Ew. Quick hack to give access to the connection-specific utils implementation. - public TimestampUtils getTimestampUtils(); + TimestampUtils getTimestampUtils(); // Get the per-connection logger. - public Logger getLogger(); + Logger getLogger(); // Get the bind-string-as-varchar config flag - public boolean getStringVarcharFlag(); + boolean getStringVarcharFlag(); /** * Get the current transaction state of this connection. * * @return a ProtocolConnection.TRANSACTION_* constant. */ - public int getTransactionState(); + int getTransactionState(); /** * Returns true if value for the given oid should be sent using binary transfer. False if value @@ -211,14 +211,14 @@ public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurre * @param oid The oid to check. * @return True for binary transfer, false for text transfer. */ - public boolean binaryTransferSend(int oid); + boolean binaryTransferSend(int oid); /** * Return whether to disable column name sanitation. * * @return true column sanitizer is disabled */ - public boolean isColumnSanitiserDisabled(); + boolean isColumnSanitiserDisabled(); /** * Schedule a TimerTask for later execution. The task will be scheduled with the shared Timer for @@ -227,18 +227,18 @@ public ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurre * @param timerTask timer task to schedule * @param milliSeconds delay in milliseconds */ - public void addTimerTask(TimerTask timerTask, long milliSeconds); + void addTimerTask(TimerTask timerTask, long milliSeconds); /** * Invoke purge() on the underlying shared Timer so that internal resources will be released. */ - public void purgeTimerTasks(); + void purgeTimerTasks(); /** * To be used for checking if the batched insert re-write optimization is enabled. * @return true if re-write feature is enabled */ - public boolean isReWriteBatchedInsertsEnabled(); + boolean isReWriteBatchedInsertsEnabled(); /** * Return metadata cache for given connection diff --git a/pgjdbc/src/main/java/org/postgresql/core/BaseStatement.java b/pgjdbc/src/main/java/org/postgresql/core/BaseStatement.java index 1eeeda1f5c..7e387c949d 100644 --- a/pgjdbc/src/main/java/org/postgresql/core/BaseStatement.java +++ b/pgjdbc/src/main/java/org/postgresql/core/BaseStatement.java @@ -27,7 +27,7 @@ public interface BaseStatement extends PGStatement, Statement { * @return the new ResultSet * @throws SQLException if something goes wrong */ - public ResultSet createDriverResultSet(Field[] fields, List tuples) throws SQLException; + ResultSet createDriverResultSet(Field[] fields, List tuples) throws SQLException; /** * Create a resultset from data retrieved from the server. @@ -41,7 +41,7 @@ public interface BaseStatement extends PGStatement, Statement { * @return the new ResultSet * @throws SQLException if something goes wrong */ - public ResultSet createResultSet(Query originalQuery, Field[] fields, List tuples, + ResultSet createResultSet(Query originalQuery, Field[] fields, List tuples, ResultCursor cursor) throws SQLException; /** @@ -53,7 +53,7 @@ public ResultSet createResultSet(Query originalQuery, Field[] fields, List useBinaryForOids); + void setBinaryReceiveOids(Set useBinaryForOids); /** * Returns true if server uses integer instead of double for binary date and time encodings. * * @return the server integer_datetime setting. */ - public boolean getIntegerDateTimes(); + boolean getIntegerDateTimes(); /** * Return the process ID (PID) of the backend server process handling this connection. * * @return process ID (PID) of the backend server process handling this connection */ - public int getBackendPID(); + int getBackendPID(); /** * Abort at network level without sending the Terminate message to the backend. */ - public void abort(); + void abort(); /** * Return TimestampUtils that is aware of connection-specific {@code TimeZone} value. diff --git a/pgjdbc/src/main/java/org/postgresql/core/QueryExecutor.java b/pgjdbc/src/main/java/org/postgresql/core/QueryExecutor.java index 388db9ae00..ab36c4f163 100644 --- a/pgjdbc/src/main/java/org/postgresql/core/QueryExecutor.java +++ b/pgjdbc/src/main/java/org/postgresql/core/QueryExecutor.java @@ -48,50 +48,50 @@ public interface QueryExecutor { /** * Flag for query execution that indicates the given Query object is unlikely to be reused. */ - static int QUERY_ONESHOT = 1; + int QUERY_ONESHOT = 1; /** * Flag for query execution that indicates that resultset metadata isn't needed and can be safely * omitted. */ - static int QUERY_NO_METADATA = 2; + int QUERY_NO_METADATA = 2; /** * Flag for query execution that indicates that a resultset isn't expected and the query executor * can safely discard any rows (although the resultset should still appear to be from a * resultset-returning query). */ - static int QUERY_NO_RESULTS = 4; + int QUERY_NO_RESULTS = 4; /** * Flag for query execution that indicates a forward-fetch-capable cursor should be used if * possible. */ - static int QUERY_FORWARD_CURSOR = 8; + int QUERY_FORWARD_CURSOR = 8; /** * Flag for query execution that indicates the automatic BEGIN on the first statement when outside * a transaction should not be done. */ - static int QUERY_SUPPRESS_BEGIN = 16; + int QUERY_SUPPRESS_BEGIN = 16; /** * Flag for query execution when we don't really want to execute, we just want to get the * parameter metadata for the statement. */ - static int QUERY_DESCRIBE_ONLY = 32; + int QUERY_DESCRIBE_ONLY = 32; /** * Flag for query execution used by generated keys where we want to receive both the ResultSet and * associated update count from the command status. */ - static int QUERY_BOTH_ROWS_AND_STATUS = 64; + int QUERY_BOTH_ROWS_AND_STATUS = 64; /** * Force this query to be described at each execution. This is done in pipelined batches where we * might need to detect mismatched result types. */ - static int QUERY_FORCE_DESCRIBE_PORTAL = 512; + int QUERY_FORCE_DESCRIBE_PORTAL = 512; /** * Flag to disable batch execution when we expect results (generated keys) from a statement. @@ -99,12 +99,12 @@ public interface QueryExecutor { * @deprecated in PgJDBC 9.4 as we now auto-size batches. */ @Deprecated - static int QUERY_DISALLOW_BATCHING = 128; + int QUERY_DISALLOW_BATCHING = 128; /** * Flag for query execution to avoid using binary transfer. */ - static int QUERY_NO_BINARY_TRANSFER = 256; + int QUERY_NO_BINARY_TRANSFER = 256; /** * Execute a Query, passing results to a provided ResultHandler. diff --git a/pgjdbc/src/main/java/org/postgresql/core/TypeInfo.java b/pgjdbc/src/main/java/org/postgresql/core/TypeInfo.java index 0245ed0b56..4d108bf285 100644 --- a/pgjdbc/src/main/java/org/postgresql/core/TypeInfo.java +++ b/pgjdbc/src/main/java/org/postgresql/core/TypeInfo.java @@ -14,10 +14,10 @@ import java.util.Iterator; public interface TypeInfo { - public void addCoreType(String pgTypeName, Integer oid, Integer sqlType, String javaClass, + void addCoreType(String pgTypeName, Integer oid, Integer sqlType, String javaClass, Integer arrayOid); - public void addDataType(String type, Class klass) throws SQLException; + void addDataType(String type, Class klass) throws SQLException; /** * Look up the SQL typecode for a given type oid. @@ -26,7 +26,7 @@ public void addCoreType(String pgTypeName, Integer oid, Integer sqlType, String * @return the SQL type code (a constant from {@link java.sql.Types}) for the type * @throws SQLException if an error occurs when retrieving sql type */ - public int getSQLType(int oid) throws SQLException; + int getSQLType(int oid) throws SQLException; /** * Look up the SQL typecode for a given postgresql type name. @@ -35,7 +35,7 @@ public void addCoreType(String pgTypeName, Integer oid, Integer sqlType, String * @return the SQL type code (a constant from {@link java.sql.Types}) for the type * @throws SQLException if an error occurs when retrieving sql type */ - public int getSQLType(String pgTypeName) throws SQLException; + int getSQLType(String pgTypeName) throws SQLException; /** * Look up the oid for a given postgresql type name. This is the inverse of @@ -45,7 +45,7 @@ public void addCoreType(String pgTypeName, Integer oid, Integer sqlType, String * @return the type's OID, or 0 if unknown * @throws SQLException if an error occurs when retrieving PG type */ - public int getPGType(String pgTypeName) throws SQLException; + int getPGType(String pgTypeName) throws SQLException; /** * Look up the postgresql type name for a given oid. This is the inverse of @@ -55,7 +55,7 @@ public void addCoreType(String pgTypeName, Integer oid, Integer sqlType, String * @return the server type name for that OID or null if unknown * @throws SQLException if an error occurs when retrieving PG type */ - public String getPGType(int oid) throws SQLException; + String getPGType(int oid) throws SQLException; /** * Look up the oid of an array's base type given the array's type oid. @@ -64,7 +64,7 @@ public void addCoreType(String pgTypeName, Integer oid, Integer sqlType, String * @return the base type's OID, or 0 if unknown * @throws SQLException if an error occurs when retrieving array element */ - public int getPGArrayElement(int oid) throws SQLException; + int getPGArrayElement(int oid) throws SQLException; /** * Determine the oid of the given base postgresql type's array type @@ -73,7 +73,7 @@ public void addCoreType(String pgTypeName, Integer oid, Integer sqlType, String * @return the array type's OID, or 0 if unknown * @throws SQLException if an error occurs when retrieving array type */ - public int getPGArrayType(String elementTypeName) throws SQLException; + int getPGArrayType(String elementTypeName) throws SQLException; /** * Determine the delimiter for the elements of the given array type oid. @@ -82,29 +82,29 @@ public void addCoreType(String pgTypeName, Integer oid, Integer sqlType, String * @return the base type's array type delimiter * @throws SQLException if an error occurs when retrieving array delimiter */ - public char getArrayDelimiter(int oid) throws SQLException; + char getArrayDelimiter(int oid) throws SQLException; - public Iterator getPGTypeNamesWithSQLTypes(); + Iterator getPGTypeNamesWithSQLTypes(); - public Class getPGobject(String type); + Class getPGobject(String type); - public String getJavaClass(int oid) throws SQLException; + String getJavaClass(int oid) throws SQLException; - public String getTypeForAlias(String alias); + String getTypeForAlias(String alias); - public int getPrecision(int oid, int typmod); + int getPrecision(int oid, int typmod); - public int getScale(int oid, int typmod); + int getScale(int oid, int typmod); - public boolean isCaseSensitive(int oid); + boolean isCaseSensitive(int oid); - public boolean isSigned(int oid); + boolean isSigned(int oid); - public int getDisplaySize(int oid, int typmod); + int getDisplaySize(int oid, int typmod); - public int getMaximumPrecision(int oid); + int getMaximumPrecision(int oid); - public boolean requiresQuoting(int oid) throws SQLException; + boolean requiresQuoting(int oid) throws SQLException; /** * Returns true if particular sqlType requires quoting. diff --git a/pgjdbc/src/main/java/org/postgresql/ds/PGPoolingDataSource.java b/pgjdbc/src/main/java/org/postgresql/ds/PGPoolingDataSource.java index 2f6446a957..e375740084 100644 --- a/pgjdbc/src/main/java/org/postgresql/ds/PGPoolingDataSource.java +++ b/pgjdbc/src/main/java/org/postgresql/ds/PGPoolingDataSource.java @@ -331,7 +331,7 @@ public Connection getConnection() throws SQLException { */ public void close() { synchronized (lock) { - while (available.size() > 0) { + while (!available.isEmpty()) { PooledConnection pci = available.pop(); try { pci.close(); @@ -339,7 +339,7 @@ public void close() { } } available = null; - while (used.size() > 0) { + while (!used.isEmpty()) { PooledConnection pci = used.pop(); pci.removeConnectionEventListener(connectionEventListener); try { @@ -372,7 +372,7 @@ private Connection getPooledConnection() throws SQLException { PSQLState.CONNECTION_DOES_NOT_EXIST); } while (true) { - if (available.size() > 0) { + if (!available.isEmpty()) { pc = available.pop(); used.push(pc); break; diff --git a/pgjdbc/src/main/java/org/postgresql/fastpath/Fastpath.java b/pgjdbc/src/main/java/org/postgresql/fastpath/Fastpath.java index f7ec863ce0..e4a4da4177 100644 --- a/pgjdbc/src/main/java/org/postgresql/fastpath/Fastpath.java +++ b/pgjdbc/src/main/java/org/postgresql/fastpath/Fastpath.java @@ -224,7 +224,7 @@ public long getOID(String name, FastpathArg[] args) throws SQLException { * @throws SQLException if a database-access error occurs or no result */ public byte[] getData(String name, FastpathArg[] args) throws SQLException { - return (byte[]) fastpath(name, args); + return fastpath(name, args); } /** diff --git a/pgjdbc/src/main/java/org/postgresql/gss/MakeGSS.java b/pgjdbc/src/main/java/org/postgresql/gss/MakeGSS.java index 93c9bd484c..ba894e48c1 100644 --- a/pgjdbc/src/main/java/org/postgresql/gss/MakeGSS.java +++ b/pgjdbc/src/main/java/org/postgresql/gss/MakeGSS.java @@ -35,8 +35,6 @@ public static void authenticate(PGStream pgStream, String host, String user, Str logger.debug(" <=BE AuthenticationReqGSS"); } - Exception result = null; - if (jaasApplicationName == null) { jaasApplicationName = "pgjdbc"; } @@ -44,13 +42,14 @@ public static void authenticate(PGStream pgStream, String host, String user, Str kerberosServerName = "postgres"; } + Exception result = null; try { boolean performAuthentication = true; GSSCredential gssCredential = null; Subject sub = Subject.getSubject(AccessController.getContext()); if (sub != null) { Set gssCreds = sub.getPrivateCredentials(GSSCredential.class); - if (gssCreds != null && gssCreds.size() > 0) { + if (gssCreds != null && !gssCreds.isEmpty()) { gssCredential = gssCreds.iterator().next(); performAuthentication = false; } diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/AbstractBlobClob.java b/pgjdbc/src/main/java/org/postgresql/jdbc/AbstractBlobClob.java index bbf4f9ff02..c5ca2cc38a 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/AbstractBlobClob.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/AbstractBlobClob.java @@ -21,7 +21,6 @@ import java.sql.Blob; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Iterator; /** * This class holds all of the methods common to both Blobs and Clobs. @@ -50,11 +49,7 @@ public AbstractBlobClob(BaseConnection conn, long oid) throws SQLException { this.currentLo = null; this.currentLoIsWriteable = false; - if (conn.haveMinimumServerVersion(90300)) { - support64bit = true; - } else { - support64bit = false; - } + support64bit = conn.haveMinimumServerVersion(90300); subLOs = new ArrayList(); } @@ -65,9 +60,7 @@ public synchronized void free() throws SQLException { currentLo = null; currentLoIsWriteable = false; } - Iterator i = subLOs.iterator(); - while (i.hasNext()) { - LargeObject subLO = i.next(); + for (LargeObject subLO : subLOs) { subLO.close(); } subLOs = null; @@ -186,7 +179,7 @@ public LOIterator(long start) throws SQLException { } public boolean hasNext() throws SQLException { - boolean result = false; + boolean result; if (idx < numBytes) { result = true; } else { diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java b/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java index 33c077ba46..247e8ad9f7 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java @@ -415,7 +415,7 @@ public static String sqlucase(List parsedArgs) throws SQLException { * @throws SQLException if something wrong happens */ public static String sqlcurdate(List parsedArgs) throws SQLException { - if (parsedArgs.size() != 0) { + if (!parsedArgs.isEmpty()) { throw new PSQLException(GT.tr("{0} function doesn''t take any argument.", "curdate"), PSQLState.SYNTAX_ERROR); } @@ -430,7 +430,7 @@ public static String sqlcurdate(List parsedArgs) throws SQLException { * @throws SQLException if something wrong happens */ public static String sqlcurtime(List parsedArgs) throws SQLException { - if (parsedArgs.size() != 0) { + if (!parsedArgs.isEmpty()) { throw new PSQLException(GT.tr("{0} function doesn''t take any argument.", "curtime"), PSQLState.SYNTAX_ERROR); } @@ -695,7 +695,7 @@ public static String sqltimestampdiff(List parsedArgs) throws SQLException { return buf.toString(); } - private final static String constantToDatePart(String type) throws SQLException { + private static String constantToDatePart(String type) throws SQLException { if (!type.startsWith(SQL_TSI_ROOT)) { throw new PSQLException(GT.tr("Interval {0} not yet implemented", type), PSQLState.SYNTAX_ERROR); @@ -733,7 +733,7 @@ private final static String constantToDatePart(String type) throws SQLException * @throws SQLException if something wrong happens */ public static String sqldatabase(List parsedArgs) throws SQLException { - if (parsedArgs.size() != 0) { + if (!parsedArgs.isEmpty()) { throw new PSQLException(GT.tr("{0} function doesn''t take any argument.", "database"), PSQLState.SYNTAX_ERROR); } @@ -763,7 +763,7 @@ public static String sqlifnull(List parsedArgs) throws SQLException { * @throws SQLException if something wrong happens */ public static String sqluser(List parsedArgs) throws SQLException { - if (parsedArgs.size() != 0) { + if (!parsedArgs.isEmpty()) { throw new PSQLException(GT.tr("{0} function doesn''t take any argument.", "user"), PSQLState.SYNTAX_ERROR); } diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgArray.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgArray.java index 064e8edfcc..5ed6a5a0ab 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/PgArray.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgArray.java @@ -462,7 +462,7 @@ private synchronized void buildArrayList() throws SQLException { i++; } else if (!insideString && chars[i] == '{') { // subarray start - if (dims.size() == 0) { + if (dims.isEmpty()) { dims.add(arrayList); } else { PgArrayList a = new PgArrayList(); @@ -506,7 +506,7 @@ private synchronized void buildArrayList() throws SQLException { String b = buffer == null ? null : buffer.toString(); // add element to current array - if (b != null && (b.length() > 0 || wasInsideString)) { + if (b != null && (!b.isEmpty() || wasInsideString)) { curArray.add(!wasInsideString && haveMinServer82 && b.equals("NULL") ? null : b); } @@ -518,7 +518,7 @@ private synchronized void buildArrayList() throws SQLException { dims.remove(dims.size() - 1); // when multi-dimension - if (dims.size() > 0) { + if (!dims.isEmpty()) { curArray = dims.get(dims.size() - 1); } @@ -881,7 +881,7 @@ public ResultSet getResultSetImpl(long index, int count, Map> m BaseStatement stat = (BaseStatement) connection .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); - return (ResultSet) stat.createDriverResultSet(fields, rows); + return stat.createDriverResultSet(fields, rows); } public String toString() { diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java index 25a7d1b064..26ae89944e 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java @@ -985,12 +985,12 @@ protected String escapeQuotes(String s) throws SQLException { return sb.toString(); } - public java.sql.ResultSet getProcedures(String catalog, String schemaPattern, + public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException { return getProcedures(getJDBCMajorVersion(), catalog, schemaPattern, procedureNamePattern); } - protected java.sql.ResultSet getProcedures(int jdbcVersion, String catalog, String schemaPattern, + protected ResultSet getProcedures(int jdbcVersion, String catalog, String schemaPattern, String procedureNamePattern) throws SQLException { String sql; if (connection.haveMinimumServerVersion(ServerVersion.v7_3)) { @@ -1044,13 +1044,13 @@ protected java.sql.ResultSet getProcedures(int jdbcVersion, String catalog, Stri return createMetaDataStatement().executeQuery(sql); } - public java.sql.ResultSet getProcedureColumns(String catalog, String schemaPattern, + public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException { return getProcedureColumns(getJDBCMajorVersion(), catalog, schemaPattern, procedureNamePattern, columnNamePattern); } - protected java.sql.ResultSet getProcedureColumns(int jdbcVersion, String catalog, + protected ResultSet getProcedureColumns(int jdbcVersion, String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException { int columns = 13; @@ -1291,7 +1291,7 @@ protected java.sql.ResultSet getProcedureColumns(int jdbcVersion, String catalog return ((BaseStatement) createMetaDataStatement()).createDriverResultSet(f, v); } - public java.sql.ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, + public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String types[]) throws SQLException { String select; String orderby; @@ -1503,7 +1503,7 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String ht.put("NOSCHEMAS", "c.relkind = 'm'"); } - public java.sql.ResultSet getSchemas() throws SQLException { + public ResultSet getSchemas() throws SQLException { return getSchemas(getJDBCMajorVersion(), null, null); } @@ -1549,7 +1549,7 @@ protected ResultSet getSchemas(int jdbcVersion, String catalog, String schemaPat * PostgreSQL does not support multiple catalogs from a single connection, so to reduce confusion * we only return the current catalog. {@inheritDoc} */ - public java.sql.ResultSet getCatalogs() throws SQLException { + public ResultSet getCatalogs() throws SQLException { Field f[] = new Field[1]; List v = new ArrayList(); f[0] = new Field("TABLE_CAT", Oid.VARCHAR); @@ -1560,7 +1560,7 @@ public java.sql.ResultSet getCatalogs() throws SQLException { return ((BaseStatement) createMetaDataStatement()).createDriverResultSet(f, v); } - public java.sql.ResultSet getTableTypes() throws SQLException { + public ResultSet getTableTypes() throws SQLException { String types[] = new String[tableTypeClauses.size()]; Iterator e = tableTypeClauses.keySet().iterator(); int i = 0; @@ -1581,7 +1581,7 @@ public java.sql.ResultSet getTableTypes() throws SQLException { return ((BaseStatement) createMetaDataStatement()).createDriverResultSet(f, v); } - protected java.sql.ResultSet getColumns(int jdbcVersion, String catalog, String schemaPattern, + protected ResultSet getColumns(int jdbcVersion, String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException { int numberOfFields; if (jdbcVersion >= 4) { @@ -1806,13 +1806,13 @@ protected java.sql.ResultSet getColumns(int jdbcVersion, String catalog, String return ((BaseStatement) createMetaDataStatement()).createDriverResultSet(f, v); } - public java.sql.ResultSet getColumns(String catalog, String schemaPattern, + public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException { return getColumns(getJDBCMajorVersion(), catalog, schemaPattern, tableNamePattern, columnNamePattern); } - public java.sql.ResultSet getColumnPrivileges(String catalog, String schema, String table, + public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException { Field f[] = new Field[8]; List v = new ArrayList(); @@ -1929,7 +1929,7 @@ public java.sql.ResultSet getColumnPrivileges(String catalog, String schema, Str return ((BaseStatement) createMetaDataStatement()).createDriverResultSet(f, v); } - public java.sql.ResultSet getTablePrivileges(String catalog, String schemaPattern, + public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { Field f[] = new Field[7]; List v = new ArrayList(); @@ -2032,7 +2032,7 @@ private static void sortStringArray(String s[]) { */ private static List parseACLArray(String aclString) { List acls = new ArrayList(); - if (aclString == null || aclString.length() == 0) { + if (aclString == null || aclString.isEmpty()) { return acls; } boolean inQuotes = false; @@ -2077,7 +2077,7 @@ private static void addACLPrivileges(String acl, Map>> parseACL(String aclArray, String return privileges; } - public java.sql.ResultSet getBestRowIdentifier(String catalog, String schema, String table, + public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLException { Field f[] = new Field[8]; List v = new ArrayList(); // The new ResultSet tuple stuff @@ -2281,7 +2281,7 @@ public java.sql.ResultSet getBestRowIdentifier(String catalog, String schema, St return ((BaseStatement) createMetaDataStatement()).createDriverResultSet(f, v); } - public java.sql.ResultSet getVersionColumns(String catalog, String schema, String table) + public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException { Field f[] = new Field[8]; List v = new ArrayList(); // The new ResultSet tuple stuff @@ -2323,7 +2323,7 @@ public java.sql.ResultSet getVersionColumns(String catalog, String schema, Strin return ((BaseStatement) createMetaDataStatement()).createDriverResultSet(f, v); } - public java.sql.ResultSet getPrimaryKeys(String catalog, String schema, String table) + public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { String sql; if (connection.haveMinimumServerVersion(ServerVersion.v8_1)) { @@ -2391,7 +2391,7 @@ public java.sql.ResultSet getPrimaryKeys(String catalog, String schema, String t * @return ResultSet * @throws SQLException if something wrong happens */ - protected java.sql.ResultSet getImportedExportedKeys(String primaryCatalog, String primarySchema, + protected ResultSet getImportedExportedKeys(String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException { Field f[] = new Field[14]; @@ -2668,7 +2668,7 @@ protected java.sql.ResultSet getImportedExportedKeys(String primaryCatalog, Stri // we are primarily interested in the column names which are the last items in the string List tokens = tokenize(targs, "\\000"); - if (tokens.size() > 0) { + if (!tokens.isEmpty()) { fkName = tokens.get(0); } @@ -2715,24 +2715,24 @@ protected java.sql.ResultSet getImportedExportedKeys(String primaryCatalog, Stri return ((BaseStatement) createMetaDataStatement()).createDriverResultSet(f, tuples); } - public java.sql.ResultSet getImportedKeys(String catalog, String schema, String table) + public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException { return getImportedExportedKeys(null, null, null, catalog, schema, table); } - public java.sql.ResultSet getExportedKeys(String catalog, String schema, String table) + public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException { return getImportedExportedKeys(catalog, schema, table, null, null, null); } - public java.sql.ResultSet getCrossReference(String primaryCatalog, String primarySchema, + public ResultSet getCrossReference(String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException { return getImportedExportedKeys(primaryCatalog, primarySchema, primaryTable, foreignCatalog, foreignSchema, foreignTable); } - public java.sql.ResultSet getTypeInfo() throws SQLException { + public ResultSet getTypeInfo() throws SQLException { Field f[] = new Field[18]; List v = new ArrayList(); // The new ResultSet tuple stuff @@ -2837,7 +2837,7 @@ public java.sql.ResultSet getTypeInfo() throws SQLException { return ((BaseStatement) createMetaDataStatement()).createDriverResultSet(f, v); } - public java.sql.ResultSet getIndexInfo(String catalog, String schema, String tableName, + public ResultSet getIndexInfo(String catalog, String schema, String tableName, boolean unique, boolean approximate) throws SQLException { /* * This is a complicated function because we have three possible situations: <= 7.2 no schemas, @@ -2997,18 +2997,18 @@ private static List tokenize(String input, String delimiter) { public boolean supportsResultSetType(int type) throws SQLException { // The only type we don't support - return type != java.sql.ResultSet.TYPE_SCROLL_SENSITIVE; + return type != ResultSet.TYPE_SCROLL_SENSITIVE; } public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException { // These combinations are not supported! - if (type == java.sql.ResultSet.TYPE_SCROLL_SENSITIVE) { + if (type == ResultSet.TYPE_SCROLL_SENSITIVE) { return false; } // We do support Updateable ResultSets - if (concurrency == java.sql.ResultSet.CONCUR_UPDATABLE) { + if (concurrency == ResultSet.CONCUR_UPDATABLE) { return true; } @@ -3059,7 +3059,7 @@ public boolean supportsBatchUpdates() throws SQLException { return true; } - public java.sql.ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, + public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException { String sql = "select " + "null as type_cat, n.nspname as type_schem, t.typname as type_name, null as class_name, " @@ -3144,8 +3144,8 @@ public boolean rowChangesAreVisible(int type) throws SQLException { } protected java.sql.Statement createMetaDataStatement() throws SQLException { - return connection.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, - java.sql.ResultSet.CONCUR_READ_ONLY); + return connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, + ResultSet.CONCUR_READ_ONLY); } public long getMaxLogicalLobSize() throws SQLException { diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java index c40557ed0d..71326a1f9c 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java @@ -344,7 +344,7 @@ public void afterLast() throws SQLException { public void beforeFirst() throws SQLException { checkScrollable(); - if (rows.size() > 0) { + if (!rows.isEmpty()) { current_row = -1; } @@ -710,7 +710,7 @@ public boolean isBeforeFirst() throws SQLException { return false; } - return ((row_offset + current_row) < 0 && rows.size() > 0); + return ((row_offset + current_row) < 0 && !rows.isEmpty()); } @@ -891,7 +891,7 @@ public synchronized void deleteRow() throws SQLException { "Currently positioned after the end of the ResultSet. You cannot call deleteRow() here."), PSQLState.INVALID_CURSOR_STATE); } - if (rows.size() == 0) { + if (rows.isEmpty()) { throw new PSQLException(GT.tr("There are no rows in this ResultSet."), PSQLState.INVALID_CURSOR_STATE); } @@ -912,7 +912,7 @@ public synchronized void deleteRow() throws SQLException { } } - deleteStatement = ((java.sql.Connection) connection).prepareStatement(deleteSQL.toString()); + deleteStatement = connection.prepareStatement(deleteSQL.toString()); } deleteStatement.clearParameters(); @@ -934,7 +934,7 @@ public synchronized void insertRow() throws SQLException { if (!onInsertRow) { throw new PSQLException(GT.tr("Not on the insert row."), PSQLState.INVALID_CURSOR_STATE); - } else if (updateValues.size() == 0) { + } else if (updateValues.isEmpty()) { throw new PSQLException(GT.tr("You must specify at least one column value to insert a row."), PSQLState.INVALID_PARAMETER_VALUE); } else { @@ -963,7 +963,7 @@ public synchronized void insertRow() throws SQLException { } insertSQL.append(paramSQL.toString()); - insertStatement = ((java.sql.Connection) connection).prepareStatement(insertSQL.toString()); + insertStatement = connection.prepareStatement(insertSQL.toString()); Iterator keys = updateValues.keySet().iterator(); @@ -1237,7 +1237,7 @@ public void refreshRow() throws SQLException { PSQLState.INVALID_CURSOR_STATE); } - if (isBeforeFirst() || isAfterLast() || rows.size() == 0) { + if (isBeforeFirst() || isAfterLast() || rows.isEmpty()) { return; } @@ -1269,7 +1269,7 @@ public void refreshRow() throws SQLException { } // because updateable result sets do not yet support binary transfers we must request refresh // with updateable result set to get field data in correct format - selectStatement = ((java.sql.Connection) connection).prepareStatement(selectSQL.toString(), + selectStatement = connection.prepareStatement(selectSQL.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); @@ -1303,7 +1303,7 @@ public synchronized void updateRow() throws SQLException { PSQLState.INVALID_CURSOR_STATE); } - if (isBeforeFirst() || isAfterLast() || rows.size() == 0) { + if (isBeforeFirst() || isAfterLast() || rows.isEmpty()) { throw new PSQLException( GT.tr( "Cannot update the ResultSet because it is either before the start or after the end of the results."), @@ -1346,7 +1346,7 @@ public synchronized void updateRow() throws SQLException { if (connection.getLogger().logDebug()) { connection.getLogger().debug("updating " + updateSQL.toString()); } - updateStatement = ((java.sql.Connection) connection).prepareStatement(updateSQL.toString()); + updateStatement = connection.prepareStatement(updateSQL.toString()); int i = 0; Iterator iterator = updateValues.values().iterator(); @@ -1517,7 +1517,7 @@ boolean isUpdateable() throws SQLException { parseQuery(); - if (singleTable == false) { + if (!singleTable) { connection.getLogger().debug("not a single table"); return false; } @@ -1553,7 +1553,7 @@ boolean isUpdateable() throws SQLException { String[] s = quotelessTableName(tableName); String quotelessTableName = s[0]; String quotelessSchemaName = s[1]; - java.sql.ResultSet rs = ((java.sql.Connection) connection).getMetaData().getPrimaryKeys("", + java.sql.ResultSet rs = connection.getMetaData().getPrimaryKeys("", quotelessSchemaName, quotelessTableName); while (rs.next()) { numPKcolumns++; @@ -1677,10 +1677,7 @@ private void parseQuery() { private void updateRowBuffer() throws SQLException { - Iterator columns = updateValues.keySet().iterator(); - - while (columns.hasNext()) { - String columnName = columns.next(); + for (String columnName : updateValues.keySet()) { int columnIndex = findColumn(columnName) - 1; Object valueObject = updateValues.get(columnName); @@ -1845,7 +1842,7 @@ public boolean next() throws SQLException { current_row = 0; // Test the new rows array. - if (rows.size() == 0) { + if (rows.isEmpty()) { this_row = null; rowBuffer = null; return false; @@ -1947,7 +1944,7 @@ public byte getByte(int columnIndex) throws SQLException { if (s != null) { s = s.trim(); - if (s.length() == 0) { + if (s.isEmpty()) { return 0; } try { @@ -3044,7 +3041,7 @@ private long readLongValue(byte[] bytes, int oid, long minVal, long maxVal, Stri protected void updateValue(int columnIndex, Object value) throws SQLException { checkUpdateable(); - if (!onInsertRow && (isBeforeFirst() || isAfterLast() || rows.size() == 0)) { + if (!onInsertRow && (isBeforeFirst() || isAfterLast() || rows.isEmpty())) { throw new PSQLException( GT.tr( "Cannot update the ResultSet because it is either before the start or after the end of the results."), diff --git a/pgjdbc/src/main/java/org/postgresql/largeobject/LargeObject.java b/pgjdbc/src/main/java/org/postgresql/largeobject/LargeObject.java index 35163208b1..d9ad7c18fb 100644 --- a/pgjdbc/src/main/java/org/postgresql/largeobject/LargeObject.java +++ b/pgjdbc/src/main/java/org/postgresql/largeobject/LargeObject.java @@ -92,7 +92,7 @@ protected LargeObject(Fastpath fp, long oid, int mode, BaseConnection conn, bool this.fp = fp; this.oid = oid; this.mode = mode; - if (commitOnClose == true) { + if (commitOnClose) { this.commitOnClose = true; this.conn = conn; } else { @@ -175,7 +175,7 @@ public void close() throws SQLException { args[0] = new FastpathArg(fd); fp.fastpath("lo_close", args); // true here as we dont care!! closed = true; - if (this.commitOnClose == true) { + if (this.commitOnClose) { this.conn.commit(); } } diff --git a/pgjdbc/src/main/java/org/postgresql/ssl/jdbc4/LibPQFactory.java b/pgjdbc/src/main/java/org/postgresql/ssl/jdbc4/LibPQFactory.java index fdd5b273ee..018c5ab284 100644 --- a/pgjdbc/src/main/java/org/postgresql/ssl/jdbc4/LibPQFactory.java +++ b/pgjdbc/src/main/java/org/postgresql/ssl/jdbc4/LibPQFactory.java @@ -20,7 +20,6 @@ import java.security.cert.Certificate; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; -import java.util.Iterator; import java.util.Properties; import javax.naming.InvalidNameException; @@ -212,7 +211,7 @@ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallback // It is used instead of cons.readPassword(prompt), because the prompt may contain '%' // characters ((PasswordCallback) callback).setPassword( - cons.readPassword("%s", new Object[]{((PasswordCallback) callback).getPrompt()})); + cons.readPassword("%s", ((PasswordCallback) callback).getPrompt())); } else { ((PasswordCallback) callback).setPassword(password); } @@ -254,10 +253,7 @@ public boolean verify(String hostname, SSLSession session) { return false; } String CN = null; - Iterator it = DN.getRdns().iterator(); - // for(Rdn rdn : DN.getRdns()) - while (it.hasNext()) { - Rdn rdn = it.next(); + for (Rdn rdn : DN.getRdns()) { if ("CN".equals(rdn.getType())) { // Multiple AVAs are not treated CN = (String) rdn.getValue(); diff --git a/pgjdbc/src/main/java/org/postgresql/util/ObjectFactory.java b/pgjdbc/src/main/java/org/postgresql/util/ObjectFactory.java index 14a37e8691..03e750d386 100644 --- a/pgjdbc/src/main/java/org/postgresql/util/ObjectFactory.java +++ b/pgjdbc/src/main/java/org/postgresql/util/ObjectFactory.java @@ -35,14 +35,13 @@ public static Object instantiate(String classname, Properties info, boolean tryS InvocationTargetException { Object[] args = {info}; Constructor ctor = null; - Class cls; - cls = Class.forName(classname); + Class cls = Class.forName(classname); try { - ctor = cls.getConstructor(new Class[]{Properties.class}); + ctor = cls.getConstructor(Properties.class); } catch (NoSuchMethodException nsme) { if (tryString) { try { - ctor = cls.getConstructor(new Class[]{String.class}); + ctor = cls.getConstructor(String.class); args = new String[]{stringarg}; } catch (NoSuchMethodException nsme2) { tryString = false; diff --git a/pgjdbc/src/main/java/org/postgresql/util/PGBinaryObject.java b/pgjdbc/src/main/java/org/postgresql/util/PGBinaryObject.java index 10a0ff13e2..7070f643d5 100644 --- a/pgjdbc/src/main/java/org/postgresql/util/PGBinaryObject.java +++ b/pgjdbc/src/main/java/org/postgresql/util/PGBinaryObject.java @@ -22,7 +22,7 @@ public interface PGBinaryObject { * @param offset the offset in the byte array where object data starts * @throws SQLException thrown if value is invalid for this type */ - public void setByteValue(byte[] value, int offset) throws SQLException; + void setByteValue(byte[] value, int offset) throws SQLException; /** * This method is called to return the number of bytes needed to store this object in the binary @@ -30,7 +30,7 @@ public interface PGBinaryObject { * * @return the number of bytes needed to store this object */ - public int lengthInBytes(); + int lengthInBytes(); /** * This method is called the to store the value of the object, in the binary form required by @@ -40,5 +40,5 @@ public interface PGBinaryObject { * {@link #lengthInBytes} in size. * @param offset the offset in the byte array where object must be stored */ - public void toBytes(byte[] bytes, int offset); + void toBytes(byte[] bytes, int offset); } diff --git a/pgjdbc/src/main/java/org/postgresql/util/PGtokenizer.java b/pgjdbc/src/main/java/org/postgresql/util/PGtokenizer.java index 27ef42df56..326f3a61d6 100644 --- a/pgjdbc/src/main/java/org/postgresql/util/PGtokenizer.java +++ b/pgjdbc/src/main/java/org/postgresql/util/PGtokenizer.java @@ -84,11 +84,7 @@ public int tokenize(String string, char delim) { } } - if (c == '\\') { - skipChar = true; - } else { - skipChar = false; - } + skipChar = c == '\\'; if (nest == 0 && c == delim) { tokens.add(string.substring(s, p));