ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [01/50] [abbrv] incubator-ignite git commit: # IGNITE-32: fixed XML generation.
Date Thu, 05 Feb 2015 07:47:27 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-58 fde5a485f -> cc6461033


# IGNITE-32: fixed XML generation.


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

Branch: refs/heads/ignite-58
Commit: 2fe9dd1bef7f49e565ccf9dc89b7fb39105a0aa9
Parents: f907780
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Mon Feb 2 15:12:00 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Mon Feb 2 15:12:00 2015 +0700

----------------------------------------------------------------------
 modules/schema-load/pom.xml                     |  1 -
 .../ignite/schema/generator/XmlGenerator.java   | 40 +++++++++++---------
 .../ignite/schema/model/PojoDescriptor.java     | 35 +++++++++++++++++
 .../apache/ignite/schema/parser/DbIndex.java    | 39 -------------------
 .../apache/ignite/schema/parser/DbTable.java    |  7 ++++
 .../parser/dialect/JdbcMetadataDialect.java     | 10 +++++
 .../parser/dialect/OracleMetadataDialect.java   |  7 ++--
 7 files changed, 79 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fe9dd1b/modules/schema-load/pom.xml
----------------------------------------------------------------------
diff --git a/modules/schema-load/pom.xml b/modules/schema-load/pom.xml
index 8c5087c..06cd2b3 100644
--- a/modules/schema-load/pom.xml
+++ b/modules/schema-load/pom.xml
@@ -40,7 +40,6 @@
             <groupId>org.apache.ignite</groupId>
             <artifactId>ignite-core</artifactId>
             <version>${ignite.version}</version>
-            <scope>test</scope>
         </dependency>
 
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fe9dd1b/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
index b56ed51..f38d884 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
@@ -17,8 +17,9 @@
 
 package org.apache.ignite.schema.generator;
 
+import org.apache.ignite.cache.query.*;
+import org.apache.ignite.lang.*;
 import org.apache.ignite.schema.model.*;
-import org.apache.ignite.schema.parser.*;
 import org.apache.ignite.schema.ui.*;
 import org.w3c.dom.*;
 
