1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.store.access.SortObserver; 25 import org.apache.derby.iapi.services.io.Storable; 26 27 import org.apache.derby.iapi.types.CloneableObject; 28 29 import org.apache.derby.iapi.services.sanity.SanityManager; 30 31 import org.apache.derby.iapi.error.StandardException; 32 33 import org.apache.derby.iapi.sql.execute.ExecRow; 34 35 import org.apache.derby.iapi.types.DataValueDescriptor; 36 37 import java.util.Vector ; 38 39 45 public class BasicSortObserver implements SortObserver 46 { 47 protected boolean doClone; 48 protected boolean distinct; 49 private boolean reuseWrappers; 50 private ExecRow execRow; 51 private Vector vector; 52 53 67 public BasicSortObserver(boolean doClone, boolean distinct, ExecRow execRow, boolean reuseWrappers) 68 { 69 this.doClone = doClone; 70 this.distinct = distinct; 71 this.execRow = execRow; 72 this.reuseWrappers = reuseWrappers; 73 vector = new Vector (); 74 } 75 76 89 public DataValueDescriptor[] insertNonDuplicateKey(DataValueDescriptor[] insertRow) 90 throws StandardException 91 { 92 return (doClone) ? 93 getClone(insertRow) : 94 insertRow; 95 } 96 109 public DataValueDescriptor[] insertDuplicateKey(DataValueDescriptor[] insertRow, DataValueDescriptor[] existingRow) 110 throws StandardException 111 { 112 return (distinct) ? 113 (DataValueDescriptor[])null : 114 (doClone) ? 115 getClone(insertRow) : 116 insertRow; 117 118 } 119 120 public void addToFreeList(DataValueDescriptor[] objectArray, int maxFreeListSize) 121 { 122 if (reuseWrappers && vector.size() < maxFreeListSize) 123 { 124 vector.addElement(objectArray); 125 } 126 } 127 128 public DataValueDescriptor[] getArrayClone() 129 throws StandardException 130 { 131 int lastElement = vector.size(); 132 133 if (lastElement > 0) 134 { 135 DataValueDescriptor[] retval = (DataValueDescriptor[]) vector.elementAt(lastElement - 1); 136 vector.removeElementAt(lastElement - 1); 137 return retval; 138 } 139 return execRow.getRowArrayClone(); 140 } 141 142 143 private DataValueDescriptor[] getClone(DataValueDescriptor[] origArray) 144 { 145 152 167 DataValueDescriptor[] newArray = new DataValueDescriptor[origArray.length]; 168 for (int i = 0; i < origArray.length; i++) 169 { 170 newArray[i] = origArray[i].getClone(); 173 } 174 175 return newArray; 176 } 177 } 178 | Popular Tags |