TurtleDB
A mini distributed database system
|
00001 /*------------------------------------------------------------------------- 00002 Simple distributed database engine 00003 Copyright (C) 2012 Sylvain Hallé 00004 00005 This program is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 -------------------------------------------------------------------------*/ 00018 package ca.uqac.dim.turtledb; 00019 00020 import ca.uqac.dim.turtledb.QueryVisitor.VisitorException; 00021 00026 public abstract class BinaryRelation extends Relation 00027 { 00028 protected Relation m_left; 00029 protected Relation m_right; 00030 00031 public void setLeft(Relation r) 00032 { 00033 m_left = r; 00034 } 00035 00036 public void setRight(Relation r) 00037 { 00038 m_right = r; 00039 } 00040 00041 public Relation getLeft() 00042 { 00043 return m_left; 00044 } 00045 00046 public Relation getRight() 00047 { 00048 return m_right; 00049 } 00050 00051 protected void acceptBinary(QueryVisitor v) throws VisitorException 00052 { 00053 m_left.accept(v); 00054 m_right.accept(v); 00055 } 00056 00057 @Override 00058 public int tupleCount() 00059 { 00060 return m_left.tupleCount() + m_right.tupleCount(); 00061 } 00062 00063 protected abstract class BinaryRelationStreamIterator extends RelationStreamIterator 00064 { 00065 00066 } 00067 00068 protected class BinaryRelationCacheIterator extends RelationCacheIterator 00069 { 00070 protected Table m_intermediateLeft; 00071 protected Table m_intermediateRight; 00072 00073 @Override 00074 protected void getIntermediateResult() 00075 { 00076 RelationIterator it = null; 00077 it = m_left.cacheIterator(); 00078 m_intermediateLeft = new Table(m_left.getSchema()); 00079 while (it.hasNext()) 00080 { 00081 Tuple t = it.next(); 00082 m_intermediateLeft.put(t); 00083 } 00084 it = m_right.cacheIterator(); 00085 m_intermediateRight = new Table(m_right.getSchema()); 00086 while (it.hasNext()) 00087 { 00088 Tuple t = it.next(); 00089 m_intermediateRight.put(t); 00090 } 00091 m_intermediateRight = new Table(m_right.getSchema()); 00092 } 00093 } 00094 00095 }