Skip to content

Commit

Permalink
Add support for nullsAreSorted* methods group
Browse files Browse the repository at this point in the history
Add support for nullsAreSortedLow as a default sorting which is provided
by Tarantool DB.

Fixes: #120
  • Loading branch information
nicktorwald committed Apr 8, 2019
1 parent 06755d5 commit e688761
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/tarantool/jdbc/SQLDatabaseMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,22 @@ public boolean isReadOnly() throws SQLException {

@Override
public boolean nullsAreSortedHigh() throws SQLException {
return true;
return false;
}

@Override
public boolean nullsAreSortedLow() throws SQLException {
return !nullsAreSortedHigh();
return true;
}

@Override
public boolean nullsAreSortedAtStart() throws SQLException {
return true;
return false;
}

@Override
public boolean nullsAreSortedAtEnd() throws SQLException {
return !nullsAreSortedAtStart();
return false;
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/org/tarantool/jdbc/AbstractJdbcIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ public abstract class AbstractJdbcIT {
"CREATE TABLE test(id INT PRIMARY KEY, val VARCHAR(100))",
"INSERT INTO test VALUES (1, 'one'), (2, 'two'), (3, 'three')",
"CREATE TABLE test_compound(id1 INT, id2 INT, val VARCHAR(100), PRIMARY KEY (id2, id1))",
"CREATE TABLE test_nulls(id INT PRIMARY KEY, val VARCHAR(100))",
"INSERT INTO test_nulls VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, NULL), (5, NULL), (6, NULL)",
getCreateTableSQL("test_types", TntSqlType.values())
};

private static String[] cleanSql = new String[] {
"DROP TABLE IF EXISTS test",
"DROP TABLE IF EXISTS test_types",
"DROP TABLE IF EXISTS test_compound"
"DROP TABLE IF EXISTS test_compound",
"DROP TABLE IF EXISTS test_nulls"
};

protected static TarantoolControl control;
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/tarantool/jdbc/JdbcDatabaseMetaDataIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public void testGetAllTables() throws SQLException {
assertTrue(rs.next());
assertEquals("TEST_COMPOUND", rs.getString("TABLE_NAME"));

assertTrue(rs.next());
assertEquals("TEST_NULLS", rs.getString("TABLE_NAME"));

assertTrue(rs.next());
assertEquals("TEST_TYPES", rs.getString("TABLE_NAME"));

Expand Down Expand Up @@ -254,4 +257,12 @@ public void testSupportsResultSetHoldability() throws SQLException {
assertFalse(meta.supportsResultSetHoldability(42));
}

@Test
public void testNullsAreSortedProperties() throws SQLException {
assertTrue(meta.nullsAreSortedLow());
assertFalse(meta.nullsAreSortedHigh());

assertFalse(meta.nullsAreSortedAtStart());
assertFalse(meta.nullsAreSortedAtEnd());
}
}
28 changes: 28 additions & 0 deletions src/test/java/org/tarantool/jdbc/JdbcResultSetIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class JdbcResultSetIT extends JdbcTypesIT {
Expand Down Expand Up @@ -132,4 +133,31 @@ public void testHoldability() throws SQLException {
assertEquals(metaData.getResultSetHoldability(), resultSet.getHoldability());
}

@Test
public void testNullsSortingAsc() throws SQLException {
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_nulls ORDER BY val ASC");
for (int i = 0; i < 3; i++) {
assertTrue(resultSet.next());
assertNull(resultSet.getString(2));
}
for (int i = 0; i < 3; i++) {
assertTrue(resultSet.next());
assertNotNull(resultSet.getString(2));
}
assertFalse(resultSet.next());
}

@Test
public void testNullsSortingDesc() throws SQLException {
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_nulls ORDER BY val DESC");
for (int i = 0; i < 3; i++) {
assertTrue(resultSet.next());
assertNotNull(resultSet.getString(2));
}
for (int i = 0; i < 3; i++) {
assertTrue(resultSet.next());
assertNull(resultSet.getString(2));
}
assertFalse(resultSet.next());
}
}

0 comments on commit e688761

Please sign in to comment.