Search in sources :

Example 21 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class JDBCCallableStatement method getObject.

//----------------------------------------------------------------------
// Advanced features:
/**
     * <!-- start generic documentation -->
     *
     * Retrieves the value of the designated parameter as an <code>Object</code>
     * in the Java programming language. If the value is an SQL <code>NULL</code>,
     * the driver returns a Java <code>null</code>.
     * <p>
     * This method returns a Java object whose type corresponds to the JDBC
     * type that was registered for this parameter using the method
     * <code>registerOutParameter</code>.  By registering the target JDBC
     * type as <code>java.sql.Types.OTHER</code>, this method can be used
     * to read database-specific abstract data types.
     *
     * <!-- end generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * HSQLDB supports this feature. <p>
     *
     * </div>
     * <!-- end release-specific documentation -->
     *
     * @param parameterIndex the first parameter is 1, the second is 2,
     *        and so on
     * @return A <code>java.lang.Object</code> holding the OUT parameter value
     * @exception SQLException if a database access error occurs or
     * this method is called on a closed <code>CallableStatement</code>
     * @see java.sql.Types
     * @see #setObject
     */
public synchronized Object getObject(int parameterIndex) throws SQLException {
    checkGetParameterIndex(parameterIndex);
    Type sourceType = parameterTypes[parameterIndex - 1];
    switch(sourceType.typeCode) {
        case Types.SQL_DATE:
            return getDate(parameterIndex);
        case Types.SQL_TIME:
        case Types.SQL_TIME_WITH_TIME_ZONE:
            return getTime(parameterIndex);
        case Types.SQL_TIMESTAMP:
        case Types.SQL_TIMESTAMP_WITH_TIME_ZONE:
            return getTimestamp(parameterIndex);
        case Types.SQL_BINARY:
        case Types.SQL_VARBINARY:
            return getBytes(parameterIndex);
        case Types.OTHER:
        case Types.JAVA_OBJECT:
            {
                Object o = getColumnInType(parameterIndex, sourceType);
                if (o == null) {
                    return null;
                }
                try {
                    return ((JavaObjectData) o).getObject();
                } catch (HsqlException e) {
                    throw Util.sqlException(e);
                }
            }
        default:
            return getColumnInType(parameterIndex, sourceType);
    }
}
Also used : Type(org.hsqldb_voltpatches.types.Type) SchemaObject(org.hsqldb_voltpatches.SchemaObject) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 22 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class JDBCResultSet method getColumnInType.

/**
     * Internal value converter. <p>
     *
     * All trivially successful getXXX methods eventually go through this
     * method, converting if neccessary from the source type to the
     * requested type.  <p>
     *
     * Conversion to the JDBC representation, if different, is handled by the
     * calling methods.
     *
     * @param columnIndex of the column value for which to perform the
     *                 conversion
     * @param targetType the org.hsqldb_voltpatches.types.Type object for targetType
     * @return an Object of the requested targetType, representing the value of the
     *       specified column
     * @throws SQLException when there is no rowData, the column index is
     *    invalid, or the conversion cannot be performed
     */
private Object getColumnInType(int columnIndex, Type targetType) throws SQLException {
    Object[] rowData = getCurrent();
    Type sourceType;
    Object value;
    checkColumn(columnIndex);
    sourceType = resultMetaData.columnTypes[--columnIndex];
    value = rowData[columnIndex];
    if (trackNull(value)) {
        return null;
    }
    if (sourceType.typeCode != targetType.typeCode) {
        try {
            value = targetType.convertToTypeJDBC(session, value, sourceType);
        } catch (Exception e) {
            String stringValue = (value instanceof Number || value instanceof String) ? value.toString() : "instance of " + value.getClass().getName();
            String msg = "from SQL type " + sourceType.getNameString() + " to " + targetType.getJDBCClassName() + ", value: " + stringValue;
            Util.throwError(Error.error(ErrorCode.X_42561, msg));
        }
    }
    return value;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) SQLException(java.sql.SQLException) IOException(java.io.IOException) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 23 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class JDBCPreparedStatement method setTime.

/**
     * <!-- start generic documentation -->
     * Sets the designated parameter to the given <code>java.sql.Time</code> value,
     * using the given <code>Calendar</code> object.  The driver uses
     * the <code>Calendar</code> object to construct an SQL <code>TIME</code> value,
     * which the driver then sends to the database.  With
     * a <code>Calendar</code> object, the driver can calculate the time
     * taking into account a custom timezone.  If no
     * <code>Calendar</code> object is specified, the driver uses the default
     * timezone, which is that of the virtual machine running the application.
     * <!-- end generic documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * When a setXXX method is used to set a parameter of type
     * TIMESTAMP WITH TIME ZONE or TIME WITH TIME ZONE the time zone (including
     * Daylight Saving Time) of the Calendar is used as time zone for the
     * value.<p>
     *
     * </div>
     * <!-- end release-specific documentation -->
     *
     * @param parameterIndex the first parameter is 1, the second is 2, ...
     * @param x the parameter value
     * @param cal the <code>Calendar</code> object the driver will use
     *            to construct the time
     * @exception SQLException if a database access error occurs or
     * this method is called on a closed <code>PreparedStatement</code>
     * @since JDK 1.2 (JDK 1.1.x developers: read the overview for
     *   JDBCParameterMetaData)
     */
