1 package com.daffodilwoods.daffodildb.server.sql99.dql.execution; 2 3 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 4 import com.daffodilwoods.daffodildb.server.serversystem.*; 5 import com.daffodilwoods.daffodildb.server.sql99.common.*; 6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 7 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition.*; 8 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.table.*; 9 import com.daffodilwoods.daffodildb.server.sql99.expression. 10 booleanvalueexpression.*; 11 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 12 import com.daffodilwoods.database.resource.*; 13 import com.daffodilwoods.database.sqlinitiator.*; 14 import java.util.*; 15 16 26 27 public class ConditionSingleTableExecuter 28 extends SingleTableExecuter { 29 30 33 34 private booleanvalueexpression condition; 35 36 public ConditionSingleTableExecuter(_Order order0, TableDetails table0, 37 _ServerSession serverSession0, 38 booleanvalueexpression condition0, 39 String [] queryColumns) { 40 super(order0, table0, serverSession0, queryColumns, null); 41 condition = condition0; 42 } 43 44 public ConditionSingleTableExecuter(_Order order0, TableDetails table0, 45 _ServerSession serverSession0, 46 booleanvalueexpression condition0, 47 String [] queryColumns, 48 ColumnDetails[] aggregateColumns0) { 49 super(order0, table0, serverSession0, queryColumns, aggregateColumns0); 50 condition = condition0; 51 } 52 53 63 64 public double getCost(_IndexTable indexTable) throws DException { 65 69 70 if (condition == null) { 71 return super.getCost(indexTable); 72 } 73 _IndexPredicateInterface indexPredicateInterface = condition.getCost(order, 74 queryColumns, indexTable, table, aggregateColumns); 75 return indexPredicateInterface.getCost(); 76 } 77 78 85 public boolean updateQuery = false; 86 public _Iterator execute(_IndexTable indexTable) throws DException { 87 91 92 if (condition == null) { 93 return super.execute(indexTable); 94 } 95 try { 96 _Iterator iterator = condition.getCost(order, queryColumns, indexTable, 97 table, 98 aggregateColumns).execute(indexTable); 99 if (updateQuery) { 100 _Reference[] ref = condition.getReferences(new TableDetails[] {table}); 101 if (ref != null) { 102 ArrayList list = new ArrayList(); 103 for (int i = 0; i < ref.length; i++) { 104 if (ref[i].getReferenceType() != SimpleConstants.VARIABLECOLUMN) 105 list.add(ref[i]); 106 } 107 if (list.size() > 0) { 108 _Reference[] ref1 = (_Reference[]) list.toArray(new _Reference[0]); 109 ref1 = GeneralPurposeStaticClass.getAllReferences(ref1); 110 if (ref1 != null) { 111 iterator.setSpecificUnderlyingReferences(ref1); 112 } 113 } 114 } 115 } 116 return iterator; 117 } 118 catch (NullPointerException ex) { 119 throw new DException("DSE0", new Object [] {"Condition cannot be null"}); 120 } 121 } 122 123 127 133 134 public void addCondition(booleanvalueexpression condition0) throws DException { 135 136 137 condition = BVEPlanMerger.addAndConditions(condition, condition0); 138 } 139 140 public _Reference[] getReferences() throws DException { 141 return condition == null ? null : 142 condition.getReferences(new TableDetails[] {table}); 143 } 144 145 public booleanvalueexpression getCondition() throws DException { 146 return condition; 147 } 148 149 public _Iterator executeForDirtyLock(_IndexTable indexTable) throws 150 DException { 151 booleanvalueexpression condition = getSingleTableCondition(); 152 if (condition == null && order != null) { 153 return super.execute(indexTable); 154 } 155 return condition.getCost(order, queryColumns, indexTable, table, 156 aggregateColumns).execute(indexTable); 157 } 158 159 private booleanvalueexpression getSingleTableCondition() throws DException { 160 if (condition == null) { 161 return null; 162 } 163 if (condition instanceof _SingleTableCondition) { 164 return ( (_SingleTableCondition) condition).getSingleTableCondition(); 165 } 166 else { 167 throw new DException("DSE0", 168 new Object [] {"Not handled the condition " + 169 condition.getClass()}); 170 } 171 } 172 173 public boolean isContainsPresent() { 174 return containsFlag; 175 } 176 177 public void setContainsClauseFlag(boolean containsFlag) throws DException { 178 this.containsFlag = containsFlag; 179 } 180 181 public boolean isParameterisedQuery() throws DException { 182 _Reference[] references = getReferences(); 183 if (references == null) 184 return false; 185 for (int i = 0; i < references.length; i++) { 186 if (references[i].getReferenceType() == SimpleConstants.VARIABLECOLUMN) 187 return true; 188 } 189 return false; 190 } 191 } 192 | Popular Tags |