1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.io.CPStorageFactory |
4 | |
5 | Copyright 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.io; |
22 | |
23 | import org.apache.derby.iapi.services.sanity.SanityManager; |
24 | |
25 | import org.apache.derby.io.StorageFactory; |
26 | import org.apache.derby.io.StorageFile; |
27 | |
28 | import java.io.FileNotFoundException; |
29 | import java.io.InputStream; |
30 | import java.io.OutputStream; |
31 | import java.io.IOException; |
32 | |
33 | import java.util.Properties; |
34 | |
35 | /** |
36 | * This class provides a class path based implementation of the StorageFactory interface. It is used by the |
37 | * database engine to access persistent data and transaction logs under the classpath subsubprotocol. |
38 | */ |
39 | |
40 | public class CPStorageFactory extends BaseStorageFactory |
41 | { |
42 | /** |
43 | * Construct a persistent StorageFile from a path name. |
44 | * |
45 | * @param path The path name of the file |
46 | * |
47 | * @return A corresponding StorageFile object |
48 | */ |
49 | StorageFile newPersistentFile( String path) |
50 | { |
51 | return new CPFile( this, path); |
52 | } |
53 | |
54 | /** |
55 | * Construct a StorageFile from a directory and file name. |
56 | * |
57 | * @param directoryName The directory part of the path name. Must not be null, nor may it be in the temp dir. |
58 | * @param fileName The name of the file within the directory. |
59 | * |
60 | * @return A corresponding StorageFile object |
61 | */ |
62 | StorageFile newPersistentFile( String directoryName, String fileName) |
63 | { |
64 | if( directoryName == null || directoryName.length() == 0) |
65 | return newPersistentFile( fileName); |
66 | return new CPFile( this, directoryName, fileName); |
67 | } |
68 | |
69 | /** |
70 | * Construct a StorageFile from a directory and file name. |
71 | * |
72 | * @param directoryName The directory part of the path name. |
73 | * @param fileName The name of the file within the directory. |
74 | * |
75 | * @return A corresponding StorageFile object |
76 | */ |
77 | StorageFile newPersistentFile( StorageFile directoryName, String fileName) |
78 | { |
79 | if( directoryName == null) |
80 | return newPersistentFile( fileName); |
81 | return new CPFile( (CPFile) directoryName, fileName); |
82 | } |
83 | |
84 | void doInit() throws IOException |
85 | { |
86 | if( dataDirectory != null) |
87 | { |
88 | separatedDataDirectory = dataDirectory + '/'; // Class paths use '/' as a separator |
89 | canonicalName = dataDirectory; |
90 | createTempDir(); |
91 | } |
92 | } // end of doInit |
93 | } |