Skip to content

Commit

Permalink
FMWK-303 Use query order for columns in result set
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn committed Jan 2, 2024
1 parent b5004ab commit 180f94b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ private List<DataColumn> filterColumns(AerospikeQuery query) {
}
return columns.stream()
.filter(c -> query.getColumns().contains(c.getName()))
.sorted(Comparator.comparing(c -> query.getColumns().indexOf(c.getName())))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ default <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
return getObject(getColumnLabel(columnIndex), type);
}

@Override
default Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
return getObject(getColumnLabel(columnIndex), map);
}
Expand Down
9 changes: 6 additions & 3 deletions src/test/java/com/aerospike/jdbc/SimpleQueriesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,20 @@ public void testSelectEqualsQuery() throws SQLException {
public void testSelectNotEqualsQuery() throws SQLException {
Statement statement = null;
ResultSet resultSet = null;
String query = format("SELECT %s, int2 FROM %s WHERE int2 <> 2", PRIMARY_KEY_COLUMN_NAME, TABLE_NAME);
String query = format("SELECT ne1, int2, ne2, bool1, ne3, %s, ne4 FROM %s WHERE int2 <> 2",
PRIMARY_KEY_COLUMN_NAME, TABLE_NAME);
try {
statement = connection.createStatement();
resultSet = statement.executeQuery(query);
assertTrue(resultSet.next());

assertEquals(resultSet.getString(PRIMARY_KEY_COLUMN_NAME), testRecord.getPrimaryKey());
assertEquals(resultSet.getInt("int2"), testRecord.getInt2());
assertEquals(resultSet.getBoolean("bool1"), testRecord.getBool1());

assertEquals(resultSet.getString(1), testRecord.getPrimaryKey());
assertEquals(resultSet.getInt(2), testRecord.getInt2());
assertEquals(resultSet.getInt(1), testRecord.getInt2());
assertEquals(resultSet.getBoolean(2), testRecord.getBool1());
assertEquals(resultSet.getString(3), testRecord.getPrimaryKey());
} finally {
closeQuietly(statement);
closeQuietly(resultSet);
Expand Down

0 comments on commit 180f94b

Please sign in to comment.