use of org.apache.derby.iapi.types.DataTypeDescriptor in project derby by apache.
the class EmbedPreparedStatement method setBinaryStreamInternal.
/**
* Set the given stream for the specified parameter.
*
* If <code>lengthLess</code> is <code>true</code>, the following
* conditions are either not checked or verified at the execution time
* of the prepared statement:
* <ol><li>If the stream length is negative.
* <li>If the stream's actual length equals the specified length.</ol>
* The <code>lengthLess</code> variable was added to differentiate between
* streams with invalid lengths and streams without known lengths.
*
* @param parameterIndex the 1-based index of the parameter to set.
* @param x the data.
* @param lengthLess tells whether we know the length of the data or not.
* @param length the length of the data. Ignored if <code>lengthLess</code>
* is <code>true</code>.
*/
private void setBinaryStreamInternal(int parameterIndex, InputStream x, final boolean lengthLess, long length) throws SQLException {
if (!lengthLess && length < 0)
throw newSQLException(SQLState.NEGATIVE_STREAM_LENGTH);
int jdbcTypeId = getParameterJDBCType(parameterIndex);
if (x == null) {
setNull(parameterIndex, jdbcTypeId);
return;
}
// in that case the cast to int would not be appropriate.
if (!lengthLess && length > Integer.MAX_VALUE) {
throw newSQLException(SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE, getParameterMetaData().getParameterTypeName(parameterIndex));
}
try {
RawToBinaryFormatStream rawStream;
if (lengthLess) {
// Indicate that we don't know the logical length of the stream.
length = DataValueDescriptor.UNKNOWN_LOGICAL_LENGTH;
DataTypeDescriptor[] dtd = preparedStatement.getParameterTypes();
rawStream = new RawToBinaryFormatStream(x, dtd[parameterIndex - 1].getMaximumWidth(), dtd[parameterIndex - 1].getTypeName());
} else {
rawStream = new RawToBinaryFormatStream(x, (int) length);
}
getParms().getParameterForSet(parameterIndex - 1).setValue(rawStream, (int) length);
} catch (StandardException t) {
throw EmbedResultSet.noStateChangeException(t);
}
}
use of org.apache.derby.iapi.types.DataTypeDescriptor in project derby by apache.
the class EmbedPreparedStatement method setCharacterStreamInternal.
/**
* Set the given character stream for the specified parameter.
*
* If <code>lengthLess</code> is <code>true</code>, the following
* conditions are either not checked or verified at the execution time
* of the prepared statement:
* <ol><li>If the stream length is negative.
* <li>If the stream's actual length equals the specified length.</ol>
* The <code>lengthLess</code> variable was added to differentiate between
* streams with invalid lengths and streams without known lengths.
*
* @param parameterIndex the 1-based index of the parameter to set.
* @param reader the data.
* @param lengthLess tells whether we know the length of the data or not.
* @param length the length of the data. Ignored if <code>lengthLess</code>
* is <code>true</code>.
*/
private void setCharacterStreamInternal(int parameterIndex, Reader reader, final boolean lengthLess, long length) throws SQLException {
// Check for negative length if length is specified.
if (!lengthLess && length < 0)
throw newSQLException(SQLState.NEGATIVE_STREAM_LENGTH);
int jdbcTypeId = getParameterJDBCType(parameterIndex);
if (reader == null) {
setNull(parameterIndex, jdbcTypeId);
return;
}
/*
The value stored should not exceed the maximum value that can be
stored in an integer
This checking needs to be done because currently derby does not
support Clob sizes greater than 2G-1
*/
if (!lengthLess && length > Integer.MAX_VALUE)
throw newSQLException(SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE, getParameterSQLType(parameterIndex));
try {
ReaderToUTF8Stream utfIn;
final StringDataValue dvd = (StringDataValue) getParms().getParameter(parameterIndex - 1);
dvd.setStreamHeaderFormat(usePreTenFiveHdrFormat());
// Need column width to figure out if truncation is needed
DataTypeDescriptor[] dtd = preparedStatement.getParameterTypes();
int colWidth = dtd[parameterIndex - 1].getMaximumWidth();
// Holds either UNKNOWN_LOGICAL_LENGTH or the exact logical length.
int usableLength = DataValueDescriptor.UNKNOWN_LOGICAL_LENGTH;
if (!lengthLess) {
// We cast the length from long to int. This wouldn't be
// appropriate if the limit of 2G-1 is decided to be increased
// at a later stage.
usableLength = (int) length;
int truncationLength = 0;
// for clob below.
if (jdbcTypeId == Types.CLOB) {
// length - colWidth has trailing blanks only
if (usableLength > colWidth) {
truncationLength = usableLength - colWidth;
usableLength = colWidth;
}
}
// Create a stream with truncation.
utfIn = new ReaderToUTF8Stream(reader, usableLength, truncationLength, getParameterSQLType(parameterIndex), dvd.getStreamHeaderGenerator());
} else {
// Create a stream without exactness checks,
// but with a maximum limit.
utfIn = new ReaderToUTF8Stream(reader, colWidth, getParameterSQLType(parameterIndex), dvd.getStreamHeaderGenerator());
}
// JDBC is one-based, DBMS is zero-based.
// Note that for lengthless stream, usableLength will be
// the maximum length for the column.
// This is okay, based on the observation that
// setValue does not use the value for anything at all.
getParms().getParameterForSet(parameterIndex - 1).setValue(utfIn, usableLength);
} catch (StandardException t) {
throw EmbedResultSet.noStateChangeException(t);
}
}
use of org.apache.derby.iapi.types.DataTypeDescriptor in project derby by apache.
the class DataDictionaryImpl method createIdentitySequence.
/**
* Create a sequence generator for an identity column on upgrade to 10.11.
*/
private void createIdentitySequence(TableDescriptor td, // the identity column
ColumnDescriptor cd, TransactionController tc) throws StandardException {
DataTypeDescriptor dtd = cd.getType();
long[] bounds = dtd.getNumericBounds();
long currentValue = cd.getAutoincValue();
long initialValue = cd.getAutoincStart();
long minValue = bounds[DataTypeDescriptor.MIN_VALUE_IDX];
long maxValue = bounds[DataTypeDescriptor.MAX_VALUE_IDX];
long stepValue = cd.getAutoincInc();
SchemaDescriptor sd = getSystemSchemaDescriptor();
SequenceDescriptor seqDef = getDataDescriptorGenerator().newSequenceDescriptor(sd, getUUIDFactory().createUUID(), TableDescriptor.makeSequenceName(td.getUUID()), dtd, currentValue, initialValue, minValue, maxValue, stepValue, // whether the sequence can wrap-around
false);
addDescriptor(seqDef, // parent
null, DataDictionary.SYSSEQUENCES_CATALOG_NUM, // duplicatesAllowed
false, tc);
}
use of org.apache.derby.iapi.types.DataTypeDescriptor in project derby by apache.
the class DataDictionaryImpl method getSPSParams.
/**
* Get all the parameter descriptors for an SPS.
* Look up the params in SYSCOLUMNS and turn them
* into parameter descriptors.
*
* @param spsd sps descriptor
* @param defaults list for storing column defaults
*
* @return array of data type descriptors
*
* @exception StandardException Thrown on error
*/
public DataTypeDescriptor[] getSPSParams(SPSDescriptor spsd, List<DataValueDescriptor> defaults) throws StandardException {
ColumnDescriptorList cdl = new ColumnDescriptorList();
getColumnDescriptorsScan(spsd.getUUID(), cdl, spsd);
int cdlSize = cdl.size();
DataTypeDescriptor[] params = new DataTypeDescriptor[cdlSize];
for (int index = 0; index < cdlSize; index++) {
ColumnDescriptor cd = (ColumnDescriptor) cdl.elementAt(index);
params[index] = cd.getType();
if (defaults != null) {
defaults.add(cd.getDefaultValue());
}
}
return params;
}
use of org.apache.derby.iapi.types.DataTypeDescriptor in project derby by apache.
the class SYSSCHEMASRowFactory method makeRow.
// ///////////////////////////////////////////////////////////////////////////
//
// METHODS
//
// ///////////////////////////////////////////////////////////////////////////
/**
* Make a SYSSCHEMAS row
*
* @return Row suitable for inserting into SYSSCHEMAS.
*
* @exception StandardException thrown on failure
*/
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
DataTypeDescriptor dtd;
ExecRow row;
DataValueDescriptor col;
String name = null;
UUID oid = null;
String uuid = null;
String aid = null;
if (td != null) {
SchemaDescriptor schemaDescriptor = (SchemaDescriptor) td;
name = schemaDescriptor.getSchemaName();
oid = schemaDescriptor.getUUID();
if (oid == null) {
oid = getUUIDFactory().createUUID();
schemaDescriptor.setUUID(oid);
}
uuid = oid.toString();
aid = schemaDescriptor.getAuthorizationId();
}
/* Build the row to insert */
row = getExecutionFactory().getValueRow(SYSSCHEMAS_COLUMN_COUNT);
/* 1st column is SCHEMAID */
row.setColumn(1, new SQLChar(uuid));
/* 2nd column is SCHEMANAME */
row.setColumn(2, new SQLVarchar(name));
/* 3rd column is SCHEMAAID */
row.setColumn(3, new SQLVarchar(aid));
return row;
}
Aggregations