Skip to content

Commit 023405d

Browse files
committed
test: add unit tests for positional column metadata tests
1 parent bbc22d8 commit 023405d

File tree

4 files changed

+38
-116
lines changed

4 files changed

+38
-116
lines changed

jdbc-core/src/main/java/com/salesforce/datacloud/jdbc/core/SimpleMetadataResultSet.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,8 @@ private static ColumnType jdbcTypeToSqlType(int jdbcType, String name) {
6464
switch (jdbcType) {
6565
case Types.SMALLINT:
6666
return new ColumnType(JDBCType.SMALLINT, 38, 18);
67-
case Types.TINYINT:
68-
return new ColumnType(JDBCType.TINYINT, 38, 18);
6967
case Types.INTEGER:
7068
return new ColumnType(JDBCType.INTEGER, 38, 18);
71-
case Types.CHAR:
72-
return new ColumnType(JDBCType.CHAR, name.length(), 0);
7369
case Types.VARCHAR:
7470
case Types.LONGVARCHAR:
7571
return new ColumnType(JDBCType.VARCHAR, name.length(), 0);

jdbc-core/src/main/java/com/salesforce/datacloud/jdbc/core/resultset/SimpleResultSet.java

Lines changed: 7 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.io.InputStream;
99
import java.io.Reader;
1010
import java.math.BigDecimal;
11-
import java.math.BigInteger;
1211
import java.net.URL;
1312
import java.sql.Array;
1413
import java.sql.Blob;
@@ -26,7 +25,6 @@
2625
import java.sql.Timestamp;
2726
import java.util.Calendar;
2827
import java.util.Map;
29-
import java.util.OptionalDouble;
3028
import java.util.OptionalLong;
3129
import lombok.AllArgsConstructor;
3230
import lombok.val;
@@ -86,7 +84,7 @@ public SQLWarning getWarnings() throws SQLException {
8684

8785
@Override
8886
public void clearWarnings() throws SQLException {
89-
// No-op, since we don't support warnings
87+
throw new SQLFeatureNotSupportedException("clearWarnings is not supported");
9088
}
9189

9290
@Override
@@ -178,35 +176,6 @@ public long getLong(int columnIndex) throws SQLException {
178176
wasNull = !v.isPresent();
179177
return v.orElse(0L);
180178
}
181-
case FLOAT:
182-
case DOUBLE: {
183-
OptionalDouble d = getAccessor(columnIndex).getAnyFloatingPoint(getSubclass());
184-
wasNull = !d.isPresent();
185-
double dv = d.orElse(0.0);
186-
// The way this condition is written, it will never be true for NaN or Infinity.
187-
// This is good because we want to throw an exception for those values.
188-
if (dv >= LONG_MIN_DOUBLE && dv <= LONG_MAX_DOUBLE) {
189-
return (long) dv;
190-
}
191-
throw new SQLException("Column " + getMetaData().getColumnName(columnIndex)
192-
+ " is out of range for an integer-like type");
193-
}
194-
case NUMERIC: {
195-
BigDecimal v = getBigDecimal(columnIndex);
196-
wasNull = v == null;
197-
if (wasNull) {
198-
return 0L;
199-
} else {
200-
BigInteger i = v.toBigInteger();
201-
int gt = i.compareTo(BigInteger.valueOf(Long.MAX_VALUE));
202-
int lt = i.compareTo(BigInteger.valueOf(Long.MIN_VALUE));
203-
if (gt > 0 || lt < 0) {
204-
throw new SQLException("Column " + getMetaData().getColumnName(columnIndex)
205-
+ " is out of range for an integer-like type");
206-
}
207-
return v.longValue();
208-
}
209-
}
210179
default:
211180
throw new SQLException("Unsupported column type for integer-like types: "
212181
+ metadata.getColumn(columnIndex).getType().toString());
@@ -236,17 +205,6 @@ public double getDouble(int columnIndex) throws SQLException {
236205
wasNull = !v.isPresent();
237206
return v.orElse(0L);
238207
}
239-
case FLOAT:
240-
case DOUBLE: {
241-
val v = getAccessor(columnIndex).getAnyFloatingPoint(getSubclass());
242-
wasNull = !v.isPresent();
243-
return v.orElse(0.0);
244-
}
245-
case NUMERIC: {
246-
BigDecimal v = getBigDecimal(columnIndex);
247-
wasNull = v == null;
248-
return v == null ? 0.0 : v.doubleValue();
249-
}
250208
default:
251209
throw new SQLException("Unsupported column type for floating-point types: "
252210
+ metadata.getColumn(columnIndex).getType().toString());
@@ -265,11 +223,6 @@ public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
265223
}
266224
// TODO: apparently, PostgreSQL does not support float/decimal conversion. Double-check this with test
267225
// cases.
268-
case NUMERIC: {
269-
val v = getAccessor(columnIndex).getBigDecimal(getSubclass());
270-
wasNull = v == null;
271-
return v;
272-
}
273226
default:
274227
throw new SQLException("Unsupported column type for numeric types: "
275228
+ metadata.getColumn(columnIndex).getType().toString());
@@ -278,22 +231,14 @@ public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
278231

279232
@Override
280233
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
281-
val v = getBigDecimal(columnIndex);
282-
if (wasNull) {
283-
return null;
284-
}
285-
try {
286-
return v.setScale(scale);
287-
} catch (ArithmeticException e) {
288-
throw new SQLException("Bad value for type BigDecimal: " + v);
289-
}
234+
// TODO implement this
235+
throw new UnsupportedOperationException("Unimplemented method 'getBigDecimal'");
290236
}
291237

292238
@Override
293239
public byte[] getBytes(int columnIndex) throws SQLException {
294-
val v = getAccessor(columnIndex).getBytes(getSubclass());
295-
wasNull = v == null;
296-
return v;
240+
// TODO implement this
241+
throw new UnsupportedOperationException("Unimplemented method 'getBytes'");
297242
}
298243

299244
@Override
@@ -331,72 +276,23 @@ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException
331276

332277
@Override
333278
public Array getArray(int columnIndex) throws SQLException {
334-
val v = getAccessor(columnIndex).getArray(getSubclass());
335-
wasNull = v == null;
336-
return v;
279+
// TODO implement this
280+
throw new UnsupportedOperationException("Unimplemented method 'getArray'");
337281
}
338282

339283
@Override
340284
public Object getObject(int columnIndex) throws SQLException {
341285
switch (metadata.getColumn(columnIndex).getType().getType()) {
342-
case BOOLEAN: {
343-
val v = getBoolean(columnIndex);
344-
if (wasNull) {
345-
return null;
346-
}
347-
return v;
348-
}
349-
case SMALLINT: {
350-
val v = getShort(columnIndex);
351-
if (wasNull) {
352-
return null;
353-
}
354-
return v;
355-
}
356286
case INTEGER: {
357287
val v = getInt(columnIndex);
358288
if (wasNull) {
359289
return null;
360290
}
361291
return v;
362292
}
363-
case BIGINT: {
364-
val v = getLong(columnIndex);
365-
if (wasNull) {
366-
return null;
367-
}
368-
return v;
369-
}
370-
case NUMERIC:
371-
return getBigDecimal(columnIndex);
372-
case FLOAT: {
373-
val v = getFloat(columnIndex);
374-
if (wasNull) {
375-
return null;
376-
}
377-
return v;
378-
}
379-
case DOUBLE: {
380-
val v = getDouble(columnIndex);
381-
if (wasNull) {
382-
return null;
383-
}
384-
return v;
385-
}
386293
case CHAR:
387294
case VARCHAR:
388295
return getString(columnIndex);
389-
case BINARY:
390-
return getBytes(columnIndex);
391-
case DATE:
392-
return getDate(columnIndex);
393-
case TIME:
394-
return getTime(columnIndex);
395-
case TIMESTAMP:
396-
case TIMESTAMP_WITH_TIMEZONE:
397-
return getTimestamp(columnIndex);
398-
case ARRAY:
399-
return getArray(columnIndex);
400296
}
401297
throw new SQLException("Unsupported column type in `getObject`: "
402298
+ metadata.getColumn(columnIndex).getType().toString());

jdbc-core/src/test/java/com/salesforce/datacloud/jdbc/core/DataCloudDatabaseMetadataTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.sql.Connection;
2020
import java.sql.ResultSet;
2121
import java.sql.SQLException;
22+
import java.sql.SQLFeatureNotSupportedException;
2223
import java.sql.Statement;
2324
import java.util.Arrays;
2425
import java.util.UUID;
@@ -1085,6 +1086,34 @@ public void testMetadataColumnAccessors() throws SQLException {
10851086
assertThrows(SQLException.class, () -> columnResultSet.getLong("TYPE_NAME"));
10861087
assertThrows(SQLException.class, () -> columnResultSet.getInt("TYPE_NAME"));
10871088
assertThrows(SQLException.class, () -> columnResultSet.getByte("ORDINAL_POSITION"));
1089+
1090+
assertThrows(UnsupportedOperationException.class, () -> columnResultSet.getDate("ORDINAL_POSITION"));
1091+
assertThrows(UnsupportedOperationException.class, () -> columnResultSet.getTimestamp("ORDINAL_POSITION"));
1092+
assertThrows(UnsupportedOperationException.class, () -> columnResultSet.getTime("ORDINAL_POSITION"));
1093+
assertThrows(UnsupportedOperationException.class, () -> columnResultSet.getDate("ORDINAL_POSITION", null));
1094+
assertThrows(UnsupportedOperationException.class, () -> columnResultSet.getTimestamp("ORDINAL_POSITION"));
1095+
assertThrows(UnsupportedOperationException.class, () -> columnResultSet.getTime("ORDINAL_POSITION", null));
1096+
1097+
assertThrows(SQLFeatureNotSupportedException.class, () -> columnResultSet.getBlob("ORDINAL_POSITION"));
1098+
assertThrows(SQLFeatureNotSupportedException.class, () -> columnResultSet.getClob("ORDINAL_POSITION"));
1099+
assertThrows(SQLFeatureNotSupportedException.class, () -> columnResultSet.getNClob("ORDINAL_POSITION"));
1100+
assertThrows(SQLFeatureNotSupportedException.class, () -> columnResultSet.getRef("ORDINAL_POSITION"));
1101+
assertThrows(SQLFeatureNotSupportedException.class, () -> columnResultSet.getURL("ORDINAL_POSITION"));
1102+
assertThrows(SQLFeatureNotSupportedException.class, () -> columnResultSet.getRowId("ORDINAL_POSITION"));
1103+
assertThrows(SQLFeatureNotSupportedException.class, () -> columnResultSet.getSQLXML("ORDINAL_POSITION"));
1104+
assertThrows(SQLFeatureNotSupportedException.class, () -> columnResultSet.getNString("ORDINAL_POSITION"));
1105+
assertThrows(
1106+
SQLFeatureNotSupportedException.class,
1107+
() -> columnResultSet.getNCharacterStream("ORDINAL_POSITION"));
1108+
assertThrows(
1109+
SQLFeatureNotSupportedException.class, () -> columnResultSet.getAsciiStream("ORDINAL_POSITION"));
1110+
assertThrows(
1111+
SQLFeatureNotSupportedException.class, () -> columnResultSet.getUnicodeStream("ORDINAL_POSITION"));
1112+
assertThrows(
1113+
SQLFeatureNotSupportedException.class, () -> columnResultSet.getBinaryStream("ORDINAL_POSITION"));
1114+
assertThrows(
1115+
SQLFeatureNotSupportedException.class,
1116+
() -> columnResultSet.getCharacterStream("ORDINAL_POSITION"));
10881117
}
10891118
}
10901119

jdbc-core/src/test/java/com/salesforce/datacloud/jdbc/core/resultset/SimpleResultSetTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ public void shouldThrowUnsupportedError() {
2727
SimpleResultSet resultSet = Mockito.mock(SimpleResultSet.class, Mockito.CALLS_REAL_METHODS);
2828

2929
// Test methods from SimpleResultSet that throw SQLFeatureNotSupportedException
30+
assertThrows(SQLFeatureNotSupportedException.class, resultSet::clearWarnings);
3031
assertThrows(SQLFeatureNotSupportedException.class, resultSet::getCursorName);
3132
assertThrows(SQLFeatureNotSupportedException.class, () -> resultSet.getBlob(1));
3233
assertThrows(SQLFeatureNotSupportedException.class, () -> resultSet.getClob(1));
34+
assertThrows(SQLFeatureNotSupportedException.class, () -> resultSet.getNClob(1));
3335
assertThrows(SQLFeatureNotSupportedException.class, () -> resultSet.getRef(1));
3436
assertThrows(SQLFeatureNotSupportedException.class, () -> resultSet.getURL(1));
3537
assertThrows(SQLFeatureNotSupportedException.class, () -> resultSet.getRowId(1));
@@ -228,6 +230,5 @@ public void shouldThrowUnsupportedError() {
228230
assertThrows(SQLFeatureNotSupportedException.class, () -> resultSet.updateNClob(1, Mockito.mock(Reader.class)));
229231
assertThrows(
230232
SQLFeatureNotSupportedException.class, () -> resultSet.updateNClob("col", Mockito.mock(Reader.class)));
231-
assertThrows(SQLFeatureNotSupportedException.class, () -> resultSet.getNClob(1));
232233
}
233234
}

0 commit comments

Comments
 (0)