Permalink
Browse files

refactor: use varargs in Gt.tr (#629)

  • Loading branch information...
AlexElin authored and vlsi committed Aug 19, 2016
1 parent 191ccf2 commit 07c790234496b4b36fe9dbdffdb33b75f0989036
Showing with 92 additions and 81 deletions.
  1. +3 −3 pgjdbc/src/main/java/org/postgresql/PGProperty.java
  2. +1 −1 pgjdbc/src/main/java/org/postgresql/core/PGStream.java
  3. +1 −1 pgjdbc/src/main/java/org/postgresql/core/Parser.java
  4. +2 −3 pgjdbc/src/main/java/org/postgresql/core/v3/CompositeParameterList.java
  5. +5 −3 pgjdbc/src/main/java/org/postgresql/core/v3/SimpleParameterList.java
  6. +2 −1 pgjdbc/src/main/java/org/postgresql/geometric/PGbox.java
  7. +3 −2 pgjdbc/src/main/java/org/postgresql/geometric/PGcircle.java
  8. +3 −2 pgjdbc/src/main/java/org/postgresql/geometric/PGline.java
  9. +2 −1 pgjdbc/src/main/java/org/postgresql/geometric/PGlseg.java
  10. +2 −1 pgjdbc/src/main/java/org/postgresql/geometric/PGpoint.java
  11. +2 −1 pgjdbc/src/main/java/org/postgresql/jdbc/BatchResultHandler.java
  12. +2 −2 pgjdbc/src/main/java/org/postgresql/jdbc/PgArray.java
  13. +5 −6 pgjdbc/src/main/java/org/postgresql/jdbc/PgCallableStatement.java
  14. +3 −1 pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java
  15. +1 −1 pgjdbc/src/main/java/org/postgresql/jdbc/PgParameterMetaData.java
  16. +6 −5 pgjdbc/src/main/java/org/postgresql/jdbc/PgPreparedStatement.java
  17. +25 −20 pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java
  18. +1 −1 pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSetMetaData.java
  19. +1 −1 pgjdbc/src/main/java/org/postgresql/jdbc/TimestampUtils.java
  20. +1 −1 pgjdbc/src/main/java/org/postgresql/ssl/MakeSSL.java
  21. +15 −9 pgjdbc/src/main/java/org/postgresql/ssl/jdbc4/LazyKeyManager.java
  22. +5 −5 pgjdbc/src/main/java/org/postgresql/ssl/jdbc4/LibPQFactory.java
  23. +1 −10 pgjdbc/src/main/java/org/postgresql/util/GT.java
@@ -138,7 +138,7 @@
*/
STRING_TYPE("stringtype", null,
"The type to bind String parameters as (usually 'varchar', 'unspecified' allows implicit casting to other types)",
false, new String[]{"unspecified", "varchar"}),
false, "unspecified", "varchar"),

