List of usage examples for java.sql Time Time
public Time(long time)
Time
object using a milliseconds time value. From source file:org.testeditor.dashboard.TableDurationTrend.java
/** * Formatting duration(ms) in h:m:s:ms.//from w w w.ja va2 s . c om * * @param number * for time formatting * @return durationFormat */ private String formatDuration(double number) { // TODO: refactor - see formatDuration in MyLabelProvider Time time = new Time((long) number); Calendar cal = Calendar.getInstance(); cal.setTime(time); String durationFormat = cal.get(Calendar.HOUR) - 1 + "h:" + cal.get(Calendar.MINUTE) + "m:" + cal.get(Calendar.SECOND) + "s:" + cal.get(Calendar.MILLISECOND) + "ms"; return durationFormat; }
From source file:org.kuali.kpme.core.leaveplan.LeavePlanBo.java
public static LeavePlanBo from(LeavePlan im) { if (im == null) { return null; }/*from w ww.ja v a 2 s . c o m*/ LeavePlanBo lp = new LeavePlanBo(); lp.setLmLeavePlanId(im.getLmLeavePlanId()); lp.setLeavePlan(im.getLeavePlan()); lp.setDescr(im.getDescr()); lp.setCalendarYearStart(im.getCalendarYearStart()); lp.setPlanningMonths(im.getPlanningMonths()); lp.setBatchPriorYearCarryOverStartDate(im.getBatchPriorYearCarryOverStartDate()); lp.setBatchPriorYearCarryOverStartTime(im.getBatchPriorYearCarryOverStartLocalTime() == null ? null : new Time(im.getBatchPriorYearCarryOverStartLocalTime().toDateTimeToday().getMillis())); lp.setEffectiveDate(im.getEffectiveLocalDate() == null ? null : im.getEffectiveLocalDate().toDate()); lp.setActive(im.isActive()); if (im.getCreateTime() != null) { lp.setTimestamp(new Timestamp(im.getCreateTime().getMillis())); } lp.setUserPrincipalId(im.getUserPrincipalId()); lp.setVersionNumber(im.getVersionNumber()); lp.setObjectId(im.getObjectId()); return lp; }
From source file:com.tesora.dve.common.TestDataGenerator.java
protected Object getColumnValue(ColumnMetadata cm) { Object cv = null;/*from w w w . ja v a2 s.c o m*/ Calendar cal = Calendar.getInstance(); switch (cm.getDataType()) { case Types.BIT: case Types.BOOLEAN: cv = Boolean.TRUE; break; case Types.BIGINT: cv = Long.MAX_VALUE; break; case Types.CHAR: case Types.VARCHAR: cv = StringUtils.left(baseString, cm.getSize()); break; case Types.SMALLINT: cv = Short.MAX_VALUE; break; case Types.TINYINT: cv = Byte.MAX_VALUE; break; case Types.INTEGER: cv = Integer.MAX_VALUE; break; case Types.DOUBLE: cv = new Double(1234.5678); // TODO need to handle s,p break; case Types.FLOAT: cv = new Float(123.56); // TODO need to handle s,p break; case Types.DECIMAL: cv = new BigDecimal("12345.6789"); // TODO need to handle s,p break; case Types.DATE: cal.setTimeInMillis(123456789); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cv = cal.getTime(); break; case Types.TIMESTAMP: cal.setTimeInMillis(123456789); cv = cal.getTime(); break; case Types.TIME: cv = new Time(123456789); break; default: break; } return cv; }
From source file:solarrecorder.SolarRecorder.java
private void sendSolarUpdate() { String dbString = "jdbc:mysql://localhost:3306/Solar"; try {//from w w w .j a va 2 s .c o m Connection con = DriverManager.getConnection(dbString, "colin", "Quackquack1"); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); String SQL = "SELECT * FROM Production"; ResultSet rs = stmt.executeQuery(SQL); rs.moveToInsertRow(); getData(); java.util.Date now = new java.util.Date(); rs.updateDate("Day", new Date(now.getTime())); rs.updateTime("Time", new Time(now.getTime())); for (Object evp : envoyData) { switch (((EnvoyData) evp).getName()) { case "Currently": rs.updateDouble("Current", extractCurrent(((EnvoyData) evp).getValue())); break; case "Today": rs.updateDouble("Today", extractToday(((EnvoyData) evp).getValue())); break; case "Number of Microinverters Online": rs.updateInt("Inverters", Integer.parseInt(((EnvoyData) evp).getValue())); break; } } rs.insertRow(); stmt.close(); rs.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.apache.nifi.csv.TestWriteCSVResult.java
@Test public void testDataTypes() throws IOException { final CSVFormat csvFormat = CSVFormat.DEFAULT.withQuoteMode(QuoteMode.ALL).withRecordSeparator("\n"); final StringBuilder headerBuilder = new StringBuilder(); final List<RecordField> fields = new ArrayList<>(); for (final RecordFieldType fieldType : RecordFieldType.values()) { if (fieldType == RecordFieldType.CHOICE) { final List<DataType> possibleTypes = new ArrayList<>(); possibleTypes.add(RecordFieldType.INT.getDataType()); possibleTypes.add(RecordFieldType.LONG.getDataType()); fields.add(new RecordField(fieldType.name().toLowerCase(), fieldType.getChoiceDataType(possibleTypes))); } else {/*from w ww.ja va 2 s . c o m*/ fields.add(new RecordField(fieldType.name().toLowerCase(), fieldType.getDataType())); } headerBuilder.append('"').append(fieldType.name().toLowerCase()).append('"').append(","); } final RecordSchema schema = new SimpleRecordSchema(fields); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final long now = System.currentTimeMillis(); try (final WriteCSVResult result = new WriteCSVResult(csvFormat, schema, new SchemaNameAsAttribute(), baos, RecordFieldType.DATE.getDefaultFormat(), RecordFieldType.TIME.getDefaultFormat(), RecordFieldType.TIMESTAMP.getDefaultFormat(), true, "UTF-8")) { final Map<String, Object> valueMap = new HashMap<>(); valueMap.put("string", "abc?123"); valueMap.put("boolean", true); valueMap.put("byte", (byte) 1); valueMap.put("char", 'c'); valueMap.put("short", (short) 8); valueMap.put("int", 9); valueMap.put("bigint", BigInteger.valueOf(8L)); valueMap.put("long", 8L); valueMap.put("float", 8.0F); valueMap.put("double", 8.0D); valueMap.put("date", new Date(now)); valueMap.put("time", new Time(now)); valueMap.put("timestamp", new Timestamp(now)); valueMap.put("record", null); valueMap.put("choice", 48L); valueMap.put("array", null); final Record record = new MapRecord(schema, valueMap); final RecordSet rs = RecordSet.of(schema, record); result.write(rs); } final String output = new String(baos.toByteArray(), StandardCharsets.UTF_8); headerBuilder.deleteCharAt(headerBuilder.length() - 1); final String headerLine = headerBuilder.toString(); final String[] splits = output.split("\n"); assertEquals(2, splits.length); assertEquals(headerLine, splits[0]); final String values = splits[1]; final StringBuilder expectedBuilder = new StringBuilder(); expectedBuilder.append("\"abc?123\",\"true\",\"1\",\"c\",\"8\",\"9\",\"8\",\"8\",\"8.0\",\"8.0\","); final String dateValue = getDateFormat(RecordFieldType.DATE.getDefaultFormat()).format(now); final String timeValue = getDateFormat(RecordFieldType.TIME.getDefaultFormat()).format(now); final String timestampValue = getDateFormat(RecordFieldType.TIMESTAMP.getDefaultFormat()).format(now); expectedBuilder.append('"').append(dateValue).append('"').append(','); expectedBuilder.append('"').append(timeValue).append('"').append(','); expectedBuilder.append('"').append(timestampValue).append('"').append(','); expectedBuilder.append(",\"48\",,"); final String expectedValues = expectedBuilder.toString(); assertEquals(expectedValues, values); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTimeField.java
private Object validateRawValue(String value) throws NumberFormatException, ParseException { if (value.equals(StringUtils.replaceChars(mask, "#U", "__"))) { return null; }//from ww w . j a va2s. co m SimpleDateFormat sdf = new SimpleDateFormat(timeFormat); sdf.setLenient(false); try { Date parsedValue = sdf.parse(value); Class targetType = null; if (datasource != null && metaPropertyPath != null) { targetType = metaPropertyPath.getRangeJavaClass(); } if (targetType == java.sql.Time.class) { return new Time(parsedValue.getTime()); } if (targetType == java.sql.Date.class) { log.warn("Do not use java.sql.Date with time field"); return new java.sql.Date(parsedValue.getTime()); } return parsedValue; } catch (ParseException e) { showValidationMessage(); return prevValue; } }
From source file:org.apache.storm.jdbc.mapper.SimpleJdbcMapper.java
@Override public List<Column> getColumns(ITuple tuple) { List<Column> columns = new ArrayList<Column>(); for (Column column : schemaColumns) { String columnName = column.getColumnName(); Integer columnSqlType = column.getSqlType(); if (Util.getJavaType(columnSqlType).equals(String.class)) { String value = tuple.getStringByField(columnName); columns.add(new Column(columnName, value, columnSqlType)); } else if (Util.getJavaType(columnSqlType).equals(Short.class)) { Short value = tuple.getShortByField(columnName); columns.add(new Column(columnName, value, columnSqlType)); } else if (Util.getJavaType(columnSqlType).equals(Integer.class)) { Integer value = tuple.getIntegerByField(columnName); columns.add(new Column(columnName, value, columnSqlType)); } else if (Util.getJavaType(columnSqlType).equals(Long.class)) { Long value = tuple.getLongByField(columnName); columns.add(new Column(columnName, value, columnSqlType)); } else if (Util.getJavaType(columnSqlType).equals(Double.class)) { Double value = tuple.getDoubleByField(columnName); columns.add(new Column(columnName, value, columnSqlType)); } else if (Util.getJavaType(columnSqlType).equals(Float.class)) { Float value = tuple.getFloatByField(columnName); columns.add(new Column(columnName, value, columnSqlType)); } else if (Util.getJavaType(columnSqlType).equals(Boolean.class)) { Boolean value = tuple.getBooleanByField(columnName); columns.add(new Column(columnName, value, columnSqlType)); } else if (Util.getJavaType(columnSqlType).equals(byte[].class)) { byte[] value = tuple.getBinaryByField(columnName); columns.add(new Column(columnName, value, columnSqlType)); } else if (Util.getJavaType(columnSqlType).equals(Date.class)) { Long value = tuple.getLongByField(columnName); columns.add(new Column(columnName, new Date(value), columnSqlType)); } else if (Util.getJavaType(columnSqlType).equals(Time.class)) { Long value = tuple.getLongByField(columnName); columns.add(new Column(columnName, new Time(value), columnSqlType)); } else if (Util.getJavaType(columnSqlType).equals(Timestamp.class)) { Long value = tuple.getLongByField(columnName); columns.add(new Column(columnName, new Timestamp(value), columnSqlType)); } else {//from www. j a v a 2 s . c o m throw new RuntimeException("Unsupported java type in tuple " + Util.getJavaType(columnSqlType)); } } return columns; }
From source file:TestPublicarEstablecimiento.java
@Test @Transactional/* ww w . j av a 2 s. c om*/ @Rollback(true) public void testRegistrarSala() throws OperationFailedException { int limite = 5; Establecimiento a = new Establecimiento(1, "nombre" + 1, "123.123.123-1", "Autonorte" + 1, new Time(700), new Time(1800), 2.0, "Puente Aranda", "1234567890", "34323892479823745600"); logica.registrarEstablecimiento(a); ArrayList<Sala> listaSala = new ArrayList<>(); for (int i = 0; i < limite; i++) { Sala b = new Sala(i, a, "" + (100 + (i * i)), "sala" + i); listaSala.add(b); logica.registrarSala(b); } Sala sala; for (int i = 0; i < limite; i++) { sala = logica.consultarSala(i); assertEquals(listaSala.get(i).getIdSala(), sala.getIdSala()); assertEquals(listaSala.get(i).getNombre(), sala.getNombre()); assertEquals(listaSala.get(i).getPrecio(), sala.getPrecio()); } }
From source file:com.zira.registration.BackgroundCheckActivity.java
@SuppressWarnings("deprecation") private void getCurrentTime() { mDateFormat = new SimpleDateFormat("dd-MMM-yyyy"); dateFormatToSend = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); getDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); hours = new Time(System.currentTimeMillis()).getHours(); minute = new Time(System.currentTimeMillis()).getMinutes(); second = new Time(System.currentTimeMillis()).getSeconds(); }
From source file:org.jabsorb.serializer.impl.DateSerializer.java
public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException { JSONObject jso = (JSONObject) o;/*w ww . j a v a2s. c o m*/ long time; try { time = jso.getLong("time"); } catch (JSONException e) { throw new UnmarshallException("Could not get the time in date serialiser", e); } if (jso.has("javaClass")) { try { clazz = Class.forName(jso.getString("javaClass")); } catch (ClassNotFoundException e) { throw new UnmarshallException(e.getMessage(), e); } catch (JSONException e) { throw new UnmarshallException("Could not find javaClass", e); } } Object returnValue = null; if (Date.class.equals(clazz)) { returnValue = new Date(time); } else if (Timestamp.class.equals(clazz)) { returnValue = new Timestamp(time); } else if (java.sql.Date.class.equals(clazz)) { returnValue = new java.sql.Date(time); } else if (java.sql.Time.class.equals(clazz)) { returnValue = new Time(time); } if (returnValue == null) { throw new UnmarshallException("invalid class " + clazz); } state.setSerialized(o, returnValue); return returnValue; }