Example usage for java.sql Time getHours

List of usage examples for java.sql Time getHours

Introduction

In this page you can find the example usage for java.sql Time getHours.

Prototype

@Deprecated
public int getHours() 

Source Link

Document

Returns the hour represented by this Date object.

Usage

From source file:com.google.visualization.datasource.util.SqlDataSourceHelper.java

/**
 * Creates a table cell from the value in the current row of the given result
 * set and the given column index. The type of the value is determined by the
 * given value type.// www  .  j  av  a 2  s .c  om
 *
 * @param rs The result set holding the data from the sql table. The result
 *     points to the current row.
 * @param valueType The value type of the column that the cell belongs to.
 * @param column The column index. Indexes are 0-based.
 *
 * @return The table cell.
 *
 * @throws SQLException Thrown when the connection to the database failed.
 */
private static TableCell buildTableCell(ResultSet rs, ValueType valueType, int column) throws SQLException {
    Value value = null;

    // SQL indexes are 1- based.
    column = column + 1;

    switch (valueType) {
    case BOOLEAN:
        value = BooleanValue.getInstance(rs.getBoolean(column));
        break;
    case NUMBER:
        value = new NumberValue(rs.getDouble(column));
        break;
    case DATE:
        Date date = rs.getDate(column);
        // If date is null it is handled later.
        if (date != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the year, month and date in the gregorian calendar.
            // Use the 'set' method with those parameters, and not the 'setTime'
            // method with the date parameter, since the Date object contains the
            // current time zone and it's impossible to change it to 'GMT'.
            gc.set(date.getYear() + 1900, date.getMonth(), date.getDate());
            value = new DateValue(gc);
        }
        break;
    case DATETIME:
        Timestamp timestamp = rs.getTimestamp(column);
        // If timestamp is null it is handled later.
        if (timestamp != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the year, month, date, hours, minutes and seconds in the
            // gregorian calendar. Use the 'set' method with those parameters,
            // and not the 'setTime' method with the timestamp parameter, since
            // the Timestamp object contains the current time zone and it's
            // impossible to change it to 'GMT'.
            gc.set(timestamp.getYear() + 1900, timestamp.getMonth(), timestamp.getDate(), timestamp.getHours(),
                    timestamp.getMinutes(), timestamp.getSeconds());
            // Set the milliseconds explicitly, as they are not saved in the
            // underlying date.
            gc.set(Calendar.MILLISECOND, timestamp.getNanos() / 1000000);
            value = new DateTimeValue(gc);
        }
        break;
    case TIMEOFDAY:
        Time time = rs.getTime(column);
        // If time is null it is handled later.
        if (time != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the hours, minutes and seconds of the time in the gregorian
            // calendar. Set the year, month and date to be January 1 1970 like
            // in the Time object.
            // Use the 'set' method with those parameters,
            // and not the 'setTime' method with the time parameter, since
            // the Time object contains the current time zone and it's
            // impossible to change it to 'GMT'.
            gc.set(1970, Calendar.JANUARY, 1, time.getHours(), time.getMinutes(), time.getSeconds());
            // Set the milliseconds explicitly, otherwise the milliseconds from
            // the time the gc was initialized are used.
            gc.set(GregorianCalendar.MILLISECOND, 0);
            value = new TimeOfDayValue(gc);
        }
        break;
    default:
        String colValue = rs.getString(column);
        if (colValue == null) {
            value = TextValue.getNullValue();
        } else {
            value = new TextValue(rs.getString(column));
        }
        break;
    }
    // Handle null values.
    if (rs.wasNull()) {
        return new TableCell(Value.getNullValueFromValueType(valueType));
    } else {
        return new TableCell(value);
    }
}

From source file:main.UIController.java

@SuppressWarnings("deprecation")
public void convertToImladris() {
    UI window = this.getUi();

    String errorEmptyYear = "Please insert a year.";
    String errorYearNotNumeric = "Please insert the year as a numeric value.";
    String errorYearNotValid = "Please insert a valid year (from 1 to "
            + Integer.toString(GregorianInfo.MAX_SUPPORTED_YEAR) + ").";
    String errorDayNotRead = "Sorry, the day could not be read.";

    JTextField year = window.getYear();
    JComboBox month = window.getMonth();
    JComboBox day = window.getDay();
    JCheckBox afterSunset = window.getAfterSunset();
    JTextPane result = window.getResImladris();
    String value = year.getText();
    if (!value.isEmpty()) {
        try {/*from  w w  w .  j a v  a  2 s.co  m*/
            int yearNum = Integer.parseInt(value);
            if (yearNum > 0 && yearNum <= GregorianInfo.MAX_SUPPORTED_YEAR) {
                int monthNum = month.getSelectedIndex() + 1;
                int dayNum = 0;
                if (day.isEnabled()) {
                    dayNum = day.getSelectedIndex() + 1;
                    ImladrisCalendar cal;
                    if (afterSunset.isSelected()) {
                        GregorianCalendar gcal = new GregorianCalendar(yearNum, monthNum, dayNum);
                        Time time = this.calculateSunsetForActualLocation(gcal, true);
                        cal = new ImladrisCalendar(time, yearNum, monthNum, dayNum, time.getHours(),
                                time.getMinutes(), time.getSeconds());
                    } else {
                        cal = new ImladrisCalendar(yearNum, monthNum, dayNum);
                    }
                    result.setText(cal.toString());
                } else {
                    result.setText(errorDayNotRead);
                }
            } else {
                result.setText(errorYearNotValid);
            }
        } catch (NumberFormatException e) {
            result.setText(errorYearNotNumeric);
        }
    } else {
        result.setText(errorEmptyYear);
    }
}

