{\r
super(targetClass, parameterName);\r
this.targetField = targetField;\r
+\r
+ if (!targetField.isAccessible())\r
+ targetField.setAccessible(true);\r
}\r
\r
@Override\r
{\r
public void visitNode(NodeType node);\r
\r
- public void visitTuple(IndexAccess<NodeType> tuple);\r
+ public void visitTuple(Tuple<NodeType> tuple);\r
\r
}\r
--- /dev/null
+/*--------------------------------------------------------------------------
+ * Copyright 2009 Taro L. Saito
+ *
+ * Licensed 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.
+ *--------------------------------------------------------------------------*/
+//--------------------------------------
+// XerialJ
+//
+// DataType.java
+// Since: May 14, 2009 11:26:50 AM
+//
+// $URL$
+// $Author$
+//--------------------------------------
+package org.xerial.relation;
+
+/**
+ * Definition of the data types for schema node
+ *
+ * @author leo
+ *
+ */
+public enum DataType {
+
+ BOOL, BYTE, I16, I32, I64, STRING, DOUBLE, BINARY;
+
+}
--- /dev/null
+/*--------------------------------------------------------------------------
+ * Copyright 2009 Taro L. Saito
+ *
+ * Licensed 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.
+ *--------------------------------------------------------------------------*/
+//--------------------------------------
+// XerialJ
+//
+// LNode.java
+// Since: May 14, 2009 11:36:59 AM
+//
+// $URL$
+// $Author$
+//--------------------------------------
+package org.xerial.relation;
+
+/**
+ * Light-weight node that holds only a node ID and node value.
+ *
+ * @author leo
+ *
+ */
+public class LNode extends NodeBase<LNode>
+{
+ private final static int INVALID_ID = -1;
+ private final static String NULL_TEXT = null;
+
+ public final int nodeID;
+ public final String nodeValue;
+
+ public LNode(int nodeID, String nodeValue)
+ {
+ this.nodeID = nodeID;
+ this.nodeValue = nodeValue;
+ }
+
+ /**
+ * Builder class for {@link Node}
+ *
+ * @author leo
+ *
+ */
+ public static class NodeBuilder
+ {
+ private int nodeID = INVALID_ID;
+ private String nodeValue = NULL_TEXT;
+
+ public NodeBuilder()
+ {}
+
+ public NodeBuilder(Node node)
+ {
+ this.nodeID = node.nodeID;
+ this.nodeValue = node.nodeValue;
+ }
+
+ public NodeBuilder nodeID(int nodeID)
+ {
+ this.nodeID = nodeID;
+ return this;
+ }
+
+ public NodeBuilder nodeValue(String nodeValue)
+ {
+ this.nodeValue = nodeValue;
+ return this;
+ }
+
+ public LNode build()
+ {
+ return new LNode(nodeID, nodeValue);
+ }
+
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder buf = new StringBuilder();
+ buf.append(nodeID);
+ if (nodeValue != null)
+ {
+ buf.append(":");
+ buf.append(nodeValue);
+ }
+ return buf.toString();
+ }
+
+}
* \r
* @param <NodeType>\r
*/\r
-public abstract class NodeBase<NodeType> implements TupleCell<NodeType, IndexAccess<NodeType>>\r
+public abstract class NodeBase<NodeType> implements TupleCell<NodeType>\r
{\r
protected NodeBase()\r
{}\r
* @author leo\r
* \r
*/\r
-public class Tuple<NodeType> implements IndexAccess<NodeType>\r
+public class Tuple<NodeType> implements TupleCell<NodeType>, Iterable<TupleCell<NodeType>>\r
{\r
\r
- private final List<TupleCell<NodeType, Tuple<NodeType>>> nodeList;\r
+ private final List<TupleCell<NodeType>> nodeList;\r
\r
public Tuple()\r
{\r
- this.nodeList = new ArrayList<TupleCell<NodeType, Tuple<NodeType>>>();\r
+ this.nodeList = new ArrayList<TupleCell<NodeType>>();\r
}\r
\r
public Tuple(Tuple<NodeType> other)\r
\r
public Tuple(int tupleSize)\r
{\r
- this.nodeList = new ArrayList<TupleCell<NodeType, Tuple<NodeType>>>(tupleSize);\r
+ this.nodeList = new ArrayList<TupleCell<NodeType>>(tupleSize);\r
}\r
\r
- public Tuple(List<TupleCell<NodeType, Tuple<NodeType>>> nodeList)\r
+ public Tuple(List<TupleCell<NodeType>> nodeList)\r
{\r
- this.nodeList = new ArrayList<TupleCell<NodeType, Tuple<NodeTpe>>>(nodeList.size());\r
- for (TupleCell<NodeType, Tuple<NodeType>> each : nodeList)\r
+ this.nodeList = new ArrayList<TupleCell<NodeType>>(nodeList.size());\r
+ for (TupleCell<NodeType> each : nodeList)\r
{\r
this.nodeList.add(each);\r
}\r
\r
}\r
\r
- public void accept(CellVisitor visitor)\r
+ public Tuple<NodeType> getTuple()\r
{\r
- visitor.visitTuple(this);\r
+ return this;\r
}\r
\r
- public Tuple<NodeType> getTuple()\r
+ public void accept(CellVisitor<NodeType> visitor)\r
{\r
- return this;\r
+ visitor.visitTuple(this);\r
}\r
\r
}\r
public interface TupleCell<NodeType>\r
{\r
/**\r
- * Returns true if this cell is a singleton node\r
+ * Returns true if this cell is a singleton\r
* \r
* @return\r
*/\r
public boolean isNode();\r
\r
/**\r
- * Returns true if this cell is a node tuple\r
+ * Returns true if this cell is a tuple\r
* \r
* @return\r
*/\r
NodeType getNode();\r
\r
/**\r
+ * If this cell is tuple, then return tuple. otherwise return null\r
+ * \r
+ * @return\r
+ */\r
+ Tuple<NodeType> getTuple();\r
+\r
+ /**\r
* Accept the visitor\r
* \r
* @param visitor\r
* @author leo
*
*/
-public class RelationalSchema extends Tuple<SchemaNode>
+public class RelationalSchema
{
+ public final String name;
+ public final Tuple<SchemaNode> schema;
+
+ public RelationalSchema(String name, Tuple<SchemaNode> schema)
+ {
+ this.name = name;
+ this.schema = schema;
+ }
+
+ @Override
+ public String toString()
+ {
+ return String.format("schema %s %s", name, schema);
+ }
}
//--------------------------------------\r
package org.xerial.relation.schema;\r
\r
+import java.io.Serializable;\r
+\r
+import org.xerial.relation.DataType;\r
import org.xerial.relation.NodeBase;\r
\r
/**\r
* @author leo\r
* \r
*/\r
-public class SchemaNode extends NodeBase<SchemaNode>\r
+public class SchemaNode extends NodeBase<SchemaNode> implements Serializable\r
{\r
- private String name;\r
+ /**\r
+ * \r
+ */\r
+ private static final long serialVersionUID = 1L;\r
+\r
+ public final String name;\r
+ public final DataType type;\r
\r
- public SchemaNode(String name)\r
+ public SchemaNode(String name, DataType type)\r
{\r
this.name = name;\r
+ this.type = type;\r
}\r
\r
public String getName()\r
return name;\r
}\r
\r
+ @Override\r
+ public String toString()\r
+ {\r
+ return String.format("%s %s", name, type.name().toLowerCase());\r
+ }\r
+\r
}\r
--- /dev/null
+/*--------------------------------------------------------------------------
+ * Copyright 2009 Taro L. Saito
+ *
+ * Licensed 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.
+ *--------------------------------------------------------------------------*/
+//--------------------------------------
+// XerialJ
+//
+// SchemaNodeTest.java
+// Since: May 14, 2009 11:51:53 AM
+//
+// $URL$
+// $Author$
+//--------------------------------------
+package org.xerial.relation.schema;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Field;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.xerial.relation.DataType;
+
+public class SchemaNodeTest
+{
+
+ @Before
+ public void setUp() throws Exception
+ {}
+
+ @After
+ public void tearDown() throws Exception
+ {}
+
+ @Test
+ public void objectSerialization() throws Exception
+ {
+ ByteArrayOutputStream buf = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(buf);
+
+ SchemaNode s = new SchemaNode("id", DataType.I64);
+ out.writeObject(s);
+ out.close();
+
+ ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray()));
+ SchemaNode s2 = (SchemaNode) in.readObject();
+
+ assertEquals(s.name, s2.name);
+ assertEquals(s.type, s2.type);
+ }
+
+ @Test
+ public void overcomeFinal() throws Exception
+ {
+ SchemaNode s = new SchemaNode("id", DataType.I64);
+ Field f = s.getClass().getField("name");
+ f.setAccessible(true);
+ f.set(s, "hello");
+
+ assertEquals("hello", s.name);
+
+ }
+
+}