use of org.apache.derby.impl.io.vfmem.DataStore in project derby by apache.
the class VFMemoryStorageFactory method init.
/**
* Initializes the storage factory instance by setting up a temporary
* directory, the database directory and checking if the database being
* named already exists.
*
* @param home the value of {@code system.home} for this storage factory
* @param databaseName the name of the database, all relative pathnames are
* relative to this name
* @param tempDirNameIgnored ignored
* @param uniqueName used to determine when the temporary directory can be
* created, but not to name the temporary directory itself
*
* @exception IOException on an error (unexpected).
*/
public void init(String home, String databaseName, String tempDirNameIgnored, String uniqueName) throws IOException {
// Handle cases where a database name is specified.
if (databaseName != null) {
if (home != null && !new File(databaseName).isAbsolute()) {
canonicalName = new File(home, databaseName).getCanonicalPath();
} else {
canonicalName = new File(databaseName).getCanonicalPath();
}
synchronized (DATABASES) {
this.dbData = (DataStore) DATABASES.get(canonicalName);
// If the store has been scheduled for deletion, purge it.
if (dbData != null && dbData.scheduledForDeletion()) {
DATABASES.remove(canonicalName);
dbData.purge();
dbDropCleanupInDummy(canonicalName);
dbData = null;
}
if (dbData == null) {
if (uniqueName != null) {
// Create a new data store.
this.dbData = new DataStore(canonicalName);
DATABASES.put(canonicalName, dbData);
} else {
// We have a database name, but no unique name.
// Assume that the client only wants to do some
// "book-keeping" operations, like getting the
// canonical name.
this.dbData = DUMMY_STORE;
}
}
}
// Specify the data directory and the temp directory.
dataDirectory = new VirtualFile(canonicalName, dbData);
tempDir = new VirtualFile(normalizePath(canonicalName, "tmp"), dbData);
// Handle cases where the database name is null, but a system home
// directory has been specified.
} else if (home != null) {
// Return the "system home directory" and specify a temporary
// directory for it (may never by used).
// As databases are created, the dummy will contain the
// directory names of the database locations, but the
// databases themselves will be stored in separate stores.
final String absHome = new File(home).getCanonicalPath();
dbData = DUMMY_STORE;
dataDirectory = new VirtualFile(absHome, dbData);
tempDir = new VirtualFile(getSeparator() + "tmp", dbData);
}
// This check is also used by BaseStorageFactory.
if (uniqueName != null && tempDir != null && !tempDir.exists()) {
tempDir.mkdirs();
// nop, but follow pattern
tempDir.limitAccessToOwner();
}
}
use of org.apache.derby.impl.io.vfmem.DataStore in project derby by apache.
the class VirtualFileTest method testMkdirsInvalidAbsolute.
public void testMkdirsInvalidAbsolute() throws IOException {
DataStore store = getStore();
VirtualFile tmp = new VirtualFile(PathUtilTest.abs("directory"), store);
assertTrue(tmp.mkdir());
tmp = new VirtualFile(PathUtilTest.joinAbs("directory", "afile"), store);
assertTrue(tmp.createNewFile());
assertTrue(tmp.exists());
assertFalse(tmp.isDirectory());
VirtualFile vFile = new VirtualFile(PathUtilTest.joinAbs("directory", "afile", "anotherdir"), store);
assertFalse(vFile.mkdir());
assertFalse(vFile.mkdirs());
}
use of org.apache.derby.impl.io.vfmem.DataStore in project derby by apache.
the class VirtualFileTest method testCreateRoot.
/**
* Makes sure that the root can be created.
*/
public void testCreateRoot() {
DataStore store = new DataStore("testCreateRootStore");
String path = PathUtilTest.joinAbs("these", "are", "directories");
assertTrue(store.createAllParents(path));
assertNotNull(store.createEntry(path, true));
VirtualFile vf = new VirtualFile(path, store);
assertTrue(vf.exists());
assertTrue(vf.isDirectory());
// Also test one Windows specific root.
path = PathUtilTest.join("c:", "Documents and Settings", "directories");
assertTrue(store.createAllParents(path));
assertNotNull(store.createEntry(path, true));
vf = new VirtualFile(path, store);
assertTrue(vf.exists());
assertTrue(vf.isDirectory());
}
use of org.apache.derby.impl.io.vfmem.DataStore in project derby by apache.
the class VirtualFileTest method testCloseIdempotent.
/**
* Verify that the close() method of VirtualRandomAccessFile can be
* called more than once.
*/
public void testCloseIdempotent() throws IOException {
DataStore store = getStore();
VirtualFile f = new VirtualFile("afile", store);
StorageRandomAccessFile raf = f.getRandomAccessFile("rw");
raf.close();
// The second close() used to throw NullPointerException (DERBY-5960)
raf.close();
}
use of org.apache.derby.impl.io.vfmem.DataStore in project derby by apache.
the class VirtualFileTest method testCreateFileInRoot.
public void testCreateFileInRoot() {
DataStore store = getStore();
VirtualFile vFile = new VirtualFile("service.properties", store);
assertFalse(new VirtualFile("service.properties", store).exists());
assertFalse(vFile.exists());
}
Aggregations