001: /*
002:
003: Derby - Class org.apache.derby.catalog.types.UserDefinedTypeIdImpl
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.StoredFormatIds;
025:
026: import java.sql.Types;
027: import java.io.ObjectOutput;
028: import java.io.ObjectInput;
029: import java.io.IOException;
030:
031: public class UserDefinedTypeIdImpl extends BaseTypeIdImpl {
032: /********************************************************
033: **
034: ** This class implements Formatable. That means that it
035: ** can write itself to and from a formatted stream. If
036: ** you add more fields to this class, make sure that you
037: ** also write/read them with the writeExternal()/readExternal()
038: ** methods.
039: **
040: ** If, inbetween releases, you add more fields to this class,
041: ** then you should bump the version number emitted by the getTypeFormatId()
042: ** method.
043: **
044: ********************************************************/
045:
046: protected String className;
047:
048: /**
049: * Public niladic constructor. Needed for Formatable interface to work.
050: *
051: */
052: public UserDefinedTypeIdImpl() {
053: super ();
054: }
055:
056: /**
057: * Constructor for a UserDefinedTypeIdImpl. The SQLTypeName of a UserDefinedType
058: * is assumed to be its className.
059: *
060: * @param className The SQL name of the type
061: */
062:
063: public UserDefinedTypeIdImpl(String className) {
064: super (className);
065: this .className = className;
066: JDBCTypeId = java.sql.Types.JAVA_OBJECT;
067: }
068:
069: /** Return the java class name for this type */
070: public String getClassName() {
071: return className;
072: }
073:
074: /** Does this type id represent a user type? */
075: public boolean userType() {
076: return true;
077: }
078:
079: // Formatable interface.
080:
081: /**
082: * Read this object from a stream of stored objects.
083: *
084: * @param in read this.
085: *
086: * @exception IOException thrown on error
087: * @exception ClassNotFoundException thrown on error
088: */
089: public void readExternal(ObjectInput in) throws IOException,
090: ClassNotFoundException {
091: super .readExternal(in);
092: className = in.readUTF();
093: JDBCTypeId = java.sql.Types.JAVA_OBJECT;
094: }
095:
096: /**
097: * Write this object to a stream of stored objects.
098: *
099: * @param out write bytes here.
100: *
101: * @exception IOException thrown on error
102: */
103: public void writeExternal(ObjectOutput out) throws IOException {
104: super .writeExternal(out);
105: out.writeUTF(className);
106: }
107:
108: /**
109: * Get the formatID which corresponds to this class.
110: *
111: * @return the formatID of this class
112: */
113: public int getTypeFormatId() {
114: return StoredFormatIds.USERDEFINED_TYPE_ID_IMPL_V3;
115: }
116:
117: /**
118: * Get the format id for the wrapper type id that corresponds to
119: * this type id.
120: */
121: public int wrapperTypeFormatId() {
122: return StoredFormatIds.USERDEFINED_TYPE_ID_V3;
123: }
124: }
|