From source file:edu.eci.cosw.logica.Logica.java

/**
 * @obj verificar si una sala esta disponible e la fecha, con hora, especificada
 * @param fecha la fecha a revisar si hay disponibilidad
 * @param idSala identificador de la sala en donde se quiere verificar la disponiblidad
 * @param idEstablecimiento identificador del establecimeinto que que tiene la sala
 * @return true si la sala esta disponible en la fecha establecida, false de lo contrario
 *///  w  ww. j av  a  2  s . com
public boolean verificarDisponibilidadSala(Date fecha, Time hora, int idSala, int idEstablecimiento) {
    boolean res = true;
    Establecimiento e = re.findOne(idEstablecimiento);
    List<Sala> salas = consultarSalaPorEstablecimiento(e.getIdEstablecimiento());
    Sala s = null;

    for (int i = 0; i < salas.size(); i++) {
        if ((salas.get(i)).getIdSala() == idSala) {
            s = salas.get(i);
        }
    }
    try {
        List<Reservacion> reservas = consultarReservacionesPorSala(s.getIdSala());

        if (reservas != null) {
            Calendar c1 = new GregorianCalendar();
            Calendar c2 = new GregorianCalendar();
            c1.setTime(fecha);
            Time h1, h2;
            h1 = hora;
            boolean n = true;
            for (int i = 0; i < reservas.size() && n; i++) {
                h2 = reservas.get(i).getHora();
                c2.setTime(reservas.get(i).getFecha());

                if ((c1.after(c2) && h2.getHours() - h1.getHours() > 0)) {
                    n = true;
                } else if (c1.before(c2) && h1.getHours() - h2.getHours() > 0) {
                    n = true;
                } else {
                    n = false;
                    System.out.println(h1 + "                                      " + h2);
                }
            }
            if (n == false)
                res = false;
        } else {
            res = true;
        }
    } catch (NullPointerException npe) {
        res = true;
    }

    return res;
}

From source file:org.apache.tajo.storage.jdbc.JdbcScanner.java

protected void convertTuple(ResultSet resultSet, VTuple tuple) {
    try {//from   w ww .  ja v a2 s  .co  m
        for (int column_idx = 0; column_idx < targets.length; column_idx++) {
            final Column c = targets[column_idx];
            final int resultIdx = column_idx + 1;

            switch (c.getDataType().getType()) {
            case INT1:
            case INT2:
                tuple.put(column_idx, DatumFactory.createInt2(resultSet.getShort(resultIdx)));
                break;
            case INT4:
                tuple.put(column_idx, DatumFactory.createInt4(resultSet.getInt(resultIdx)));
                break;
            case INT8:
                tuple.put(column_idx, DatumFactory.createInt8(resultSet.getLong(resultIdx)));
                break;
            case FLOAT4:
                tuple.put(column_idx, DatumFactory.createFloat4(resultSet.getFloat(resultIdx)));
                break;
            case FLOAT8:
                tuple.put(column_idx, DatumFactory.createFloat8(resultSet.getDouble(resultIdx)));
                break;
            case CHAR:
                tuple.put(column_idx, DatumFactory.createText(resultSet.getString(resultIdx)));
                break;
            case VARCHAR:
            case TEXT:
                // TODO - trim is unnecessary in many cases, so we can use it for certain cases
                tuple.put(column_idx, DatumFactory.createText(resultSet.getString(resultIdx).trim()));
                break;
            case DATE:
                final Date date = resultSet.getDate(resultIdx);
                tuple.put(column_idx,
                        DatumFactory.createDate(1900 + date.getYear(), 1 + date.getMonth(), date.getDate()));
                break;
            case TIME:
                final Time time = resultSet.getTime(resultIdx);
                tuple.put(column_idx, new TimeDatum(
                        DateTimeUtil.toTime(time.getHours(), time.getMinutes(), time.getSeconds(), 0)));
                break;
            case TIMESTAMP:
                tuple.put(column_idx, DatumFactory
                        .createTimestampDatumWithJavaMillis(resultSet.getTimestamp(resultIdx).getTime()));
                break;
            case BINARY:
            case VARBINARY:
            case BLOB:
                tuple.put(column_idx, DatumFactory.createBlob(resultSet.getBytes(resultIdx)));
                break;
            default:
                throw new TajoInternalError(new UnsupportedDataTypeException(c.getDataType().getType().name()));
            }
        }
    } catch (SQLException s) {
        throw new TajoInternalError(s);
    }
}