Search in sources :

Example 6 with ExecRow

use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.

the class DataDictionaryImpl method upgrade_addColumns.

/**
 *	Upgrade an existing catalog by adding columns.
 *
 *	@param	rowFactory				Associated with this catalog.
 *	@param	newColumnIDs			Array of 1-based column ids.
 *	@param	tc						Transaction controller
 *
 *	@exception StandardException Standard Derby error policy
 */
public void upgrade_addColumns(CatalogRowFactory rowFactory, int[] newColumnIDs, TransactionController tc) throws StandardException {
    int columnID;
    SystemColumn currentColumn;
    SystemColumn[] columns = rowFactory.buildColumnList();
    ExecRow templateRow = rowFactory.makeEmptyRowForCurrentVersion();
    int columnCount = newColumnIDs.length;
    SchemaDescriptor sd = getSystemSchemaDescriptor();
    TableDescriptor td;
    long conglomID;
    // table/column descriptor until after we add and populate the new column.
    if (rowFactory instanceof SYSTABLESRowFactory) {
        td = dataDescriptorGenerator.newTableDescriptor("SYSTABLES", sd, TableDescriptor.BASE_TABLE_TYPE, TableDescriptor.ROW_LOCK_GRANULARITY);
        td.setUUID(getUUIDForCoreTable("SYSTABLES", sd.getUUID().toString(), tc));
        conglomID = coreInfo[SYSTABLES_CORE_NUM].getHeapConglomerate();
    } else if (rowFactory instanceof SYSCOLUMNSRowFactory) {
        td = dataDescriptorGenerator.newTableDescriptor("SYSCOLUMNS", sd, TableDescriptor.BASE_TABLE_TYPE, TableDescriptor.ROW_LOCK_GRANULARITY);
        td.setUUID(getUUIDForCoreTable("SYSCOLUMNS", sd.getUUID().toString(), tc));
        conglomID = coreInfo[SYSCOLUMNS_CORE_NUM].getHeapConglomerate();
    } else {
        td = getTableDescriptor(rowFactory.getCatalogName(), sd, tc);
        conglomID = td.getHeapConglomerateId();
    }
    widenConglomerate(templateRow, newColumnIDs, conglomID, tc);
    ColumnDescriptor[] cdArray = new ColumnDescriptor[columnCount];
    for (int ix = 0; ix < columnCount; ix++) {
        columnID = newColumnIDs[ix];
        // from 1 to 0 based
        currentColumn = columns[columnID - 1];
        cdArray[ix] = makeColumnDescriptor(currentColumn, columnID, td);
    }
    addDescriptorArray(cdArray, td, SYSCOLUMNS_CATALOG_NUM, false, tc);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) SystemColumn(org.apache.derby.iapi.sql.dictionary.SystemColumn) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLLongint(org.apache.derby.iapi.types.SQLLongint) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 7 with ExecRow

use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.

the class DataDictionaryImpl method addSPSDescriptor.

/**
 * Adds the given SPSDescriptor to the data dictionary,
 * associated with the given table and constraint type.
 *
 * @param descriptor	The descriptor to add
 * @param tc			The transaction controller
 *
 * @exception StandardException		Thrown on error
 */
public void addSPSDescriptor(SPSDescriptor descriptor, TransactionController tc) throws StandardException {
    ExecRow row;
    TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM);
    SYSSTATEMENTSRowFactory rf = (SYSSTATEMENTSRowFactory) ti.getCatalogRowFactory();
    int insertRetCode;
    /*
		** We must make sure the descriptor is locked
		** while we are writing it out.  Otherwise,
		** the descriptor could be invalidated while
		** we are writing.
		*/
    synchronized (descriptor) {
        // build the row to be stuffed into SYSSTATEMENTS. this will stuff an
        // UUID into the descriptor
        boolean compileMe = descriptor.initiallyCompilable();
        row = rf.makeSYSSTATEMENTSrow(compileMe, descriptor);
        // insert row into catalog and all its indices
        insertRetCode = ti.insertRow(row, tc);
    }
    // Throw an exception duplicate table descriptor
    if (insertRetCode != TabInfoImpl.ROWNOTDUPLICATE) {
        throw StandardException.newException(SQLState.LANG_OBJECT_ALREADY_EXISTS_IN_OBJECT, descriptor.getDescriptorType(), descriptor.getDescriptorName(), descriptor.getSchemaDescriptor().getDescriptorType(), descriptor.getSchemaDescriptor().getSchemaName());
    }
    addSPSParams(descriptor, tc);
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 8 with ExecRow

use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.

the class DataDictionaryImpl method dropTablePermDescriptor.

/**
 * Delete the appropriate rows from systableperms when
 * dropping a table
 *
 * @param tc			The TransactionController
 * @param keyRow		Start/stop position.
 *
 * @exception StandardException		Thrown on failure
 */
