01: /*
02:
03: Derby - Class org.apache.derby.impl.io.DirStorageFactory4
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.io.StorageFile;
25: import org.apache.derby.iapi.services.info.JVMInfo;
26:
27: import java.io.IOException;
28:
29: /**
30: * This class implements the WritableStorageFactory interface using features found in Java 1.4 but
31: * not in earlier versions of Java.
32: */
33: public class DirStorageFactory4 extends DirStorageFactory {
34:
35: private static final boolean rwsOK = JVMInfo.JDK_ID >= JVMInfo.J2SE_142;
36:
37: /**
38: * Most of the initialization is done in the init method.
39: */
40: public DirStorageFactory4() {
41: super ();
42: }
43:
44: /**
45: * Construct a persistent StorageFile from a path name.
46: *
47: * @param path The path name of the file. Guaranteed not to be in the temporary file directory. If null
48: * then the database directory should be returned.
49: *
50: * @return A corresponding StorageFile object
51: */
52: StorageFile newPersistentFile(String path) {
53: if (path == null)
54: return new DirFile4(dataDirectory, rwsOK);
55: return new DirFile4(dataDirectory, path, rwsOK);
56: }
57:
58: /**
59: * Construct a persistent StorageFile from a directory and path name.
60: *
61: * @param directoryName The path name of the directory. Guaranteed not to be in the temporary file directory.
62: * Guaranteed not to be null
63: * @param fileName The name of the file within the directory. Guaranteed not to be null.
64: *
65: * @return A corresponding StorageFile object
66: */
67: StorageFile newPersistentFile(String directoryName, String fileName) {
68: return new DirFile4(separatedDataDirectory + directoryName,
69: fileName, rwsOK);
70: }
71:
72: /**
73: * Construct a persistent StorageFile from a directory and path name.
74: *
75: * @param directoryName The path name of the directory. Guaranteed not to be to be null. Guaranteed to be
76: * created by a call to one of the newPersistentFile methods.
77: * @param fileName The name of the file within the directory. Guaranteed not to be null.
78: *
79: * @return A corresponding StorageFile object
80: */
81: StorageFile newPersistentFile(StorageFile directoryName,
82: String fileName) {
83: return new DirFile4((DirFile) directoryName, fileName, rwsOK);
84: }
85:
86: /**
87: * This method tests whether the "rws" and "rwd" modes are implemented. If the "rws" method is supported
88: * then the database engine will conclude that the write methods of "rws" mode StorageRandomAccessFiles are
89: * slow but the sync method is fast and optimize accordingly.
90: *
91: * @return <b>true</b> if an StIRandomAccess file opened with "rws" or "rwd" modes immediately writes data to the
92: * underlying storage, <b>false</b> if not.
93: */
94: public boolean supportsRws() {
95: return rwsOK;
96: }
97:
98: }
|