Search in sources :

Example 6 with StorageFactory

use of org.apache.derby.io.StorageFactory in project derby by apache.

the class BasicDatabase method backupLucene.

/**
 * <p>
 * Backup Lucene indexes to the backup directory. This assumes
 * that the rest of the database has been backup up and sanity
 * checks have been run.
 * </p>
 */
private void backupLucene(String backupDir) throws StandardException {
    try {
        File backupRoot = new File(backupDir);
        StorageFactory storageFactory = getStorageFactory();
        String canonicalDbName = storageFactory.getCanonicalName();
        String dbname = StringUtil.shortDBName(canonicalDbName, storageFactory.getSeparator());
        File backupDB = new File(backupRoot, dbname);
        final File targetDir = new File(backupDB, Database.LUCENE_DIR);
        final StorageFile sourceDir = getLuceneDir();
        AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {

            public Boolean run() throws StandardException {
                if (!FileUtil.copyDirectory(getStorageFactory(), sourceDir, targetDir, null, null, true)) {
                    throw StandardException.newException(SQLState.UNABLE_TO_COPY_FILE_FROM_BACKUP, sourceDir.getPath(), targetDir.getAbsolutePath());
                }
                return null;
            }
        });
    } catch (IOException ioe) {
        throw StandardException.plainWrapException(ioe);
    } catch (PrivilegedActionException pae) {
        throw StandardException.plainWrapException(pae);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) StorageFactory(org.apache.derby.io.StorageFactory) PrivilegedActionException(java.security.PrivilegedActionException) StorageFile(org.apache.derby.io.StorageFile) IOException(java.io.IOException) StorageFile(org.apache.derby.io.StorageFile) File(java.io.File)

Example 7 with StorageFactory

use of org.apache.derby.io.StorageFactory in project derby by apache.

the class BaseDataFileFactory method luceneLoaded.

/**
 * Return true if the Lucene plugin is loaded
 */
public boolean luceneLoaded() throws StandardException {
    try {
        return AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>() {

            public Boolean run() {
                StorageFactory storageFactory = getStorageFactory();
                StorageFile luceneDir = storageFactory.newStorageFile(Database.LUCENE_DIR);
                return luceneDir.exists();
            }
        }).booleanValue();
    } catch (PrivilegedActionException pae) {
        throw StandardException.plainWrapException(pae);
    }
}
Also used : WritableStorageFactory(org.apache.derby.io.WritableStorageFactory) StorageFactory(org.apache.derby.io.StorageFactory) PrivilegedActionException(java.security.PrivilegedActionException) StorageFile(org.apache.derby.io.StorageFile) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 8 with StorageFactory

use of org.apache.derby.io.StorageFactory in project derby by apache.

the class LuceneSupport method getDerbyLuceneDir.

// ///////////////////////////////////////////////////////////////////
// 
// DERBY STORE
// 
// ///////////////////////////////////////////////////////////////////
/**
 * <p>
 * Get the handle on the Lucene directory inside the database.
 * </p>
 */
static DerbyLuceneDir getDerbyLuceneDir(Connection conn, String schema, String table, String textcol) throws SQLException {
    StorageFactory storageFactory = getStorageFactory(conn);
    DerbyLuceneDir result = DerbyLuceneDir.getDirectory(storageFactory, schema, table, textcol);
    return result;
}
Also used : StorageFactory(org.apache.derby.io.StorageFactory)

Example 9 with StorageFactory

use of org.apache.derby.io.StorageFactory in project derby by apache.

the class StorageFactoryService method getCanonicalServiceName.

// end of removeServiceRoot
public String getCanonicalServiceName(String name) throws StandardException {
    int colon = name.indexOf(':');
    // in the directory or database name.
    if (colon < 2 && !getType().equals(PersistentService.DIRECTORY)) {
        return null;
    }
    if (// Subsubprotocols must be at least 2 characters long
    colon > 1) {
        if (!name.startsWith(getType() + ":"))
            // It is not our database
            return null;
        name = name.substring(colon + 1);
    }
    final String nm = name;
    try {
        return getProtocolLeadIn() + AccessController.doPrivileged(new PrivilegedExceptionAction<String>() {

            public String run() throws StandardException, IOException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
                StorageFactory storageFactory = privGetStorageFactoryInstance(true, nm, null, null);
                try {
                    return storageFactory.getCanonicalName();
                } finally {
                    storageFactory.shutdown();
                }
            }
        });
    } catch (PrivilegedActionException pae) {
        throw Monitor.exceptionStartingModule(pae.getException());
    }
}
Also used : WritableStorageFactory(org.apache.derby.io.WritableStorageFactory) StorageFactory(org.apache.derby.io.StorageFactory) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Aggregations

StorageFactory (org.apache.derby.io.StorageFactory)9 PrivilegedActionException (java.security.PrivilegedActionException)6 StorageFile (org.apache.derby.io.StorageFile)6 WritableStorageFactory (org.apache.derby.io.WritableStorageFactory)6 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)4 File (java.io.File)3 IOException (java.io.IOException)3 StandardException (org.apache.derby.shared.common.error.StandardException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 StorageRandomAccessFile (org.apache.derby.io.StorageRandomAccessFile)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Properties (java.util.Properties)1 EmbedConnection (org.apache.derby.impl.jdbc.EmbedConnection)1