Search in sources :

Example 36 with ConglomerateController

use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.

the class T_ConsistencyChecker method insertBadRowLocation.

/**
 * Get the first row from the heap and insert it into
 * the specified index, with a bad row location, without
 * inserting it into the heap or the other indexes on the table.
 *
 * @param schemaName	The schema name.
 * @param tableName		The table name.
 * @param indexName		The specified index.
 *
 * @exception StandardException		Thrown on error
 */
public static void insertBadRowLocation(String schemaName, String tableName, String indexName) throws StandardException {
    T_ConsistencyChecker t_cc = new T_ConsistencyChecker(schemaName, tableName, indexName);
    t_cc.getContexts();
    t_cc.getDescriptors();
    /* Open a scan on the heap */
    ScanController heapScan = t_cc.openUnqualifiedHeapScan();
    // Get the RowLocation
    RowLocation baseRL = heapScan.newRowLocationTemplate();
    RowLocation badRL = heapScan.newRowLocationTemplate();
    heapScan.close();
    /* Open a scan on the index */
    ExecRow indexRow = t_cc.getIndexTemplateRow(baseRL);
    ScanController indexScan = t_cc.openUnqualifiedIndexScan();
    // Move to the 1st row in the index
    indexScan.next();
    // Fetch the 1st row
    indexScan.fetch(indexRow.getRowArray());
    indexScan.close();
    // Insert another copy of the 1st row into the index with a bad row location
    int keyLength = t_cc.getIndexDescriptor().getIndexDescriptor().baseColumnPositions().length;
    indexRow.setColumn(keyLength + 1, badRL);
    ConglomerateController indexCC = t_cc.openIndexCC();
    indexCC.insert(indexRow.getRowArray());
    indexCC.close();
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 37 with ConglomerateController

use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.

the class T_ConsistencyChecker method getHeapRowOfNulls.

/* Get a heap row full of nulls */
private ExecRow getHeapRowOfNulls() throws StandardException {
    ConglomerateController baseCC;
    ExecRow baseRow;
    /* Open the heap for reading */
    baseCC = tc.openConglomerate(td.getHeapConglomerateId(), false, 0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE);
    /* Get a row template for the base table */
    baseRow = lcc.getLanguageConnectionFactory().getExecutionFactory().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);
        DataTypeDescriptor dts = cd.getType();
        baseRow.setColumn(cd.getPosition(), dts.getNull());
    }
    baseCC.close();
    return baseRow;
}
Also used : ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Example 38 with ConglomerateController

use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.

the class T_ConsistencyChecker method reinsertFirstHeapRow.

/**
 * Get the first row from the heap and insert it into
 * the heap again, without
 * inserting it from the indexes on the table.
 *
 * @param schemaName	The schema name.
 * @param tableName		The table name.
 *
 * @exception StandardException		Thrown on error
 */
public static void reinsertFirstHeapRow(String schemaName, String tableName) throws StandardException {
    T_ConsistencyChecker t_cc = new T_ConsistencyChecker(schemaName, tableName, null);
    t_cc.getContexts();
    t_cc.getDescriptors();
    /* Open a scan on the heap */
    ScanController heapScan = t_cc.openUnqualifiedHeapScan();
    // Move to the 1st row in the heap
    heapScan.next();
    // Fetch the 1st row
    ExecRow firstRow = t_cc.getHeapRowOfNulls();
    heapScan.fetch(firstRow.getRowArray());
    heapScan.close();
    // Insert another copy of the 1st row into the heap
    ConglomerateController heapCC = t_cc.openHeapCC();
    heapCC.insert(firstRow.getRowArray());
    heapCC.close();
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Example 39 with ConglomerateController

use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.

the class T_ConsistencyChecker method openHeapCC.

/* Open the heap conglomerate for update */
private ConglomerateController openHeapCC() throws StandardException {
    ConglomerateController heapCC;
    heapCC = tc.openConglomerate(td.getHeapConglomerateId(), false, // forUpdate
    TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE);
    return heapCC;
}
Also used : ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController)

Example 40 with ConglomerateController

use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.

the class TestPropertyInfo method getConglomerateProperties.

private static Properties getConglomerateProperties(String schemaName, String conglomerateName, boolean isIndex) throws java.sql.SQLException {
    ConglomerateController cc;
    ConglomerateDescriptor cd;
    DataDictionary dd;
    Properties properties;
    SchemaDescriptor sd;
    TableDescriptor td;
    TransactionController tc;
    long conglomerateNumber;
    // find the language context.
    LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
    // Get the current transaction controller
    tc = lcc.getTransactionExecute();
    try {
        // find the DataDictionary
        dd = lcc.getDataDictionary();
        // get the SchemaDescriptor
        sd = dd.getSchemaDescriptor(schemaName, tc, true);
        if (!isIndex) {
            // get the TableDescriptor for the table
            td = dd.getTableDescriptor(conglomerateName, sd, tc);
            // Return an empty Properties if table does not exist or if it is for a view.
            if ((td == null) || td.getTableType() == TableDescriptor.VIEW_TYPE) {
                return new Properties();
            }
            conglomerateNumber = td.getHeapConglomerateId();
        } else {
            // get the ConglomerateDescriptor for the index
            cd = dd.getConglomerateDescriptor(conglomerateName, sd, false);
            // Return an empty Properties if index does not exist
            if (cd == null) {
                return new Properties();
            }
            conglomerateNumber = cd.getConglomerateNumber();
        }
        cc = tc.openConglomerate(conglomerateNumber, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
        properties = cc.getInternalTablePropertySet(new Properties());
        cc.close();
    } catch (StandardException se) {
        throw PublicAPI.wrapStandardException(se);
    }
    return properties;
}
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) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) Properties(java.util.Properties) TransactionController(org.apache.derby.iapi.store.access.TransactionController) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Aggregations

ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)73 RowLocation (org.apache.derby.iapi.types.RowLocation)40 ScanController (org.apache.derby.iapi.store.access.ScanController)32 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)32 SQLLongint (org.apache.derby.iapi.types.SQLLongint)24 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)22 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)18 Properties (java.util.Properties)14 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)14 StandardException (org.apache.derby.shared.common.error.StandardException)12 TransactionController (org.apache.derby.iapi.store.access.TransactionController)11 SQLChar (org.apache.derby.iapi.types.SQLChar)9 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)8 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)6 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)5 ColumnOrdering (org.apache.derby.iapi.store.access.ColumnOrdering)5 UUID (org.apache.derby.catalog.UUID)4 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)4 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)4 IndexRowGenerator (org.apache.derby.iapi.sql.dictionary.IndexRowGenerator)4