001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.util.TestPropertyInfo
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.derbyTesting.functionTests.util;
023:
024: import org.apache.derby.iapi.error.StandardException;
025: import org.apache.derby.iapi.error.PublicAPI;
026:
027: import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
028: import org.apache.derby.iapi.sql.conn.ConnectionUtil;
029:
030: import org.apache.derby.iapi.db.PropertyInfo;
031: import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
032: import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
033: import org.apache.derby.iapi.sql.dictionary.DataDictionary;
034: import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
035: import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
036:
037: import org.apache.derby.iapi.store.access.ConglomerateController;
038: import org.apache.derby.iapi.store.access.TransactionController;
039:
040: import java.util.Properties;
041:
042: /**
043: * This class extends PropertyInfo to provide support for viewing ALL
044: * table/index properties, not just the user-visible ones.
045: */
046: public class TestPropertyInfo {
047:
048: /**
049: * Get ALL the Properties associated with a given table, not just the
050: * customer-visible ones.
051: *
052: * @param schemaName The name of the schema that the table is in.
053: * @param tableName The name of the table.
054: *
055: * @return Properties The Properties associated with the specified table.
056: * (An empty Properties is returned if the table does not exist.)
057: * @exception java.sql.SQLException thrown on error
058: */
059: public static String getAllTableProperties(String schemaName,
060: String tableName) throws java.sql.SQLException {
061: Properties p = TestPropertyInfo.getConglomerateProperties(
062: schemaName, tableName, false);
063: if (p == null)
064: return null;
065:
066: return org.apache.derbyTesting.functionTests.util.PropertyUtil
067: .sortProperties(p);
068: }
069:
070: /**
071: * Get a specific property associated with a given table, not just the
072: * customer-visible ones.
073: *
074: * @param schemaName The name of the schema that the table is in.
075: * @param tableName The name of the table.
076: *
077: * @param key The table property to retrieve
078: * @return Property value
079: * @exception java.sql.SQLException thrown on error
080: */
081: public static String getTableProperty(String schemaName,
082: String tableName, String key) throws java.sql.SQLException {
083: return TestPropertyInfo.getConglomerateProperties(schemaName,
084: tableName, false).getProperty(key);
085: }
086:
087: /**
088: * Get ALL the Properties associated with a given index, not just the customer-visible ones.
089: *
090: * @param schemaName The name of the schema that the index is in.
091: * @param indexName The name of the index.
092: *
093: * @return Properties The Properties associated with the specified index.
094: * (An empty Properties is returned if the index does not exist.)
095: * @exception java.sql.SQLException thrown on error
096: */
097: public static String getAllIndexProperties(String schemaName,
098: String indexName) throws java.sql.SQLException {
099: Properties p = TestPropertyInfo.getConglomerateProperties(
100: schemaName, indexName, true);
101:
102: if (p == null)
103: return null;
104:
105: return org.apache.derbyTesting.functionTests.util.PropertyUtil
106: .sortProperties(p);
107: }
108:
109: /**
110: Return the passed in Properties object with a property filtered out.
111: This is useful for filtering system depenent properties to make
112: test canons stable.
113: */
114: public static Properties filter(Properties p, String filterMe) {
115: p.remove(filterMe);
116: return p;
117: }
118:
119: private static Properties getConglomerateProperties(
120: String schemaName, String conglomerateName, boolean isIndex)
121: throws java.sql.SQLException {
122: ConglomerateController cc;
123: ConglomerateDescriptor cd;
124: DataDictionary dd;
125: Properties 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: // get the SchemaDescriptor
143: sd = dd.getSchemaDescriptor(schemaName, tc, true);
144: if (!isIndex) {
145: // get the TableDescriptor for the table
146: td = dd.getTableDescriptor(conglomerateName, sd);
147:
148: // Return an empty Properties if table does not exist or if it is for a view.
149: if ((td == null)
150: || td.getTableType() == TableDescriptor.VIEW_TYPE) {
151: return new Properties();
152: }
153:
154: conglomerateNumber = td.getHeapConglomerateId();
155: } else {
156: // get the ConglomerateDescriptor for the index
157: cd = dd.getConglomerateDescriptor(conglomerateName, sd,
158: false);
159:
160: // Return an empty Properties if index does not exist
161: if (cd == null) {
162: return new Properties();
163: }
164:
165: conglomerateNumber = cd.getConglomerateNumber();
166: }
167:
168: cc = tc.openConglomerate(conglomerateNumber, false, 0,
169: TransactionController.MODE_RECORD,
170: TransactionController.ISOLATION_SERIALIZABLE);
171:
172: properties = cc
173: .getInternalTablePropertySet(new Properties());
174:
175: cc.close();
176:
177: } catch (StandardException se) {
178: throw PublicAPI.wrapStandardException(se);
179: }
180:
181: return properties;
182: }
183: }
|