Search in sources :

Example 1 with SchemaDescriptor

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

the class SystemProcedures method SYSCS_INPLACE_COMPRESS_TABLE.

/**
 *    Implementation of SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE().
 *    <p>
 *    Code which implements the following system procedure:
 *
 *    void SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE(
 *        IN SCHEMANAME        VARCHAR(128),
 *        IN TABLENAME         VARCHAR(128),
 *        IN PURGE_ROWS        SMALLINT,
 *        IN DEFRAGMENT_ROWS   SMALLINT,
 *        IN TRUNCATE_END      SMALLINT)
 *    <p>
 *    Use the SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE system procedure to reclaim
 *    unused, allocated space in a table and its indexes. Typically, unused allocated
 *    space exists when a large amount of data is deleted from a table, and there
 *    have not been subsequent inserts to use the space freed by the deletes.
 *    By default, Derby does not return unused space to the operating system. For
 *    example, once a page has been allocated to a table or index, it is not
 *    automatically returned to the operating system until the table or index is
 *    destroyed. SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE allows you to return unused
 *    space to the operating system.
 *    <p>
 *    This system procedure can be used to force 3 levels of in place compression
 *    of a SQL table: PURGE_ROWS, DEFRAGMENT_ROWS, TRUNCATE_END.  Unlike
 *    SYSCS_UTIL.SYSCS_COMPRESS_TABLE() all work is done in place in the existing
 *    table/index.
 *    <p>
 *    Syntax:
 *    SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE(
 *        IN SCHEMANAME        VARCHAR(128),
 *        IN TABLENAME         VARCHAR(128),
 *        IN PURGE_ROWS        SMALLINT,
 *        IN DEFRAGMENT_ROWS   SMALLINT,
 *        IN TRUNCATE_END      SMALLINT)
 *    <p>
 *    SCHEMANAME:
 *    An input argument of type VARCHAR(128) that specifies the schema of the table. Passing a null will result in an error.
 *    <p>
 *    TABLENAME:
 *    An input argument of type VARCHAR(128) that specifies the table name of the
 *    table. The string must exactly match the case of the table name, and the
 *    argument of "Fred" will be passed to SQL as the delimited identifier 'Fred'.
 *    Passing a null will result in an error.
 *    <p>
 *    PURGE_ROWS:
 *    If PURGE_ROWS is set to non-zero then a single pass is made through the table
 *    which will purge committed deleted rows from the table.  This space is then
 *    available for future inserted rows, but remains allocated to the table.
 *    As this option scans every page of the table, it's performance is linearly
 *    related to the size of the table.
 *    <p>
 *    DEFRAGMENT_ROWS:
 *    If DEFRAGMENT_ROWS is set to non-zero then a single defragment pass is made
 *    which will move existing rows from the end of the table towards the front
 *    of the table.  The goal of the defragment run is to empty a set of pages
 *    at the end of the table which can then be returned to the OS by the
 *    TRUNCATE_END option.  It is recommended to only run DEFRAGMENT_ROWS, if also
 *    specifying the TRUNCATE_END option.  This option scans the whole table and
 *    needs to update index entries for every base table row move, and thus execution
 *    time is linearly related to the size of the table.
 *    <p>
 *    TRUNCATE_END:
 *    If TRUNCATE_END is set to non-zero then all contiguous pages at the end of
 *    the table will be returned to the OS.  Running the PURGE_ROWS and/or
 *    DEFRAGMENT_ROWS passes options may increase the number of pages affected.
 *    This option itself does no scans of the table, so performs on the order of a
 *    few system calls.
 *    <p>
 *    SQL example:
 *    To compress a table called CUSTOMER in a schema called US, using all
 *    available compress options:
 *    call SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE('US', 'CUSTOMER', 1, 1, 1);
 *
 *    To quickly just return the empty free space at the end of the same table,
 *    this option will run much quicker than running all phases but will likely
 *    return much less space:
 *    call SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE('US', 'CUSTOMER', 0, 0, 1);
 *
 *    Java example:
 *    To compress a table called CUSTOMER in a schema called US, using all
 *    available compress options:
 *
 *    CallableStatement cs = conn.prepareCall
 *    ("CALL SYSCS_UTIL.SYSCS_COMPRESS_TABLE(?, ?, ?, ?, ?)");
 *    cs.setString(1, "US");
 *    cs.setString(2, "CUSTOMER");
 *    cs.setShort(3, (short) 1);
 *    cs.setShort(4, (short) 1);
 *    cs.setShort(5, (short) 1);
 *    cs.execute();
 *
 *    To quickly just return the empty free space at the end of the same table,
 *    this option will run much quicker than running all phases but will likely
 *    return much less space:
 *
 *    CallableStatement cs = conn.prepareCall
 *    ("CALL SYSCS_UTIL.SYSCS_COMPRESS_TABLE(?, ?, ?, ?, ?)");
 *    cs.setString(1, "US");
 *    cs.setString(2, "CUSTOMER");
 *    cs.setShort(3, (short) 0);
 *    cs.setShort(4, (short) 0);
 *    cs.setShort(5, (short) 1);
 *    cs.execute();
 *
 *    <p>
 *    It is recommended that the SYSCS_UTIL.SYSCS_COMPRESS_TABLE procedure is
 *    issued in auto-commit mode.
 *    Note: This procedure acquires an exclusive table lock on the table being compressed. All statement plans dependent on the table or its indexes are invalidated. For information on identifying unused space, see the Derby Server and Administration Guide.
 *
 *    TODO LIST:
 *    o defragment requires table level lock in nested user transaction, which
 *      will conflict with user lock on same table in user transaction.
 */
