1 package com.daffodilwoods.daffodildb.server.sql99.expression. 2 numericvalueexpression; 3 4 import java.math.*; 5 6 import com.daffodilwoods.daffodildb.server.serversystem.*; 7 import com.daffodilwoods.daffodildb.server.sql99.common.*; 8 import com.daffodilwoods.daffodildb.server.sql99.expression.*; 9 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 10 import com.daffodilwoods.daffodildb.utils.field.*; 11 import com.daffodilwoods.database.resource.*; 12 13 public abstract class AbstractTerm 14 extends AbstractValueExpression 15 implements term, Datatypes { 16 public void checkSemantic(_ServerSession parent, ByteComparison bc1, 17 ByteComparison bc2) throws DException { 18 int type1 = bc1.getDataTypes()[0]; 19 int type2 = bc2.getDataTypes()[0]; 20 Check.checkForDatatypeForArthmeticOperations(type1, type2); 21 } 22 23 public Object run(Object object) throws DException { 24 initializeChildren(); 25 if (childs.length == 2) { 26 FieldBase result1 = (FieldBase) childs[0].run(object); 27 FieldBase result2 = (FieldBase) childs[1].run(object); 28 if (result1.isNull()) { 29 return result1; 30 } 31 if (result2.isNull()) { 32 return result2; 33 } 34 Object obj1 = result1.getObject(); 35 Object obj2 = result2.getObject(); 36 return getObject(result1.getDatatype(), result2.getDatatype(), obj1, obj2); 37 } 38 throw new DException("DSE3554", new Object [] {new Integer (2)}); 39 } 40 41 public Object clone() throws CloneNotSupportedException { 42 43 throw new java.lang.UnsupportedOperationException ( 44 "Method clone() not yet implemented."); 45 } 46 47 int getDataType(Object object, String name) throws DException { 48 if (object instanceof Integer ) { 49 return INTEGER; 50 } 51 else if (object instanceof Float ) { 52 return FLOAT; 53 } 54 else if (object instanceof Double ) { 55 return DOUBLE; 56 } 57 else if (object instanceof Long ) { 58 return LONG; 59 } 60 else if (object instanceof String ) { 61 return CHARACTER; 62 } 63 else if (object instanceof Short ) { 64 return SHORT; 65 } 66 else if (object instanceof BigDecimal) { 67 return BIGDECIMAL; 68 } 69 else { 70 throw new DException("DSE419", new Object [] {name}); 71 } 72 } 73 74 protected int getDataType(Object object) throws DException { 75 throw new UnsupportedOperationException (" NOT IMPLEMENTED "); 76 } 77 78 public abstract FieldBase getObject(int type1, int type2, Object result1, 79 Object result2) throws DException; 80 81 public ParameterInfo[] getParameterInfo() throws DException { 82 initializeChildren(); 83 Object [][] parms = new Object [childs.length][]; 84 int length = 0; 85 for (int i = 0; i < childs.length; i++) { 86 parms[i] = childs[i] == null ? null : childs[i].getParameterInfo(); 87 length += parms[i] == null ? 0 : parms[i].length; 88 } 89 ParameterInfo[] parameterInfo = new ParameterInfo[length]; 90 int index = 0; 91 for (int i = 0; i < childs.length; i++) { 92 ParameterInfo[] par = GeneralPurposeStaticClass.changeIntoParameterInfo( 93 parms[i]); 94 for (int j = 0; j < par.length; j++) { 95 parameterInfo[index++] = par[j]; 96 } 97 } 98 return parameterInfo; 99 } 100 101 public ByteComparison getByteComparison(Object object) throws DException { 102 initializeChildren(); 103 int dataType = getAppropriateDataType(object); 104 return new ByteComparison(false, new int[] {dataType}); 105 } 106 107 public void releaseResource() throws DException { 108 initializeChildren(); 109 for (int i = 0; i < childs.length; i++) { 110 childs[i].releaseResource(); 111 } 112 } 113 114 protected int getAppropriateDataType(Object object) throws DException { 115 int dataType1 = getDataTypeForByte(childs[0].getByteComparison(object)); 116 int dataType2 = getDataTypeForByte(childs[1].getByteComparison(object)); 117 return GeneralPurposeStaticClass.getDataTypeForArithmetic(dataType1, 118 dataType2); 119 } 120 121 protected void checkForQuestion(ColumnDetails[] leftCD, ColumnDetails[] rightCD) throws 122 DException { 123 int noOfQuestions = 0; 124 int leftQuestionMarks = checkInexp(leftCD, noOfQuestions); 125 noOfQuestions = 0; 126 int RightQuestionMarks = checkInexp(rightCD, noOfQuestions); 127 if (leftQuestionMarks >= 1 && RightQuestionMarks >= 1) { 128 throw new DException("DSE3550", null); 129 } 130 } 131 132 private int checkInexp(ColumnDetails[] cd, int noOfQuestions) throws 133 DException { 134 for (int i = 0; i < cd.length; i++) { 135 int type = cd[i].getType(); 136 if (cd[i].getQuestion()) { 137 noOfQuestions++; 138 } 139 if (type == FUNCTIONAL || type == GROUPING || 140 type == SCALARFUNCTION || 141 type == CASEEXPRESSION || type == USERFUNCTION) { 142 ColumnDetails[] cdChild = cd[i].getChildColumnDetails(); 143 noOfQuestions = noOfQuestions + checkInexp(cdChild, noOfQuestions); 144 } 145 } 146 return noOfQuestions; 147 } 148 } 149 | Popular Tags |