1 package com.daffodilwoods.daffodildb.server.sql99.dql.iterator.table; 2 3 import com.daffodilwoods.daffodildb.server.sql99.common.*; 4 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 5 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 6 import com.daffodilwoods.database.resource.*; 7 import com.daffodilwoods.database.sqlinitiator.*; 8 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Utility; 9 import com.daffodilwoods.daffodildb.utils.field.FieldLiteral; 10 import com.daffodilwoods.daffodildb.utils.FieldUtility; 11 12 22 public class AbstractQualifiedJoinIterator extends BaseJoinIterator implements SimpleConstants { 23 24 27 protected int leftColumnCount = -1; 28 31 protected int rightColumnCount = -1; 32 35 protected _KeyColumnInformation[] leftKeyColumnInformation; 36 39 protected _KeyColumnInformation[] rightKeyColumnInformation; 40 44 protected Object [][] tableDetailsMapping; 45 48 protected int leftKeyCount = 0; 49 52 protected int rightKeyCount = 0; 53 56 protected TableDetails[] leftTableDetails = null; 57 60 protected TableDetails[] rightTableDetails = null; 61 62 68 protected boolean rightNull; 69 70 71 75 protected Object [] nullFieldLiterals; 76 77 78 public AbstractQualifiedJoinIterator(_Iterator leftIterator0, _Iterator rightIterator0, _KeyColumnInformation[] leftKeyColumnInformation0, _KeyColumnInformation[] rightKeyColumnInformation0, ColumnDetails[] hasRecordReferences0) { 79 super(leftIterator0, rightIterator0, hasRecordReferences0); 80 leftKeyColumnInformation = leftKeyColumnInformation0; 81 rightKeyColumnInformation = rightKeyColumnInformation0; 82 state = INVALIDSTATE; 83 } 84 85 93 public void setKeyCount(Object [][] tableAndKeyCount) throws DException { 94 int[] count = GeneralPurposeStaticClass.getLeftandRightKeyCount(leftIterator,rightIterator,tableAndKeyCount,tableDetailsMapping); 95 leftTableDetails = leftIterator.getTableDetails(); 96 rightTableDetails = rightIterator.getTableDetails(); 97 leftKeyCount = count[0]; 98 rightKeyCount = count[1]; 99 } 100 101 102 109 public TableDetails[] getTableDetails() throws com.daffodilwoods.database.resource.DException { 110 TableDetails[] tableDetails1 = leftIterator.getTableDetails(); 111 leftColumnCount = GeneralPurposeStaticClass.getColumnCount(tableDetails1); 112 TableDetails[] tableDetails2 = rightIterator.getTableDetails(); 113 rightColumnCount = GeneralPurposeStaticClass.getColumnCount(tableDetails2); 114 int len = tableDetails1.length + tableDetails2.length; 115 tableDetailsMapping = new Object [len][2]; 116 int i = 0; 117 Integer flag = new Integer (SimpleConstants.LEFT); 118 for (int j = 0; j < tableDetails1.length; j++) { 119 tableDetailsMapping[i][0] = tableDetails1[j]; 120 tableDetailsMapping[i++][1] = flag; 121 } 122 flag = new Integer (SimpleConstants.RIGHT); 123 for (int j = 0; j < tableDetails2.length; j++) { 124 tableDetailsMapping[i][0] = tableDetails2[j]; 125 tableDetailsMapping[i++][1] = flag; 126 } 127 TableDetails[] resultantTableDetails = new TableDetails[len]; 128 System.arraycopy(tableDetails1, 0, resultantTableDetails, 0, tableDetails1.length); 129 System.arraycopy(tableDetails2, 0, resultantTableDetails, tableDetails1.length, tableDetails2.length); 130 return resultantTableDetails; 131 } 132 133 141 public _Order getDefaultOrder() throws DException { 142 return GeneralPurposeStaticClass.getJoinOrdered(leftIterator.getDefaultOrder(), rightIterator.getDefaultOrder()); 143 } 144 145 151 public _KeyColumnInformation[] getKeyColumnInformations() throws DException { 152 int len = leftKeyColumnInformation.length + rightKeyColumnInformation.length; 153 _KeyColumnInformation[] resultantKeyColumnInformation = new _KeyColumnInformation[len]; 154 System.arraycopy(leftKeyColumnInformation, 0, resultantKeyColumnInformation, 0, leftKeyColumnInformation.length); 155 System.arraycopy(rightKeyColumnInformation, 0, resultantKeyColumnInformation, leftKeyColumnInformation.length, rightKeyColumnInformation.length); 156 return resultantKeyColumnInformation; 157 } 158 159 168 protected boolean isKeyNull(byte[] rightKeys) throws DException { 169 int length = rightKeys.length; 170 for (int i = 0; i < length; i++) 171 if(rightKeys[i] != -1) 172 return false; 173 return true; 174 } 175 176 185 protected boolean isKeyNull(Object [] rightKeys) throws DException { 186 int length = rightKeys.length; 187 for (int i = 0; i < length; i++) { 188 if (rightKeys[i] != null) { 189 return false; 190 } 191 } 192 return true; 193 } 194 195 201 public boolean seek(Object indexKey) throws DException { 202 return GeneralPurposeStaticClass.seek(indexKey, leftIterator, rightIterator); 203 } 204 205 212 public Object [] getUniqueColumnReference() throws DException { 213 return GeneralPurposeStaticClass.getUniqueColumnReference(leftIterator, rightIterator); 214 } 215 216 224 public _Iterator getBaseIteratorHasRecord(ColumnDetails hasRecordColumn) throws DException { 225 if (hasRecordReferences != null) { 226 for (int i = 0, length = hasRecordReferences.length; i < length; i++) { 227 if (hasRecordReferences[i] == hasRecordColumn) { 228 return this; 229 } 230 } 231 } 232 _Iterator iterator = leftIterator.getBaseIteratorHasRecord(hasRecordColumn); 233 if (iterator != null) { 234 return iterator; 235 } 236 return rightIterator.getBaseIteratorHasRecord(hasRecordColumn); 237 } 238 239 240 247 public Object getHasRecordColumnValues() throws DException { 248 249 return Utility.getBooleanValue(!rightNull); 250 } 251 252 260 protected Object [] makeNullFieldLiteralArray(int length) throws DException { 261 if (nullFieldLiterals != null && nullFieldLiterals.length == length) 262 return nullFieldLiterals; 263 264 nullFieldLiterals = new FieldLiteral[length]; 265 for (int i = 0; i < nullFieldLiterals.length; i++) { 266 nullFieldLiterals[i] = new FieldLiteral(FieldUtility.NULLBUFFERRANGE, -1); 267 } 268 return nullFieldLiterals; 269 } 270 271 272 } 273 | Popular Tags |