Search in sources :

Example 11 with DataStore

use of org.apache.derby.impl.io.vfmem.DataStore in project derby by apache.

the class VirtualFileTest method testGetRAFNonExistingReadMode.

/**
 * Getting a random access file in read mode for a non-existing file
 * should fail, and the file shouldn't be created.
 */
public void testGetRAFNonExistingReadMode() throws FileNotFoundException {
    DataStore store = getStore();
    VirtualFile vFile = new VirtualFile("aNewFile.txt", store);
    assertFalse(vFile.exists());
    try {
        vFile.getRandomAccessFile("r");
        fail("Cannot read from a non-exsiting file");
    } catch (FileNotFoundException fnfe) {
    // Expected.
    }
    assertFalse(vFile.exists());
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore) FileNotFoundException(java.io.FileNotFoundException)

Example 12 with DataStore

use of org.apache.derby.impl.io.vfmem.DataStore in project derby by apache.

the class VirtualFileTest method testMkdirsInvalidRelative.

public void testMkdirsInvalidRelative() throws IOException {
    DataStore store = getStore();
    VirtualFile tmp = new VirtualFile("seg0", store);
    assertTrue(tmp.mkdir());
    tmp = new VirtualFile(PathUtilTest.join("seg0", "datafile"), store);
    assertTrue(tmp.createNewFile());
    assertTrue(tmp.exists());
    assertFalse(tmp.isDirectory());
    VirtualFile vFile = new VirtualFile(PathUtilTest.join("seg0", "datafile", "anotherdir"), store);
    assertFalse(vFile.mkdir());
    assertFalse(vFile.mkdirs());
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Example 13 with DataStore

use of org.apache.derby.impl.io.vfmem.DataStore in project derby by apache.

the class VFMemoryStorageFactory method shutdown.

/**
 * Normally does nothing, but if the database is in a state such that it
 * should be deleted this will happen here.
 */
public void shutdown() {
    // delete the whole store to release the memory.
    if (dbData.scheduledForDeletion()) {
        DataStore store;
        synchronized (DATABASES) {
            store = (DataStore) DATABASES.remove(canonicalName);
            // Must clean up the dummy while holding monitor.
            if (store != null && store == dbData) {
                dbDropCleanupInDummy(canonicalName);
            }
        }
        // If this is the correct store, purge it now.
        if (store != null && store == dbData) {
            // Idempotent.
            dbData.purge();
            dbData = null;
        }
    }
}
Also used : DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Example 14 with DataStore

use of org.apache.derby.impl.io.vfmem.DataStore in project derby by apache.

the class VirtualFileTest method testMkdirsValidAbsolute.

public void testMkdirsValidAbsolute() {
    DataStore store = getStore();
    VirtualFile vFile = new VirtualFile(PathUtilTest.joinAbs(NON_EXISTING_DIRS), store);
    assertTrue(vFile.mkdirs());
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Example 15 with DataStore

use of org.apache.derby.impl.io.vfmem.DataStore in project derby by apache.

the class VirtualFileTest method testDeleteAll.

public void testDeleteAll() throws IOException {
    DataStore store = getStore();
    String[] dirs = new String[] { "seg0", PathUtilTest.join("seg0", "dir1"), "seg1", PathUtilTest.join("seg0", "dir2") };
    for (int i = 0; i < dirs.length; i++) {
        assertTrue(new VirtualFile(dirs[i], store).mkdir());
    }
    String[] files = new String[] { PathUtilTest.join("seg0", "f1"), PathUtilTest.join("seg0", "dir1", "f1"), PathUtilTest.join("seg1", "f1"), PathUtilTest.join("seg0", "f5") };
    for (int i = 0; i < files.length; i++) {
        assertTrue(new VirtualFile(files[i], store).createNewFile());
    }
    String root = "seg0";
    VirtualFile rootToDelete = new VirtualFile(root, store);
    assertTrue(rootToDelete.deleteAll());
    for (int i = 0; i < dirs.length; i++) {
        assertEquals(!dirs[i].startsWith(root), new VirtualFile(dirs[i], store).exists());
    }
    for (int i = 0; i < files.length; i++) {
        assertEquals(!files[i].startsWith(root), new VirtualFile(files[i], store).exists());
    }
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Aggregations

DataStore (org.apache.derby.impl.io.vfmem.DataStore)21 VirtualFile (org.apache.derby.impl.io.vfmem.VirtualFile)19 FileNotFoundException (java.io.FileNotFoundException)3 StorageFile (org.apache.derby.io.StorageFile)3 StorageRandomAccessFile (org.apache.derby.io.StorageRandomAccessFile)2 File (java.io.File)1