public Object convertJavaToSQL(SessionInterface session, Object a) {

        switch (typeCode) {

            case Types.SQL_TIME :
            case Types.SQL_TIME_WITH_TIME_ZONE :
                if (a instanceof java.sql.Date) {
                    break;
                }

                if (a instanceof java.util.Date) {
                    long seconds =
                        HsqlDateTime.getNormalisedTime(
                            ((java.util.Date) a).getTime()) / 1000;;
                    int zoneSeconds;
                    int nanos = 0;

                    if (this.isDateTimeTypeWithZone()) {
                        zoneSeconds = session.getZoneSeconds();
                    } else {
                        zoneSeconds = 0;
                        seconds     += session.getZoneSeconds();
                    }

                    if (a instanceof java.sql.Timestamp) {
                        nanos = ((java.sql.Timestamp) a).getNanos();
                        nanos = this.normaliseFraction(nanos, (int) scale);
                    }

                    return new TimeData((int) seconds, nanos, zoneSeconds);
                }
                break;

            case Types.SQL_DATE : {
                if (a instanceof java.sql.Time) {
                    break;
                }

                if (a instanceof java.util.Date) {
                    long nanos = ((java.util.Date) a).getTime()
                                 + session.getZoneSeconds() * 1000;

                    return new TimestampData(
                        HsqlDateTime.getNormalisedDate(nanos) / 1000);
                }

                break;
            }
            case Types.SQL_TIMESTAMP :
            case Types.SQL_TIMESTAMP_WITH_TIME_ZONE : {
                if (a instanceof java.sql.Time) {
                    break;
                }

                if (a instanceof java.util.Date) {
                    long seconds = ((java.util.Date) a).getTime() / 1000;
                    int  zoneSeconds;
                    int  nanos = 0;

                    if (this.isDateTimeTypeWithZone()) {
                        zoneSeconds = session.getZoneSeconds();
                    } else {
                        zoneSeconds = 0;
                        seconds     += session.getZoneSeconds();
                    }

                    if (a instanceof java.sql.Timestamp) {
                        nanos = ((java.sql.Timestamp) a).getNanos();
                        nanos = this.normaliseFraction(nanos, (int) scale);
                    }

                    return new TimestampData(seconds, nanos, zoneSeconds);
                }

                break;
            }
        }

        throw Error.error(ErrorCode.X_42561);
    }
public Object convertJavaToSQL ( SessionInterface session , Object a ) { switch ( typeCode ) { case Types . SQL_TIME : case Types . SQL_TIME_WITH_TIME_ZONE : if ( a instanceof java . sql . Date ) { break ; } if ( a instanceof java . util . Date ) { long seconds = HsqlDateTime . getNormalisedTime ( ( ( java . util . Date ) a ) . getTime ( ) ) / 1000 ; ; int zoneSeconds ; int nanos = 0 ; if ( this . isDateTimeTypeWithZone ( ) ) { zoneSeconds = session . getZoneSeconds ( ) ; } else { zoneSeconds = 0 ; seconds += session . getZoneSeconds ( ) ; } if ( a instanceof java . sql . Timestamp ) { nanos = ( ( java . sql . Timestamp ) a ) . getNanos ( ) ; nanos = this . normaliseFraction ( nanos , ( int ) scale ) ; } return new TimeData ( ( int ) seconds , nanos , zoneSeconds ) ; } break ; case Types . SQL_DATE : { if ( a instanceof java . sql . Time ) { break ; } if ( a instanceof java . util . Date ) { long nanos = ( ( java . util . Date ) a ) . getTime ( ) + session . getZoneSeconds ( ) * 1000 ; return new TimestampData ( HsqlDateTime . getNormalisedDate ( nanos ) / 1000 ) ; } break ; } case Types . SQL_TIMESTAMP : case Types . SQL_TIMESTAMP_WITH_TIME_ZONE : { if ( a instanceof java . sql . Time ) { break ; } if ( a instanceof java . util . Date ) { long seconds = ( ( java . util . Date ) a ) . getTime ( ) / 1000 ; int zoneSeconds ; int nanos = 0 ; if ( this . isDateTimeTypeWithZone ( ) ) { zoneSeconds = session . getZoneSeconds ( ) ; } else { zoneSeconds = 0 ; seconds += session . getZoneSeconds ( ) ; } if ( a instanceof java . sql . Timestamp ) { nanos = ( ( java . sql . Timestamp ) a ) . getNanos ( ) ; nanos = this . normaliseFraction ( nanos , ( int ) scale ) ; } return new TimestampData ( seconds , nanos , zoneSeconds ) ; } break ; } } throw Error . error ( ErrorCode . X_42561 ) ; }
@todo - do the time zone