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 00027 public class VariableTable extends UnaryRelation 00028 { 00032 protected String m_name; 00033 00037 protected String m_site; 00038 00039 protected VariableTable() 00040 { 00041 super(); 00042 m_name = ""; 00043 m_site = ""; 00044 } 00045 00046 public VariableTable(String name) 00047 { 00048 this(); 00049 m_name = name; 00050 } 00051 00052 public VariableTable(String name, String site) 00053 { 00054 this(); 00055 m_name = name; 00056 m_site = site; 00057 } 00058 00064 public void setSite(String site) 00065 { 00066 m_site = site; 00067 } 00068 00076 public String getSite() 00077 { 00078 return m_site; 00079 } 00080 00081 @Override 00082 public Schema getSchema() 00083 { 00084 if (m_relation != null) 00085 return m_relation.getSchema(); 00086 else 00087 return null; 00088 } 00089 00090 @Override 00091 public void accept(QueryVisitor v) throws EmptyQueryVisitor.VisitorException 00092 { 00093 if (m_relation != null) 00094 m_relation.accept(v); 00095 v.visit(this); 00096 } 00097 00098 @Override 00099 public String toString() 00100 { 00101 if (m_relation == null) 00102 return "?" + m_name; 00103 return m_relation.toString(); 00104 } 00105 00110 public void setName(String name) 00111 { 00112 m_name = name; 00113 } 00114 00119 public String getName() 00120 { 00121 return m_name; 00122 } 00123 00124 @Override 00125 public int tupleCount() 00126 { 00127 if (m_relation == null) 00128 return 0; 00129 return m_relation.tupleCount(); 00130 } 00131 00132 @Override 00133 public final boolean isFragment() 00134 { 00135 return true; 00136 } 00137 00138 @Override 00139 public boolean equals(Object o) 00140 { 00141 if (o == null) 00142 return false; 00143 if (!(o instanceof VariableTable)) 00144 return false; 00145 return equals((VariableTable) o); 00146 } 00147 00148 public boolean equals(VariableTable t) 00149 { 00150 if (t == null) 00151 return false; 00152 return t.m_name.compareTo(m_name) == 0; 00153 } 00154 00155 @Override 00156 public boolean isLeaf() 00157 { 00158 // A VariableTable is a leaf only when it has not 00159 // yet been connected to a relation 00160 if (m_relation == null) 00161 return true; 00162 if (m_relation instanceof VariableTable) 00163 { 00164 VariableTable vt = (VariableTable) m_relation; 00165 return vt.isLeaf(); 00166 } 00167 return false; 00168 } 00169 00170 protected class VariableTableStreamIterator extends UnaryRelationStreamIterator 00171 { 00172 protected RelationIterator m_iterator = null; 00173 00174 protected Tuple m_nextTuple; 00175 00176 public VariableTableStreamIterator() 00177 { 00178 super(); 00179 reset(); 00180 } 00181 00182 @Override 00183 protected Tuple internalNext() 00184 { 00185 if (m_iterator == null) 00186 return null; 00187 if (!m_iterator.hasNext()) 00188 return null; 00189 return (m_iterator.next()); 00190 } 00191 00192 @Override 00193 public void reset() 00194 { 00195 if (m_relation != null) 00196 m_iterator = m_relation.streamIterator(); 00197 } 00198 } 00199 00200 protected class VariableTableCacheIterator extends UnaryRelationCacheIterator 00201 { 00202 protected RelationIterator m_iterator = null; 00203 00204 protected Tuple m_nextTuple; 00205 00206 public VariableTableCacheIterator() 00207 { 00208 super(); 00209 reset(); 00210 } 00211 00212 @Override 00213 public void reset() 00214 { 00215 if (m_relation != null) 00216 m_iterator = m_relation.cacheIterator(); 00217 } 00218 } 00219 00220 @Override 00221 public RelationStreamIterator streamIterator() 00222 { 00223 return new VariableTableStreamIterator(); 00224 } 00225 00226 @Override 00227 public RelationIterator cacheIterator() 00228 { 00229 return new VariableTableCacheIterator(); 00230 } 00231 00232 }