private void dropTablePermDescriptor(TransactionController tc, ExecIndexRow keyRow) throws StandardException {
    ExecRow curRow;
    PermissionsDescriptor perm;
    TabInfoImpl ti = getNonCoreTI(SYSTABLEPERMS_CATALOG_NUM);
    SYSTABLEPERMSRowFactory rf = (SYSTABLEPERMSRowFactory) ti.getCatalogRowFactory();
    while ((curRow = ti.getRow(tc, keyRow, rf.TABLEID_INDEX_NUM)) != null) {
        perm = (PermissionsDescriptor) rf.buildDescriptor(curRow, (TupleDescriptor) null, this);
        removePermEntryInCache(perm);
        // Build key on UUID and drop the entry as we want to drop only this row
        ExecIndexRow uuidKey;
        uuidKey = rf.buildIndexKeyRow(rf.TABLEPERMSID_INDEX_NUM, perm);
        ti.deleteRow(tc, uuidKey, rf.TABLEPERMSID_INDEX_NUM);
    }
}
Also used : PermissionsDescriptor(org.apache.derby.iapi.sql.dictionary.PermissionsDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 9 with ExecRow

use of org.apache.derby.iapi.sql.execute.ExecRow 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 10 with ExecRow

use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.

the class DataDictionaryImpl method visitPermsByGrantee.

/**
 * Scan <code>indexNo</code> index on a permission table
 * <code>catalog</code>, looking for match(es) for the grantee column
 * (given by granteeColnoInIndex for the catalog in question).
 *
 * The action argument can be either <code>EXISTS</code> or
 * <code>DROP</code> (to check for existence, or to drop that row).
 *
 * There is no index on grantee column only on on any of the
 * permissions tables, so we use the index which contain grantee
 * and scan that, setting up a scan qualifier to match the
 * grantee, then fetch the base row.
 *
 * If this proves too slow, we should add an index on grantee
 * only.
 *
 * @param authId grantee to match against
 * @param tc transaction controller
 * @param catalog the underlying permission table to visit
 * @param indexNo the number of the index by which to access the catalog
 * @param granteeColnoInIndex the column number to match
 *        <code>authId</code> against
 * @param action drop matching rows (<code>DROP</code>), or return
 *        <code>true</code> if there is a matching row
 *        (<code>EXISTS</code>)
 *
 * @return action=EXISTS: return {@code true} if there is a matching row
 *      else return {@code false}.
 * @exception StandardException
 */
private boolean visitPermsByGrantee(String authId, TransactionController tc, int catalog, int indexNo, int granteeColnoInIndex, int action) throws StandardException {
    TabInfoImpl ti = getNonCoreTI(catalog);
    PermissionsCatalogRowFactory rf = (PermissionsCatalogRowFactory) ti.getCatalogRowFactory();
    ConglomerateController heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
    DataValueDescriptor authIdOrderable = new SQLVarchar(authId);
    ScanQualifier[][] scanQualifier = exFactory.getScanQualifier(1);
    scanQualifier[0][0].setQualifier(granteeColnoInIndex - 1, /* to zero-based */
    authIdOrderable, Orderable.ORDER_OP_EQUALS, false, false, false);
    ScanController sc = tc.openScan(ti.getIndexConglomerate(indexNo), // don't hold open across commit
    false, // for update
    0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
    (FormatableBitSet) null, // start position -
    (DataValueDescriptor[]) null, // startSearchOperation - none
    0, // 
    scanQualifier, // stop position -through last row
    (DataValueDescriptor[]) null, // stopSearchOperation - none
    0);
    try {
        ExecRow outRow = rf.makeEmptyRow();
        ExecIndexRow indexRow = getIndexRowFromHeapRow(ti.getIndexRowGenerator(indexNo), heapCC.newRowLocationTemplate(), outRow);
        while (sc.fetchNext(indexRow.getRowArray())) {
            RowLocation baseRowLocation = (RowLocation) indexRow.getColumn(indexRow.nColumns());
            boolean base_row_exists = heapCC.fetch(baseRowLocation, outRow.getRowArray(), (FormatableBitSet) null);
            if (SanityManager.DEBUG) {
                // it can not be possible for heap row to
                // disappear while holding scan cursor on index at
                // ISOLATION_REPEATABLE_READ.
                SanityManager.ASSERT(base_row_exists, "base row doesn't exist");
            }
            if (action == DataDictionaryImpl.EXISTS) {
                return true;
            } else if (action == DataDictionaryImpl.DROP) {
                PermissionsDescriptor perm = (PermissionsDescriptor) rf.buildDescriptor(outRow, (TupleDescriptor) null, this);
                removePermEntryInCache(perm);
                ti.deleteRow(tc, indexRow, indexNo);
            }
        }
    } finally {
        if (sc != null) {
            sc.close();
        }
        if (heapCC != null) {
            heapCC.close();
        }
    }
    return false;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) PermissionsDescriptor(org.apache.derby.iapi.sql.dictionary.PermissionsDescriptor) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) RowLocation(org.apache.derby.iapi.types.RowLocation)

Aggregations

ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)155 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)62 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)34 RowLocation (org.apache.derby.iapi.types.RowLocation)27 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)23 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)22 ScanController (org.apache.derby.iapi.store.access.ScanController)22 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)22 SQLChar (org.apache.derby.iapi.types.SQLChar)21 SQLLongint (org.apache.derby.iapi.types.SQLLongint)21 UUID (org.apache.derby.catalog.UUID)19 Properties (java.util.Properties)12 TransactionController (org.apache.derby.iapi.store.access.TransactionController)12 CursorResultSet (org.apache.derby.iapi.sql.execute.CursorResultSet)11 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)10 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)10 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)10 UserType (org.apache.derby.iapi.types.UserType)9 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)8 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)7