/**
* Specifies the length to return for types of unknown length.
@@ -500,7 +500,7 @@ public int getInt(Properties properties) throws PSQLException {
return Integer.parseInt(value);
} catch (NumberFormatException nfe) {
throw new PSQLException(GT.tr("{0} parameter value must be an integer but was: {1}",
new Object[]{getName(), value}), PSQLState.INVALID_PARAMETER_VALUE, nfe);
getName(), value), PSQLState.INVALID_PARAMETER_VALUE, nfe);
}
}

@@ -520,7 +520,7 @@ public Integer getInteger(Properties properties) throws PSQLException {
return Integer.parseInt(value);
} catch (NumberFormatException nfe) {
throw new PSQLException(GT.tr("{0} parameter value must be an integer but was: {1}",
new Object[]{getName(), value}), PSQLState.INVALID_PARAMETER_VALUE, nfe);
getName(), value), PSQLState.INVALID_PARAMETER_VALUE, nfe);
}
}

@@ -525,7 +525,7 @@ public void sendStream(InputStream inStream, int remaining) throws IOException {
if (readCount < 0) {
throw new EOFException(
GT.tr("Premature end of input stream, expected {0} bytes, but only read {1}.",
new Object[]{expectedLength, expectedLength - remaining}));
expectedLength, expectedLength - remaining));
}
} catch (IOException ioe) {
while (remaining > 0) {
@@ -1175,7 +1175,7 @@ private static String escapeFunction(String functionName, String args, boolean s
// we can now translate escape functions
try {
Method escapeMethod = EscapedFunctions.getFunction(functionName);
return (String) escapeMethod.invoke(null, new Object[]{parsedArgs});
return (String) escapeMethod.invoke(null, parsedArgs);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof SQLException) {
throw (SQLException) e.getTargetException();
@@ -30,11 +30,10 @@
this.total = offsets[offsets.length - 1] + subparams[offsets.length - 1].getInParameterCount();
}

private final int findSubParam(int index) throws SQLException {
private int findSubParam(int index) throws SQLException {
if (index < 1 || index > total) {
throw new PSQLException(
GT.tr("The column index is out of range: {0}, number of columns: {1}.",
new Object[]{index, total}),
GT.tr("The column index is out of range: {0}, number of columns: {1}.", index, total),
PSQLState.INVALID_PARAMETER_VALUE);
}

@@ -50,11 +50,12 @@
this.transferModeRegistry = transferModeRegistry;
}

@Override
public void registerOutParameter(int index, int sqlType) throws SQLException {
if (index < 1 || index > paramValues.length) {
throw new PSQLException(
GT.tr("The column index is out of range: {0}, number of columns: {1}.",
new Object[]{index, paramValues.length}),
index, paramValues.length),
PSQLState.INVALID_PARAMETER_VALUE);
}

@@ -65,7 +66,7 @@ private void bind(int index, Object value, int oid, byte binary) throws SQLExcep
if (index < 1 || index > paramValues.length) {
throw new PSQLException(
GT.tr("The column index is out of range: {0}, number of columns: {1}.",
new Object[]{index, paramValues.length}),
index, paramValues.length),
PSQLState.INVALID_PARAMETER_VALUE);
}

@@ -409,6 +410,7 @@ public void clear() {
return encoded;
}

@Override
public void appendAll(ParameterList list) throws SQLException {
if (list instanceof org.postgresql.core.v3.SimpleParameterList ) {
/* only v3.SimpleParameterList is compatible with this type
@@ -418,7 +420,7 @@ public void appendAll(ParameterList list) throws SQLException {
if ((pos + inParamCount) > paramValues.length) {
throw new PSQLException(
GT.tr("Added parameters index out of range: {0}, number of columns: {1}.",
new Object[]{(pos + inParamCount), paramValues.length}),
(pos + inParamCount), paramValues.length),
PSQLState.INVALID_PARAMETER_VALUE);
}
System.arraycopy(spl.getValues(), 0, this.paramValues, pos, inParamCount);
@@ -72,11 +72,12 @@ public PGbox() {
* @param value a string representation of the value of the object
* @throws SQLException thrown if value is invalid for this type
*/
@Override
public void setValue(String value) throws SQLException {
PGtokenizer t = new PGtokenizer(value, ',');
if (t.getSize() != 2) {
throw new PSQLException(
GT.tr("Conversion to type {0} failed: {1}.", new Object[]{type, value}),
GT.tr("Conversion to type {0} failed: {1}.", type, value),
PSQLState.DATA_TYPE_MISMATCH);
}

@@ -70,18 +70,19 @@ public PGcircle() {
* @param s definition of the circle in PostgreSQL's syntax.
* @throws SQLException on conversion failure
*/
@Override
public void setValue(String s) throws SQLException {
PGtokenizer t = new PGtokenizer(PGtokenizer.removeAngle(s), ',');
if (t.getSize() != 2) {
throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", new Object[]{type, s}),
throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", type, s),
PSQLState.DATA_TYPE_MISMATCH);
}

try {
center = new PGpoint(t.getToken(0));
radius = Double.parseDouble(t.getToken(1));
} catch (NumberFormatException e) {
throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", new Object[]{type, s}),
throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", type, s),
PSQLState.DATA_TYPE_MISMATCH, e);
}
}
@@ -102,11 +102,12 @@ public PGline() {
* @param s Definition of the line in PostgreSQL's syntax
* @throws SQLException on conversion failure
*/
@Override
public void setValue(String s) throws SQLException {
if (s.trim().startsWith("{")) {
PGtokenizer t = new PGtokenizer(PGtokenizer.removeCurlyBrace(s), ',');
if (t.getSize() != 3) {
throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", new Object[]{type, s}),
throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", type, s),
PSQLState.DATA_TYPE_MISMATCH);
}
a = Double.parseDouble(t.getToken(0));
@@ -115,7 +116,7 @@ public void setValue(String s) throws SQLException {
} else if (s.trim().startsWith("[")) {
PGtokenizer t = new PGtokenizer(PGtokenizer.removeBox(s), ',');
if (t.getSize() != 2) {
throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", new Object[]{type, s}),
throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", type, s),
PSQLState.DATA_TYPE_MISMATCH);
}
PGpoint point1 = new PGpoint(t.getToken(0));
@@ -66,10 +66,11 @@ public PGlseg() {
* @param s Definition of the line segment in PostgreSQL's syntax
* @throws SQLException on conversion failure
*/
@Override
public void setValue(String s) throws SQLException {
PGtokenizer t = new PGtokenizer(PGtokenizer.removeBox(s), ',');
if (t.getSize() != 2) {
throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", new Object[]{type, s}),
throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", type, s),
PSQLState.DATA_TYPE_MISMATCH);
}

@@ -69,13 +69,14 @@ public PGpoint() {
* @param s Definition of this point in PostgreSQL's syntax
* @throws SQLException on conversion failure
*/
@Override
public void setValue(String s) throws SQLException {
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(s), ',');
try {
x = Double.parseDouble(t.getToken(0));
y = Double.parseDouble(t.getToken(1));
} catch (NumberFormatException e) {
throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", new Object[]{type, s}),
throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", type, s),
PSQLState.DATA_TYPE_MISMATCH, e);
}
}
@@ -132,6 +132,7 @@ public void handleWarning(SQLWarning warning) {
pgStatement.addWarning(warning);
}

@Override
public void handleError(SQLException newError) {
if (getException() == null) {
Arrays.fill(updateCounts, committedRows, updateCounts.length, Statement.EXECUTE_FAILED);
@@ -146,7 +147,7 @@ public void handleError(SQLException newError) {

super.handleError(new BatchUpdateException(
GT.tr("Batch entry {0} {1} was aborted: {2} Call getNextException to see the cause.",
new Object[]{resultIndex, queryString, newError.getMessage()}),
resultIndex, queryString, newError.getMessage()),
newError.getSQLState(), uncompressUpdateCount()));
}
resultIndex++;
@@ -185,7 +185,7 @@ public Object getArrayImpl(long index, int count, Map<String, Class<?>> map) thr
if ((--index) + count > arrayList.size()) {
throw new PSQLException(
GT.tr("The array index is out of range: {0}, number of elements: {1}.",
new Object[]{index + count, (long) arrayList.size()}),
index + count, (long) arrayList.size()),
PSQLState.DATA_ERROR);
}

@@ -841,7 +841,7 @@ public ResultSet getResultSetImpl(long index, int count, Map<String, Class<?>> m
if ((--index) + count > arrayList.size()) {
throw new PSQLException(
GT.tr("The array index is out of range: {0}, number of elements: {1}.",
new Object[]{index + count, (long) arrayList.size()}),
index + count, (long) arrayList.size()),
PSQLState.DATA_ERROR);
}

@@ -136,8 +136,7 @@ public boolean executeWithFlags(int flags) throws SQLException {
} else {
throw new PSQLException(GT.tr(
"A CallableStatement function was executed and the out parameter {0} was of type {1} however type {2} was registered.",
new Object[]{i + 1, "java.sql.Types=" + columnType,
"java.sql.Types=" + functionReturnType[j]}),
i + 1, "java.sql.Types=" + columnType, "java.sql.Types=" + functionReturnType[j]),
PSQLState.DATA_TYPE_MISMATCH);
}
}
@@ -374,8 +373,8 @@ protected void checkIndex(int parameterIndex, int type1, int type2, String getNa
&& type2 != this.testReturn[parameterIndex - 1]) {
throw new PSQLException(
GT.tr("Parameter of type {0} was registered, but call to get{1} (sqltype={2}) was made.",
new Object[]{"java.sql.Types=" + testReturn[parameterIndex - 1], getName,
"java.sql.Types=" + type1}),
"java.sql.Types=" + testReturn[parameterIndex - 1], getName,
"java.sql.Types=" + type1),
PSQLState.MOST_SPECIFIC_TYPE_DOES_NOT_MATCH);
}
}
@@ -393,8 +392,8 @@ protected void checkIndex(int parameterIndex, int type, String getName) throws S
if (type != this.testReturn[parameterIndex - 1]) {
throw new PSQLException(
GT.tr("Parameter of type {0} was registered, but call to get{1} (sqltype={2}) was made.",
new Object[]{"java.sql.Types=" + testReturn[parameterIndex - 1], getName,
"java.sql.Types=" + type}),
"java.sql.Types=" + testReturn[parameterIndex - 1], getName,
"java.sql.Types=" + type),
PSQLState.MOST_SPECIFIC_TYPE_DOES_NOT_MATCH);
}
}
@@ -638,6 +638,7 @@ public TypeInfo getTypeInfo() {
return _typeCache;
}

