Search in sources :

Example 1 with FileInfoDescriptor

use of org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor 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 FileInfoDescriptor

use of org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor in project derby by apache.

the class BasicDatabase method validate.

/**
 *	  @see PropertySetCallback#validate
 *	  @exception StandardException Thrown on error.
 */
public boolean validate(String key, Serializable value, Dictionary p) throws StandardException {
    // Disallow setting static creation time only configuration properties
    if (key.equals(EngineType.PROPERTY))
        throw StandardException.newException(SQLState.PROPERTY_UNSUPPORTED_CHANGE, key, value);
    // only interested in the classpath
    if (!key.equals(Property.DATABASE_CLASSPATH))
        return false;
    String newClasspath = (String) value;
    // The parsed dbclasspath
    String[][] dbcp = null;
    if (newClasspath != null) {
        // parse it when it is set to ensure only valid values
        // are written to the actual conglomerate.
        dbcp = IdUtil.parseDbClassPath(newClasspath);
    }
    // Verify that all jar files on the database classpath are in the data dictionary.
    if (dbcp != null) {
        for (int ix = 0; ix < dbcp.length; ix++) {
            SchemaDescriptor sd = dd.getSchemaDescriptor(dbcp[ix][IdUtil.DBCP_SCHEMA_NAME], null, false);
            FileInfoDescriptor fid = null;
            if (sd != null)
                fid = dd.getFileInfoDescriptor(sd, dbcp[ix][IdUtil.DBCP_SQL_JAR_NAME]);
            if (fid == null) {
                throw StandardException.newException(SQLState.LANG_DB_CLASS_PATH_HAS_MISSING_JAR, IdUtil.mkQualifiedName(dbcp[ix]));
            }
        }
    }
    return true;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) FileInfoDescriptor(org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor)

Example 3 with FileInfoDescriptor

use of org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor 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 4 with FileInfoDescriptor

use of org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor in project derby by apache.

the class DataDictionaryImpl method getFileInfoDescriptorIndex1Scan.

/**
 * Scan sysfiles_index1 (schemaid,name) for a match.
 * @return The matching descriptor or null.
 * @exception StandardException		Thrown on failure
 */
private FileInfoDescriptor getFileInfoDescriptorIndex1Scan(UUID schemaId, String name) throws StandardException {
    DataValueDescriptor schemaIDOrderable;
    DataValueDescriptor nameOrderable;
    TabInfoImpl ti = getNonCoreTI(SYSFILES_CATALOG_NUM);
    nameOrderable = new SQLVarchar(name);
    schemaIDOrderable = getIDValueAsCHAR(schemaId);
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = exFactory.getIndexableRow(2);
    keyRow.setColumn(1, nameOrderable);
    keyRow.setColumn(2, schemaIDOrderable);
    FileInfoDescriptor r = getDescriptorViaIndex(SYSFILESRowFactory.SYSFILES_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, FileInfoDescriptor.class, false);
    return r;
}
Also used : FileInfoDescriptor(org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor) TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 5 with FileInfoDescriptor

use of org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor in project derby by apache.

the class SYSFILESRowFactory method buildDescriptor.

// /////////////////////////////////////////////////////////////////////////
// 
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
// 
// /////////////////////////////////////////////////////////////////////////
/**
 * Make a descriptor out of a SYSFILES row
 *
 * @param row a row
 * @param parentTupleDescriptor	Null for this kind of descriptor.
 * @param dd dataDictionary
 *
 * @return	a descriptor equivalent to a row
 *
 * @exception   StandardException thrown on failure
 */
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
    if (SanityManager.DEBUG) {
        if (row.nColumns() != SYSFILES_COLUMN_COUNT) {
            SanityManager.THROWASSERT("Wrong number of columns for a SYSFILES row: " + row.nColumns());
        }
    }
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    String id_S;
    UUID id;
    String schemaId_S;
    UUID schemaId;
    String name;
    long generationId;
    DataValueDescriptor col;
    SchemaDescriptor schemaDescriptor;
    FileInfoDescriptor result;
    /* 1st column is ID (UUID - char(36)) */
    col = row.getColumn(ID_COL_NUM);
    id_S = col.getString();
    id = getUUIDFactory().recreateUUID(id_S);
    /* 2nd column is SchemaId */
    col = row.getColumn(SCHEMA_ID_COL_NUM);
    schemaId_S = col.getString();
    schemaId = getUUIDFactory().recreateUUID(schemaId_S);
    schemaDescriptor = dd.getSchemaDescriptor(schemaId, null);
    if (SanityManager.DEBUG) {
        if (schemaDescriptor == null) {
            SanityManager.THROWASSERT("Missing schema for FileInfo: " + id_S);
        }
    }
    /* 3nd column is NAME (varchar(128)) */
    col = row.getColumn(NAME_COL_NUM);
    name = col.getString();
    /* 4th column is generationId (long) */
    col = row.getColumn(GENERATION_ID_COL_NUM);
    generationId = col.getLong();
    result = ddg.newFileInfoDescriptor(id, schemaDescriptor, name, generationId);
    return result;
}
Also used : DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) FileInfoDescriptor(org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID)

Aggregations

FileInfoDescriptor (org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor)9 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)4 UUID (org.apache.derby.catalog.UUID)3 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)3 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)2 FileResource (org.apache.derby.iapi.store.access.FileResource)2 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)2 HashMap (java.util.HashMap)1 ContextManager (org.apache.derby.iapi.services.context.ContextManager)1 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)1 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)1 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)1 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)1 ScanController (org.apache.derby.iapi.store.access.ScanController)1 SQLChar (org.apache.derby.iapi.types.SQLChar)1 SQLLongint (org.apache.derby.iapi.types.SQLLongint)1