KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > catalog > types > DecimalTypeIdImpl


1 /*
2
3    Derby - Class org.apache.derby.catalog.types.DecimalTypeIdImpl
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.catalog.types;
23 import org.apache.derby.iapi.services.io.StoredFormatIds;
24 import java.io.ObjectOutput JavaDoc;
25 import java.io.ObjectInput JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.sql.Types JavaDoc;
28
29 public class DecimalTypeIdImpl extends BaseTypeIdImpl
30 {
31     /* this class is needed because writeexternal for this class stores
32        extra information; when the object is sent over the wire the niladic
33        constructor is first called and then we call the readExternal method.
34        the readExternal needs to know the formatId atleast for decimal types
35        to read the extra information.
36     */

37     public DecimalTypeIdImpl()
38     {
39         super(StoredFormatIds.DECIMAL_TYPE_ID_IMPL);
40     }
41     
42     /**
43      * Read this object from a stream of stored objects.
44      *
45      * @param in read this.
46      *
47      * @exception IOException thrown on error
48      * @exception ClassNotFoundException thrown on error
49      */

50     public void readExternal( ObjectInput JavaDoc in )
51          throws IOException JavaDoc, ClassNotFoundException JavaDoc
52     {
53         boolean isNumeric = in.readBoolean();
54
55         super.readExternal(in);
56
57         if (isNumeric)
58         {
59             setNumericType();
60         }
61
62     }
63
64     /**
65      * Write this object to a stream of stored objects.
66      *
67      * @param out write bytes here.
68      *
69      * @exception IOException thrown on error
70      */

71     public void writeExternal( ObjectOutput JavaDoc out )
72          throws IOException JavaDoc
73     {
74         out.writeBoolean(JDBCTypeId == Types.NUMERIC);
75
76         super.writeExternal(out);
77     }
78
79     public void setNumericType()
80     {
81         SQLTypeName = "NUMERIC";
82         JDBCTypeId = Types.NUMERIC;
83     }
84 }
85
Popular Tags