1 package com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents; 2 3 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.ColumnMapping; 4 5 import java.util.*; 6 import com.daffodilwoods.database.resource.DException; 7 import com.daffodilwoods.database.utility.P; 8 import com.daffodilwoods.database.general.QualifiedIdentifier; 9 import com.daffodilwoods.daffodildb.server.sql99.common.TableDetails; 10 11 21 22 public class ColumnMappingHandler { 23 24 27 28 ArrayList tablesForInsertion ; 29 30 33 34 ArrayList tablesForDeletion ; 35 36 39 40 HashMap tableColumnMapping; 41 42 public ColumnMappingHandler() { 43 tablesForInsertion = new ArrayList(); 44 tableColumnMapping = new HashMap(); 45 tablesForDeletion = new ArrayList(); 46 } 47 48 54 55 public void addTableForInsertion( TableDetails obj ) throws DException { 56 if( obj != null && !tablesForInsertion.contains(obj) ){ 57 tablesForInsertion.add(obj); 58 } 59 } 60 61 67 68 public void addTableForDeletion( TableDetails[] obj ) { 69 for (int i = 0; i < obj.length; i++) { 70 addTablesForDeletion( obj[i] ); 71 } 72 } 73 74 80 81 public void addTablesForDeletion( TableDetails td ) { 82 if( !tablesForDeletion.contains(td) ) 83 tablesForDeletion.add(td); 84 } 85 86 91 92 public void setTableColumnMapping( ColumnMapping[] columnMappings ) throws DException { 93 int len = columnMappings.length; 94 for( int i=0; i<len; i++ ) 95 addColumnMapping( columnMappings[i] ); 96 97 } 98 99 public void addColumnMapping( ColumnMapping cm ) throws DException { 100 tableColumnMapping.put( cm.getTableDetails(),cm ); 101 } 102 103 111 112 public boolean isTableInUserTableMapping( TableDetails[] tables ) throws DException { 113 int len = tables.length; 114 for( int i=0; i<len; i++ ) 115 if( tableColumnMapping.containsKey(tables[i]) ) 116 return true; 117 return false; 118 } 119 120 public boolean tableAlreadyInsertedForInsert( TableDetails tableName ) throws DException { 121 return tablesForInsertion.contains(tableName); 122 } 123 124 135 136 public TableDetails[] getTablesForInsertProcess( HashMap tableKeyMapping ) throws DException { 137 int len = tablesForInsertion.size(); 138 ArrayList toReturn = new ArrayList(); 139 boolean inserted = false; 140 141 if( len > 0 ) 142 for( int i=0; i<len; i++ ) 143 if( !tableKeyMapping.containsKey( tablesForInsertion.get(i) ) ){ 144 inserted = true; 145 toReturn.add( tablesForInsertion.get(i) ); 146 } 147 148 Iterator iterator = tableColumnMapping.keySet().iterator(); 149 while( iterator.hasNext() ){ 150 TableDetails td = (TableDetails)iterator.next(); 151 if( !tableKeyMapping.containsKey( td ) ){ 152 ColumnMapping cmp = (ColumnMapping) tableColumnMapping.get(td) ; 153 if( cmp.isHasRecord_False()!= 0 && cmp.isHasRecord_False()!= 1 && !toReturn.contains(td)){ 154 inserted = true; 155 toReturn.add( td ); 156 } 157 } 158 } 159 if(inserted) 160 return (TableDetails[]) toReturn.toArray( new TableDetails[0] ); 161 162 return null; 163 164 } 165 166 175 176 public int containsTableAndColumnInMapping( TableDetails table , String columnName ) throws DException { 177 if( tableColumnMapping.containsKey( table ) ){ 178 ColumnMapping cm = (ColumnMapping) tableColumnMapping.get(table); 179 return cm.getIndexOfColumn(columnName); 180 } 181 return -1; 182 } 183 184 193 194 public Object getValueAtIndex( TableDetails table , int index ) throws DException { 195 ColumnMapping cm = (ColumnMapping) tableColumnMapping.get(table); 196 return cm.getValueAtIndex(index); 197 } 198 199 206 207 public int getLengthOfTableColumnValues() throws DException { 208 return tableColumnMapping.size(); 209 } 210 211 217 218 public Iterator getIteratorOnTableKeys( ) throws DException { 219 return tableColumnMapping.keySet().iterator(); 220 } 221 222 public ColumnMapping getColumnMappingForTableDetail( TableDetails td ) throws DException { 223 return (ColumnMapping)tableColumnMapping.get( td ); 224 } 225 226 public ColumnMapping[] getColumnMappings() throws DException { 227 return (ColumnMapping[]) tableColumnMapping.values().toArray( new ColumnMapping[0]); 228 } 229 230 236 237 public TableDetails[] getTablesForInsert() throws DException { 238 return (TableDetails[]) tablesForInsertion.toArray( new TableDetails[0] ); 239 } 240 241 247 248 public TableDetails[] getTablesForDelete() throws DException { 249 return (TableDetails[]) tablesForDeletion.toArray( new TableDetails[0] ); 250 } 251 252 private void addUserTables( ArrayList arr , HashMap tableKeyMapping ) throws DException { 253 } 254 255 public int isHasRecord_False( TableDetails tdd ) throws DException { 256 ColumnMapping cm = (ColumnMapping)tableColumnMapping.get( tdd ); 257 return cm==null ? -1 : cm.hasRecord; 258 } 259 260 private void show() { 261 Iterator iter = tableColumnMapping.keySet().iterator(); 262 while( iter.hasNext() ){ 263 Object oo = iter.next(); 264 } 265 } 266 267 public ColumnMapping getColumnMappingForTableDetails( TableDetails td ) throws DException { 268 return (ColumnMapping) tableColumnMapping.get(td); 269 } 270 271 public void showForTablesToBEInserted() { 272 int len = tablesForInsertion.size(); 273 if( len == 0 ) 274 ; for( int i=0; i<len; i++ ) 276 ; } 278 } 279 | Popular Tags |