| 1 package com.daffodilwoods.daffodildb.server.datasystem.interfaces; 2 3 import com.daffodilwoods.database.general.QualifiedIdentifier; 4 import com.daffodilwoods.database.resource.DException; 5 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.DatabaseConstants; 6 import com.daffodilwoods.daffodildb.utils.BufferRange; 7 import com.daffodilwoods.daffodildb.utils.field.FieldBase; 8 import com.daffodilwoods.daffodildb.utils.FieldUtility; 9 import java.text.Collator ; 10 import com.daffodilwoods.daffodildb.utils.field.FieldStringLiteral; 11 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.*; 12 import com.daffodilwoods.daffodildb.utils.byteconverter.CCzufDpowfsufs; 13 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.VersionHandler; 14 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator._Iterator; 15 import com.daffodilwoods.database.general.SystemFields; 16 import com.daffodilwoods.daffodildb.utils.comparator.SuperComparator; 17 import com.daffodilwoods.daffodildb.server.sessionsystem.sessioncondition.SessionConditionReferences; 18 import com.daffodilwoods.daffodildb.server.sessionsystem.SystemFieldsCharacteristics; 19 import com.daffodilwoods.database.utility.P; 20 21 public class Utility implements Datatype,DatabaseConstants{ 22 23 24 static DatabaseProperties databaseProperties; 25 public static BufferRange[] getBufferRangeForTableName(QualifiedIdentifier tableName){ 26 BufferRange[] buff = new BufferRange[] {new BufferRange(tableName.catalog.getBytes()) 27 ,new BufferRange(tableName.schema.getBytes()) 28 ,new BufferRange(tableName.name.getBytes())}; 29 return buff; 30 } 31 32 public static boolean isBlobClob(int type) { 33 return type == Datatype.BLOB || 34 type == BINARYLARGEOBJECT || 35 type == LONGVARBINARY || 36 type == CLOB || 37 type == CHARACTERLARGEOBJECT || 38 type == CHARLARGEOBJECT || 39 type == LONGVARCHAR; 40 } 41 42 public static boolean isFixed(int type) throws DException { 43 return !(type == ARRAY || type == BIGDECIMAL || type == VARCHAR || 44 type == NUMERIC || type == DECIMAL || type == DEC || 45 type == CHARACTERVARYING || type == CHARVARYING || 46 type == BITVARYING || type == SUM || 47 type == VARBINARY || type == REF || type == STRUCT ); 48 } 49 50 private static Object [][] indexTableStructure; 51 public static Object [][] getIndexTableStructure() throws DException{ 52 if(indexTableStructure == null){ 53 indexTableStructure = new Object [][]{ 54 {"RecordClusterAddress" ,new Long (LONG) ,new Integer (LONGSIZE), new Long (0)}, 55 {"RecordNumber" ,new Long (INTEGER) ,new Integer (INTSIZE) , new Long (1)}, 56 {"ClusterSize" ,new Long (INTEGER) ,new Integer (INTSIZE) , new Long (2)}, 57 {"NextNodeAddress" ,new Long (LONG) ,new Integer (LONGSIZE), new Long (3)}, 58 {"NextNodeRecordNumber" ,new Long (INTEGER) ,new Integer (INTSIZE) , new Long (4)}, 59 {"NextClusterSize" ,new Long (INTEGER) ,new Integer (INTSIZE) , new Long (5)}, 60 }; 61 } 62 return indexTableStructure; 63 } 64 65 69 70 public int getBytesCount(int type,int size) throws DException { 71 switch (type){ 72 case INT : 73 case INTEGER : return INTSIZE; 74 case REAL : return REALSIZE; 75 case DATE : return DATESIZE; 76 case BIGINT : 77 case LONG : 78 case FLOAT : 79 case DOUBLE : 80 case DOUBLEPRECISION : return DOUBLESIZE; 81 case SHORT : 82 case SMALLINT : return SHORTSIZE; 83 case BOOLEAN : return BOOLEANSIZE; 84 case TINYINT : 85 case BYTE : return BYTESIZE; 86 case TIME : return TIMESIZE; 87 case TIMESTAMP : return TIMESTAMPSIZE; 88 case BINARY : 89 case VARBINARY : 90 case CHARACTER : 91 case CHAR : 92 case CHARACTERVARYING : 93 case CHARVARYING : 94 case VARCHAR : 95 case BIT : 96 case BITVARYING : return size; 97 case DEC : 98 case DECIMAL : 99 case BIGDECIMAL : return BIGDECIMAL_PRECISION; 100 101 case LONGVARBINARY : 102 case LONGVARCHAR : 103 case BLOB : 104 case CLOB : 105 case CHARLARGEOBJECT : 106 case CHARACTERLARGEOBJECT : 107 case BINARYLARGEOBJECT : return 6; 109 } 110 return -1; 111 } 112 113 public static Object [] convertIntoFieldBase(Object [] values) throws DException{ 114 Object [] array = new Object [values.length]; 115 for (int i = 0; i < values.length; i++) { 116 array[i] = ((FieldBase)values[i]).getObject(); 117 } 118 return array; 119 } 120 121 public static FieldBase[] convertIntoFieldBase(int[] datatypes,Object [] values,Collator collator) throws DException{ 122 FieldBase[] array = new FieldBase[datatypes.length]; 123 for (int i = 0; i < datatypes.length; i++) { 124 array[i] = FieldUtility.getField(datatypes[i],values[i],collator); 125 } 126 return array; 127 } 128 129 public static BufferRange[] convertIntoBufferRange(int[] datatypes,Object [] values,Collator collator) throws DException{ 130 BufferRange[] array = new BufferRange[datatypes.length]; 131 for (int i = 0; i < datatypes.length; i++) { 132 array[i] = FieldUtility.getField(datatypes[i],values[i],collator).getBufferRange(); 133 } 134 return array; 135 } 136 137 public static void showCluster(Cluster cluster) throws DException{ 138 byte[] bytes = cluster.getBytes(); 139 VersionHandler versionHandler = cluster.getVersionHandler(); 140 int pointer = cluster.getDatabaseProperties().CLUSTERSIZE - versionHandler.NEWADDRESSLENGTH - versionHandler.LENGTH; 141 for (int i = 1; i <= cluster.getActualRecordCount() ; i++) { 142 ; short start = CCzufDpowfsufs.getShortValue(bytes,pointer); 144 boolean active = bytes[start] == versionHandler.ACTIVE; 145 if(active){ 146 byte full = bytes[start+1]; 147 } 148 pointer -= versionHandler.LENGTH; 149 } 150 } 151 152 public static boolean isBlob(int type) { 153 return type == Datatype.BLOB || 154 type == BINARYLARGEOBJECT || 155 type == LONGVARBINARY; 156 } 157 158 public static boolean isClob(int type) { 159 return type == CLOB || 160 type == CHARACTERLARGEOBJECT || 161 type == CHARLARGEOBJECT || 162 type == LONGVARCHAR; 163 } 164 165 public static boolean recordFound(_Iterator iterator,Object [] key) throws DException { 166 167 Object rowid = key[0]; 168 if(iterator.seek(rowid)) 169 do{ 170 Object [] values = (Object [])iterator.getColumnValues(SystemFieldsCharacteristics.RTS ); 171 if(!values[0].equals(rowid)) 172 return false; 173 if(values[1].equals(key[1]) && values[2].equals(key[2])) 174 return true; 175 }while(iterator.next()); 176 return false; 177 } 178 179 public static boolean recordFound(_IndexIterator iterator,_IndexIterator keyIterator, Object actualKey, SuperComparator comparator) throws DException { 180 if(iterator.seek(actualKey)){ 181 Object [] key = (Object []) keyIterator.getColumnValues(SystemFieldsCharacteristics.TS); 182 Object [] values; 183 do { 184 values = (Object []) iterator.getColumnValues(SystemFieldsCharacteristics.TS); 185 if (values[0].equals(key[0]) && values[1].equals(key[1])) 186 return true; 187 } 188 while (iterator.next() && comparator.compare(( (_Key) iterator.getKey()).getKeyValue(), actualKey) == 0); 189 } 190 return false; 191 } 192 193 public static boolean findRecord(_Iterator iterator,Object actualKey, Object [] key) throws DException { 194 SuperComparator sc = ((_IndexIteratorInfo)iterator).getComparator(); 195 if(iterator.seek(actualKey)) 196 do{ 197 Object [] values = (Object [])iterator.getColumnValues(SystemFieldsCharacteristics.TS ); 198 if(values[0].equals(key[0]) && values[1].equals(key[1])) 199 return true; 200 }while(iterator.next() && sc.compare(((FieldBase)iterator.getColumnValues(SessionConditionReferences.rowIdReference_0)).getBufferRange(),actualKey) ==0); 201 return false; 202 } 203 204 205 public static Boolean getBooleanValue(String value){ 206 return value.equalsIgnoreCase("true") ? Boolean.TRUE : Boolean.FALSE ; 207 } 208 public static Boolean getBooleanValue(boolean value){ 209 return value ? Boolean.TRUE : Boolean.FALSE ; 210 } 211 212 } 213 | Popular Tags |