ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [02/50] [abbrv] ignite git commit: IGNITE-6529: JDBC: fixed not-null column metadata. This closes #2884.
Date Wed, 25 Oct 2017 09:40:36 GMT
IGNITE-6529: JDBC: fixed not-null column metadata. This closes #2884.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5c8c4920
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5c8c4920
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5c8c4920

Branch: refs/heads/ignite-3478
Commit: 5c8c492005868e6ee2bad1fb8daac5b202da52dd
Parents: 8f23bca
Author: tledkov-gridgain <tledkov@gridgain.com>
Authored: Thu Oct 19 22:20:18 2017 +0300
Committer: devozerov <ppozerov@gmail.com>
Committed: Thu Oct 19 22:20:18 2017 +0300

----------------------------------------------------------------------
 .../internal/jdbc2/JdbcMetadataSelfTest.java    |  12 +++
 .../jdbc/thin/JdbcThinMetadataSelfTest.java     |  14 +++
 .../jdbc/thin/JdbcThinDatabaseMetadata.java     |  89 +++++++++-------
 .../internal/jdbc2/JdbcDatabaseMetadata.java    | 104 +++++++++++++------
 4 files changed, 149 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/5c8c4920/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcMetadataSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcMetadataSelfTest.java
b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcMetadataSelfTest.java
index bdc6644..1e5db0a 100755
--- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcMetadataSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcMetadataSelfTest.java
@@ -220,6 +220,8 @@ public class JdbcMetadataSelfTest extends GridCommonAbstractTest {
 
             assertNotNull(rs);
 
+            assertEquals(24, rs.getMetaData().getColumnCount());
+
             Collection<String> names = new ArrayList<>(2);
 
             names.add("NAME");
@@ -237,14 +239,20 @@ public class JdbcMetadataSelfTest extends GridCommonAbstractTest {
                     assertEquals(VARCHAR, rs.getInt("DATA_TYPE"));
                     assertEquals("VARCHAR", rs.getString("TYPE_NAME"));
                     assertEquals(0, rs.getInt("NULLABLE"));
+                    assertEquals(0, rs.getInt(11)); // nullable column by index
+                    assertEquals("NO", rs.getString("IS_NULLABLE"));
                 } else if ("AGE".equals(name)) {
                     assertEquals(INTEGER, rs.getInt("DATA_TYPE"));
                     assertEquals("INTEGER", rs.getString("TYPE_NAME"));
                     assertEquals(0, rs.getInt("NULLABLE"));
+                    assertEquals(0, rs.getInt(11)); // nullable column by index
+                    assertEquals("NO", rs.getString("IS_NULLABLE"));
                 } else if ("ORGID".equals(name)) {
                     assertEquals(INTEGER, rs.getInt("DATA_TYPE"));
                     assertEquals("INTEGER", rs.getString("TYPE_NAME"));
                     assertEquals(1, rs.getInt("NULLABLE"));
+                    assertEquals(1, rs.getInt(11)); // nullable column by index
+                    assertEquals("YES", rs.getString("IS_NULLABLE"));
                 }
 
                 cnt++;
@@ -271,10 +279,14 @@ public class JdbcMetadataSelfTest extends GridCommonAbstractTest {
                     assertEquals(INTEGER, rs.getInt("DATA_TYPE"));
                     assertEquals("INTEGER", rs.getString("TYPE_NAME"));
                     assertEquals(0, rs.getInt("NULLABLE"));
+                    assertEquals(0, rs.getInt(11)); // nullable column by index
+                    assertEquals("NO", rs.getString("IS_NULLABLE"));
                 } else if ("name".equals(name)) {
                     assertEquals(VARCHAR, rs.getInt("DATA_TYPE"));
                     assertEquals("VARCHAR", rs.getString("TYPE_NAME"));
                     assertEquals(1, rs.getInt("NULLABLE"));
+                    assertEquals(1, rs.getInt(11)); // nullable column by index
+                    assertEquals("YES", rs.getString("IS_NULLABLE"));
                 }
 
                 cnt++;

http://git-wip-us.apache.org/repos/asf/ignite/blob/5c8c4920/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java
b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java
index 4e1ae4d..2fd40d1 100644
--- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java
@@ -260,6 +260,10 @@ public class JdbcThinMetadataSelfTest extends JdbcThinAbstractSelfTest
{
 
             ResultSet rs = meta.getColumns("", "pers", "PERSON", "%");
 
+            ResultSetMetaData rsMeta = rs.getMetaData();
+
+            assert rsMeta.getColumnCount() == 24 : "Invalid columns count: " + rsMeta.getColumnCount();
+
             assert rs != null;
 
             Collection<String> names = new ArrayList<>(2);
@@ -279,24 +283,34 @@ public class JdbcThinMetadataSelfTest extends JdbcThinAbstractSelfTest
{
                     assert rs.getInt("DATA_TYPE") == VARCHAR;
                     assert "VARCHAR".equals(rs.getString("TYPE_NAME"));
                     assert rs.getInt("NULLABLE") == 0;
+                    assert rs.getInt(11) == 0; // nullable column by index
+                    assert rs.getString("IS_NULLABLE").equals("NO");
                 } else if ("ORGID".equals(name)) {
                     assert rs.getInt("DATA_TYPE") == INTEGER;
                     assert "INTEGER".equals(rs.getString("TYPE_NAME"));
                     assert rs.getInt("NULLABLE") == 1;
+                    assert rs.getInt(11) == 1;  // nullable column by index
+                    assert rs.getString("IS_NULLABLE").equals("YES");
                 } else if ("AGE".equals(name)) {
                     assert rs.getInt("DATA_TYPE") == INTEGER;
                     assert "INTEGER".equals(rs.getString("TYPE_NAME"));
                     assert rs.getInt("NULLABLE") == 0;
+                    assert rs.getInt(11) == 0;  // nullable column by index
+                    assert rs.getString("IS_NULLABLE").equals("NO");
                 }
                 else if ("_KEY".equals(name)) {
                     assert rs.getInt("DATA_TYPE") == OTHER;
                     assert "OTHER".equals(rs.getString("TYPE_NAME"));
                     assert rs.getInt("NULLABLE") == 0;
+                    assert rs.getInt(11) == 0;  // nullable column by index
+                    assert rs.getString("IS_NULLABLE").equals("NO");
                 }
                 else if ("_VAL".equals(name)) {
                     assert rs.getInt("DATA_TYPE") == OTHER;
                     assert "OTHER".equals(rs.getString("TYPE_NAME"));
                     assert rs.getInt("NULLABLE") == 0;
+                    assert rs.getInt(11) == 0;  // nullable column by index
+                    assert rs.getString("IS_NULLABLE").equals("NO");
                 }
 
                 cnt++;

http://git-wip-us.apache.org/repos/asf/ignite/blob/5c8c4920/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinDatabaseMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinDatabaseMetadata.java
b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinDatabaseMetadata.java
index 8b26900..cfc3b68 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinDatabaseMetadata.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinDatabaseMetadata.java
@@ -793,26 +793,31 @@ public class JdbcThinDatabaseMetadata implements DatabaseMetaData {
         conn.ensureNotClosed();
 
         final List<JdbcColumnMeta> meta = Arrays.asList(
-            new JdbcColumnMeta(null, null, "TABLE_CAT", String.class),
-            new JdbcColumnMeta(null, null, "TABLE_SCHEM", String.class),
-            new JdbcColumnMeta(null, null, "TABLE_NAME", String.class),
-            new JdbcColumnMeta(null, null, "COLUMN_NAME", String.class),
-            new JdbcColumnMeta(null, null, "DATA_TYPE", Short.class),
-            new JdbcColumnMeta(null, null, "TYPE_NAME", String.class),
-            new JdbcColumnMeta(null, null, "COLUMN_SIZE", Integer.class),
-            new JdbcColumnMeta(null, null, "DECIMAL_DIGITS", Integer.class),
-            new JdbcColumnMeta(null, null, "NUM_PREC_RADIX", Short.class),
-            new JdbcColumnMeta(null, null, "NULLABLE", Short.class),
-            new JdbcColumnMeta(null, null, "REMARKS", String.class),
-            new JdbcColumnMeta(null, null, "COLUMN_DEF", String.class),
-            new JdbcColumnMeta(null, null, "CHAR_OCTET_LENGTH", Integer.class),
-            new JdbcColumnMeta(null, null, "ORDINAL_POSITION", Integer.class),
-            new JdbcColumnMeta(null, null, "IS_NULLABLE", String.class),
-            new JdbcColumnMeta(null, null, "SCOPE_CATLOG", String.class),
-            new JdbcColumnMeta(null, null, "SCOPE_SCHEMA", String.class),
-            new JdbcColumnMeta(null, null, "SCOPE_TABLE", String.class),
-            new JdbcColumnMeta(null, null, "SOURCE_DATA_TYPE", Short.class),
-            new JdbcColumnMeta(null, null, "IS_AUTOINCREMENT", String.class));
+            new JdbcColumnMeta(null, null, "TABLE_CAT", String.class),      // 1
+            new JdbcColumnMeta(null, null, "TABLE_SCHEM", String.class),    // 2
+            new JdbcColumnMeta(null, null, "TABLE_NAME", String.class),     // 3
+            new JdbcColumnMeta(null, null, "COLUMN_NAME", String.class),    // 4
+            new JdbcColumnMeta(null, null, "DATA_TYPE", Short.class),       // 5
+            new JdbcColumnMeta(null, null, "TYPE_NAME", String.class),      // 6
+            new JdbcColumnMeta(null, null, "COLUMN_SIZE", Integer.class),   // 7
+            new JdbcColumnMeta(null, null, "BUFFER_LENGTH ", Integer.class), // 8
+            new JdbcColumnMeta(null, null, "DECIMAL_DIGITS", Integer.class), // 9
+            new JdbcColumnMeta(null, null, "NUM_PREC_RADIX", Short.class),  // 10
+            new JdbcColumnMeta(null, null, "NULLABLE", Short.class),        // 11
+            new JdbcColumnMeta(null, null, "REMARKS", String.class),        // 12
+            new JdbcColumnMeta(null, null, "COLUMN_DEF", String.class),     // 13
+            new JdbcColumnMeta(null, null, "SQL_DATA_TYPE", Integer.class), // 14
+            new JdbcColumnMeta(null, null, "SQL_DATETIME_SUB", Integer.class), // 15
+            new JdbcColumnMeta(null, null, "CHAR_OCTET_LENGTH", Integer.class), // 16
+            new JdbcColumnMeta(null, null, "ORDINAL_POSITION", Integer.class), // 17
+            new JdbcColumnMeta(null, null, "IS_NULLABLE", String.class),    // 18
+            new JdbcColumnMeta(null, null, "SCOPE_CATLOG", String.class),   // 19
+            new JdbcColumnMeta(null, null, "SCOPE_SCHEMA", String.class),   // 20
+            new JdbcColumnMeta(null, null, "SCOPE_TABLE", String.class),    // 21
+            new JdbcColumnMeta(null, null, "SOURCE_DATA_TYPE", Short.class), // 22
+            new JdbcColumnMeta(null, null, "IS_AUTOINCREMENT", String.class), // 23
+            new JdbcColumnMeta(null, null, "IS_GENERATEDCOLUMN ", String.class) // 24
+        );
 
         if (!validCatalogPattern(catalog))
             return new JdbcThinResultSet(Collections.<List<Object>>emptyList(),
meta);
@@ -835,26 +840,30 @@ public class JdbcThinDatabaseMetadata implements DatabaseMetaData {
     private List<Object> columnRow(JdbcColumnMeta colMeta, int pos) {
         List<Object> row = new ArrayList<>(20);
 
-        row.add((String)null);
-        row.add(colMeta.schemaName());
-        row.add(colMeta.tableName());
-        row.add(colMeta.columnName());
-        row.add(colMeta.dataType());
-        row.add(colMeta.dataTypeName());
-        row.add((Integer)null);
-        row.add((Integer)null);
-        row.add(10);
-        row.add(colMeta.isNullable() ? 1 : 0);
-        row.add((String)null);
-        row.add((String)null);
-        row.add(Integer.MAX_VALUE);
-        row.add(pos);
-        row.add("YES");
-        row.add((String)null);
-        row.add((String)null);
-        row.add((String)null);
-        row.add((Short)null);
-        row.add("NO");
+        row.add((String)null);                  // 1. TABLE_CAT
+        row.add(colMeta.schemaName());          // 2. TABLE_SCHEM
+        row.add(colMeta.tableName());           // 3. TABLE_NAME
+        row.add(colMeta.columnName());          // 4. COLUMN_NAME
+        row.add(colMeta.dataType());            // 5. DATA_TYPE
+        row.add(colMeta.dataTypeName());        // 6. TYPE_NAME
+        row.add((Integer)null);                 // 7. COLUMN_SIZE
+        row.add((Integer)null);                 // 8. BUFFER_LENGTH
+        row.add((Integer)null);                 // 9. DECIMAL_DIGITS
+        row.add(10);                            // 10. NUM_PREC_RADIX
+        row.add(colMeta.isNullable() ? columnNullable : columnNoNulls);  // 11. NULLABLE
+        row.add((String)null);                  // 12. REMARKS
+        row.add((String)null);                  // 13. COLUMN_DEF
+        row.add(colMeta.dataType());            // 14. SQL_DATA_TYPE
+        row.add((Integer)null);                 // 15. SQL_DATETIME_SUB
+        row.add(Integer.MAX_VALUE);             // 16. CHAR_OCTET_LENGTH
+        row.add(pos);                           // 17. ORDINAL_POSITION
+        row.add(colMeta.isNullable() ? "YES" : "NO"); // 18. IS_NULLABLE
+        row.add((String)null);                  // 19. SCOPE_CATALOG
+        row.add((String)null);                  // 20. SCOPE_SCHEMA
+        row.add((String)null);                  // 21. SCOPE_TABLE
+        row.add((Short)null);                   // 22. SOURCE_DATA_TYPE
+        row.add("NO");                          // 23. IS_AUTOINCREMENT
+        row.add("NO");                          // 23. IS_GENERATEDCOLUMN
 
         return row;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/5c8c4920/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcDatabaseMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcDatabaseMetadata.java
b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcDatabaseMetadata.java
index 2fe24bb..eb55e4f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcDatabaseMetadata.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcDatabaseMetadata.java
@@ -815,16 +815,56 @@ public class JdbcDatabaseMetadata implements DatabaseMetaData {
         return new JdbcResultSet(true, null,
             conn.createStatement0(),
             Collections.<String>emptyList(),
-            Arrays.asList("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE",
-                "TYPE_NAME", "COLUMN_SIZE", "DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE",
-                "REMARKS", "COLUMN_DEF", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION", "IS_NULLABLE",
-                "SCOPE_CATLOG", "SCOPE_SCHEMA", "SCOPE_TABLE", "SOURCE_DATA_TYPE", "IS_AUTOINCREMENT"),
-            Arrays.asList(String.class.getName(), String.class.getName(), String.class.getName(),
-                String.class.getName(), Integer.class.getName(), String.class.getName(),
Integer.class.getName(),
-                Integer.class.getName(), Integer.class.getName(), Integer.class.getName(),
String.class.getName(),
-                String.class.getName(), Integer.class.getName(), Integer.class.getName(),
String.class.getName(),
-                String.class.getName(), String.class.getName(), String.class.getName(), Short.class.getName(),
-                String.class.getName()),
+            Arrays.asList(
+                "TABLE_CAT",        // 1
+                "TABLE_SCHEM",      // 2
+                "TABLE_NAME",       // 3
+                "COLUMN_NAME",      // 4
+                "DATA_TYPE",        // 5
+                "TYPE_NAME",        // 6
+                "COLUMN_SIZE",      // 7
+                "BUFFER_LENGTH",    // 8
+                "DECIMAL_DIGITS",   // 9
+                "NUM_PREC_RADIX",   // 10
+                "NULLABLE",         // 11
+                "REMARKS",          // 12
+                "COLUMN_DEF",       // 13
+                "SQL_DATA_TYPE",    // 14
+                "SQL_DATETIME_SUB", // 15
+                "CHAR_OCTET_LENGTH", // 16
+                "ORDINAL_POSITION",  // 17
+                "IS_NULLABLE",      // 18
+                "SCOPE_CATLOG",     // 19
+                "SCOPE_SCHEMA",     // 20
+                "SCOPE_TABLE",      // 21
+                "SOURCE_DATA_TYPE", // 22
+                "IS_AUTOINCREMENT", // 23
+                "IS_GENERATEDCOLUMN"), // 23
+            Arrays.asList(
+                String.class.getName(),     // 1
+                String.class.getName(),     // 2
+                String.class.getName(),     // 3
+                String.class.getName(),     // 4
+                Integer.class.getName(),    // 5
+                String.class.getName(),     // 6
+                Integer.class.getName(),    // 7
+                Integer.class.getName(),    // 8
+                Integer.class.getName(),    // 9
+                Integer.class.getName(),    // 10
+                Integer.class.getName(),    // 11
+                String.class.getName(),     // 12
+                String.class.getName(),     // 13
+                Integer.class.getName(),    // 14
+                Integer.class.getName(),    // 15
+                Integer.class.getName(),    // 16
+                Integer.class.getName(),    // 17
+                String.class.getName(),     // 18
+                String.class.getName(),     // 19
+                String.class.getName(),     // 20
+                String.class.getName(),     // 21
+                Short.class.getName(),      // 22
+                String.class.getName(),     // 23
+                String.class.getName()),    // 24
             rows, true
         );
     }
@@ -843,26 +883,30 @@ public class JdbcDatabaseMetadata implements DatabaseMetaData {
         boolean nullable, int pos) {
         List<Object> row = new ArrayList<>(20);
 
-        row.add(null);
-        row.add(schema);
-        row.add(tbl);
-        row.add(col);
-        row.add(type);
-        row.add(typeName);
-        row.add(null);
-        row.add(null);
-        row.add(10);
-        row.add(nullable ? columnNullable : columnNoNulls);
-        row.add(null);
-        row.add(null);
-        row.add(Integer.MAX_VALUE);
-        row.add(pos);
-        row.add("YES");
-        row.add(null);
-        row.add(null);
-        row.add(null);
-        row.add(null);
-        row.add("NO");
+        row.add(null);                  // 1. TABLE_CAT
+        row.add(schema);                // 2. TABLE_SCHEM
+        row.add(tbl);                   // 3. TABLE_NAME
+        row.add(col);                   // 4. COLUMN_NAME
+        row.add(type);                  // 5. DATA_TYPE
+        row.add(typeName);              // 6. TYPE_NAME
+        row.add(null);                  // 7. COLUMN_SIZE
+        row.add(null);                  // 8. BUFFER_LENGTH
+        row.add(null);                  // 9. DECIMAL_DIGITS
+        row.add(10);                    // 10. NUM_PREC_RADIX
+        row.add(nullable ? columnNullable : columnNoNulls); // 11. NULLABLE
+        row.add(null);                  // 12. REMARKS
+        row.add(null);                  // 13. COLUMN_DEF
+        row.add(type);                  // 14. SQL_DATA_TYPE
+        row.add(null);                  // 15. SQL_DATETIME_SUB
+        row.add(Integer.MAX_VALUE);     // 16. CHAR_OCTET_LENGTH
+        row.add(pos);                   // 17. ORDINAL_POSITION
+        row.add(nullable ? "YES" : "NO"); // 18. IS_NULLABLE
+        row.add(null);                  // 19. SCOPE_CATALOG
+        row.add(null);                  // 20. SCOPE_SCHEMA
+        row.add(null);                  // 21. SCOPE_TABLE
+        row.add(null);                  // 22. SOURCE_DATA_TYPE
+        row.add("NO");                  // 23. IS_AUTOINCREMENT
+        row.add("NO");                  // 24. IS_GENERATEDCOLUMN
 
         return row;
     }


Mime
View raw message