public static void SYSCS_INPLACE_COMPRESS_TABLE(String schema, String tablename, short purgeRows, short defragmentRows, short truncateEnd) throws SQLException {
    // Inplace compress let's the user call compress on VTI but it
    // is really a no-op. In order to avoid having to go throught
    // the ALTER TABLE code just for a no-op, we simply do the check
    // here and return if we are dealing with VTI.
    LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
    TransactionController tc = lcc.getTransactionExecute();
    try {
        DataDictionary data_dictionary = lcc.getDataDictionary();
        SchemaDescriptor sd = data_dictionary.getSchemaDescriptor(schema, tc, true);
        TableDescriptor td = data_dictionary.getTableDescriptor(tablename, sd, tc);
        if (td != null && td.getTableType() == TableDescriptor.VTI_TYPE) {
            return;
        }
    } catch (StandardException se) {
        throw PublicAPI.wrapStandardException(se);
    }
    // Send all the other inplace compress requests to ALTER TABLE
    // machinery
    String escapedSchema = IdUtil.normalToDelimited(schema);
    String escapedTableName = IdUtil.normalToDelimited(tablename);
    String query = "alter table " + escapedSchema + "." + escapedTableName + " compress inplace" + (purgeRows != 0 ? " purge" : "") + (defragmentRows != 0 ? " defragment" : "") + (truncateEnd != 0 ? " truncate_end" : "");
    Connection conn = getDefaultConn();
    PreparedStatement ps = conn.prepareStatement(query);
    ps.executeUpdate();
    ps.close();
    conn.close();
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) TransactionController(org.apache.derby.iapi.store.access.TransactionController) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) XPLAINTableDescriptor(org.apache.derby.impl.sql.catalog.XPLAINTableDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 2 with SchemaDescriptor

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

the class ConglomInfo method getConglomInfo.

private void getConglomInfo(LanguageConnectionContext lcc) throws StandardException {
    DataDictionary dd = lcc.getDataDictionary();
    if (schemaName == null) {
        schemaName = lcc.getCurrentSchemaName();
    }
    ConglomerateDescriptor[] cds;
    if (tableName != null) {
        // if schemaName is null, it gets the default schema
        SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, true);
        TableDescriptor td = dd.getTableDescriptor(tableName, sd, tc);
        if (// table does not exist
        td == null) {
            // make empty conglom table
            conglomTable = new ConglomInfo[0];
            return;
        }
        cds = td.getConglomerateDescriptors();
    } else // 0-arg constructor, no table name, get all conglomerates
    {
        cds = dd.getConglomerateDescriptors(null);
    }
    // initialize spaceTable
    conglomTable = new ConglomInfo[cds.length];
    for (int i = 0; i < cds.length; i++) {
        String conglomerateName;
        if (cds[i].isIndex()) {
            conglomerateName = cds[i].getConglomerateName();
        } else if (tableName != null) {
            conglomerateName = tableName;
        } else {
            // 0-arg constructor. need to ask data dictionary for name of table
            conglomerateName = dd.getTableDescriptor(cds[i].getTableID()).getName();
        }
        conglomTable[i] = new ConglomInfo(cds[i].getTableID().toString(), cds[i].getConglomerateNumber(), conglomerateName, cds[i].isIndex());
    }
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 3 with SchemaDescriptor

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

the class ConsistencyChecker method checkTable.

/**
 * Check the named table, ensuring that all of its indexes are consistent
 * with the base table.
 * Use this
 *  method only within an SQL-J statement; do not call it directly.
 * <P>When tables are consistent, the method returns true. Otherwise, the method throws an exception.
 * <p>To check the consistency of a single table:
 * <p><code>
 * VALUES ConsistencyChecker::checkTable(<i>SchemaName</i>, <i>TableName</i>)</code></p>
 * <P>For example, to check the consistency of the table <i>APP.Flights</i>:
 * <p><code>
 * VALUES ConsistencyChecker::checkTable('APP', 'FLIGHTS')</code></p>
 * <p>To check the consistency of all of the tables in the 'APP' schema,
 * stopping at the first failure:
 *
 * <P><code>SELECT tablename, ConsistencyChecker::checkTable(<br>
 * 'APP', tablename)<br>
 * FROM sys.sysschemas s, sys.systables t
 * WHERE s.schemaname = 'APP' AND s.schemaid = t.schemaid</code>
 *
 * <p> To check the consistency of an entire database, stopping at the first failure:
 *
 * <p><code>SELECT schemaname, tablename,<br>
 * ConsistencyChecker::checkTable(schemaname, tablename)<br>
 * FROM sys.sysschemas s, sys.systables t<br>
 * WHERE s.schemaid = t.schemaid</code>
 *
 * @param schemaName	The schema name of the table.
 * @param tableName		The name of the table
 *
 * @return	true, if the table is consistent, exception thrown if inconsistent
 *
 * @exception	SQLException	Thrown if some inconsistency
 *									is found, or if some unexpected
 *									exception is thrown..
 */
public static boolean checkTable(String schemaName, String tableName) throws SQLException {
    DataDictionary dd;
    TableDescriptor td;
    long baseRowCount = -1;
    TransactionController tc;
    ConglomerateDescriptor heapCD;
    ConglomerateDescriptor indexCD;
    ExecRow baseRow;
    ExecRow indexRow;
    RowLocation rl = null;
    RowLocation scanRL = null;
    ScanController scan = null;
    int[] baseColumnPositions;
    int baseColumns = 0;
    DataValueFactory dvf;
    long indexRows;
    ConglomerateController baseCC = null;
    ConglomerateController indexCC = null;
    SchemaDescriptor sd;
    ConstraintDescriptor constraintDesc;
    LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
    tc = lcc.getTransactionExecute();
    try {
        // make sure that application code doesn't bypass security checks
        // by calling this public entry point
        SecurityUtil.authorize(Securable.CHECK_TABLE);
        dd = lcc.getDataDictionary();
        dvf = lcc.getDataValueFactory();
        ExecutionFactory ef = lcc.getLanguageConnectionFactory().getExecutionFactory();
        sd = dd.getSchemaDescriptor(schemaName, tc, true);
        td = dd.getTableDescriptor(tableName, sd, tc);
        if (td == null) {
            throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, schemaName + "." + tableName);
        }
        /* Skip views */
        if (td.getTableType() == TableDescriptor.VIEW_TYPE) {
            return true;
        }
        /* Open the heap for reading */
        baseCC = tc.openConglomerate(td.getHeapConglomerateId(), false, 0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE);
        /* Check the consistency of the heap */
        baseCC.checkConsistency();
        heapCD = td.getConglomerateDescriptor(td.getHeapConglomerateId());
        /* Get a row template for the base table */
        baseRow = ef.getValueRow(td.getNumberOfColumns());
        /* Fill the row with nulls of the correct type */
        ColumnDescriptorList cdl = td.getColumnDescriptorList();
        int cdlSize = cdl.size();
        for (int index = 0; index < cdlSize; index++) {
            ColumnDescriptor cd = (ColumnDescriptor) cdl.elementAt(index);
            baseRow.setColumn(cd.getPosition(), cd.getType().getNull());
        }
        /* Look at all the indexes on the table */
        ConglomerateDescriptor[] cds = td.getConglomerateDescriptors();
        for (int index = 0; index < cds.length; index++) {
            indexCD = cds[index];
            /* Skip the heap */
            if (!indexCD.isIndex())
                continue;
            /* Check the internal consistency of the index */
            indexCC = tc.openConglomerate(indexCD.getConglomerateNumber(), false, 0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE);
            indexCC.checkConsistency();
            indexCC.close();
            indexCC = null;
            if (indexCD.isConstraint()) {
                constraintDesc = dd.getConstraintDescriptor(td, indexCD.getUUID());
                if (constraintDesc == null) {
                    throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "CONSTRAINT for INDEX", indexCD.getConglomerateName());
                }
            }
            /*
				** Set the base row count when we get to the first index.
				** We do this here, rather than outside the index loop, so
				** we won't do the work of counting the rows in the base table
				** if there are no indexes to check.
				*/
            if (baseRowCount < 0) {
                scan = tc.openScan(heapCD.getConglomerateNumber(), // hold
                false, // not forUpdate
                0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE, RowUtil.EMPTY_ROW_BITSET, // startKeyValue
                null, // not used with null start posn.
                0, // qualifier
                null, // stopKeyValue
                null, // not used with null stop posn.
                0);
                /* Also, get the row location template for index rows */
                rl = scan.newRowLocationTemplate();
                scanRL = scan.newRowLocationTemplate();
                for (baseRowCount = 0; scan.next(); baseRowCount++) ;
                /* Empty statement */
                scan.close();
                scan = null;
            }
            baseColumnPositions = indexCD.getIndexDescriptor().baseColumnPositions();
            baseColumns = baseColumnPositions.length;
            FormatableBitSet indexColsBitSet = new FormatableBitSet();
            for (int i = 0; i < baseColumns; i++) {
                indexColsBitSet.grow(baseColumnPositions[i]);
                indexColsBitSet.set(baseColumnPositions[i] - 1);
            }
            /* Get one row template for the index scan, and one for the fetch */
            indexRow = ef.getValueRow(baseColumns + 1);
            /* Fill the row with nulls of the correct type */
            for (int column = 0; column < baseColumns; column++) {
                /* Column positions in the data dictionary are one-based */
                ColumnDescriptor cd = td.getColumnDescriptor(baseColumnPositions[column]);
                indexRow.setColumn(column + 1, cd.getType().getNull());
            }
            /* Set the row location in the last column of the index row */
            indexRow.setColumn(baseColumns + 1, rl);
            /* Do a full scan of the index */
            scan = tc.openScan(indexCD.getConglomerateNumber(), // hold
            false, // not forUpdate
            0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, // startKeyValue
            null, // not used with null start posn.
            0, // qualifier
            null, // stopKeyValue
            null, // not used with null stop posn.
            0);
            DataValueDescriptor[] baseRowIndexOrder = new DataValueDescriptor[baseColumns];
            DataValueDescriptor[] baseObjectArray = baseRow.getRowArray();
            for (int i = 0; i < baseColumns; i++) {
                baseRowIndexOrder[i] = baseObjectArray[baseColumnPositions[i] - 1];
            }
            /* Get the index rows and count them */
            for (indexRows = 0; scan.fetchNext(indexRow.getRowArray()); indexRows++) {
                /*
					** Get the base row using the RowLocation in the index row,
					** which is in the last column.  
					*/
                RowLocation baseRL = (RowLocation) indexRow.getColumn(baseColumns + 1);
                boolean base_row_exists = baseCC.fetch(baseRL, baseObjectArray, indexColsBitSet);
                /* Throw exception if fetch() returns false */
                if (!base_row_exists) {
                    String indexName = indexCD.getConglomerateName();
                    throw StandardException.newException(SQLState.LANG_INCONSISTENT_ROW_LOCATION, (schemaName + "." + tableName), indexName, baseRL.toString(), indexRow.toString());
                }
                /* Compare all the column values */
                for (int column = 0; column < baseColumns; column++) {
                    DataValueDescriptor indexColumn = indexRow.getColumn(column + 1);
                    DataValueDescriptor baseColumn = baseRowIndexOrder[column];
                    /*
						** With this form of compare(), null is considered equal
						** to null.
						*/
                    if (indexColumn.compare(baseColumn) != 0) {
                        ColumnDescriptor cd = td.getColumnDescriptor(baseColumnPositions[column]);
                        throw StandardException.newException(SQLState.LANG_INDEX_COLUMN_NOT_EQUAL, indexCD.getConglomerateName(), td.getSchemaName(), td.getName(), baseRL.toString(), cd.getColumnName(), indexColumn.toString(), baseColumn.toString(), indexRow.toString());
                    }
                }
            }
            /* Clean up after the index scan */
            scan.close();
            scan = null;
            /*
				** The index is supposed to have the same number of rows as the
				** base conglomerate.
				*/
            if (indexRows != baseRowCount) {
                throw StandardException.newException(SQLState.LANG_INDEX_ROW_COUNT_MISMATCH, indexCD.getConglomerateName(), td.getSchemaName(), td.getName(), Long.toString(indexRows), Long.toString(baseRowCount));
            }
        }
        /* check that all constraints have backing index */
        ConstraintDescriptorList constraintDescList = dd.getConstraintDescriptors(td);
        for (int index = 0; index < constraintDescList.size(); index++) {
            constraintDesc = constraintDescList.elementAt(index);
            if (constraintDesc.hasBackingIndex()) {
                ConglomerateDescriptor conglomDesc;
                conglomDesc = td.getConglomerateDescriptor(constraintDesc.getConglomerateId());
                if (conglomDesc == null) {
                    throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "INDEX for CONSTRAINT", constraintDesc.getConstraintName());
                }
            }
        }
    } catch (StandardException se) {
        throw PublicAPI.wrapStandardException(se);
    } finally {
        try {
            /* Clean up before we leave */
            if (baseCC != null) {
                baseCC.close();
                baseCC = null;
            }
            if (indexCC != null) {
                indexCC.close();
                indexCC = null;
            }
            if (scan != null) {
                scan.close();
                scan = null;
            }
        } catch (StandardException se) {
            throw PublicAPI.wrapStandardException(se);
        }
    }
    return true;
}
Also used : ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) StandardException(org.apache.derby.shared.common.error.StandardException) ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) DataValueFactory(org.apache.derby.iapi.types.DataValueFactory) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) RowLocation(org.apache.derby.iapi.types.RowLocation) ScanController(org.apache.derby.iapi.store.access.ScanController) SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) ExecutionFactory(org.apache.derby.iapi.sql.execute.ExecutionFactory) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 4 with SchemaDescriptor

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

