KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.util.ConsistencyChecker
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
26 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
27 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
28 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
29 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
30 import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;
31 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
32
33 import org.apache.derby.iapi.sql.depend.DependencyManager;
34
35 import org.apache.derby.iapi.sql.execute.ExecutionContext;
36
37 import org.apache.derby.iapi.types.DataValueFactory;
38
39 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
40
41 import org.apache.derby.iapi.store.access.TransactionController;
42 import org.apache.derby.iapi.types.RowLocation;
43 import org.apache.derby.iapi.store.access.ScanController;
44 import org.apache.derby.iapi.store.access.ConglomerateController;
45
46 import org.apache.derby.iapi.services.context.ContextService;
47
48 import org.apache.derby.iapi.services.io.FormatableBitSet;
49
50 /**
51  * This class provides static methods for checking the consistency of database
52  * objects like tables.
53  */

54 public class ConsistencyChecker
55 {
56
57     /**
58      * Run all of the consistency checkers which do not take parameters.
59      * Actually, just run the ones that "make sense" to run. Today,
60      * that is:
61      * countOpens()
62      *
63      * @return String If an inconsistency is found, and if DEBUG is on,
64      * then a string will be returned with more info.
65      * If DEBUG is off, then a simple string will be
66      * returned stating whether or not there are open scans.
67      *
68      * @exception StandardException Thrown on error
69      * @exception java.sql.SQLException Thrown on error
70      */

71     public static String JavaDoc runConsistencyChecker() throws StandardException, java.sql.SQLException JavaDoc
72     {
73         return countOpens() + countDependencies();
74     }
75
76     /**
77      * Check to make sure that there are no open conglomerates, scans or sorts.
78      *
79      * @return String If an inconsistency is found, and if DEBUG is on,
80      * then a string will be returned with more info.
81      * If DEBUG is off, then a simple string will be
82      * returned stating whether or not there are open scans.
83      *
84      * @exception StandardException Thrown on error
85      */

86     public static String JavaDoc countOpens() throws StandardException
87     {
88         int numOpens = 0;
89         LanguageConnectionContext lcc;
90         String JavaDoc output = "No open scans, etc.\n";
91         TransactionController tc;
92
93         lcc = (LanguageConnectionContext)
94             ContextService.getContext(LanguageConnectionContext.CONTEXT_ID);
95         tc = lcc.getTransactionExecute();
96
97         numOpens = tc.countOpens(TransactionController.OPEN_TOTAL);
98
99         if (numOpens > 0)
100         {
101             output = numOpens + " conglomerates/scans/sorts found open\n";
102
103         }
104
105         return output;
106     }
107
108     /**
109      * Check to make sure that there are no active dependencies (stored or
110      * in memory).
111      *
112      * @return String If an inconsistency is found, and if DEBUG is on,
113      * then a string will be returned with more info.
114      * If DEBUG is off, then a simple string will be
115      * returned stating whether or not there are open scans.
116      *
117      * @exception StandardException Thrown on error
118      * @exception java.sql.SQLException Thrown on error
119      */

120     public static String JavaDoc countDependencies() throws StandardException, java.sql.SQLException JavaDoc
121     {
122         int numDependencies = 0;
123         DataDictionary dd;
124         DataDictionaryContext ddc;
125         DependencyManager dm;
126         StringBuffer JavaDoc debugBuf = new StringBuffer JavaDoc();
127
128         ddc = (DataDictionaryContext)
129                 (ContextService.getContext(DataDictionaryContext.CONTEXT_ID));
130
131         dd = ddc.getDataDictionary();
132         dm = dd.getDependencyManager();
133
134         numDependencies = dm.countDependencies();
135
136         if (numDependencies > 0)
137         {
138             debugBuf.append(numDependencies + " dependencies found");
139         }
140         else
141         {
142             debugBuf.append("No outstanding dependencies.\n");
143         }
144
145         return debugBuf.toString();
146     }
147 }
148
Popular Tags