Skip to content

Add support for nullsAreSorted* methods group #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -38,13 +38,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 @@ -272,4 +275,12 @@ public void testSupportGeneratedKeys() throws SQLException {
assertFalse(meta.supportsGetGeneratedKeys());
}

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

assertFalse(meta.nullsAreSortedAtStart());
assertFalse(meta.nullsAreSortedAtEnd());
}
}
30 changes: 30 additions & 0 deletions src/test/java/org/tarantool/jdbc/JdbcResultSetIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,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.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -17,6 +18,7 @@
import java.sql.Statement;

public class JdbcResultSetIT extends JdbcTypesIT {

private Statement stmt;
private DatabaseMetaData metaData;

Expand Down Expand Up @@ -148,4 +150,32 @@ public void testIsWrapperFor() throws SQLException {
assertFalse(resultSet.isWrapperFor(Integer.class));
}

@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());
}

}