the class StatementUtil method getSchemaDescriptor.

/**
 * Get the descriptor for the named schema. If the schemaName
 * parameter is NULL, it gets the descriptor for the current
 * compilation schema.
 *
 * @param schemaName The name of the schema we're interested in.
 * If the name is NULL, get the descriptor for the current compilation schema.
 * @param raiseError True to raise an error if the schema does not exist,
 * false to return null if the schema does not exist.
 * @return Valid SchemaDescriptor or null if raiseError is false and the
 * schema does not exist.
 * @throws StandardException Schema does not exist and raiseError is true.
 */
public static SchemaDescriptor getSchemaDescriptor(String schemaName, boolean raiseError, DataDictionary dataDictionary, LanguageConnectionContext lcc, CompilerContext cc) throws StandardException {
    /*
		** Check for a compilation context.  Sometimes
		** there is a special compilation context in
	 	** place to recompile something that may have
		** been compiled against a different schema than
		** the current schema (e.g views):
	 	**
	 	** 	CREATE SCHEMA x
	 	** 	CREATE TABLE t
		** 	CREATE VIEW vt as SEELCT * FROM t
		** 	SET SCHEMA app
		** 	SELECT * FROM X.vt 
		**
		** In the above view vt must be compiled against
		** the X schema.
		*/
    SchemaDescriptor sd = null;
    boolean isCurrent = false;
    boolean isCompilation = false;
    if (schemaName == null) {
        sd = cc.getCompilationSchema();
        if (sd == null) {
            // Set the compilation schema to be the default,
            // notes that this query has schema dependencies.
            sd = lcc.getDefaultSchema();
            isCurrent = true;
            cc.setCompilationSchema(sd);
        } else {
            isCompilation = true;
        }
        schemaName = sd.getSchemaName();
    }
    SchemaDescriptor sdCatalog = dataDictionary.getSchemaDescriptor(schemaName, lcc.getTransactionCompile(), raiseError);
    if (isCurrent || isCompilation) {
        // create table t1(c11 int);
        if (sdCatalog != null && sdCatalog.getUUID() != null) {
            // so reset default schema.
            if (!sdCatalog.getUUID().equals(sd.getUUID())) {
                if (isCurrent) {
                    lcc.setDefaultSchema(sdCatalog);
                }
                cc.setCompilationSchema(sdCatalog);
            }
        } else {
            // this schema does not exist, so ensure its UUID is null.
            sd.setUUID(null);
            sdCatalog = sd;
        }
    }
    return sdCatalog;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)

Example 5 with SchemaDescriptor

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

Aggregations

SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)85 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)33 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)27 UUID (org.apache.derby.catalog.UUID)21 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)20 TransactionController (org.apache.derby.iapi.store.access.TransactionController)20 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)14 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)12 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)12 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)9 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)9 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)8 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)8 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)8 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)8 Properties (java.util.Properties)5 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)5 StandardException (org.apache.derby.shared.common.error.StandardException)5 RoutineAliasInfo (org.apache.derby.catalog.types.RoutineAliasInfo)4