Search in sources :

Example 6 with FileInfoDescriptor

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

the class JarUtil method add.

/**
 *	  Add a jar file to the current connection's database.
 *
 *	  <P> The reason for adding the jar file in this private instance
 *	  method is that it allows us to share set up logic with drop and
 *	  replace.
 *	  @param is A stream for reading the content of the file to add.
 *	  @exception StandardException Opps
 */
private long add(final InputStream is) throws StandardException {
    // 
    // Like create table we say we are writing before we read the dd
    dd.startWriting(lcc);
    FileInfoDescriptor fid = getInfo();
    if (fid != null)
        throw StandardException.newException(SQLState.LANG_OBJECT_ALREADY_EXISTS_IN_OBJECT, fid.getDescriptorType(), sqlName, fid.getSchemaDescriptor().getDescriptorType(), schemaName);
    SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, null, true);
    try {
        notifyLoader(false);
        dd.invalidateAllSPSPlans();
        UUID id = BaseActivation.getMonitor().getUUIDFactory().createUUID();
        final String jarExternalName = JarUtil.mkExternalName(id, schemaName, sqlName, fr.getSeparatorChar());
        long generationId = setJar(jarExternalName, is, true, 0L);
        fid = ddg.newFileInfoDescriptor(id, sd, sqlName, generationId);
        dd.addDescriptor(fid, sd, DataDictionary.SYSFILES_CATALOG_NUM, false, lcc.getTransactionExecute());
        return generationId;
    } finally {
        notifyLoader(true);
    }
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) FileInfoDescriptor(org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor) UUID(org.apache.derby.catalog.UUID)

Example 7 with FileInfoDescriptor

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

the class JarUtil method drop.

/**
 *	  Drop a jar file from the current connection's database.
 *
 *	  <P> The reason for dropping  the jar file in this private instance
 *	  method is that it allows us to share set up logic with add and
 *	  replace.
 *
 *	  @exception StandardException Opps
 */
private void drop() throws StandardException {
    // 
    // Like create table we say we are writing before we read the dd
    dd.startWriting(lcc);
    FileInfoDescriptor fid = getInfo();
    if (fid == null)
        throw StandardException.newException(SQLState.LANG_FILE_DOES_NOT_EXIST, sqlName, schemaName);
    String dbcp_s = PropertyUtil.getServiceProperty(lcc.getTransactionExecute(), Property.DATABASE_CLASSPATH);
    if (dbcp_s != null) {
        String[][] dbcp = IdUtil.parseDbClassPath(dbcp_s);
        boolean found = false;
        // a database classpath that is stored in the propert congomerate.
        for (int ix = 0; ix < dbcp.length; ix++) if (dbcp.length == 2 && dbcp[ix][0].equals(schemaName) && dbcp[ix][1].equals(sqlName))
            found = true;
        if (found)
            throw StandardException.newException(SQLState.LANG_CANT_DROP_JAR_ON_DB_CLASS_PATH_DURING_EXECUTION, IdUtil.mkQualifiedName(schemaName, sqlName), dbcp_s);
    }
    try {
        notifyLoader(false);
        dd.invalidateAllSPSPlans();
        DependencyManager dm = dd.getDependencyManager();
        dm.invalidateFor(fid, DependencyManager.DROP_JAR, lcc);
        UUID id = fid.getUUID();
        dd.dropFileInfoDescriptor(fid);
        fr.remove(JarUtil.mkExternalName(id, schemaName, sqlName, fr.getSeparatorChar()), fid.getGenerationId());
    } finally {
        notifyLoader(true);
    }
}
Also used : FileInfoDescriptor(org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) UUID(org.apache.derby.catalog.UUID)

Example 8 with FileInfoDescriptor

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

the class SYSFILESRowFactory method makeRow.

// ///////////////////////////////////////////////////////////////////////////
// 
// METHODS
// 
// ///////////////////////////////////////////////////////////////////////////
/**
 * Make a SYSFILES row
 *
 * @return	Row suitable for inserting into SYSFILES
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    String id_S = null;
    String schemaId_S = null;
    String SQLname = null;
    long generationId = 0;
    ExecRow row;
    if (td != null) {
        FileInfoDescriptor descriptor = (FileInfoDescriptor) td;
        id_S = descriptor.getUUID().toString();
        schemaId_S = descriptor.getSchemaDescriptor().getUUID().toString();
        SQLname = descriptor.getName();
        generationId = descriptor.getGenerationId();
    }
    /* Build the row to insert  */
    row = getExecutionFactory().getValueRow(SYSFILES_COLUMN_COUNT);
    /* 1st column is ID (UUID - char(36)) */
    row.setColumn(ID_COL_NUM, new SQLChar(id_S));
    /* 2nd column is SCHEMAID (UUID - char(36)) */
    row.setColumn(SCHEMA_ID_COL_NUM, new SQLChar(schemaId_S));
    /* 3rd column is NAME (varchar(30)) */
    row.setColumn(NAME_COL_NUM, new SQLVarchar(SQLname));
    /* 4th column is GENERATIONID (long) */
    row.setColumn(GENERATION_ID_COL_NUM, new SQLLongint(generationId));
    return row;
}
Also used : FileInfoDescriptor(org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor) SQLLongint(org.apache.derby.iapi.types.SQLLongint) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLChar(org.apache.derby.iapi.types.SQLChar) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar)

Example 9 with FileInfoDescriptor

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

the class JarUtil method replace.

/**
 *	  Replace a jar file in the current connection's database with the
 *	  content of an external file.
 *
 *	  <P> The reason for adding the jar file in this private instance
 *	  method is that it allows us to share set up logic with add and
 *	  drop.
 *	  @param is An input stream for reading the new content of the jar file.
 *	  @exception StandardException Opps
 */
private long replace(InputStream is) throws StandardException {
    // 
    // Like create table we say we are writing before we read the dd
    dd.startWriting(lcc);
    // 
    // Temporarily drop the FileInfoDescriptor from the data dictionary.
    FileInfoDescriptor fid = getInfo();
    if (fid == null)
        throw StandardException.newException(SQLState.LANG_FILE_DOES_NOT_EXIST, sqlName, schemaName);
    try {
        // disable loads from this jar
        notifyLoader(false);
        dd.invalidateAllSPSPlans();
        dd.dropFileInfoDescriptor(fid);
        final String jarExternalName = JarUtil.mkExternalName(fid.getUUID(), schemaName, sqlName, fr.getSeparatorChar());
        // 
        // Replace the file.
        long generationId = setJar(jarExternalName, is, false, fid.getGenerationId());
        // 
        // Re-add the descriptor to the data dictionary.
        FileInfoDescriptor fid2 = ddg.newFileInfoDescriptor(fid.getUUID(), fid.getSchemaDescriptor(), sqlName, generationId);
        dd.addDescriptor(fid2, fid.getSchemaDescriptor(), DataDictionary.SYSFILES_CATALOG_NUM, false, lcc.getTransactionExecute());
        return generationId;
    } finally {
        // reenable class loading from this jar
        notifyLoader(true);
    }
}
Also used : FileInfoDescriptor(org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor)

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