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