01: /*
02:
03: Derby - Class org.apache.derby.impl.io.CPStorageFactory
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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.derby.impl.io;
23:
24: import org.apache.derby.iapi.services.sanity.SanityManager;
25:
26: import org.apache.derby.io.StorageFactory;
27: import org.apache.derby.io.StorageFile;
28:
29: import java.io.FileNotFoundException;
30: import java.io.InputStream;
31: import java.io.OutputStream;
32: import java.io.IOException;
33:
34: import java.util.Properties;
35:
36: /**
37: * This class provides a class path based implementation of the StorageFactory interface. It is used by the
38: * database engine to access persistent data and transaction logs under the classpath subsubprotocol.
39: */
40:
41: public class CPStorageFactory extends BaseStorageFactory {
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: return new CPFile(this , path);
51: }
52:
53: /**
54: * Construct a StorageFile from a directory and file name.
55: *
56: * @param directoryName The directory part of the path name. Must not be null, nor may it be in the temp dir.
57: * @param fileName The name of the file within the directory.
58: *
59: * @return A corresponding StorageFile object
60: */
61: StorageFile newPersistentFile(String directoryName, String fileName) {
62: if (directoryName == null || directoryName.length() == 0)
63: return newPersistentFile(fileName);
64: return new CPFile(this , directoryName, fileName);
65: }
66:
67: /**
68: * Construct a StorageFile from a directory and file name.
69: *
70: * @param directoryName The directory part of the path name.
71: * @param fileName The name of the file within the directory.
72: *
73: * @return A corresponding StorageFile object
74: */
75: StorageFile newPersistentFile(StorageFile directoryName,
76: String fileName) {
77: if (directoryName == null)
78: return newPersistentFile(fileName);
79: return new CPFile((CPFile) directoryName, fileName);
80: }
81:
82: void doInit() throws IOException {
83: if (dataDirectory != null) {
84: separatedDataDirectory = dataDirectory + '/'; // Class paths use '/' as a separator
85: canonicalName = dataDirectory;
86: createTempDir();
87: }
88: } // end of doInit
89: }
|