Search in sources :

Example 1 with DataStore

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();
    }
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore) StorageFile(org.apache.derby.io.StorageFile) VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) File(java.io.File)

Example 2 with DataStore

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());
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Example 3 with DataStore

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());
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Example 4 with DataStore

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();
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) StorageRandomAccessFile(org.apache.derby.io.StorageRandomAccessFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Example 5 with DataStore

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());
}
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