Search in sources :

Example 1 with FileResource

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);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) FileInfoDescriptor(org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor) ContextManager(org.apache.derby.iapi.services.context.ContextManager) FileResource(org.apache.derby.iapi.store.access.FileResource)

Example 2 with FileResource

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());
    }
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) FileInfoDescriptor(org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor) HashMap(java.util.HashMap) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) FileResource(org.apache.derby.iapi.store.access.FileResource) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 3 with FileResource

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 (&gt;= 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);
}
Also used : FileResource(org.apache.derby.iapi.store.access.FileResource) StorageFile(org.apache.derby.io.StorageFile) StorageFile(org.apache.derby.io.StorageFile) File(java.io.File)

Example 4 with FileResource

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();
}
Also used : FileResource(org.apache.derby.iapi.store.access.FileResource)

Aggregations

FileResource (org.apache.derby.iapi.store.access.FileResource)4 FileInfoDescriptor (org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor)2 File (java.io.File)1 HashMap (java.util.HashMap)1 ContextManager (org.apache.derby.iapi.services.context.ContextManager)1 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)1 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)1 ScanController (org.apache.derby.iapi.store.access.ScanController)1 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)1 StorageFile (org.apache.derby.io.StorageFile)1