From: Sergei Kalashnikov <ztarvos@gmail.com> To: tarantool-patches@freelists.org Cc: Sergei Kalashnikov <ztarvos@gmail.com> Subject: [tarantool-patches] [PATCH] jdbc: fix primary keys meta retrieval Date: Wed, 26 Sep 2018 12:33:28 +0300 [thread overview] Message-ID: <1537954408-3275-1-git-send-email-ztarvos@gmail.com> (raw) Fixed parsing primary keys metadata response. Updated integration tests. Closes #41 --- https://github.com/tarantool/tarantool-java/issues/41 https://github.com/ztarvos/tarantool-java/commits/gh-41-fix-jdbc-pk-meta .../org/tarantool/jdbc/SQLDatabaseMetadata.java | 8 +++--- .../java/org/tarantool/jdbc/AbstractJdbcIT.java | 11 ++++---- .../org/tarantool/jdbc/JdbcDatabaseMetaDataIT.java | 32 ++++++++++++++++++++-- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/tarantool/jdbc/SQLDatabaseMetadata.java b/src/main/java/org/tarantool/jdbc/SQLDatabaseMetadata.java index e43bcdc..790bbe7 100644 --- a/src/main/java/org/tarantool/jdbc/SQLDatabaseMetadata.java +++ b/src/main/java/org/tarantool/jdbc/SQLDatabaseMetadata.java @@ -774,12 +774,12 @@ public class SQLDatabaseMetadata implements DatabaseMetaData { List<Map<String, Object>> fields = (List<Map<String, Object>>) space.get(FORMAT_IDX); List<List<Object>> indexes = (List<List<Object>>) connection.connection.select(_VINDEX, 0, Arrays.asList(space.get(SPACE_ID_IDX), 0), 0, 1, 0); List<Object> primaryKey = indexes.get(0); - List<List<Object>> parts = (List<List<Object>>) primaryKey.get(INDEX_FORMAT_IDX); + List<Map<String, Object>> parts = (List<Map<String, Object>>) primaryKey.get(INDEX_FORMAT_IDX); for (int i = 0; i < parts.size(); i++) { - List<Object> part = parts.get(i); - int ordinal = ((Number) part.get(0)).intValue(); + Map<String, Object> part = parts.get(i); + int ordinal = ((Number) part.get("field")).intValue(); String column = (String) fields.get(ordinal).get("name"); - rows.add(Arrays.asList(table, column, i + 1, "primary", primaryKey.get(NAME_IDX))); + rows.add(Arrays.asList(table, column, i + 1, primaryKey.get(NAME_IDX))); } } return new SQLNullResultSet((JDBCBridge.mock( diff --git a/src/test/java/org/tarantool/jdbc/AbstractJdbcIT.java b/src/test/java/org/tarantool/jdbc/AbstractJdbcIT.java index 21e3f53..abed9b6 100644 --- a/src/test/java/org/tarantool/jdbc/AbstractJdbcIT.java +++ b/src/test/java/org/tarantool/jdbc/AbstractJdbcIT.java @@ -32,9 +32,6 @@ public abstract class AbstractJdbcIT { private static String URL = String.format("tarantool://%s:%d?user=%s&password=%s", host, port, user, pass); private static String[] initSql = new String[] { - "DROP TABLE IF EXISTS test", - "DROP TABLE IF EXISTS test_types", - "CREATE TABLE test(id INT PRIMARY KEY, val VARCHAR(100))", "INSERT INTO test VALUES (1, 'one'), (2, 'two'), (3, 'three')", @@ -78,12 +75,15 @@ public abstract class AbstractJdbcIT { "X'010203040506'," + //LONGVARBINARY "'1983-03-14'," + //DATE "'12:01:06'," + //TIME - "129479994)" //TIMESTAMP + "129479994)", //TIMESTAMP + + "CREATE TABLE test_compound(id1 INT, id2 INT, val VARCHAR(100), PRIMARY KEY (id1, id2))" }; private static String[] cleanSql = new String[] { "DROP TABLE IF EXISTS test", - "DROP TABLE IF EXISTS test_types" + "DROP TABLE IF EXISTS test_types", + "DROP TABLE IF EXISTS test_compound" }; static Object[] testRow = new Object[] { @@ -112,6 +112,7 @@ public abstract class AbstractJdbcIT { @BeforeAll public static void setupEnv() throws Exception { + sqlExec(cleanSql); sqlExec(initSql); } diff --git a/src/test/java/org/tarantool/jdbc/JdbcDatabaseMetaDataIT.java b/src/test/java/org/tarantool/jdbc/JdbcDatabaseMetaDataIT.java index b934bbe..984a60b 100644 --- a/src/test/java/org/tarantool/jdbc/JdbcDatabaseMetaDataIT.java +++ b/src/test/java/org/tarantool/jdbc/JdbcDatabaseMetaDataIT.java @@ -1,6 +1,5 @@ package org.tarantool.jdbc; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeEach; @@ -45,6 +44,9 @@ public class JdbcDatabaseMetaDataIT extends AbstractJdbcIT { assertTrue(rs.next()); assertEquals("TEST_TYPES", rs.getString("TABLE_NAME")); + assertTrue(rs.next()); + assertEquals("TEST_COMPOUND", rs.getString("TABLE_NAME")); + assertFalse(rs.next()); rs.close(); @@ -84,7 +86,6 @@ public class JdbcDatabaseMetaDataIT extends AbstractJdbcIT { rs.close(); } - @Disabled(value="Test ignored, issue#41") @Test public void testGetPrimaryKeys() throws SQLException { ResultSet rs = meta.getPrimaryKeys(null, null, "TEST"); @@ -103,4 +104,31 @@ public class JdbcDatabaseMetaDataIT extends AbstractJdbcIT { rs.close(); } + + @Test + public void testGetPrimaryKeysCompound() throws SQLException { + ResultSet rs = meta.getPrimaryKeys(null, null, "TEST_COMPOUND"); + + assertNotNull(rs); + assertTrue(rs.next()); + + assertNull(rs.getString("TABLE_CAT")); + assertNull(rs.getString("TABLE_SCHEM")); + assertEquals("TEST_COMPOUND", rs.getString("TABLE_NAME")); + assertEquals("ID1", rs.getString("COLUMN_NAME")); + assertEquals(1, rs.getInt("KEY_SEQ")); + assertEquals("pk_unnamed_TEST_COMPOUND_1", rs.getString("PK_NAME")); + + assertTrue(rs.next()); + assertNull(rs.getString("TABLE_CAT")); + assertNull(rs.getString("TABLE_SCHEM")); + assertEquals("TEST_COMPOUND", rs.getString("TABLE_NAME")); + assertEquals("ID2", rs.getString("COLUMN_NAME")); + assertEquals(2, rs.getInt("KEY_SEQ")); + assertEquals("pk_unnamed_TEST_COMPOUND_1", rs.getString("PK_NAME")); + + assertFalse(rs.next()); + + rs.close(); + } } -- 1.8.3.1
next reply other threads:[~2018-09-26 9:33 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-09-26 9:33 Sergei Kalashnikov [this message] 2018-10-01 13:04 ` [tarantool-patches] " Alexander Turenko 2018-10-02 17:09 ` Sergei Kalashnikov 2018-10-09 9:21 ` Sergei Kalashnikov 2018-10-09 15:40 ` Alexander Turenko 2018-10-10 8:14 ` Sergei Kalashnikov 2018-10-10 10:19 ` Alexander Turenko 2018-10-10 11:09 ` Sergei Kalashnikov 2018-10-10 12:50 ` Alexander Turenko 2018-10-10 13:19 ` Sergei Kalashnikov 2018-10-10 13:40 ` Alexander Turenko
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1537954408-3275-1-git-send-email-ztarvos@gmail.com \ --to=ztarvos@gmail.com \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH] jdbc: fix primary keys meta retrieval' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox