Search in sources :

Example 11 with DataValueDescriptor

use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.

the class EmbedCallableStatement method getBinaryStream.

/**
 * Get binary stream for a parameter.
 *
 * @param parameterIndex first parameter is 1, second is 2 etc.
 * @return a stream for the binary parameter, or <code>null</code>.
 *
 * @throws SQLException if a database access error occurs.
 */
private InputStream getBinaryStream(int parameterIndex) throws SQLException {
    int paramType = getParameterJDBCType(parameterIndex);
    switch(paramType) {
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case Types.BLOB:
            break;
        default:
            throw newSQLException(SQLState.LANG_DATA_TYPE_GET_MISMATCH, "java.io.InputStream", Util.typeName(paramType));
    }
    boolean pushStack = false;
    synchronized (getConnectionSynchronization()) {
        try {
            DataValueDescriptor param = getParms().getParameterForGet(parameterIndex - 1);
            wasNull = param.isNull();
            if (wasNull) {
                return null;
            }
            pushStack = true;
            setupContextStack();
            // The stream we will return to the user
            InputStream stream;
            if (param.hasStream()) {
                stream = new BinaryToRawStream(param.getStream(), param);
            } else {
                stream = new ByteArrayInputStream(param.getBytes());
            }
            return stream;
        } catch (Throwable t) {
            throw EmbedResultSet.noStateChangeException(t);
        } finally {
            if (pushStack) {
                restoreContextStack();
            }
        }
    }
// End synchronized block
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 12 with DataValueDescriptor

use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.

the class DataDictionaryImpl method getUUIDForCoreTable.

/**
 * Get the UUID for the specified system table.  Prior
 * to Plato, system tables did not have canonical UUIDs, so
 * we need to scan systables to get the UUID when we
 * are updating the core tables.
 *
 * @param tableName		Name of the table
 * @param schemaUUID	UUID of schema
 * @param tc			TransactionController to user
 *
 * @return UUID	The UUID of the core table.
 *
 * @exception StandardException		Thrown on failure
 */
private UUID getUUIDForCoreTable(String tableName, String schemaUUID, TransactionController tc) throws StandardException {
    ConglomerateController heapCC;
    ExecRow row;
    DataValueDescriptor schemaIDOrderable;
    DataValueDescriptor tableNameOrderable;
    ScanController scanController;
    TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM];
    SYSTABLESRowFactory rf = (SYSTABLESRowFactory) ti.getCatalogRowFactory();
    // We only want the 1st column from the heap
    row = exFactory.getValueRow(1);
    /* Use tableNameOrderable and schemaIdOrderable in both start 
		 * and stop position for scan. 
		 */
    tableNameOrderable = new SQLVarchar(tableName);
    schemaIDOrderable = new SQLChar(schemaUUID);
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = exFactory.getIndexableRow(2);
    keyRow.setColumn(1, tableNameOrderable);
    keyRow.setColumn(2, schemaIDOrderable);
    heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
    ExecRow indexTemplateRow = rf.buildEmptyIndexRow(SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, heapCC.newRowLocationTemplate());
    /* Scan the index and go to the data pages for qualifying rows to
		 * build the column descriptor.
		 */
    scanController = tc.openScan(// conglomerate to open
    ti.getIndexConglomerate(SYSTABLESRowFactory.SYSTABLES_INDEX1_ID), // don't hold open across commit
    false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
    (FormatableBitSet) null, // start position - first row
    keyRow.getRowArray(), // startSearchOperation
    ScanController.GE, // scanQualifier,
    (ScanQualifier[][]) null, // stop position - through last row
    keyRow.getRowArray(), // stopSearchOperation
    ScanController.GT);
    /* OK to fetch into the template row, 
         * since we won't be doing a next.
         */
    if (scanController.fetchNext(indexTemplateRow.getRowArray())) {
        RowLocation baseRowLocation;
        baseRowLocation = (RowLocation) indexTemplateRow.getColumn(indexTemplateRow.nColumns());
        /* 1st column is TABLEID (UUID - char(36)) */
        row.setColumn(SYSTABLESRowFactory.SYSTABLES_TABLEID, new SQLChar());
        FormatableBitSet bi = new FormatableBitSet(1);
        bi.set(0);
        boolean base_row_exists = heapCC.fetch(baseRowLocation, row.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 not found");
        }
    }
    scanController.close();
    heapCC.close();
    return uuidFactory.recreateUUID(row.getColumn(1).toString());
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLChar(org.apache.derby.iapi.types.SQLChar) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) ScanQualifier(org.apache.derby.iapi.sql.execute.ScanQualifier) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 13 with DataValueDescriptor

