ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [50/79] [abbrv] incubator-ignite git commit: # sprint-2 Fixed load schemas and tables for MySql.
Date Fri, 06 Mar 2015 06:49:02 GMT
# sprint-2 Fixed load schemas and tables for MySql.


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

Branch: refs/heads/ignite-45
Commit: 49af1cf28a0c15d208375f821c2c262794704c9b
Parents: e4d0476
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Thu Mar 5 15:40:09 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Thu Mar 5 15:40:09 2015 +0700

----------------------------------------------------------------------
 .../parser/dialect/JdbcMetadataDialect.java     | 95 ++++++++++----------
 1 file changed, 46 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/49af1cf2/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/JdbcMetadataDialect.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/JdbcMetadataDialect.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/JdbcMetadataDialect.java
index 38b095a..ab65e7a 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/JdbcMetadataDialect.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/JdbcMetadataDialect.java
@@ -32,11 +32,11 @@ public class JdbcMetadataDialect extends DatabaseMetadataDialect {
     /** */
     private static final String[] TABLES_AND_VIEWS = {"TABLE", "VIEW"};
 
-    /** Schema name index. */
-    private static final int SCHEMA_NAME_IDX = 1;
-
     /** Schema catalog index. */
-    private static final int SCHEMA_CATALOG_IDX = 2;
+    private static final int TBL_CATALOG_IDX = 1;
+
+    /** Schema name index. */
+    private static final int TBL_SCHEMA_IDX = 2;
 
     /** Table name index. */
     private static final int TBL_NAME_IDX = 3;
@@ -70,72 +70,69 @@ public class JdbcMetadataDialect extends DatabaseMetadataDialect {
 
         Collection<DbTable> tbls = new ArrayList<>();
 
-        try (ResultSet schemasRs = dbMeta.getSchemas()) {
-            while (schemasRs.next()) {
-                String schema = schemasRs.getString(SCHEMA_NAME_IDX);
+        try (ResultSet tblsRs = dbMeta.getTables(null, null, "%",
+            tblsOnly ? TABLES_ONLY : TABLES_AND_VIEWS)) {
+            while (tblsRs.next()) {
+                String tblCatalog = tblsRs.getString(TBL_CATALOG_IDX);
+                String tblSchema = tblsRs.getString(TBL_SCHEMA_IDX);
+                String tblName = tblsRs.getString(TBL_NAME_IDX);
+
+                // In case of MySql we should use catalog.
+                String schema = tblSchema != null ? tblSchema : tblCatalog;
 
                 // Skip system schemas.
                 if (sys.contains(schema))
                     continue;
 
-                String catalog = schemasRs.getString(SCHEMA_CATALOG_IDX);
-
-                try (ResultSet tblsRs = dbMeta.getTables(catalog, schema, "%",
-                    tblsOnly ? TABLES_ONLY : TABLES_AND_VIEWS)) {
-                    while (tblsRs.next()) {
-                        String tblName = tblsRs.getString(TBL_NAME_IDX);
-
-                        Set<String> pkCols = new HashSet<>();
-
-                        try (ResultSet pkRs = dbMeta.getPrimaryKeys(catalog, schema, tblName))
{
-                            while (pkRs.next())
-                                pkCols.add(pkRs.getString(PK_COL_NAME_IDX));
-                        }
+                Set<String> pkCols = new HashSet<>();
 
-                        List<DbColumn> cols = new ArrayList<>();
+                try (ResultSet pkRs = dbMeta.getPrimaryKeys(tblCatalog, tblSchema, tblName))
{
+                    while (pkRs.next())
+                        pkCols.add(pkRs.getString(PK_COL_NAME_IDX));
+                }
 
-                        try (ResultSet colsRs = dbMeta.getColumns(catalog, schema, tblName,
null)) {
-                            while (colsRs.next()) {
-                                String colName = colsRs.getString(COL_NAME_IDX);
+                List<DbColumn> cols = new ArrayList<>();
 
-                                cols.add(new DbColumn(
-                                    colName,
-                                    colsRs.getInt(COL_DATA_TYPE_IDX),
-                                    pkCols.contains(colName),
-                                    colsRs.getInt(COL_NULLABLE_IDX) == DatabaseMetaData.columnNullable));
-                            }
-                        }
+                try (ResultSet colsRs = dbMeta.getColumns(tblCatalog, tblSchema, tblName,
null)) {
+                    while (colsRs.next()) {
+                        String colName = colsRs.getString(COL_NAME_IDX);
 
-                        Map<String, Map<String, Boolean>> idxs = new LinkedHashMap<>();
+                        cols.add(new DbColumn(
+                            colName,
+                            colsRs.getInt(COL_DATA_TYPE_IDX),
+                            pkCols.contains(colName),
+                            colsRs.getInt(COL_NULLABLE_IDX) == DatabaseMetaData.columnNullable));
+                    }
+                }
 
-                        try (ResultSet idxRs = dbMeta.getIndexInfo(catalog, schema, tblName,
false, true)) {
-                            while (idxRs.next()) {
-                                String idxName = idxRs.getString(IDX_NAME_IDX);
+                Map<String, Map<String, Boolean>> idxs = new LinkedHashMap<>();
 
-                                String colName = idxRs.getString(IDX_COL_NAME_IDX);
+                try (ResultSet idxRs = dbMeta.getIndexInfo(tblCatalog, tblSchema, tblName,
false, true)) {
+                    while (idxRs.next()) {
+                        String idxName = idxRs.getString(IDX_NAME_IDX);
 
-                                if (idxName == null || colName == null)
-                                    continue;
+                        String colName = idxRs.getString(IDX_COL_NAME_IDX);
 
-                                Map<String, Boolean> idx = idxs.get(idxName);
+                        if (idxName == null || colName == null)
+                            continue;
 
-                                if (idx == null) {
-                                    idx = new LinkedHashMap<>();
+                        Map<String, Boolean> idx = idxs.get(idxName);
 
-                                    idxs.put(idxName, idx);
-                                }
+                        if (idx == null) {
+                            idx = new LinkedHashMap<>();
 
-                                String askOrDesc = idxRs.getString(IDX_ASC_OR_DESC_IDX);
+                            idxs.put(idxName, idx);
+                        }
 
-                                Boolean desc = askOrDesc != null ? "D".equals(askOrDesc)
: null;
+                        String askOrDesc = idxRs.getString(IDX_ASC_OR_DESC_IDX);
 
-                                idx.put(colName, desc);
-                            }
-                        }
+                        Boolean desc = askOrDesc != null ? "D".equals(askOrDesc) : null;
 
-                        tbls.add(table(schema, tblName, cols, idxs));
+                        idx.put(colName, desc);
                     }
                 }
+
+                tbls.add(table(schema, tblName, cols, idxs));
             }
         }
 


Mime
View raw message