1 21 22 package org.apache.derby.impl.sql.catalog; 23 24 import org.apache.derby.iapi.types.DataValueDescriptor; 25 26 import org.apache.derby.iapi.types.TypeId; 27 import org.apache.derby.iapi.sql.dictionary.SystemColumn; 28 import org.apache.derby.catalog.TypeDescriptor; 29 30 import org.apache.derby.iapi.types.DataValueFactory; 31 import org.apache.derby.iapi.types.RowLocation; 32 33 import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory; 34 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 35 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator; 36 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 37 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 38 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor; 39 import org.apache.derby.iapi.sql.dictionary.ViewDescriptor; 40 41 import org.apache.derby.iapi.sql.execute.ExecutionContext; 42 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 43 import org.apache.derby.iapi.sql.execute.ExecRow; 44 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 45 46 import org.apache.derby.iapi.error.StandardException; 47 48 import org.apache.derby.iapi.services.sanity.SanityManager; 49 50 import org.apache.derby.iapi.services.uuid.UUIDFactory; 51 import org.apache.derby.catalog.UUID; 52 import org.apache.derby.catalog.IndexDescriptor; 53 54 import java.util.Properties ; 55 56 61 62 public class SYSVIEWSRowFactory extends CatalogRowFactory 63 { 64 private static final String TABLENAME_STRING = "SYSVIEWS"; 65 66 protected static final int SYSVIEWS_COLUMN_COUNT = 4; 67 protected static final int SYSVIEWS_TABLEID = 1; 68 protected static final int SYSVIEWS_VIEWDEFINITION = 2; 69 protected static final int SYSVIEWS_CHECKOPTION = 3; 70 protected static final int SYSVIEWS_COMPILATION_SCHEMAID = 4; 71 72 protected static final int SYSVIEWS_TABLEID_WIDTH = 36; 74 75 protected static final int SYSVIEWS_INDEX1_ID = 0; 76 77 private static final int[][] indexColumnPositions = 78 { 79 {SYSVIEWS_TABLEID} 80 }; 81 82 83 private static final boolean[] uniqueness = null; 85 86 private static final String [] uuids = 87 { 88 "8000004d-00d0-fd77-3ed8-000a0a0b1900" ,"80000050-00d0-fd77-3ed8-000a0a0b1900" ,"8000004f-00d0-fd77-3ed8-000a0a0b1900" }; 92 93 99 public SYSVIEWSRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf, 100 boolean convertIdToLower) 101 { 102 super(uuidf,ef,dvf,convertIdToLower); 103 initInfo(SYSVIEWS_COLUMN_COUNT, TABLENAME_STRING, 104 indexColumnPositions, uniqueness, uuids ); 105 } 106 107 113 120 public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) 121 throws StandardException 122 { 123 DataValueDescriptor col; 124 ExecRow row; 125 String tableID = null; 126 String compSchemaId = null; 127 String viewText = null; 128 String checkSType = null; 129 int checkIType; 130 131 if (td != null) 132 { 133 UUID tableUUID; 134 ViewDescriptor vd = (ViewDescriptor)td; 135 136 140 tableUUID = vd.getUUID(); 141 if ( tableUUID == null ) 142 { 143 tableUUID = getUUIDFactory().createUUID(); 144 vd.setUUID(tableUUID); 145 } 146 tableID = tableUUID.toString(); 147 viewText = vd.getViewText(); 148 149 150 checkIType = vd.getCheckOptionType(); 151 152 if (SanityManager.DEBUG) 153 { 154 if (checkIType != ViewDescriptor.NO_CHECK_OPTION) 155 { 156 SanityManager.THROWASSERT("checkIType expected to be " + 157 ViewDescriptor.NO_CHECK_OPTION + 158 ", not " + checkIType); 159 } 160 } 161 checkSType = "N"; 162 163 UUID tmpId = vd.getCompSchemaId(); 164 compSchemaId = (tmpId == null) ? null : tmpId.toString(); 165 } 166 167 168 169 172 173 174 row = getExecutionFactory().getValueRow(SYSVIEWS_COLUMN_COUNT); 175 176 177 row.setColumn(SYSVIEWS_TABLEID, dvf.getCharDataValue(tableID)); 178 179 180 row.setColumn(SYSVIEWS_VIEWDEFINITION, 181 dvf.getLongvarcharDataValue(viewText)); 182 183 184 row.setColumn(SYSVIEWS_CHECKOPTION, dvf.getCharDataValue(checkSType)); 185 186 187 row.setColumn(SYSVIEWS_COMPILATION_SCHEMAID, dvf.getCharDataValue(compSchemaId)); 188 189 return row; 190 } 191 192 198 207 public TupleDescriptor buildDescriptor( 208 ExecRow row, 209 TupleDescriptor parentTupleDescriptor, 210 DataDictionary dd ) 211 throws StandardException 212 { 213 ViewDescriptor vd = null; 214 215 if (SanityManager.DEBUG) 216 { 217 SanityManager.ASSERT( 218 row.nColumns() == SYSVIEWS_COLUMN_COUNT, 219 "Wrong number of columns for a SYSVIEWS row"); 220 } 221 222 DataValueDescriptor col; 223 DataDescriptorGenerator ddg; 224 int checkIType; 225 String checkSType; 226 String tableID; 227 String compSchemaId; 228 String viewDefinition; 229 UUID tableUUID; 230 UUID compSchemaUUID = null; 231 232 ddg = dd.getDataDescriptorGenerator(); 233 234 235 col = row.getColumn(SYSVIEWS_TABLEID); 236 tableID = col.getString(); 237 tableUUID = getUUIDFactory().recreateUUID(tableID); 238 239 240 col = row.getColumn(SYSVIEWS_VIEWDEFINITION); 241 viewDefinition = col.getString(); 242 243 244 col = row.getColumn(SYSVIEWS_CHECKOPTION); 245 checkSType = col.getString(); 246 247 if (SanityManager.DEBUG) 248 { 249 if (!checkSType.equals("N")) 250 { 251 SanityManager.THROWASSERT("checkSType expected to be 'N', not " + checkSType); 252 } 253 } 254 255 256 checkIType = ViewDescriptor.NO_CHECK_OPTION; 257 258 259 col = row.getColumn(SYSVIEWS_COMPILATION_SCHEMAID); 260 compSchemaId = col.getString(); 261 if (compSchemaId != null) 262 { 263 compSchemaUUID = getUUIDFactory().recreateUUID(compSchemaId); 264 } 265 266 267 vd = ddg.newViewDescriptor(tableUUID, null, viewDefinition, 268 checkIType, compSchemaUUID); 269 return vd; 270 } 271 272 278 public SystemColumn[] buildColumnList() 279 { 280 SystemColumn[] columnList = new SystemColumn[SYSVIEWS_COLUMN_COUNT]; 281 282 columnList[0] = new SystemColumnImpl( 283 convertIdCase( "TABLEID"), SYSVIEWS_TABLEID, 0, 0, false, "CHAR", true, 36 ); 292 294 columnList[1] = 295 new SystemColumnImpl( 296 convertIdCase( "VIEWDEFINITION"), SYSVIEWS_VIEWDEFINITION, 0, 0, false, "LONG VARCHAR", true, TypeId.LONGVARCHAR_MAXWIDTH ); 305 columnList[2] = 306 new SystemColumnImpl( 307 convertIdCase( "CHECKOPTION"), SYSVIEWS_CHECKOPTION, 0, 0, false, "CHAR", true, 1 ); 316 317 columnList[3] = new SystemColumnImpl( 318 convertIdCase( "COMPILATIONSCHEMAID"), SYSVIEWS_COMPILATION_SCHEMAID, 0, 0, false, "CHAR", true, 36 ); 327 return columnList; 328 } 329 } 330 | Popular Tags |