001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.AggregatorInfoList
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.execute;
023:
024: import org.apache.derby.iapi.services.io.StoredFormatIds;
025: import org.apache.derby.iapi.services.io.FormatIdUtil;
026: import org.apache.derby.iapi.services.io.Formatable;
027:
028: import java.io.ObjectOutput;
029: import java.io.ObjectInput;
030: import java.io.IOException;
031: import java.util.Vector;
032:
033: /**
034: * Vector of AggergatorInfo objects.
035: *
036: * @see java.util.Vector
037: *
038: * @author jamie
039: */
040: public class AggregatorInfoList extends Vector implements Formatable {
041: /********************************************************
042: **
043: ** This class implements Formatable. That means that it
044: ** can write itself to and from a formatted stream. If
045: ** you add more fields to this class, make sure that you
046: ** also write/read them with the writeExternal()/readExternal()
047: ** methods.
048: **
049: ** If, inbetween releases, you add more fields to this class,
050: ** then you should bump the version number emitted by the getTypeFormatId()
051: ** method. OR, since this is something that is used
052: ** in stored prepared statements, it is ok to change it
053: ** if you make sure that stored prepared statements are
054: ** invalidated across releases.
055: **
056: ********************************************************/
057:
058: /**
059: * Niladic constructor for Formatable
060: */
061: public AggregatorInfoList() {
062: }
063:
064: /**
065: * Indicate whether i have a distinct or not.
066: *
067: * @return indicates if there is a distinct
068: */
069: public boolean hasDistinct() {
070: int count = size();
071: for (int i = 0; i < count; i++) {
072: AggregatorInfo aggInfo = (AggregatorInfo) elementAt(i);
073: if (aggInfo.isDistinct()) {
074: return true;
075: }
076: }
077: return false;
078: }
079:
080: //////////////////////////////////////////////
081: //
082: // FORMATABLE
083: //
084: //////////////////////////////////////////////
085:
086: /** @exception IOException thrown on error */
087: public void writeExternal(ObjectOutput out) throws IOException {
088: int count = size();
089: out.writeInt(count);
090: for (int i = 0; i < count; i++) {
091: out.writeObject(elementAt(i));
092: }
093: }
094:
095: /**
096: * @see java.io.Externalizable#readExternal
097: *
098: * @exception IOException on error
099: * @exception ClassNotFoundException on error
100: */
101: public void readExternal(ObjectInput in) throws IOException,
102: ClassNotFoundException {
103: int count = in.readInt();
104:
105: ensureCapacity(count);
106: for (int i = 0; i < count; i++) {
107: AggregatorInfo agg = (AggregatorInfo) in.readObject();
108: addElement(agg);
109: }
110: }
111:
112: /**
113: * Get the formatID which corresponds to this class.
114: *
115: * @return the formatID of this class
116: */
117: public int getTypeFormatId() {
118: return StoredFormatIds.AGG_INFO_LIST_V01_ID;
119: }
120:
121: ///////////////////////////////////////////////////////////////
122: //
123: // OBJECT INTERFACE
124: //
125: ///////////////////////////////////////////////////////////////
126: }
|