public synchronized void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
    checkSetParameterIndex(parameterIndex, false);
    int i = parameterIndex - 1;
    if (x == null) {
        parameterValues[i] = null;
        return;
    }
    Type outType = parameterTypes[i];
    long millis = x.getTime();
    int zoneOffset = 0;
    if (cal != null) {
        zoneOffset = HsqlDateTime.getZoneMillis(cal, millis);
    }
    switch(outType.typeCode) {
        case Types.SQL_TIME:
            millis += zoneOffset;
            zoneOffset = 0;
        // $FALL-THROUGH$
        case Types.SQL_TIME_WITH_TIME_ZONE:
            break;
        default:
            throw Util.sqlException(ErrorCode.X_42561);
    }
    millis = HsqlDateTime.convertToNormalisedTime(millis);
    parameterValues[i] = new TimeData((int) (millis / 1000), 0, zoneOffset / 1000);
}
Also used : Type(org.hsqldb_voltpatches.types.Type) TimeData(org.hsqldb_voltpatches.types.TimeData)

Example 24 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class JDBCPreparedStatement method setDate.

/**
     * <!-- start generic documentation -->
     * Sets the designated parameter to the given <code>java.sql.Date</code> value,
     * using the given <code>Calendar</code> object.  The driver uses
     * the <code>Calendar</code> object to construct an SQL <code>DATE</code> value,
     * which the driver then sends to the database.  With
     * a <code>Calendar</code> object, the driver can calculate the date
     * taking into account a custom timezone.  If no
     * <code>Calendar</code> object is specified, the driver uses the default
     * timezone, which is that of the virtual machine running the application.
     * <!-- end generic documentation -->
     *
     * @param parameterIndex the first parameter is 1, the second is 2, ...
     * @param x the parameter value
     * @param cal the <code>Calendar</code> object the driver will use
     *            to construct the date
     * @exception SQLException if a database access error occurs or
     * this method is called on a closed <code>PreparedStatement</code>
     * @since JDK 1.2 (JDK 1.1.x developers: read the overview for
     *   JDBCParameterMetaData)
     */
public synchronized void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
    checkSetParameterIndex(parameterIndex, false);
    int i = parameterIndex - 1;
    if (x == null) {
        parameterValues[i] = null;
        return;
    }
    Type outType = parameterTypes[i];
    long millis = HsqlDateTime.convertToNormalisedDate(x.getTime(), cal);
    int zoneOffset = HsqlDateTime.getZoneMillis(cal, millis);
    switch(outType.typeCode) {
        case Types.SQL_DATE:
        case Types.SQL_TIMESTAMP:
        case Types.SQL_TIMESTAMP_WITH_TIME_ZONE:
            break;
        default:
            throw Util.sqlException(ErrorCode.X_42561);
    }
    parameterValues[i] = new TimestampData((millis + zoneOffset) / 1000);
}
Also used : Type(org.hsqldb_voltpatches.types.Type) TimestampData(org.hsqldb_voltpatches.types.TimestampData)

Example 25 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class JDBCPreparedStatement method setBlob.

/**
     * <!-- start generic documentation -->
     * Sets the designated parameter to the given <code>java.sql.Blob</code> object.
     * The driver converts this to an SQL <code>BLOB</code> value when it
     * sends it to the database.
     * <!-- end generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * For parameters of type Blob, setBlob works normally.<p>
     *
     * In addition since 1.7.2, setBlob is supported for BINARY and VARBINARY
     * parameters. In this context, the Blob object is
     * hard-limited to those of length less than or equal to Integer.MAX_VALUE.
     * In practice, soft limits such as available heap and maximum disk usage
     * per file (such as the transaction log) dictate a much smaller maximum
     * length. <p>
     *
     * For BINARY and VARBINARY parameter types setBlob(i,x) is roughly
     * equivalent (null and length handling not shown) to:<p>
     *
     * <pre class="JavaCodeExample">
     * <b>setBinaryStream</b>(i, x.<b>getBinaryStream</b>(), (<span class="JavaKeyWord">int</span>) x.<b>length</b>());
     * </pre></div>
     * <!-- end release-specific documentation -->
     *
     * @param parameterIndex the first parameter is 1, the second is 2, ...
     * @param x a <code>Blob</code> object that maps an SQL <code>BLOB</code> value
     * @exception SQLException if a database access error occurs or
     * this method is called on a closed <code>PreparedStatement</code>
     * @throws SQLFeatureNotSupportedException  if the JDBC driver does not support this method
     * @since JDK 1.2 (JDK 1.1.x developers: read the overview for
     * JDBCParameterMetaData)
     */
public synchronized void setBlob(int parameterIndex, Blob x) throws SQLException {
    checkSetParameterIndex(parameterIndex, false);
    Type outType = parameterTypes[parameterIndex - 1];
    switch(outType.typeCode) {
        case Types.SQL_BINARY:
        case Types.SQL_VARBINARY:
            setBlobForBinaryParameter(parameterIndex, x);
            return;
        case Types.SQL_BLOB:
            setBlobParameter(parameterIndex, x);
            break;
        default:
            throw Util.invalidArgument();
    }
}
Also used : Type(org.hsqldb_voltpatches.types.Type)

Aggregations

Type (org.hsqldb_voltpatches.types.Type)72 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)20 CharacterType (org.hsqldb_voltpatches.types.CharacterType)20 NumberType (org.hsqldb_voltpatches.types.NumberType)14 SchemaObject (org.hsqldb_voltpatches.SchemaObject)11 Table (org.hsqldb_voltpatches.Table)9 Iterator (org.hsqldb_voltpatches.lib.Iterator)9 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)9 IntervalType (org.hsqldb_voltpatches.types.IntervalType)9 Constraint (org.hsqldb_voltpatches.Constraint)8 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)8 HsqlException (org.hsqldb_voltpatches.HsqlException)7 TextTable (org.hsqldb_voltpatches.TextTable)6 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)6 DTIType (org.hsqldb_voltpatches.types.DTIType)6 ColumnSchema (org.hsqldb_voltpatches.ColumnSchema)4 DateTimeType (org.hsqldb_voltpatches.types.DateTimeType)4 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)3 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2