OSDN Git Service

git-svn-id: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core@3297 ae02f08e...
authorleo <leo@ae02f08e-27ec-0310-ae8c-8ba02fe2eafd>
Tue, 19 May 2009 01:09:39 +0000 (01:09 +0000)
committerleo <leo@ae02f08e-27ec-0310-ae8c-8ba02fe2eafd>
Tue, 19 May 2009 01:09:39 +0000 (01:09 +0000)
src/main/java/org/xerial/relation/LNode.java
src/main/java/org/xerial/relation/Node.java
src/main/java/org/xerial/relation/query/AmoebaJoinHandler.java
src/main/java/org/xerial/relation/query/AmoebaJoinHandlerBase.java [new file with mode: 0644]
src/main/java/org/xerial/relation/query/StreamAmoebaJoin.java

index b5857c8..12b389e 100644 (file)
@@ -32,13 +32,13 @@ package org.xerial.relation;
  */
 public class LNode extends NodeBase<LNode>
 {
-    private final static int INVALID_ID = -1;
+    private final static long INVALID_ID = -1;
     private final static String NULL_TEXT = null;
 
-    public final int nodeID;
+    public final long nodeID;
     public final String nodeValue;
 
-    public LNode(int nodeID, String nodeValue)
+    public LNode(long nodeID, String nodeValue)
     {
         this.nodeID = nodeID;
         this.nodeValue = nodeValue;
@@ -52,7 +52,7 @@ public class LNode extends NodeBase<LNode>
      */
     public static class NodeBuilder
     {
-        private int nodeID = INVALID_ID;
+        private long nodeID = INVALID_ID;
         private String nodeValue = NULL_TEXT;
 
         public NodeBuilder()
@@ -64,7 +64,7 @@ public class LNode extends NodeBase<LNode>
             this.nodeValue = node.nodeValue;
         }
 
-        public NodeBuilder nodeID(int nodeID)
+        public NodeBuilder nodeID(long nodeID)
         {
             this.nodeID = nodeID;
             return this;
index 7e2641f..9022d89 100644 (file)
@@ -24,7 +24,6 @@
 //--------------------------------------\r
 package org.xerial.relation;\r
 \r
-\r
 /**\r
  * Node is an element ({@link Cell}) of a relation.\r
  * \r
@@ -36,11 +35,11 @@ public class Node extends NodeBase<Node>
     public static final int INVALID_ID = -1;\r
     public static final String NULL_TEXT = null;\r
 \r
-    public final int nodeID;\r
+    public final long nodeID;\r
     public final String nodeName;\r
     public final String nodeValue;\r
 \r
-    private Node(String nodeName, int nodeID, String nodeValue)\r
+    private Node(String nodeName, long nodeID, String nodeValue)\r
     {\r
         this.nodeID = nodeID;\r
         this.nodeName = nodeName;\r
@@ -55,7 +54,7 @@ public class Node extends NodeBase<Node>
      */\r
     public static class NodeBuilder\r
     {\r
-        private int nodeID = INVALID_ID;\r
+        private long nodeID = INVALID_ID;\r
         private String nodeValue = NULL_TEXT;\r
         private final String nodeName;\r
 \r
@@ -71,7 +70,7 @@ public class Node extends NodeBase<Node>
             this.nodeValue = node.nodeValue;\r
         }\r
 \r
-        public NodeBuilder nodeID(int nodeID)\r
+        public NodeBuilder nodeID(long nodeID)\r
         {\r
             this.nodeID = nodeID;\r
             return this;\r
index da12d26..6268f8d 100644 (file)
@@ -29,9 +29,9 @@ import org.xerial.relation.schema.Schema;
 
 public interface AmoebaJoinHandler
 {
-    public void newAmoeba(Schema schema, Node n1, Node n2);
+    public void newAmoeba(Schema schema, Node coreNode, Node attributeNode);
 
     public void leaveNode(Schema schema, Node node);
 
-    public void text(Schema schema, Node contextNode, String nodeName, String text);
+    public void text(Schema schema, Node coreNode, String nodeName, String text);
 }
diff --git a/src/main/java/org/xerial/relation/query/AmoebaJoinHandlerBase.java b/src/main/java/org/xerial/relation/query/AmoebaJoinHandlerBase.java
new file mode 100644 (file)
index 0000000..7f1caea
--- /dev/null
@@ -0,0 +1,54 @@
+/*--------------------------------------------------------------------------\r
+ *  Copyright 2009 Taro L. Saito\r
+ *\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ *--------------------------------------------------------------------------*/\r
+//--------------------------------------\r
+// XerialJ\r
+//\r
+// AmoebaJoinHandlerBase.java\r
+// Since: 2009/05/18 19:15:42\r
+//\r
+// $URL$\r
+// $Author$\r
+//--------------------------------------\r
+package org.xerial.relation.query;\r
+\r
+import org.xerial.relation.Node;\r
+import org.xerial.relation.schema.Schema;\r
+\r
+/**\r
+ * An empty implementation of {@link AmoebaJoinHandler}\r
+ * \r
+ * @author leo\r
+ * \r
+ */\r
+public class AmoebaJoinHandlerBase implements AmoebaJoinHandler\r
+{\r
+\r
+    public void leaveNode(Schema schema, Node node)\r
+    {\r
+\r
+    }\r
+\r
+    public void newAmoeba(Schema schema, Node coreNode, Node attributeNode)\r
+    {\r
+\r
+    }\r
+\r
+    public void text(Schema schema, Node coreNode, String nodeName, String text)\r
+    {\r
+\r
+    }\r
+\r
+}\r
index d932cd5..6828ed1 100644 (file)
@@ -77,7 +77,7 @@ public class StreamAmoebaJoin implements TreeVisitor
     final AmoebaJoinHandler handler;
 
     // for running amoeba join
-    int nodeCount = 0;
+    long nodeCount = 0;
     Lattice<String> nodeNameLattice = new Lattice<String>();
     LatticeCursor<String> latticeCursor;
 
@@ -106,33 +106,23 @@ public class StreamAmoebaJoin implements TreeVisitor
     class SimpleTextOperation implements TextOperation
     {
         final Schema schema;
-        final String contextNodeName;
+        final String coreNodeName;
 
         public SimpleTextOperation(Schema schema, String contextNodeName)
         {
             this.schema = schema;
-            this.contextNodeName = contextNodeName;
+            this.coreNodeName = contextNodeName;
         }
 
         public SimpleTextOperation(PushRelation pr)
         {
             this.schema = pr.schema;
-            if (isCoreNodeIndex(schema.getNodeIndex(pr.previouslyFoundTag)))
-            {
-                this.contextNodeName = pr.previouslyFoundTag;
-            }
-            else if (isCoreNodeIndex(schema.getNodeIndex(pr.newlyFoundTag)))
-            {
-                this.contextNodeName = pr.newlyFoundTag;
-            }
-            else
-                throw new XerialError(XerialErrorCode.INVALID_STATE, "no core node in action: " + pr);
-
+            this.coreNodeName = pr.coreNodeName;
         }
 
         public void execute(String nodeName, String textData)
         {
-            Deque<Node> nodeStack = getNodeStack(contextNodeName);
+            Deque<Node> nodeStack = getNodeStack(coreNodeName);
             Node contextNode = nodeStack.getLast();
             handler.text(schema, contextNode, nodeName, textData);
         }
@@ -158,6 +148,7 @@ public class StreamAmoebaJoin implements TreeVisitor
                 if (coreNode_action.containsKey(contextNode))
                 {
                     coreNode_action.get(contextNode).execute(nodeName, textData);
+                    return;
                 }
             }
         }
@@ -178,32 +169,44 @@ public class StreamAmoebaJoin implements TreeVisitor
     class PushRelation implements Operation
     {
         final Schema schema;
-        final String previouslyFoundTag;
-        final String newlyFoundTag;
+        final String coreNodeName;
+        final String attributeNodeName;
+        final String newlyFoundNodeName;
 
         public PushRelation(Schema schema, String previouslyFoundTag, String newlyFoundTag)
         {
             this.schema = schema;
-            this.previouslyFoundTag = previouslyFoundTag;
-            this.newlyFoundTag = newlyFoundTag;
+            this.newlyFoundNodeName = newlyFoundTag;
+
+            if (isCoreNodeIndex(schema.getNodeIndex(previouslyFoundTag)))
+            {
+                this.coreNodeName = previouslyFoundTag;
+                this.attributeNodeName = newlyFoundTag;
+            }
+            else if (isCoreNodeIndex(schema.getNodeIndex(newlyFoundTag)))
+            {
+                this.coreNodeName = newlyFoundTag;
+                this.attributeNodeName = previouslyFoundTag;
+            }
+            else
+                throw new XerialError(XerialErrorCode.INVALID_STATE, "no core node in " + schema);
         }
 
         public void execute()
         {
-            Node knownNode = getNodeStack(previouslyFoundTag).getLast();
-            Node newNode = getNodeStack(newlyFoundTag).getLast();
+            Node coreNode = getNodeStack(coreNodeName).getLast();
+            Node attributeNode = getNodeStack(attributeNodeName).getLast();
 
             if (_logger.isTraceEnabled())
-                _logger.trace(String.format("push:(%s, %s)", knownNode, newNode));
-
-            handler.newAmoeba(schema, knownNode, newNode);
+                _logger.trace(String.format("push:(%s, %s)", coreNode, attributeNode));
 
+            handler.newAmoeba(schema, coreNode, attributeNode);
         }
 
         @Override
         public String toString()
         {
-            return String.format("push: %s for (%s, %s)", schema, previouslyFoundTag, newlyFoundTag);
+            return String.format("push: %s for (%s, %s)", schema, coreNodeName, attributeNodeName);
         }
     }
 
@@ -216,17 +219,7 @@ public class StreamAmoebaJoin implements TreeVisitor
             for (PushRelation each : candidates)
             {
                 Schema s = each.schema;
-
-                if (isCoreNodeIndex(s.getNodeIndex(each.previouslyFoundTag)))
-                {
-                    coreNode_action.put(each.previouslyFoundTag, each);
-                }
-                else if (isCoreNodeIndex(s.getNodeIndex(each.newlyFoundTag)))
-                {
-                    coreNode_action.put(each.newlyFoundTag, each);
-                }
-                else
-                    throw new XerialError(XerialErrorCode.INVALID_STATE, "no core node is found");
+                coreNode_action.put(each.coreNodeName, each);
             }
         }
 
@@ -258,7 +251,7 @@ public class StreamAmoebaJoin implements TreeVisitor
             {
                 Schema s = each.schema;
 
-                coreNode_action.put(each.previouslyFoundTag, new PopRelation(s, each.newlyFoundTag));
+                coreNode_action.put(each.coreNodeName, new PopRelation(s, each.newlyFoundNodeName));
             }
         }
 
@@ -502,7 +495,7 @@ public class StreamAmoebaJoin implements TreeVisitor
                 for (PushRelation each : foundAction)
                 {
                     actionList.add(each);
-                    backActionList.add(new PopRelation(each.schema, each.newlyFoundTag));
+                    backActionList.add(new PopRelation(each.schema, each.newlyFoundNodeName));
                 }
             }