Example usage for java.sql Time valueOf

List of usage examples for java.sql Time valueOf

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static Time valueOf(LocalTime time) 

Source Link

Document

Obtains an instance of Time from a LocalTime object with the same hour, minute and second time value as the given LocalTime .

Usage

From source file:org.motechproject.server.svc.impl.RegistrarBeanImplTest.java

public void testAdjustDateBlackoutInTheNight() {
    Calendar calendar = getCalendarWithTime(22, 13, 54);
    Date eveningMessageTime = calendar.getTime();
    Blackout blackout = new Blackout(Time.valueOf("22:00:00"), Time.valueOf("06:00:00"));

    expect(contextService.getMotechService()).andReturn(motechService);
    expect(motechService.getBlackoutSettings()).andReturn(blackout);
    replay(contextService, adminService, motechService);

    Date prefDate = registrarBean.adjustDateForBlackout(eveningMessageTime);

    verify(contextService, adminService, motechService);
    Calendar preferredCalendar = getCalendar(prefDate);
    assertFalse("Hour not updated",
            calendar.get(Calendar.HOUR_OF_DAY) == preferredCalendar.get(Calendar.HOUR_OF_DAY));
    assertEquals(6, preferredCalendar.get(Calendar.HOUR_OF_DAY));
    assertFalse("Minute not updated", calendar.get(Calendar.MINUTE) == preferredCalendar.get(Calendar.MINUTE));
    assertEquals(0, preferredCalendar.get(Calendar.MINUTE));
    assertFalse("Second not updated", calendar.get(Calendar.SECOND) == preferredCalendar.get(Calendar.SECOND));
    assertEquals(0, preferredCalendar.get(Calendar.SECOND));
}

From source file:org.ofbiz.core.entity.GenericEntity.java

/**
 * Sets the named field to the passed value, converting the value from a String to the correct type using
 * {@code Type.valueOf()} or similar./*from  w  ww .j a v a2s . c  o  m*/
 * <p>
 * <strong>WARNING</strong>: calling this for an {@link FieldType#OBJECT OBJECT} field is ambiguous, because
 * you could mean either that the {@code String} is the Base64-encoded representation of the object and
 * should be be deserialized or that the {@code String} is the actual object to be stored.  Since this
 * method is intended for use in restoring the entity from an XML export, it assumes that the value is
 * the Base64-encoding of an arbitrary object and attempts to deserialize it.  If this is not what is
 * intended, then it is up to the caller to use {@link #set(String, Object)} for those fields, instead.
 * </p>
 *
 * @param name  The field name to set
 * @param value The String value to convert and set
 */
public void setString(String name, String value) {
    ModelField field = getModelEntity().getField(name);
    if (field == null) {
        throw new IllegalArgumentException(
                "[GenericEntity.setString] \"" + name + "\" is not a field of " + entityName);
    }

    final ModelFieldType type = getModelFieldType(field.getType());
    final FieldType fieldType = SqlJdbcUtil.getFieldType(type.getJavaType());
    switch (fieldType) {
    case STRING:
        set(name, value);
        break;

    case TIMESTAMP:
        set(name, Timestamp.valueOf(value));
        break;

    case TIME:
        set(name, Time.valueOf(value));
        break;

    case DATE:
        set(name, Date.valueOf(value));
        break;

    case INTEGER:
        set(name, Integer.valueOf(value));
        break;

    case LONG:
        set(name, Long.valueOf(value));
        break;

    case FLOAT:
        set(name, Float.valueOf(value));
        break;

    case DOUBLE:
        set(name, Double.valueOf(value));
        break;

    case BOOLEAN:
        set(name, Boolean.valueOf(value));
        break;

    case OBJECT:
        set(name, deserialize(decodeBase64(value)));
        break;

    case CLOB:
        set(name, value);
        break;

    case BLOB:
        set(name, decodeBase64(value));
        break;

    case BYTE_ARRAY:
        set(name, decodeBase64(value));
        break;

    default:
        throw new UnsupportedOperationException("Unsupported type: " + fieldType);
    }
}

From source file:org.ojbc.adapters.analyticsstaging.custody.dao.AnalyticalDatastoreDAOImpl.java

private void saveCustodyRelease(Integer bookingId, String bookingNumber, LocalDate releaseDate,
        LocalTime releaseTime, String releaseCondition) {

    final String sql = "Insert into CustodyRelease (BookingID, BookingNumber, "
            + "ReleaseDate, ReleaseTime, ReleaseCondition) "
            + "values (:bookingId, :bookingNumber, :releaseDate, :releaseTime, :releaseCondition)";

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("releaseDate", Date.valueOf(releaseDate));
    params.put("releaseTime", Time.valueOf(releaseTime));
    params.put("bookingId", bookingId);
    params.put("bookingNumber", bookingNumber);
    params.put("releaseCondition", releaseCondition);

    namedParameterJdbcTemplate.update(sql, params);
}

From source file:org.openxdata.server.export.rdbms.engine.DataBuilder.java

private Object getColumnValue(Document schemaDocument, Node node) {
    String x = node.getTextContent();
    if (x == null || x.trim().length() == 0) {
        return null;
    }/*w  w w.j  ava2s .c  om*/
    String columnType = Functions.resolveType(schemaDocument, node.getNodeName());
    if (columnType.equalsIgnoreCase(Constants.TYPE_DATE)) {
        java.sql.Date date = java.sql.Date.valueOf(x); // must be yyyy-MM-dd format
        return date;
    }
    if (columnType.equalsIgnoreCase(Constants.TYPE_TIME)) {
        Time time = null;
        String xTime = x.toUpperCase();
        try {
            if (xTime.contains("PM") || xTime.contains("AM")) {
                time = new Time(new SimpleDateFormat("hh:mm:ss aaa").parse(xTime).getTime());
            } else {
                time = Time.valueOf(x); // must be HH:mm:ss format
            }
        } catch (Exception e) {
            log.warn("Could not convert time '" + x + "' to sql Time", e);
        }
        return time;
    }
    if (columnType.equalsIgnoreCase(Constants.TYPE_DATETIME)) {
        Timestamp datetime = Timestamp.valueOf(x); // must be yyyy-MM-dd HH:mm:ss format
        return datetime;
    }
    if (columnType.equalsIgnoreCase(Constants.TYPE_BOOLEAN)) {
        Boolean bool = new Boolean(x); // note: see Functions.resolveType - boolean is actually VARCHAR
        return bool;
    }
    if (columnType.equalsIgnoreCase(Constants.TYPE_DECIMAL)) {
        Double dub = new Double(x);
        return dub;
    }
    if (columnType.equalsIgnoreCase(Constants.TYPE_INTEGER)) {
        Integer in = new Integer(x);
        return in;
    }
    // VARCHAR or CHAR
    return x;
}