Search in sources :

Example 6 with ResultDescription

use of org.apache.derby.iapi.sql.ResultDescription in project derby by apache.

the class IndexChanger method doDeferredInsert.

/**
 *	  Insert a row into the temporary conglomerate
 *
 *	  <P>This opens our deferred ConglomeratController the first time it
 *	  is called.
 *
 *	  @exception StandardException		Thrown on error
 */
private void doDeferredInsert() throws StandardException {
    if (rowHolder == null) {
        Properties properties = new Properties();
        // Get the properties on the index
        openIndexCC().getInternalTablePropertySet(properties);
        /*
			** Create our row holder.  it is ok to skip passing
			** in the result description because if we don't already
			** have a row holder, then we are the only user of the
			** row holder (the description is needed when the row
			** holder is going to be handed to users for triggers).
			*/
        rowHolder = new TemporaryRowHolderImpl(activation, properties, (ResultDescription) null);
    }
    /*
		** If the user of the IndexChanger already
		** had a row holder, then we don't need to
		** bother saving deferred inserts -- they
		** have already done so.	
		*/
    if (!rowHolderPassedIn) {
        rowHolder.insert(ourIndexRow);
    }
}
Also used : ResultDescription(org.apache.derby.iapi.sql.ResultDescription) Properties(java.util.Properties)

Example 7 with ResultDescription

use of org.apache.derby.iapi.sql.ResultDescription in project derby by apache.

the class DMLWriteGeneratedColumnsResultSet method firstExecuteSpecialHandlingAutoGen.

protected void firstExecuteSpecialHandlingAutoGen(boolean firstExecute, RowChanger rowChanger, UUID targetUUID) throws StandardException {
    if (firstExecute && activation.getAutoGeneratedKeysResultsetMode()) {
        ResultDescription rd;
        Properties properties = new Properties();
        autoGeneratedKeysColumnIndexes = activation.getAutoGeneratedKeysColumnIndexes();
        // Get the properties on the old heap
        rowChanger.getHeapConglomerateController().getInternalTablePropertySet(properties);
        if (autoGeneratedKeysColumnIndexes != null) {
            // Use user-provided column positions array.
            autoGeneratedKeysColumnIndexes = uniqueColumnPositionArray(autoGeneratedKeysColumnIndexes, targetUUID);
        } else {
            // Prepare array of auto-generated keys for the table since
            // user didn't provide any.
            autoGeneratedKeysColumnIndexes = generatedColumnPositionsArray(targetUUID);
        }
        rd = lcc.getLanguageFactory().getResultDescription(resultDescription, autoGeneratedKeysColumnIndexes);
        autoGeneratedKeysRowsHolder = new TemporaryRowHolderImpl(activation, properties, rd);
    }
}
Also used : ResultDescription(org.apache.derby.iapi.sql.ResultDescription) Properties(java.util.Properties)

Example 8 with ResultDescription

use of org.apache.derby.iapi.sql.ResultDescription in project derby by apache.

the class NoRowsResultSetImpl method setupGeneratedColumns.

/**
 * Construct support for normalizing generated columns. This figures out
 * which columns in the target row have generation clauses which need to be run.
 */
private void setupGeneratedColumns(Activation activation, ValueRow newRow) throws StandardException {
    ResultDescription resultDescription = activation.getResultDescription();
    int columnCount = resultDescription.getColumnCount();
    ExecRow emptyRow = newRow.getNewNullRow();
    int generatedColumnCount = 0;
    // first count the number of generated columns
    for (int i = 1; i <= columnCount; i++) {
        if (i < firstColumn) {
            continue;
        }
        ResultColumnDescriptor rcd = resultDescription.getColumnDescriptor(i);
        if (rcd.hasGenerationClause()) {
            generatedColumnCount++;
        }
    }
    // now allocate and populate support structures
    generatedColumnPositions = new int[generatedColumnCount];
    normalizedGeneratedValues = new DataValueDescriptor[generatedColumnCount];
    int idx = 0;
    for (int i = 1; i <= columnCount; i++) {
        if (i < firstColumn) {
            continue;
        }
        ResultColumnDescriptor rcd = resultDescription.getColumnDescriptor(i);
        if (rcd.hasGenerationClause()) {
            generatedColumnPositions[idx] = i;
            normalizedGeneratedValues[idx] = emptyRow.getColumn(i);
            idx++;
        }
    }
}
Also used : ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor) ResultDescription(org.apache.derby.iapi.sql.ResultDescription) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Example 9 with ResultDescription

