Search in sources :

Example 96 with DataTypeDescriptor

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

the class DataDictionaryImpl method addSPSParams.

/**
 * Add a column in SYS.SYSCOLUMNS for each parameter in the
 * parameter list.
 */
private void addSPSParams(SPSDescriptor spsd, TransactionController tc) throws StandardException {
    UUID uuid = spsd.getUUID();
    DataTypeDescriptor[] params = spsd.getParams();
    Object[] parameterDefaults = spsd.getParameterDefaults();
    if (params == null)
        return;
    /* Create the columns */
    int pdlSize = params.length;
    for (int index = 0; index < pdlSize; index++) {
        int parameterId = index + 1;
        // RESOLVEAUTOINCREMENT
        ColumnDescriptor cd = new ColumnDescriptor("PARAM" + parameterId, // position
        parameterId, params[index], (// default
        (parameterDefaults == null) || (index >= parameterDefaults.length)) ? (DataValueDescriptor) null : (DataValueDescriptor) parameterDefaults[index], (DefaultInfo) null, uuid, (UUID) null, 0, 0, 0, false);
        addDescriptor(cd, null, SYSCOLUMNS_CATALOG_NUM, // no chance of duplicates here
        false, tc);
    }
}
Also used : DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 97 with DataTypeDescriptor

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

the class DataDictionaryImpl method genColumnReferenceSQL.

/*
	** Make sure the given column name is found in the trigger
	** target table.  Generate the appropriate SQL to get it.
	**
	** @return a string that is used to get the column using
	** getObject() on the desired result set and CAST it back
	** to the proper type in the SQL domain. 
	**
	** @exception StandardException on invalid column name
	*/
private String genColumnReferenceSQL(TableDescriptor td, String colName, String tabName, boolean isOldTable, int colPositionInRuntimeResultSet) throws StandardException {
    ColumnDescriptor colDesc = null;
    if ((colDesc = td.getColumnDescriptor(colName)) == null) {
        throw StandardException.newException(SQLState.LANG_COLUMN_NOT_FOUND, tabName + "." + colName);
    }
    /*
		** Generate something like this:
		**
		** 		CAST (org.apache.derby.iapi.db.Factory::
		**			getTriggerExecutionContext().getNewRow().
		**				getObject(<colPosition>) AS DECIMAL(6,2))
	    **
	    ** Column position is used to avoid the wrong column being
	    ** selected problem (DERBY-1258) caused by the case insensitive
	    ** JDBC rules for fetching a column by name.
		**
		** The cast back to the SQL Domain may seem redundant
		** but we need it to make the column reference appear
		** EXACTLY like a regular column reference, so we need
		** the object in the SQL Domain and we need to have the
		** type information.  Thus a user should be able to do 
		** something like
		**
		**		CREATE TRIGGER ... INSERT INTO T length(Column), ...
	    **
	    */
    DataTypeDescriptor dts = colDesc.getType();
    TypeId typeId = dts.getTypeId();
    if (!typeId.isXMLTypeId()) {
        StringBuffer methodCall = new StringBuffer();
        methodCall.append("CAST (org.apache.derby.iapi.db.Factory::getTriggerExecutionContext().");
        methodCall.append(isOldTable ? "getOldRow()" : "getNewRow()");
        methodCall.append(".getObject(");
        methodCall.append(colPositionInRuntimeResultSet);
        methodCall.append(") AS ");
        /*
	        ** getSQLString() returns <typeName> 
	        ** for user types, so call getSQLTypeName in that
	        ** case.
	        */
        methodCall.append((typeId.userType() ? typeId.getSQLTypeName() : dts.getSQLstring()));
        methodCall.append(") ");
        return methodCall.toString();
    } else {
        /*  DERBY-2350
	        **
	        **  Triggers currently use jdbc 1.2 to access columns.  The default
	        **  uses getObject() which is not supported for an XML type until
	        **  jdbc 4.  In the meantime use getString() and then call 
	        **  XMLPARSE() on the string to get the type.  See Derby issue and
	        **  http://wiki.apache.org/db-derby/TriggerImplementation , for
	        **  better long term solutions.  Long term I think changing the
	        **  trigger architecture to not rely on jdbc, but instead on an
	        **  internal direct access interface to execution nodes would be
	        **  best future direction, but believe such a change appropriate
	        **  for a major release, not a bug fix.
	        **
	        **  Rather than the above described code generation, use the 
	        **  following for XML types to generate an XML column from the
	        **  old or new row.
	        ** 
	        **          XMLPARSE(DOCUMENT
	        **              CAST (org.apache.derby.iapi.db.Factory::
	        **                  getTriggerExecutionContext().getNewRow().
	        **                      getString(<colPosition>) AS CLOB)  
	        **                        PRESERVE WHITESPACE)
	        */
        StringBuffer methodCall = new StringBuffer();
        methodCall.append("XMLPARSE(DOCUMENT CAST( ");
        methodCall.append("org.apache.derby.iapi.db.Factory::getTriggerExecutionContext().");
        methodCall.append(isOldTable ? "getOldRow()" : "getNewRow()");
        methodCall.append(".getString(");
        methodCall.append(colPositionInRuntimeResultSet);
        methodCall.append(") AS CLOB) PRESERVE WHITESPACE ) ");
        return methodCall.toString();
    }
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)

