use of org.apache.derby.iapi.store.access.FileResource in project derby by apache.
the class BasicDatabase method getJarFile.
/*
** Methods of JarReader
*/
public StorageFile getJarFile(String schemaName, String sqlName) throws StandardException {
SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, null, true);
FileInfoDescriptor fid = dd.getFileInfoDescriptor(sd, sqlName);
if (fid == null)
throw StandardException.newException(SQLState.LANG_FILE_DOES_NOT_EXIST, sqlName, schemaName);
long generationId = fid.getGenerationId();
ContextManager cm = getContextService().getCurrentContextManager();
FileResource fr = af.getTransaction(cm).getFileHandler();
String externalName = JarUtil.mkExternalName(fid.getUUID(), schemaName, sqlName, fr.getSeparatorChar());
return fr.getAsFile(externalName, generationId);
}
use of org.apache.derby.iapi.store.access.FileResource in project derby by apache.
the class DataDictionaryImpl method upgradeJarStorage.
/**
* Called by the upgrade code to upgrade the way we store jar files in the
* database.<p/>
* We now use UUID as part of the file name to avoid problems with path
* delimiters. Also, we henceforth use no schema subdirectories since there
* is no chance of name collision with the UUID.
*
* @param tc TransactionController to use.
*/
protected void upgradeJarStorage(TransactionController tc) throws StandardException {
TabInfoImpl ti = getNonCoreTI(SYSFILES_CATALOG_NUM);
SYSFILESRowFactory rf = (SYSFILESRowFactory) ti.getCatalogRowFactory();
ExecRow outRow = rf.makeEmptyRow();
/*
** Table scan
*/
ScanController scanController = tc.openScan(// conglomerate to open
ti.getHeapConglomerate(), // don't hold open across commit
false, // for read
0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
(FormatableBitSet) null, // start position - first row
(DataValueDescriptor[]) null, // startSearchOperation - none
0, // scanQualifier,
(Qualifier[][]) null, // stop position -through last row
(DataValueDescriptor[]) null, // stopSearchOperation - none
0);
Map<String, Object> schemas = new HashMap<String, Object>();
try {
while (scanController.fetchNext(outRow.getRowArray())) {
FileInfoDescriptor fid = (FileInfoDescriptor) rf.buildDescriptor(outRow, null, this);
schemas.put(fid.getSchemaDescriptor().getSchemaName(), null);
JarUtil.upgradeJar(tc, fid);
}
} finally {
scanController.close();
}
Iterator<String> i = schemas.keySet().iterator();
FileResource fh = tc.getFileHandler();
// remove those directories with their contents
while (i.hasNext()) {
fh.removeJarDir(FileResource.JAR_DIRECTORY_NAME + File.separatorChar + i.next());
}
}
use of org.apache.derby.iapi.store.access.FileResource in project derby by apache.
the class JarUtil method upgradeJar.
/**
* Upgrade code: upgrade one jar file to new style (>= 10.9)
*
* @param tc transaction controller
* @param fid the jar file to be upgraded
* @throws StandardException
*/
public static void upgradeJar(TransactionController tc, FileInfoDescriptor fid) throws StandardException {
FileResource fh = tc.getFileHandler();
StorageFile oldFile = fh.getAsFile(mkExternalNameInternal(fid.getUUID(), fid.getSchemaDescriptor().getSchemaName(), fid.getName(), File.separatorChar, true, false), fid.getGenerationId());
StorageFile newFile = fh.getAsFile(mkExternalNameInternal(fid.getUUID(), fid.getSchemaDescriptor().getSchemaName(), fid.getName(), File.separatorChar, true, true), fid.getGenerationId());
FileUtil.copyFile(new File(oldFile.getPath()), new File(newFile.getPath()), null);
}
use of org.apache.derby.iapi.store.access.FileResource in project derby by apache.
the class RemoveFileOperation method needsRedo.
/**
* @exception StandardException Standard Derby error policy
*/
public boolean needsRedo(Transaction xact) throws StandardException {
if (!removeAtOnce)
return false;
FileResource fr = ((RawTransaction) xact).getDataFactory().getFileHandler();
fileToGo = fr.getAsFile(name, generationId);
if (fileToGo == null)
return false;
return fileToGo.exists();
}
Aggregations