Search in sources :

Example 21 with StorageFile

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

the class EncryptOrDecryptData method encryptOrDecryptContainer.

/**
 * Encrypts or decrypts the specified container.
 *
 * @param t transaction that used to perform the cryptographic operation
 * @param ckey the key of the container that is being encrypted/decrypted
 * @param doEncrypt tells whether to encrypt or decrypt
 * @exception StandardException Standard Derby error policy
 */
private void encryptOrDecryptContainer(RawTransaction t, ContainerKey ckey, boolean doEncrypt) throws StandardException {
    LockingPolicy cl = t.newLockingPolicy(LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_SERIALIZABLE, true);
    if (SanityManager.DEBUG)
        SanityManager.ASSERT(cl != null);
    RawContainerHandle containerHdl = (RawContainerHandle) t.openContainer(ckey, cl, ContainerHandle.MODE_FORUPDATE);
    if (SanityManager.DEBUG)
        SanityManager.ASSERT(containerHdl != null);
    EncryptContainerOperation lop = new EncryptContainerOperation(containerHdl);
    t.logAndDo(lop);
    // flush the log to reduce the window between where
    // the encrypted container is created & synced and the
    // log record for it makes it to disk. if we fail during
    // encryption of the container, log record will make sure
    // container is restored to the original state and
    // any temporary files are cleaned up.
    dataFactory.flush(t.getLastLogInstant());
    // encrypt the container.
    String newFilePath = getFilePath(ckey, false);
    StorageFile newFile = storageFactory.newStorageFile(newFilePath);
    containerHdl.encryptOrDecryptContainer(newFilePath, doEncrypt);
    containerHdl.close();
    // discard pages in the cache related to this container.
    if (!dataFactory.getPageCache().discard(ckey)) {
        if (SanityManager.DEBUG)
            SanityManager.THROWASSERT("unable to discard pages releated to " + "container " + ckey + " from the page cache");
    }
    // get rid of the container entry from conatainer cache
    if (!dataFactory.getContainerCache().discard(ckey)) {
        if (SanityManager.DEBUG)
            SanityManager.THROWASSERT("unable to discard a container " + ckey + " from the container cache");
    }
    StorageFile currentFile = dataFactory.getContainerPath(ckey, false);
    StorageFile oldFile = getFile(ckey, true);
    if (!privRename(currentFile, oldFile)) {
        throw StandardException.newException(SQLState.RAWSTORE_ERROR_RENAMING_FILE, currentFile, oldFile);
    }
    // now replace current container file with the new file.
    if (!privRename(newFile, currentFile)) {
        throw StandardException.newException(SQLState.RAWSTORE_ERROR_RENAMING_FILE, newFile, currentFile);
    }
}
Also used : StorageFile(org.apache.derby.io.StorageFile) RawContainerHandle(org.apache.derby.iapi.store.raw.data.RawContainerHandle) LockingPolicy(org.apache.derby.iapi.store.raw.LockingPolicy)

Example 22 with StorageFile

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

the class LogToFile method createDataWarningFile.

/**
 * Create readme file in log directory warning users against touching
 *  any files in the directory
 * @throws StandardException
 */
public void createDataWarningFile() throws StandardException {
    // Put a readme file in the log directory, alerting users to not
    // touch or remove any of the files there
    StorageFile fileReadMe = logStorageFactory.newStorageFile(LogFactory.LOG_DIRECTORY_NAME, PersistentService.DB_README_FILE_NAME);
    if (!privExists(fileReadMe)) {
        OutputStreamWriter osw = null;
        try {
            osw = privGetOutputStreamWriter(fileReadMe);
            osw.write(MessageService.getTextMessage(MessageId.README_AT_LOG_LEVEL));
        } catch (IOException ioe) {
        } finally {
            if (osw != null) {
                try {
                    osw.close();
                } catch (IOException ioe) {
                // Ignore exception on close
                }
            }
        }
    }
}
Also used : StorageFile(org.apache.derby.io.StorageFile) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException)

Example 23 with StorageFile

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

the class DerbyLuceneDir method createOutput.

/**
 *  Create a new, empty file for writing
 */
public DerbyIndexOutput createOutput(String name, IOContext context) throws IOException {
    checkIfClosed();
    DerbyIndexOutput indexOutput = _outputFiles.get(name);
    if (indexOutput != null) {
        indexOutput.close();
    }
    StorageFile file = getStorageFile(name);
    if (file.exists()) {
        deleteFile(name);
    }
    indexOutput = new DerbyIndexOutput(file, this);
    _outputFiles.put(name, indexOutput);
    return indexOutput;
}
Also used : StorageFile(org.apache.derby.io.StorageFile)

Example 24 with StorageFile

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

the class DerbyLuceneDir method deleteFile.

public void deleteFile(String name) throws IOException {
    checkIfClosed();
    StorageFile file = getStorageFile(name);
    if (file.exists()) {
        if (!file.delete()) {
            throw newIOException(SQLState.UNABLE_TO_DELETE_FILE, file.getPath());
        }
    }
}
Also used : StorageFile(org.apache.derby.io.StorageFile)

Example 25 with StorageFile

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

the class DerbyLuceneDir method openInput.

public DerbyIndexInput openInput(String name, IOContext context) throws IOException {
    checkIfClosed();
    StorageFile file = getStorageFile(name);
    if (!file.exists()) {
        throw new FileNotFoundException(file.getPath());
    }
    return getIndexInput(file);
}
Also used : StorageFile(org.apache.derby.io.StorageFile) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

StorageFile (org.apache.derby.io.StorageFile)53 IOException (java.io.IOException)21 StorageRandomAccessFile (org.apache.derby.io.StorageRandomAccessFile)13 File (java.io.File)12 PrivilegedActionException (java.security.PrivilegedActionException)9 StandardException (org.apache.derby.shared.common.error.StandardException)9 StorageFactory (org.apache.derby.io.StorageFactory)6 FileNotFoundException (java.io.FileNotFoundException)4 Properties (java.util.Properties)4 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)4 WritableStorageFactory (org.apache.derby.io.WritableStorageFactory)4 OutputStreamWriter (java.io.OutputStreamWriter)3 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)3 FileInputStream (java.io.FileInputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 ContextManager (org.apache.derby.iapi.services.context.ContextManager)2 DataStore (org.apache.derby.impl.io.vfmem.DataStore)2 VirtualFile (org.apache.derby.impl.io.vfmem.VirtualFile)2