use of org.apache.derby.iapi.sql.ResultDescription in project derby by apache.

the class EmbedPreparedStatement method getMetaData.

/**
 * JDBC 2.0
 *
 * The number, types and properties of a ResultSet's columns
 * are provided by the getMetaData method.
 *
 * @return the description of a ResultSet's columns
 * @exception SQLException Feature not implemented for now.
 */
public java.sql.ResultSetMetaData getMetaData() throws SQLException {
    checkExecStatus();
    synchronized (getConnectionSynchronization()) {
        // reason for casting is getActivationClass is not available on PreparedStatement
        ExecPreparedStatement execp = (ExecPreparedStatement) preparedStatement;
        // make sure there's context
        setupContextStack();
        try {
            // bug 4579 - gcDuringGetMetaData will be null if this is the first time
            // getMetaData call is made.
            // Second check - if the statement was revalidated since last getMetaData call,
            // then gcDuringGetMetaData wouldn't match with current generated class name
            GeneratedClass currAc = null;
            ResultDescription resd = null;
            synchronized (execp) {
                // DERBY-3823 Some other thread may be repreparing
                do {
                    while (!execp.upToDate()) {
                        execp.rePrepare(lcc);
                    }
                    currAc = execp.getActivationClass();
                    resd = execp.getResultDescription();
                } while (currAc == null);
            }
            if (gcDuringGetMetaData == null || !gcDuringGetMetaData.equals(currAc.getName())) {
                rMetaData = null;
                gcDuringGetMetaData = currAc.getName();
            }
            if (rMetaData == null && resd != null) {
                // Internally, the result description has information
                // which is used for insert, update and delete statements
                // Externally, we decided that statements which don't
                // produce result sets such as insert, update and delete
                // should not return ResultSetMetaData.  This is enforced
                // here
                String statementType = resd.getStatementType();
                if (statementType.equals("INSERT") || statementType.equals("UPDATE") || statementType.equals("DELETE"))
                    rMetaData = null;
                else
                    rMetaData = newEmbedResultSetMetaData(resd);
            }
            InterruptStatus.restoreIntrFlagIfSeen(lcc);
        } catch (Throwable t) {
            throw handleException(t);
        } finally {
            restoreContextStack();
        }
    }
    return rMetaData;
}
Also used : GeneratedClass(org.apache.derby.iapi.services.loader.GeneratedClass) ExecPreparedStatement(org.apache.derby.iapi.sql.execute.ExecPreparedStatement) ResultDescription(org.apache.derby.iapi.sql.ResultDescription)

Aggregations

ResultDescription (org.apache.derby.iapi.sql.ResultDescription)9 Properties (java.util.Properties)2 Activation (org.apache.derby.iapi.sql.Activation)2 ResultSet (org.apache.derby.iapi.sql.ResultSet)2 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)2 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)2 CursorActivation (org.apache.derby.iapi.sql.execute.CursorActivation)2 ExecCursorTableReference (org.apache.derby.iapi.sql.execute.ExecCursorTableReference)2 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)2 SQLWarning (java.sql.SQLWarning)1 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)1 GeneratedClass (org.apache.derby.iapi.services.loader.GeneratedClass)1 ResultColumnDescriptor (org.apache.derby.iapi.sql.ResultColumnDescriptor)1 ExecPreparedStatement (org.apache.derby.iapi.sql.execute.ExecPreparedStatement)1 StaticCompiledOpenConglomInfo (org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo)1 TransactionController (org.apache.derby.iapi.store.access.TransactionController)1 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)1