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);
}
}
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();
}
}
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());
}
}
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;
}
Aggregations