use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.

the class DataDictionaryImpl method dropAllConglomerateDescriptors.

/**
 * Drops all conglomerates associated with a table.
 *
 * @param td		The TableDescriptor of the table
 * @param tc		TransactionController for the transaction
 *
 * @exception StandardException		Thrown on failure
 */
public void dropAllConglomerateDescriptors(TableDescriptor td, TransactionController tc) throws StandardException {
    ExecIndexRow keyRow3 = null;
    DataValueDescriptor tableIDOrderable;
    TabInfoImpl ti = coreInfo[SYSCONGLOMERATES_CORE_NUM];
    /* Use tableIDOrderable in both start 
		 * and stop position for index 3 scan. 
		 */
    tableIDOrderable = getIDValueAsCHAR(td.getUUID());
    /* Set up the start/stop position for the scan */
    keyRow3 = (ExecIndexRow) exFactory.getIndexableRow(1);
    keyRow3.setColumn(1, tableIDOrderable);
    ti.deleteRow(tc, keyRow3, SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX3_ID);
}
Also used : DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 14 with DataValueDescriptor

use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.

the class DataDictionaryImpl method locateSchemaRowBody.

private SchemaDescriptor locateSchemaRowBody(UUID schemaId, int isolationLevel, TransactionController tc) throws StandardException {
    DataValueDescriptor UUIDStringOrderable;
    TabInfoImpl ti = coreInfo[SYSSCHEMAS_CORE_NUM];
    /* Use UUIDStringOrderable in both start and stop positions for scan */
    UUIDStringOrderable = getIDValueAsCHAR(schemaId);
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = exFactory.getIndexableRow(1);
    keyRow.setColumn(1, UUIDStringOrderable);
    return getDescriptorViaIndex(SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX2_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, SchemaDescriptor.class, false, isolationLevel, tc);
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 15 with DataValueDescriptor

use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.

the class DataDictionaryImpl method updateSchemaAuth.

/**
 * Update authorizationId of specified schemaName
 *
 * @param schemaName			Schema Name of system schema
 * @param authorizationId		authorizationId of new schema owner
 * @param tc					The TransactionController to use
 *
 * @exception StandardException		Thrown on failure
 */
public void updateSchemaAuth(String schemaName, String authorizationId, TransactionController tc) throws StandardException {
    ExecIndexRow keyRow;
    DataValueDescriptor schemaNameOrderable;
    TabInfoImpl ti = coreInfo[SYSSCHEMAS_CORE_NUM];
    /* Use schemaNameOrderable in both start 
		 * and stop position for index 1 scan. 
		 */
    schemaNameOrderable = new SQLVarchar(schemaName);
    /* Set up the start/stop position for the scan */
    keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
    keyRow.setColumn(1, schemaNameOrderable);
    SYSSCHEMASRowFactory rf = (SYSSCHEMASRowFactory) ti.getCatalogRowFactory();
    ExecRow row = rf.makeEmptyRow();
    row.setColumn(SYSSCHEMASRowFactory.SYSSCHEMAS_SCHEMAAID, new SQLVarchar(authorizationId));
    boolean[] bArray = { false, false };
    int[] colsToUpdate = { SYSSCHEMASRowFactory.SYSSCHEMAS_SCHEMAAID };
    ti.updateRow(keyRow, row, SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX1_ID, bArray, colsToUpdate, tc);
}
Also used : 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)

Aggregations

DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)328 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)72 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)62 RowLocation (org.apache.derby.iapi.types.RowLocation)54 SQLLongint (org.apache.derby.iapi.types.SQLLongint)51 StandardException (org.apache.derby.shared.common.error.StandardException)43 SQLChar (org.apache.derby.iapi.types.SQLChar)42 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)36 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)36 ScanController (org.apache.derby.iapi.store.access.ScanController)35 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)32 UUID (org.apache.derby.catalog.UUID)31 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)24 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)16 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)15 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)15 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)15 Properties (java.util.Properties)14 UserType (org.apache.derby.iapi.types.UserType)13 Page (org.apache.derby.iapi.store.raw.Page)11