KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > util > TestPropertyInfo


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.util.TestPropertyInfo
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.derbyTesting.functionTests.util;
23
24 import org.apache.derby.iapi.error.StandardException;
25 import org.apache.derby.iapi.error.PublicAPI;
26
27 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
28 import org.apache.derby.iapi.sql.conn.ConnectionUtil;
29
30 import org.apache.derby.iapi.db.PropertyInfo;
31 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
32 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
33 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
34 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
35 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
36
37 import org.apache.derby.iapi.store.access.ConglomerateController;
38 import org.apache.derby.iapi.store.access.TransactionController;
39
40 import java.util.Properties JavaDoc;
41
42 /**
43  * This class extends PropertyInfo to provide support for viewing ALL
44  * table/index properties, not just the user-visible ones.
45  */

46 public class TestPropertyInfo
47 {
48
49     /**
50      * Get ALL the Properties associated with a given table, not just the
51      * customer-visible ones.
52      *
53      * @param schemaName The name of the schema that the table is in.
54      * @param tableName The name of the table.
55      *
56      * @return Properties The Properties associated with the specified table.
57      * (An empty Properties is returned if the table does not exist.)
58      * @exception java.sql.SQLException thrown on error
59      */

60     public static String JavaDoc getAllTableProperties(String JavaDoc schemaName, String JavaDoc tableName)
61         throws java.sql.SQLException JavaDoc
62     {
63         Properties JavaDoc p = TestPropertyInfo.getConglomerateProperties( schemaName, tableName, false );
64         if (p == null)
65             return null;
66
67         return org.apache.derbyTesting.functionTests.util.PropertyUtil.sortProperties(p);
68     }
69
70 /**
71      * Get a specific property associated with a given table, not just the
72      * customer-visible ones.
73      *
74      * @param schemaName The name of the schema that the table is in.
75      * @param tableName The name of the table.
76      *
77      * @param key The table property to retrieve
78      * @return Property value
79      * @exception java.sql.SQLException thrown on error
80      */

81     public static String JavaDoc getTableProperty(String JavaDoc schemaName, String JavaDoc tableName,
82                                           String JavaDoc key) throws java.sql.SQLException JavaDoc
83     {
84         return TestPropertyInfo.getConglomerateProperties( schemaName, tableName, false ).getProperty(key);
85     }
86
87     /**
88      * Get ALL the Properties associated with a given index, not just the customer-visible ones.
89      *
90      * @param schemaName The name of the schema that the index is in.
91      * @param indexName The name of the index.
92      *
93      * @return Properties The Properties associated with the specified index.
94      * (An empty Properties is returned if the index does not exist.)
95      * @exception java.sql.SQLException thrown on error
96      */

97     public static String JavaDoc getAllIndexProperties(String JavaDoc schemaName, String JavaDoc indexName)
98         throws java.sql.SQLException JavaDoc
99     {
100         Properties JavaDoc p = TestPropertyInfo.getConglomerateProperties( schemaName, indexName, true );
101
102         if (p == null)
103             return null;
104
105         return org.apache.derbyTesting.functionTests.util.PropertyUtil.sortProperties(p);
106     }
107
108     /**
109       Return the passed in Properties object with a property filtered out.
110       This is useful for filtering system depenent properties to make
111       test canons stable.
112       */

113     public static Properties JavaDoc filter(Properties JavaDoc p, String JavaDoc filterMe)
114     {
115         p.remove(filterMe);
116         return p;
117     }
118
119     private static Properties JavaDoc getConglomerateProperties( String JavaDoc schemaName, String JavaDoc conglomerateName, boolean isIndex )
120         throws java.sql.SQLException JavaDoc
121     {
122         ConglomerateController cc;
123         ConglomerateDescriptor cd;
124         DataDictionary dd;
125         Properties JavaDoc properties;
126         SchemaDescriptor sd;
127         TableDescriptor td;
128         TransactionController tc;
129         long conglomerateNumber;
130
131         // find the language context.
132
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
133
134         // Get the current transaction controller
135
tc = lcc.getTransactionExecute();
136
137         try {
138
139         // find the DataDictionary
140
dd = lcc.getDataDictionary();
141
142
143         // get the SchemaDescriptor
144
sd = dd.getSchemaDescriptor(schemaName, tc, true);
145         if ( !isIndex)
146         {
147             // get the TableDescriptor for the table
148
td = dd.getTableDescriptor(conglomerateName, sd);
149
150             // Return an empty Properties if table does not exist or if it is for a view.
151
if ((td == null) || td.getTableType() == TableDescriptor.VIEW_TYPE) { return new Properties JavaDoc(); }
152
153             conglomerateNumber = td.getHeapConglomerateId();
154         }
155         else
156         {
157             // get the ConglomerateDescriptor for the index
158
cd = dd.getConglomerateDescriptor(conglomerateName, sd, false);
159
160             // Return an empty Properties if index does not exist
161
if (cd == null) { return new Properties JavaDoc(); }
162
163             conglomerateNumber = cd.getConglomerateNumber();
164         }
165
166         cc = tc.openConglomerate(
167                 conglomerateNumber,
168                 false,
169                 0,
170                 TransactionController.MODE_RECORD,
171                 TransactionController.ISOLATION_SERIALIZABLE);
172
173         properties = cc.getInternalTablePropertySet( new Properties JavaDoc() );
174
175         cc.close();
176
177         } catch (StandardException se) {
178             throw PublicAPI.wrapStandardException(se);
179         }
180
181         return properties;
182     }
183 }
184
Popular Tags