Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/derby/impl/sql/catalog/DDColumnDependableFinder.java


1   /*
2   
3      Derby - Class org.apache.derby.impl.sql.catalog.DDColumnDependableFinder
4   
5      Copyright 2001, 2004 The Apache Software Foundation or its licensors, as applicable.
6   
7      Licensed under the Apache License, Version 2.0 (the "License");
8      you may not use this file except in compliance with the License.
9      You may obtain a copy of the License at
10  
11        http://www.apache.org/licenses/LICENSE-2.0
12  
13     Unless required by applicable law or agreed to in writing, software
14     distributed under the License is distributed on an "AS IS" BASIS,
15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16     See the License for the specific language governing permissions and
17     limitations under the License.
18  
19   */
20  
21  package org.apache.derby.impl.sql.catalog;
22  
23  import org.apache.derby.catalog.UUID;
24  import org.apache.derby.catalog.Dependable;
25  import org.apache.derby.iapi.sql.dictionary.DataDictionary;
26  import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
27  import org.apache.derby.iapi.error.StandardException;
28  
29  import org.apache.derby.iapi.services.io.FormatableHashtable;
30  import org.apache.derby.iapi.services.io.FormatableBitSet;
31  
32  import java.io.ObjectOutput;
33  import java.io.ObjectInput;
34  import java.io.IOException;
35  
36  /**
37   *  Class for implementation of DependableFinder in the core DataDictionary 
38   *  for referenced columns in a table.
39   *
40   *
41   * @author Tingjian Ge
42   */
43  
44  public class DDColumnDependableFinder extends DDdependableFinder
45  {
46    ////////////////////////////////////////////////////////////////////////
47    //
48    //  STATE
49    //
50    ////////////////////////////////////////////////////////////////////////
51  
52    // write least amount of data to disk, just the byte array, not even
53    // a FormatableBitSet
54    private byte[] columnBitMap;
55  
56      ////////////////////////////////////////////////////////////////////////
57      //
58      //  CONSTRUCTORS
59      //
60      ////////////////////////////////////////////////////////////////////////
61  
62    /**
63     * Constructor same as in parent.
64     */
65    public  DDColumnDependableFinder(int formatId)
66    {
67      super(formatId);
68    }
69  
70    /**
71     * Constructor given referenced column bit map byte array as in FormatableBitSet
72     */
73    public  DDColumnDependableFinder(int formatId, byte[] columnBitMap)
74    {
75      super(formatId);
76      this.columnBitMap = columnBitMap;
77    }
78  
79      ////////////////////////////////////////////////////////////////////////
80      //
81      //  DDColumnDependable METHODS
82      //
83      ////////////////////////////////////////////////////////////////////////
84  
85    /**
86     * Get the byte array encoding the bitmap of referenced columns in
87     * a table.
88     *
89     * @param    none
90     * @return    byte array as in a FormatableBitSet encoding column bit map
91     */
92    public   byte[]  getColumnBitMap()
93    {
94      return columnBitMap;
95    }
96  
97    /**
98     * Set the byte array encoding the bitmap of referenced columns in
99     * a table.
100    *
101    * @param    byte array as in a FormatableBitSet encoding column bit map
102    * @return    none
103    */
104   public  void  setColumnBitMap(byte[] columnBitMap)
105   {
106     this.columnBitMap = columnBitMap;
107   }
108 
109   /**
110    * Get a dependable object, which is essentially a table descriptor with
111    * referencedColumnMap field set.
112    *
113    * @param  data dictionary
114    * @param  dependable object ID (table UUID)
115    * @return  a dependable, a table descriptor with referencedColumnMap
116    *      field set
117    */
118   protected Dependable getDependable(DataDictionary dd, UUID dependableObjectID)
119     throws StandardException
120   {
121     TableDescriptor td = dd.getTableDescriptor(dependableObjectID);
122     if (td != null)  // see beetle 4444
123       td.setReferencedColumnMap(new FormatableBitSet(columnBitMap));
124     return td;
125   }
126 
127     //////////////////////////////////////////////////////////////////
128     //
129     //  FORMATABLE METHODS
130     //
131     //////////////////////////////////////////////////////////////////
132 
133   /**
134    * Read this object from a stream of stored objects.  Just read the
135    * byte array, besides what the parent does.
136    *
137    * @param in read this.
138    */
139   public void readExternal( ObjectInput in )
140       throws IOException, ClassNotFoundException
141   {
142     super.readExternal(in);
143     FormatableHashtable fh = (FormatableHashtable)in.readObject();
144     columnBitMap = (byte[])fh.get("columnBitMap");
145   }
146 
147   /**
148    * Write this object to a stream of stored objects.  Just write the
149    * byte array, besides what the parent does.
150    *
151    * @param out write bytes here.
152    */
153   public void writeExternal( ObjectOutput out )
154       throws IOException
155   {
156     super.writeExternal(out);
157     FormatableHashtable fh = new FormatableHashtable();
158     fh.put("columnBitMap", columnBitMap);
159     out.writeObject(fh);
160   }
161 }