@@ -68,10 +69,10 @@ public class XmlGenerator {
      * @param parent Parent XML node.
      * @param clazz Bean class.
      */
-    private static Element addBean(Document doc, Node parent, String clazz) {
+    private static Element addBean(Document doc, Node parent, Class<?> clazz) {
         Element elem = doc.createElement("bean");
 
-        elem.setAttribute("class", clazz);
+        elem.setAttribute("class", clazz.getName());
 
         parent.appendChild(elem);
 
@@ -174,7 +175,7 @@ public class XmlGenerator {
             Element list = addElement(doc, prop, "list");
 
             for (PojoField field : fields) {
-                Element item = addBean(doc, list, "org.apache.ignite.cache.query.CacheQueryTableColumnMetadata");
+                Element item = addBean(doc, list, CacheQueryTableColumnMetadata.class);
 
                 addProperty(doc, item, "dbName", field.dbName());
                 addProperty(doc, item, "dbType", String.valueOf(field.dbType()));
@@ -192,7 +193,9 @@ public class XmlGenerator {
      * @param pojo POJO descriptor.
      */
     private static void addTableMetadata(Document doc, Node parent, PojoDescriptor pojo,
boolean includeKeys) {
-        Element bean = addBean(doc, parent, "org.apache.ignite.cache.query.CacheQueryTableMetadata");
+        Element tblMeta = addProperty(doc, parent, "tableMetadata", null);
+
+        Element bean = addBean(doc, tblMeta, CacheQueryTableMetadata.class);
 
         addProperty(doc, bean, "schema", pojo.schema());
 
@@ -210,28 +213,29 @@ public class XmlGenerator {
      * @param parent Parent XML node.
      * @param groups Map with indexes.
      */
-    private static void addGroups(Document doc, Node parent, Map<String, LinkedHashMap<String,
DbIndex>> groups) {
+    private static void addGroups(Document doc, Node parent,
+        Map<String, Map<String, IgniteBiTuple<String, Boolean>>> groups)
{
         if (!groups.isEmpty()) {
             Element prop = addProperty(doc, parent, "groups", null);
 
             Element map = addElement(doc, prop, "map");
 
-            for (Map.Entry<String, LinkedHashMap<String, DbIndex>> group : groups.entrySet())
{
+            for (Map.Entry<String, Map<String, IgniteBiTuple<String, Boolean>>>
group : groups.entrySet()) {
                 Element entry1 = addElement(doc, map, "entry", "key", group.getKey());
 
                 Element val1 = addElement(doc, entry1, "map");
 
-                LinkedHashMap<String, DbIndex> fields = group.getValue();
+                Map<String, IgniteBiTuple<String, Boolean>> fields = group.getValue();
 
-                for (Map.Entry<String, DbIndex> field : fields.entrySet()) {
+                for (Map.Entry<String, IgniteBiTuple<String, Boolean>> field
: fields.entrySet()) {
                     Element entry2 = addElement(doc, val1, "entry", "key", field.getKey());
 
-                    Element val2 = addBean(doc, entry2, "org.apache.ignite.lang.IgniteBiTuple");
+                    Element val2 = addBean(doc, entry2, IgniteBiTuple.class);
 
-                    DbIndex idx = field.getValue();
+                    IgniteBiTuple<String, Boolean> idx = field.getValue();
 
-                    addElement(doc, val2, "constructor-arg", null, null, "value", idx.name());
-                    addElement(doc, val2, "constructor-arg", null, null, "value", String.valueOf(idx.descending()));
+                    addElement(doc, val2, "constructor-arg", null, null, "value", idx.get1());
+                    addElement(doc, val2, "constructor-arg", null, null, "value", String.valueOf(idx.get2()));
                 }
             }
         }
@@ -245,8 +249,9 @@ public class XmlGenerator {
      * @param pkg Package fo types.
      * @param pojo POJO descriptor.
      */
-    private static void addTypeMetadata(Document doc, Node parent, String pkg, PojoDescriptor
pojo, boolean includeKeys) {
-        Element bean = addBean(doc, parent, "org.apache.ignite.cache.query.CacheQueryTypeMetadata");
+    private static void addTypeMetadata(Document doc, Node parent, String pkg, PojoDescriptor
pojo,
+        boolean includeKeys) {
+        Element bean = addBean(doc, parent, CacheQueryTypeMetadata.class);
 
         addProperty(doc, bean, "type", pkg + "." + pojo.valueClassName());
 
@@ -260,7 +265,7 @@ public class XmlGenerator {
 
         addFields(doc, bean, "descendingFields", pojo.descendingFields());
 
-//        addGroups(doc, bean, typeMeta.getGroups());
+        addGroups(doc, bean, pojo.groups());
     }
 
     /**
@@ -271,7 +276,8 @@ public class XmlGenerator {
      * @param out File to output result.
      * @param askOverwrite Callback to ask user to confirm file overwrite.
      */
-    public static void generate(String pkg, PojoDescriptor pojo, boolean includeKeys, File
out, ConfirmCallable askOverwrite) {
+    public static void generate(String pkg, PojoDescriptor pojo, boolean includeKeys, File
out,
+        ConfirmCallable askOverwrite) {
         generate(pkg, Collections.singleton(pojo), includeKeys, out, askOverwrite);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fe9dd1b/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
index be69cc6..6b0f785 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
@@ -20,6 +20,7 @@ package org.apache.ignite.schema.model;
 import javafx.beans.property.*;
 import javafx.beans.value.*;
 import javafx.collections.*;
+import org.apache.ignite.lang.*;
 import org.apache.ignite.schema.parser.*;
 
 import java.math.*;
@@ -64,6 +65,9 @@ public class PojoDescriptor {
     /** Java class fields. */
     private final ObservableList<PojoField> fields;
 
+    /** Fields map for quick access. */
+    private final Map<String, PojoField> fieldsMap;
+
     /**
      * Constructor of POJO descriptor.
      *
@@ -116,6 +120,8 @@ public class PojoDescriptor {
 
         List<PojoField> flds = new ArrayList<>(cols.size());
 
+        fieldsMap = new HashMap<>(cols.size());
+
         for (DbColumn col : cols) {
             PojoField fld = new PojoField(col.name(), col.type(),
                 toJavaFieldName(col.name()), toJavaType(col.type(), col.nullable()).getName(),
@@ -124,6 +130,8 @@ public class PojoDescriptor {
             fld.owner(this);
 
             flds.add(fld);
+
+            fieldsMap.put(col.name(), fld);
         }
 
         fields = FXCollections.observableList(flds);
@@ -429,4 +437,31 @@ public class PojoDescriptor {
                 return Object.class;
         }
     }
+
+    /**
+     * Gets indexes groups.
+     */
+    public Map<String, Map<String, IgniteBiTuple<String, Boolean>>> groups()
{
+        Map<String, Map<String, Boolean>> idxs = tbl.indexes();
+
+        Map<String, Map<String, IgniteBiTuple<String, Boolean>>> groups
= new LinkedHashMap<>(idxs.size());
+
+        for (Map.Entry<String, Map<String, Boolean>> idx : idxs.entrySet()) {
+            String idxName = idx.getKey();
+
+            Map<String, Boolean> idxCols = idx.getValue();
+
+            Map<String, IgniteBiTuple<String, Boolean>> grp = new LinkedHashMap<>();
+
+            groups.put(idxName, grp);
+
+            for (Map.Entry<String, Boolean> idxCol : idxCols.entrySet()) {
+                PojoField fld = fieldsMap.get(idxCol.getKey());
+
+                grp.put(fld.javaName(), new IgniteBiTuple<>(fld.javaTypeName(), idxCol.getValue()));
+            }
+        }
+
+        return groups;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fe9dd1b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbIndex.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbIndex.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbIndex.java
deleted file mode 100644
index e94d1dc..0000000
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbIndex.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.schema.parser;
-
-/**
- * TODO: Add class description.
- */
-public class DbIndex {
-    private final String name;
-    private final boolean desc;
-
-    public DbIndex(String name, boolean desc) {
-        this.name = name;
-        this.desc = desc;
-    }
-
-    public String name() {
-        return name;
-    }
-
-    public boolean descending() {
-        return desc;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fe9dd1b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbTable.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbTable.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbTable.java
index 218d07b..35c7d91 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbTable.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbTable.java
@@ -95,4 +95,11 @@ public class DbTable {
     public Set<String> descendingColumns() {
         return descCols;
     }
+
+    /**
+     * @return Indexes.
+     */
+    public Map<String, Map<String, Boolean>> indexes() {
+        return idxs;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fe9dd1b/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 b0b47e9..4e34f35 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
@@ -91,10 +91,20 @@ public class JdbcMetadataDialect extends DatabaseMetadataDialect {
                                 if (idxName == null || colName == null)
                                     continue;
 
+                                Map<String, Boolean> idx = idxs.get(idxName);
+
+                                if (idx == null) {
+                                    idx = new LinkedHashMap<>();
+
+                                    idxs.put(idxName, idx);
+                                }
+
                                 String askOrDesc = idxRs.getString("ASC_OR_DESC");
 
                                 Boolean desc = askOrDesc != null ? "D".equals(askOrDesc)
: null;
 
+                                idx.put(colName, desc);
+
                                 if (desc != null) {
                                     if (desc)
                                         descCols.add(colName);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fe9dd1b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/OracleMetadataDialect.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/OracleMetadataDialect.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/OracleMetadataDialect.java
index 222d1b6..304c911 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/OracleMetadataDialect.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/OracleMetadataDialect.java
@@ -101,7 +101,7 @@ public class OracleMetadataDialect extends DatabaseMetadataDialect {
         try (Statement stmt = conn.createStatement()) {
             Collection<DbColumn> cols = new ArrayList<>();
 
-            try(ResultSet colsRs = stmt.executeQuery(String.format(SQL_COLUMNS, "TEST")))
{
+            try (ResultSet colsRs = stmt.executeQuery(String.format(SQL_COLUMNS, "TEST")))
{
                 String prevSchema = "";
                 String prevTbl = "";
 
@@ -133,8 +133,9 @@ public class OracleMetadataDialect extends DatabaseMetadataDialect {
                 }
 
                 if (!cols.isEmpty())
-                    tbls.add(new DbTable(prevSchema, prevTbl, cols, Collections.<String>emptySet(),
-                        Collections.<String>emptySet(), null));
+                    tbls.add(new DbTable(prevSchema, prevTbl, cols,
+                        Collections.<String>emptySet(), Collections.<String>emptySet(),
+                        Collections.<String, Map<String, Boolean>>emptyMap()));
             }
         }
 


Mime
View raw message