TurtleDB
A mini distributed database system
src/ca/uqac/dim/turtledb/UnaryRelation.java
Go to the documentation of this file.
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 public abstract class UnaryRelation extends Relation
00021 {
00022   protected Relation m_relation;
00023   
00024   public void setRelation(Relation r)
00025   {
00026     m_relation = r;
00027   }
00028 
00029   
00030   public int tupleCount()
00031   {
00032     return m_relation.tupleCount();
00033   }
00034   
00035   protected abstract class UnaryRelationStreamIterator extends RelationStreamIterator
00036   {
00037     protected RelationIterator m_childIterator;
00038     
00039     public UnaryRelationStreamIterator()
00040     {
00041       super();
00042       m_childIterator = m_relation.streamIterator();
00043     }
00044     
00045     @Override
00046     public void reset()
00047     {
00048       super.reset();
00049       m_childIterator.reset();
00050     }
00051   }
00052   
00053   protected abstract class UnaryRelationCacheIterator extends RelationCacheIterator
00054   {
00055     protected void getIntermediateResult()
00056     {
00057       Table tab_out = new Table(m_relation.getSchema());
00058       RelationIterator it = m_relation.cacheIterator();
00059       while (it.hasNext())
00060       {
00061         Tuple t = it.next();
00062         tab_out.put(t);
00063       }
00064       m_intermediateResult = tab_out;
00065     }
00066   }
00067 }