1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 import org.apache.derby.iapi.types.DataValueDescriptor; 26 import org.apache.derby.iapi.error.StandardException; 27 28 import org.apache.derby.iapi.sql.execute.ExecAggregator; 29 import org.apache.derby.iapi.services.io.StoredFormatIds; 30 import java.io.ObjectOutput ; 31 import java.io.ObjectInput ; 32 import java.io.IOException ; 33 34 42 public final class MaxMinAggregator 43 extends OrderableAggregator 44 { 45 46 private boolean isMax; 48 50 public void setup(String aggregateName) 51 { 52 super.setup(aggregateName); 53 isMax = aggregateName.equals("MAX"); 54 } 55 63 protected void accumulate(DataValueDescriptor addend) 64 throws StandardException 65 { 66 if ( (value == null) || 67 (isMax && (value.compare(addend) < 0)) || 68 (!isMax && (value.compare(addend) > 0)) 69 ) 70 { 71 74 value = addend.getClone(); 75 } 76 } 77 78 81 public ExecAggregator newAggregator() 82 { 83 MaxMinAggregator ma = new MaxMinAggregator(); 84 ma.isMax = isMax; 85 return ma; 86 } 87 88 public void writeExternal(ObjectOutput out) throws IOException 94 { 95 super.writeExternal(out); 96 out.writeBoolean(isMax); 97 } 98 99 105 public void readExternal(ObjectInput in) 106 throws IOException , ClassNotFoundException { 107 super.readExternal(in); 108 isMax = in.readBoolean(); 109 } 110 115 public int getTypeFormatId() { return StoredFormatIds.AGG_MAX_MIN_V01_ID; } 116 } 117 | Popular Tags |