001: /*
002:
003: Derby - Class org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl
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.catalog.types;
023:
024: import org.apache.derby.iapi.services.io.Formatable;
025: import org.apache.derby.iapi.services.io.StoredFormatIds;
026: import org.apache.derby.catalog.ReferencedColumns;
027:
028: import java.io.ObjectInput;
029: import java.io.ObjectOutput;
030: import java.io.IOException;
031:
032: public class ReferencedColumnsDescriptorImpl implements
033: ReferencedColumns, Formatable {
034: /********************************************************
035: **
036: ** This class implements Formatable. That means that it
037: ** can write itself to and from a formatted stream. If
038: ** you add more fields to this class, make sure that you
039: ** also write/read them with the writeExternal()/readExternal()
040: ** methods.
041: **
042: ** If, inbetween releases, you add more fields to this class,
043: ** then you should bump the version number emitted by the getTypeFormatId()
044: ** method.
045: **
046: ********************************************************/
047:
048: private int[] referencedColumns;
049:
050: /**
051: * Constructor for an ReferencedColumnsDescriptorImpl
052: *
053: * @param referencedColumns The array of referenced columns.
054: */
055:
056: public ReferencedColumnsDescriptorImpl(int[] referencedColumns) {
057: this .referencedColumns = referencedColumns;
058: }
059:
060: /** Zero-argument constructor for Formatable interface */
061: public ReferencedColumnsDescriptorImpl() {
062: }
063:
064: /**
065: * @see ReferencedColumns#getReferencedColumnPositions
066: */
067: public int[] getReferencedColumnPositions() {
068: return referencedColumns;
069: }
070:
071: /* Externalizable interface */
072:
073: /**
074: * @see java.io.Externalizable#readExternal
075: *
076: * @exception IOException Thrown on read error
077: */
078: public void readExternal(ObjectInput in) throws IOException {
079: int rcLength = in.readInt();
080: referencedColumns = new int[rcLength];
081: for (int i = 0; i < rcLength; i++) {
082: referencedColumns[i] = in.readInt();
083: }
084: }
085:
086: /**
087: * @see java.io.Externalizable#writeExternal
088: *
089: * @exception IOException Thrown on write error
090: */
091: public void writeExternal(ObjectOutput out) throws IOException {
092: out.writeInt(referencedColumns.length);
093: for (int i = 0; i < referencedColumns.length; i++) {
094: out.writeInt(referencedColumns[i]);
095: }
096: }
097:
098: /* TypedFormat interface */
099: public int getTypeFormatId() {
100: return StoredFormatIds.REFERENCED_COLUMNS_DESCRIPTOR_IMPL_V01_ID;
101: }
102:
103: /**
104: @see java.lang.Object#toString
105: */
106: public String toString() {
107: StringBuffer sb = new StringBuffer(60);
108:
109: sb.append('(');
110: for (int index = 0; index < referencedColumns.length; index++) {
111: if (index > 0)
112: sb.append(',');
113: sb.append(String.valueOf(referencedColumns[index]));
114:
115: }
116: sb.append(')');
117: return sb.toString();
118: }
119: }
|