1 package com.daffodilwoods.daffodildb.server.sql99.dql.resultsetmetadata; 2 3 import java.io.*; 4 5 import com.daffodilwoods.daffodildb.server.sql99.common.*; 6 import com.daffodilwoods.daffodildb.utils.comparator.*; 7 import com.daffodilwoods.database.resource.*; 8 import com.daffodilwoods.database.utility.*; 9 10 20 21 public class SelectKeyColumnInformation implements Serializable { 22 23 26 27 private int[] mapping; 28 29 32 33 private boolean[] orderSpecifications; 34 35 38 39 private SuperComparator comparator; 40 41 public SelectKeyColumnInformation(_KeyColumnInformation[] keyColumns, int[] mapping1, boolean isAggregateAndNoGroup) throws DException { 42 mapping = mapping1; 43 orderSpecifications = getOrderSpecification(keyColumns); 44 comparator = isAggregateAndNoGroup 45 ? (SuperComparator)new DefaultKeyComparator() : new KeyComparator(orderSpecifications); 46 } 47 48 55 56 private SuperComparator getKeyComparator(_KeyColumnInformation[] keyColumns) throws DException { 57 ColumnDetails[] columns = getColumnDetails(keyColumns); 58 return GeneralPurposeStaticClass.getOrderComparator(columns, orderSpecifications); 59 } 60 61 67 68 private boolean[] getOrderSpecification(_KeyColumnInformation[] keyColumnInformation) throws DException { 69 int length = keyColumnInformation.length; 70 boolean[] result = new boolean[length]; 71 for (int i = 0; i < length; i++) { 72 result[i] = keyColumnInformation[i].getOrderSpecification(); 73 } 74 return result; 75 } 76 77 83 84 private ColumnDetails[] getColumnDetails(_KeyColumnInformation[] keyColumnInformation) throws DException { 85 int length = keyColumnInformation.length; 86 ColumnDetails[] result = new ColumnDetails[length]; 87 for (int i = 0; i < length; i++) { 88 result[i] = keyColumnInformation[i].getColumnDetails(); 89 } 90 return result; 91 } 92 93 99 100 public Object getKey(Object row) throws DException { 101 try { 102 int length = mapping.length; 103 Object [] result = new Object [length]; 104 for (int i = 0; i < length; i++) { 105 result[i] = ( (Object []) row)[mapping[i] - 1]; 106 } 107 return result; 108 } catch (ArrayIndexOutOfBoundsException ex) { 109 throw ex; 110 } 111 } 112 113 118 119 public SuperComparator getComparator() throws DException { 120 return comparator; 121 } 122 123 127 128 public boolean[] getOrder() { 129 return orderSpecifications; 130 } 131 } 132 | Popular Tags |