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