@Override
public void addDataType(String type, String name) {
try {
addDataType(type, Class.forName(name).asSubclass(PGobject.class));
@@ -646,6 +647,7 @@ public void addDataType(String type, String name) {
}
}

@Override
public void addDataType(String type, Class<? extends PGobject> klass) throws SQLException {
checkClosed();
_typeCache.addDataType(type, klass);
@@ -678,7 +680,7 @@ private void initObjectTypes(Properties info) throws SQLException {
} catch (ClassNotFoundException cnfe) {
throw new PSQLException(
GT.tr("Unable to load the class {0} responsible for the datatype {1}",
new Object[]{className, typeName}),
className, typeName),
PSQLState.SYSTEM_ERROR, cnfe);
}

@@ -84,7 +84,7 @@ private void checkParamIndex(int param) throws PSQLException {
if (param < 1 || param > _oids.length) {
throw new PSQLException(
GT.tr("The parameter index is out of range: {0}, number of parameters: {1}.",
new Object[]{param, _oids.length}),
param, _oids.length),
PSQLState.INVALID_PARAMETER_VALUE);
}
}
@@ -573,6 +573,7 @@ private void setMap(int parameterIndex, Map<?, ?> x) throws SQLException {
}
}

@Override
public void setObject(int parameterIndex, Object in, int targetSqlType, int scale)
throws SQLException {
checkClosed();
@@ -693,7 +694,7 @@ public void setObject(int parameterIndex, Object in, int targetSqlType, int scal
} else {
throw new PSQLException(
GT.tr("Cannot cast an instance of {0} to type {1}",
new Object[]{in.getClass().getName(), "Types.TIMESTAMP_WITH_TIMEZONE"}),
in.getClass().getName(), "Types.TIMESTAMP_WITH_TIMEZONE"),
PSQLState.INVALID_PARAMETER_TYPE);
}
break;
@@ -715,7 +716,7 @@ public void setObject(int parameterIndex, Object in, int targetSqlType, int scal
} else {
throw new PSQLException(
GT.tr("Cannot cast an instance of {0} to type {1}",
new Object[]{in.getClass().getName(), "Types.BLOB"}),
in.getClass().getName(), "Types.BLOB"),
PSQLState.INVALID_PARAMETER_TYPE);
}
break;
@@ -725,7 +726,7 @@ public void setObject(int parameterIndex, Object in, int targetSqlType, int scal
} else {
throw new PSQLException(
GT.tr("Cannot cast an instance of {0} to type {1}",
new Object[]{in.getClass().getName(), "Types.CLOB"}),
in.getClass().getName(), "Types.CLOB"),
PSQLState.INVALID_PARAMETER_TYPE);
}
break;
@@ -735,7 +736,7 @@ public void setObject(int parameterIndex, Object in, int targetSqlType, int scal
} else {
throw new PSQLException(
GT.tr("Cannot cast an instance of {0} to type {1}",
new Object[]{in.getClass().getName(), "Types.ARRAY"}),
in.getClass().getName(), "Types.ARRAY"),
PSQLState.INVALID_PARAMETER_TYPE);
}
break;
@@ -981,7 +982,7 @@ private static PSQLException cannotCastException(final String fromType, final St
private static PSQLException cannotCastException(final String fromType, final String toType,
final Exception cause) {
return new PSQLException(
GT.tr("Cannot convert an instance of {0} to type {1}", new Object[]{fromType, toType}),
GT.tr("Cannot convert an instance of {0} to type {1}", fromType, toType),
PSQLState.INVALID_PARAMETER_TYPE, cause);
}

Oops, something went wrong.

0 comments on commit 07c7902

Please sign in to comment.