1 package com.daffodilwoods.daffodildb.server.sql99.ddl.schemadefinition; 2 3 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 4 import com.daffodilwoods.daffodildb.server.serversystem.*; 5 import com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors.*; 6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 7 import com.daffodilwoods.database.resource.*; 8 9 public class oncolumns implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter { 10 11 public String toString() { 12 StringBuffer sb = new StringBuffer (); 13 sb.append(" "); 14 sb.append("("); 15 sb.append(" "); 16 sb.append(_indextypelist0); 17 sb.append(" "); 18 sb.append(")"); 19 return sb.toString(); 20 } 21 22 public indextypelist _indextypelist0; 23 24 private IndexDescriptor indexDes; 25 private TableDescriptor tableDes; 26 27 35 36 public Object run(Object object) throws DException { 37 _ServerSession currentSession = (_ServerSession) object; 38 String [] columns = _indextypelist0.getColumnNames(); 39 Boolean [] orderTypes = _indextypelist0.getOrderTypes(); 40 ensureColumns(columns); 41 setIsVariable(columns); 42 checkIsColumnListAlreadyIndexed(columns, orderTypes, currentSession); 43 setIndexColumnDescriptor(columns, orderTypes); 44 return null; 45 } 46 47 private void ensureColumns(String [] columns) throws DException { 48 int index = tableDes.isTableColumns(columns); 49 if (index != -1) { 50 throw new DException("DSE255", new Object [] {columns[index], 51 tableDes.getQualifiedTableName()}); 52 } 53 } 54 55 62 63 private void setIsVariable(String [] columns) throws DException { 64 int len = columns.length; 65 int size = 0; 66 Boolean fixedVariable = Boolean.FALSE; 67 String countryCode = tableDes.country_code; 68 for (int i = 0; i < len; i++) { 69 ColumnDescriptor columnDescriptor = tableDes.getColumnDescriptor( 70 columns[i]); 71 DataTypeDescriptor dtd = columnDescriptor.dataTypeDescriptor; 72 if (columnDescriptor.isBlobClob()) { 73 throw new DException("DSE478", 74 new Object [] {columnDescriptor.column_name, 75 dtd.data_Type}); 76 } 77 if (!columnDescriptor.isFixedColumn()) { 78 fixedVariable = Boolean.TRUE; 79 } 80 int columnSize = dtd.getBytesCount(); 81 size += countryCode != null && dtd.isCharacterType() ? 2 * (columnSize + 1) : columnSize; 82 } 83 if (size > IndexDescriptor.maxIndexColumnSize) { 84 throw new DException("DSE8049", 85 new Object [] {new Integer (IndexDescriptor.maxIndexColumnSize), 86 indexDes.indexname, new Integer (size)}); 87 } 88 indexDes.fixedVariable = fixedVariable; 89 } 90 91 private void setIndexColumnDescriptor(String [] columnNames, 92 Boolean [] orderTypes) throws 93 DException { 94 for (int i = 0; i < columnNames.length; i++) { 95 IndexColumnDescriptor indexColDes = new IndexColumnDescriptor(SystemTables.INDEXCOLUMNS); 96 indexColDes.table_catalog = indexDes.table_catalog; 97 indexColDes.table_schema = indexDes.table_schema; 98 indexColDes.table_name = indexDes.table_name; 99 indexColDes.indexname = indexDes.indexname; 100 indexColDes.columnName = columnNames[i]; 101 indexColDes.orderType = orderTypes[i]; 102 indexDes.addIndexColumnDescriptor(indexColDes); 103 } 104 } 105 106 public void setIndexDescriptor(_Descriptor indexDes0) { 107 indexDes = (IndexDescriptor) indexDes0; 108 } 109 110 public void setTableDescriptor(_Descriptor tableDes0) { 111 tableDes = (TableDescriptor) tableDes0; 112 } 113 114 private void checkIsColumnListAlreadyIndexed(String [] columnNames, 115 Boolean [] orderTypes, _ServerSession currentSession) throws DException { 116 PreparedStatementGetter psg = ( (DataDictionary) currentSession.getDataDictionary()).getPreparedStatementGetter(); 117 _SelectQueryIterator indexIterator = (_SelectQueryIterator) psg.getIndexInfoExecuter().executeForFresh(new Object [] {tableDes.table_catalog, tableDes.table_schema, tableDes.table_name}); 118 int numberOfIndexColumns = columnNames.length; 119 if (indexIterator.first()) { 120 do { 121 Object [] record = (Object []) indexIterator.getObject(); 122 String indexName = null; 123 indexName = (String ) record[SystemTablesFields.indexInfo_indexname]; 124 _SelectQueryIterator indexColumnIterator = (_SelectQueryIterator) psg.getIndexColumnsExecuter().executeForFresh(new Object [] {tableDes.table_catalog, tableDes.table_schema, tableDes.table_name, indexName}); 125 int rowCount = indexColumnIterator.getRowCount(); 126 boolean matched = true; 127 if (rowCount == numberOfIndexColumns) { 128 int i = 0; 129 indexColumnIterator.first(); 130 do { 131 Object [] columnsRecord = (Object []) indexColumnIterator.getObject(); 132 String columnName = (String ) columnsRecord[SystemTablesFields.indexColumns_column_name]; 133 Boolean orderType = (Boolean ) columnsRecord[SystemTablesFields.indexColumns_orderType]; 134 if (!columnName.equalsIgnoreCase(columnNames[i])) { 135 matched = false; 136 break; 137 } 138 if (!orderType.equals(orderTypes[i])) { 139 matched = false; 140 break; 141 } 142 i++; 143 } while (indexColumnIterator.next()); 144 if (matched) { 145 throw new DException("DSE8050", null); 146 } 147 } 148 } while (indexIterator.next()); 149 } 150 151 } 152 153 public Object clone() throws CloneNotSupportedException { 154 return this; 155 } 156 157 } 158 | Popular Tags |