KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > util > corruptio > CorruptDiskStorageFactory


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.util.corruptio.CorruptDiskStorageFactory
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.corruptio;
23 import org.apache.derby.io.WritableStorageFactory;
24 import org.apache.derby.io.StorageFactory;
25 import org.apache.derby.iapi.services.info.JVMInfo;
26
27 /**
28  * This class provides proxy implementation of the StorageFactory
29  * interface for testing.
30  *
31  * Storage Factory is used by the database engine to access
32  * persistent data and transaction logs. By default all the method calls
33  * delegate the work to the real disk storage factory
34  * (org.apache.derby.impl.io.DirStorageFactory)
35  * based on the classes in the java.io packgs. In some cases this factory
36  * instruments some methods to corrupt the io to simulate disk corruptions for
37  * testing. For example to simulate out of order partial writes to disk before
38  * the crash.
39  *
40  * Derby by default uses the storage factory implementation in
41  * DirStorageFactory/DirStorageFactory4 when a database is accessed with
42  * "jdbc:derby:<databaseName>". This factory can be specified instead using
43  * derby.subSubProtocol.<sub protocol name> For example:
44  *
45  * derby.subSubProtocol.csf=org.apache.derbyTesting.functionTests.
46  * util.corruptio.CorruptDiskStorageFactory
47  * database need to be accessed by specifying the subporotocol name like
48  * 'jdbc:derby:csf:wombat'.
49  *
50  * Interaction between the tests that requires instrumenting the i/o and
51  * this factory is through the flags in CorruptibleIo class. Tests should not
52  * call the methods in this factory directly. Database engine invokes the
53  * methods in this factory, so they can instrumented to do whatever is
54  * required for testing.
55  *
56  * @author <a HREF="mailto:suresh.thalamati@gmail.com">Suresh Thalamati</a>
57  * @version 1.0
58  * @see CorruptibleIo
59  * @see WritableStorageFactory
60  * @see StorageFactory
61  *
62  */

63
64 public class CorruptDiskStorageFactory extends CorruptBaseStorageFactory
65 {
66     /*
67      * returns the real storage factory to which all the call should be
68      * delegated from the proxy methods.
69      */

70     WritableStorageFactory getRealStorageFactory()
71     {
72         String JavaDoc dirStorageFactoryClass;
73         if( JVMInfo.JDK_ID >= JVMInfo.J2SE_14)
74         {
75             dirStorageFactoryClass =
76                 "org.apache.derby.impl.io.DirStorageFactory4";
77         }
78         else
79         {
80             dirStorageFactoryClass =
81                 "org.apache.derby.impl.io.DirStorageFactory";
82         }
83         
84         WritableStorageFactory storageFactory = null;
85         try{
86             Class JavaDoc storageFactoryClass = Class.forName(dirStorageFactoryClass);
87             storageFactory =
88                 (WritableStorageFactory) storageFactoryClass.newInstance();
89         }catch(Exception JavaDoc e)
90         {
91             System.out.println(
92                 "Failed to instantiate the disk storeage classes");
93             e.printStackTrace();
94         }
95         
96         return storageFactory;
97     }
98 }
99
Popular Tags