Example 98 with DataTypeDescriptor

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

the class GenericParameterValueSet method initialize.

/*
	** ParameterValueSet interface methods
	*/
/**
 * Initialize the set by allocating a holder DataValueDescriptor object
 * for each parameter.
 */
public void initialize(DataTypeDescriptor[] types) throws StandardException {
    for (int i = 0; i < parms.length; i++) {
        DataTypeDescriptor dtd = types[i];
        parms[i].initialize(dtd.getNull(), dtd.getJDBCTypeId(), dtd.getTypeId().getCorrespondingJavaTypeName());
    }
}
Also used : DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor)

Example 99 with DataTypeDescriptor

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

the class IndexRowGenerator method getNullIndexRow.

/**
 * Get a NULL Index Row for this index. This is useful to create objects
 * that need to be passed to ScanController.
 *
 * @param columnList ColumnDescriptors describing the base table.
 * @param rowLocation   empty row location.
 *
 * @exception StandardException thrown on error.
 */
public ExecIndexRow getNullIndexRow(ColumnDescriptorList columnList, RowLocation rowLocation) throws StandardException {
    int[] baseColumnPositions = id.baseColumnPositions();
    ExecIndexRow indexRow = getIndexRowTemplate();
    for (int i = 0; i < baseColumnPositions.length; i++) {
        DataTypeDescriptor dtd = columnList.elementAt(baseColumnPositions[i] - 1).getType();
        indexRow.setColumn(i + 1, dtd.getNull());
    }
    indexRow.setColumn(baseColumnPositions.length + 1, rowLocation);
    return indexRow;
}
Also used : DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Aggregations

DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)99 TypeId (org.apache.derby.iapi.types.TypeId)32 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)14 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)14 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)9 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)8 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)8 TypeDescriptor (org.apache.derby.catalog.TypeDescriptor)7 UUID (org.apache.derby.catalog.UUID)5 ClassFactory (org.apache.derby.iapi.services.loader.ClassFactory)5 ResultColumnDescriptor (org.apache.derby.iapi.sql.ResultColumnDescriptor)5 TypeCompiler (org.apache.derby.iapi.sql.compile.TypeCompiler)5 StandardException (org.apache.derby.shared.common.error.StandardException)5 Properties (java.util.Properties)4 UserDefinedTypeIdImpl (org.apache.derby.catalog.types.UserDefinedTypeIdImpl)4 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)4 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)3 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)3 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)3 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)3