*/
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;
*/
public static class NodeBuilder
{
- private int nodeID = INVALID_ID;
+ private long nodeID = INVALID_ID;
private String nodeValue = NULL_TEXT;
public NodeBuilder()
this.nodeValue = node.nodeValue;
}
- public NodeBuilder nodeID(int nodeID)
+ public NodeBuilder nodeID(long nodeID)
{
this.nodeID = nodeID;
return this;
//--------------------------------------\r
package org.xerial.relation;\r
\r
-\r
/**\r
* Node is an element ({@link Cell}) of a relation.\r
* \r
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
*/\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
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
--- /dev/null
+/*--------------------------------------------------------------------------\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
final AmoebaJoinHandler handler;
// for running amoeba join
- int nodeCount = 0;
+ long nodeCount = 0;
Lattice<String> nodeNameLattice = new Lattice<String>();
LatticeCursor<String> latticeCursor;
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);
}
if (coreNode_action.containsKey(contextNode))
{
coreNode_action.get(contextNode).execute(nodeName, textData);
+ return;
}
}
}
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);
}
}
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);
}
}
{
Schema s = each.schema;
- coreNode_action.put(each.previouslyFoundTag, new PopRelation(s, each.newlyFoundTag));
+ coreNode_action.put(each.coreNodeName, new PopRelation(s, each.newlyFoundNodeName));
}
}
for (PushRelation each : foundAction)
{
actionList.add(each);
- backActionList.add(new PopRelation(each.schema, each.newlyFoundTag));
+ backActionList.add(new PopRelation(each.schema, each.newlyFoundNodeName));
}
}