Search in sources :

Example 1 with ExecRowBuilder

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

the class InsertNode method generate.

/**
 * Code generation for insert
 * creates an expression for:
 *   ResultSetFactory.getInsertResultSet(resultSet.generate(ps), generationClausesResult, checkConstrainResult, this )
 *
 * @param acb	The ActivationClassBuilder for the class being built
 * @param mb the method  for the execute() method to be built
 *
 * @exception StandardException		Thrown on error
 */
@Override
void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException {
    // If the DML is on the temporary table, generate the code to
    // mark temporary table as modified in the current UOW. After
    // DERBY-827 this must be done in execute() since
    // createResultSet() will only be called once.
    generateCodeForTemporaryTable(acb);
    /* generate the parameters */
    generateParameterValueSet(acb);
    // Base table
    if (targetTableDescriptor != null) {
        /*
			** Generate the insert result set, giving it either the original
			** source or the normalize result set, the constant action,
			** and "this".
			*/
        acb.pushGetResultSetFactoryExpression(mb);
        // arg 1
        if (inMatchingClause()) {
            matchingClause.generateResultSetField(acb, mb);
        } else {
            resultSet.generate(acb, mb);
        }
        // arg 2 generate code to evaluate generation clauses
        generateGenerationClauses(resultColumnList, resultSet.getResultSetNumber(), false, acb, mb);
        // arg 3 generate code to evaluate CHECK CONSTRAINTS
        generateCheckConstraints(checkConstraints, acb, mb);
        // arg 4 row template used by bulk insert
        if (bulkInsert) {
            ColumnDescriptorList cdl = targetTableDescriptor.getColumnDescriptorList();
            ExecRowBuilder builder = new ExecRowBuilder(cdl.size(), false);
            for (int i = 0; i < cdl.size(); i++) {
                ColumnDescriptor cd = cdl.get(i);
                builder.setColumn(i + 1, cd.getType());
            }
            mb.push(acb.addItem(builder));
        } else {
            mb.push(-1);
        }
        // arg 5, 6 table name
        if (targetTableName.getSchemaName() == null) {
            mb.pushNull("java.lang.String");
        } else {
            mb.push(targetTableName.getSchemaName());
        }
        mb.push(targetTableName.getTableName());
        mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getInsertResultSet", ClassName.ResultSet, 6);
    } else {
        /* Generate code for the VTI
			 * NOTE: we need to create a dummy cost estimate for the
			 * targetVTI since we never optimized it.
			 * RESOLVEVTI - we will have to optimize it in order to 
			 * push predicates into the VTI.
			 */
        targetVTI.assignCostEstimate(resultSet.getNewCostEstimate());
        /*
			** Generate the insert VTI result set, giving it either the original
			** source or the normalize result set, the constant action,
			*/
        acb.pushGetResultSetFactoryExpression(mb);
        // arg 1
        resultSet.generate(acb, mb);
        // arg 2
        targetVTI.generate(acb, mb);
        mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getInsertVTIResultSet", ClassName.ResultSet, 2);
    }
}
Also used : ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) ExecRowBuilder(org.apache.derby.iapi.sql.execute.ExecRowBuilder) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)

Example 2 with ExecRowBuilder

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

the class ResultColumnList method buildRowTemplate.

/**
 * Build an {@code ExecRowBuilder} instance that produces a row of the
 * same shape as this result column list.
 *
 * @param referencedCols a bit map that tells which columns in the
 * source result set that are used, or {@code null} if all are used
 * @param skipPropagatedCols whether to skip virtual columns whose
 * source is the immediate child result set
 * @return an instance that produces rows of the same shape as this
 * result column list
 */
ExecRowBuilder buildRowTemplate(FormatableBitSet referencedCols, boolean skipPropagatedCols) throws StandardException {
    int columns = (referencedCols == null) ? size() : referencedCols.getNumBitsSet();
    ExecRowBuilder builder = new ExecRowBuilder(columns, indexRow);
    // Get the index of the first column to set in the row template.
    int colNum = (referencedCols == null) ? 0 : referencedCols.anySetBit();
    for (ResultColumn rc : this) {
        ValueNode sourceExpr = rc.getExpression();
        if (sourceExpr instanceof CurrentRowLocationNode) {
            builder.setColumn(colNum + 1, newRowLocationTemplate());
        } else if (skipPropagatedCols && sourceExpr instanceof VirtualColumnNode) {
            // that wrapper to the store.)
            continue;
        } else {
            builder.setColumn(colNum + 1, rc.getType());
        }
        // Get the index of the next column to set in the row template.
        if (referencedCols == null) {
            colNum++;
        } else {
            colNum = referencedCols.anySetBit(colNum);
        }
    }
    return builder;
}
Also used : ExecRowBuilder(org.apache.derby.iapi.sql.execute.ExecRowBuilder)

Example 3 with ExecRowBuilder

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

the class InsertResultSet method open.

/**
 *		@exception StandardException Standard Derby error policy
 */
public void open() throws StandardException {
    setup();
    // Remember if this is the 1st execution
    firstExecute = (rowChanger == null);
    autoincrementGenerated = false;
    dd = lcc.getDataDictionary();
    verifyAutoGeneratedRScolumnsList(constants.targetUUID);
    rowCount = 0L;
    if (numOpens++ == 0) {
        sourceResultSet.openCore();
    } else {
        sourceResultSet.reopenCore();
    }
    /* If the user specified bulkInsert (or replace) then we need 
		 * to get an exclusive table lock on the table.  If it is a
		 * regular bulk insert then we need to check to see if the
		 * table is empty.  (If not empty, then we end up doing a row
		 * at a time insert.)
		 */
    if (userSpecifiedBulkInsert) {
        if (!bulkInsertReplace) {
            bulkInsert = verifyBulkInsert();
        } else {
            getExclusiveTableLock();
        }
    }
    if (bulkInsert) {
        // Notify the source that we are the target
        sourceResultSet.setTargetResultSet(this);
        ExecRow fullTemplate = ((ExecRowBuilder) activation.getPreparedStatement().getSavedObject(fullTemplateId)).build(activation.getExecutionFactory());
        bulkInsertCore(lcc, fullTemplate, heapConglom);
        if (triggerInfo != null) {
            if (SanityManager.DEBUG) {
                // If we have triggers, we do not use bulkInsert
                SanityManager.NOTREACHED();
            }
        }
        bulkValidateForeignKeys(tc, lcc.getContextManager(), fullTemplate);
        bulkInsertPerformed = true;
    } else {
        row = getNextRowCore(sourceResultSet);
        normalInsertCore(lcc, firstExecute);
    }
    /* Cache query plan text for source, before it gets blown away */
    if (lcc.getRunTimeStatisticsMode()) {
        /* savedSource nulled after run time statistics generation */
        savedSource = sourceResultSet;
    }
    cleanUp();
    saveAIcacheInformation(constants.getSchemaName(), constants.getTableName(), constants.getColumnNames());
    endTime = getCurrentTimeMillis();
}
Also used : ExecRowBuilder(org.apache.derby.iapi.sql.execute.ExecRowBuilder) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Aggregations

ExecRowBuilder (org.apache.derby.iapi.sql.execute.ExecRowBuilder)3 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)1 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)1 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)1