List of usage examples for java.sql Time Time
public Time(long time)
Time
object using a milliseconds time value. From source file:org.pentaho.reporting.platform.plugin.ReportContentUtil.java
private static Object convert(final ParameterContext context, final ParameterDefinitionEntry parameter, final Class targetType, final Object rawValue) throws ReportProcessingException { if (targetType == null) { throw new NullPointerException(); }/*from www . ja va2 s . c o m*/ if (rawValue == null) { return null; } if (targetType.isInstance(rawValue)) { return rawValue; } if (targetType.isAssignableFrom(TableModel.class) && IPentahoResultSet.class.isAssignableFrom(rawValue.getClass())) { // wrap IPentahoResultSet to simulate TableModel return new PentahoTableModel((IPentahoResultSet) rawValue); } final String valueAsString = String.valueOf(rawValue); if (StringUtils.isEmpty(valueAsString)) { // none of the converters accept empty strings as valid input. So we can return null instead. return null; } if (targetType.equals(Timestamp.class)) { try { final Date date = parseDate(parameter, context, valueAsString); return new Timestamp(date.getTime()); } catch (ParseException pe) { // ignore, we try to parse it as real date now .. } } else if (targetType.equals(Time.class)) { try { final Date date = parseDate(parameter, context, valueAsString); return new Time(date.getTime()); } catch (ParseException pe) { // ignore, we try to parse it as real date now .. } } else if (targetType.equals(java.sql.Date.class)) { try { final Date date = parseDate(parameter, context, valueAsString); return new java.sql.Date(date.getTime()); } catch (ParseException pe) { // ignore, we try to parse it as real date now .. } } else if (targetType.equals(Date.class)) { try { final Date date = parseDate(parameter, context, valueAsString); return new Date(date.getTime()); } catch (ParseException pe) { // ignore, we try to parse it as real date now .. } } final String dataFormat = parameter.getParameterAttribute(ParameterAttributeNames.Core.NAMESPACE, ParameterAttributeNames.Core.DATA_FORMAT, context); if (dataFormat != null) { try { if (Number.class.isAssignableFrom(targetType)) { final DecimalFormat format = new DecimalFormat(dataFormat, new DecimalFormatSymbols(LocaleHelper.getLocale())); format.setParseBigDecimal(true); final Number number = format.parse(valueAsString); final String asText = ConverterRegistry.toAttributeValue(number); return ConverterRegistry.toPropertyValue(asText, targetType); } else if (Date.class.isAssignableFrom(targetType)) { final SimpleDateFormat format = new SimpleDateFormat(dataFormat, new DateFormatSymbols(LocaleHelper.getLocale())); format.setLenient(false); final Date number = format.parse(valueAsString); final String asText = ConverterRegistry.toAttributeValue(number); return ConverterRegistry.toPropertyValue(asText, targetType); } } catch (Exception e) { // again, ignore it . } } final ValueConverter valueConverter = ConverterRegistry.getInstance().getValueConverter(targetType); if (valueConverter != null) { try { return valueConverter.toPropertyValue(valueAsString); } catch (BeanException e) { throw new ReportProcessingException(Messages.getInstance() .getString("ReportPlugin.unableToConvertParameter", parameter.getName(), valueAsString)); //$NON-NLS-1$ } } return rawValue; }
From source file:org.omnaest.utils.table.impl.adapter.TableToResultSetAdapter.java
@Override public Time getTime(String columnLabel) throws SQLException { return new Time(this.getLong(columnLabel)); }
From source file:org.jasig.ssp.util.importer.job.validation.map.metadata.database.MapColumnMetadata.java
public Object convertValueToType(String columnValue, MapReference mapReference, DatabaseConstraintMapValidationContext validation) { Object propertyValue = null;/*w w w . j av a2s . c o m*/ String typeAsString = ""; if (columnValue != null) { try { switch (javaSqlType) { case Types.BIGINT: typeAsString = "BIGINT"; propertyValue = Long.parseLong(columnValue); break; case Types.INTEGER: typeAsString = "INTEGER"; propertyValue = Integer.parseInt(columnValue); break; case Types.DECIMAL: typeAsString = "DECIMAL"; case Types.DOUBLE: typeAsString = "DOUBLE"; case Types.FLOAT: typeAsString = "FLOAT"; case Types.NUMERIC: typeAsString = "NUMERIC"; propertyValue = new BigDecimal(columnValue); break; case Types.DATE: typeAsString = "DATE"; propertyValue = DateUtils.parseDateStrictly(columnValue, DATE_PATTERNS); break; case Types.TIMESTAMP: typeAsString = "TIMESTAMP"; propertyValue = new java.sql.Timestamp(Long.getLong(columnValue)); break; case Types.TIME: typeAsString = "TIME"; propertyValue = new Time(DateUtils.parseDateStrictly(columnValue, TIME_PATTERNS).getTime()); break; default: typeAsString = javaSqlType.toString(); propertyValue = columnValue; break; } } catch (Exception exception) { validation.addViolation(new UnableToParseMapViolation(mapReference, columnValue, typeAsString)); propertyValue = columnValue; } } return propertyValue; }
From source file:org.kuali.kpme.core.calendar.entry.CalendarEntryBo.java
public Time getBatchInitiateTime() { return batchInitiateDateTime != null ? new Time(batchInitiateDateTime.getTime()) : null; }
From source file:freemarker.ext.dump.DumpDirectiveTest.java
@Test public void dumpTime() { String varName = "time"; Map<String, Object> dataModel = new HashMap<String, Object>(); Time time = new Time(1302297332043L); dataModel.put(varName, time);//from w w w. jav a2 s. c om Map<String, Object> expectedDumpValue = new HashMap<String, Object>(); expectedDumpValue.put(Key.TYPE.toString(), Type.DATE); expectedDumpValue.put(Key.DATE_TYPE.toString(), DateType.TIME); expectedDumpValue.put(Key.VALUE.toString(), time); Map<String, Object> expectedDump = new HashMap<String, Object>(); expectedDump.put(varName, expectedDumpValue); test(varName, dataModel, expectedDump); }
From source file:com.icesoft.applications.faces.auctionMonitor.beans.LogBean.java
/** * Convenience method to pad the passed message with the time then append it * to the control log/*from w ww. j ava 2s.com*/ * * @param controlMessage message to append */ private void appendControl(String controlMessage) { if (controlLog.size() > CONTROL_LOG_CAP) { controlLog = clear(controlLog); appendControl("Control log cleared (max size of " + CONTROL_LOG_CAP + ")"); } controlLog.add((new Time(System.currentTimeMillis()) + ": " + controlMessage)); }
From source file:com.jk.framework.util.FakeRunnable.java
/** * Convert date to time./*from w ww. j a v a 2 s . c o m*/ * * @param date * the date * @return the time */ public static Time convertDateToTime(final Date date) { final Time time = new Time(date.getTime()); time.setSeconds(0); return time; }
From source file:org.latticesoft.util.common.ClassUtil.java
/** * Instantiate a new object from a string value * //www . jav a2s.c o m */ public static Object newInstance(String type, String value, String format) { Object o = null; Class clazz = null; if (type == null || value == null) { return null; } if (type.equals("java.lang.String")) { return value; } try { clazz = Class.forName(type); if ("java.lang.Character".equals(type)) { o = new Character(value.charAt(0)); } else if ("java.util.Date".equals(type) || "java.sql.Time".equals(type) || "java.sql.Timestamp".equals(type)) { if (format == null) { format = "yyyy-MM-dd HH:mm:ss.SSS"; } DateFormat fmt = new SimpleDateFormat(format); try { o = fmt.parse(value); } catch (ParseException pe) { } if (o != null && "java.sql.Time".equals(type)) { Date d = (Date) o; o = new Time(d.getTime()); } if (o != null && "java.sql.Timestamp".equals(type)) { Date d = (Date) o; o = new Timestamp(d.getTime()); } } } catch (Exception e) { e.printStackTrace(); } if (o != null) return o; try { Method[] m = clazz.getMethods(); for (int i = 0; i < m.length; i++) { if ("fromString".equalsIgnoreCase(m[i].getName())) { Object[] args = { value }; o = m[i].invoke(clazz, args); break; } else if ("parse".equalsIgnoreCase(m[i].getName())) { Object[] args = { value }; o = m[i].invoke(clazz, args); break; } else if ("newInstance".equalsIgnoreCase(m[i].getName())) { Object[] args = { value }; o = m[i].invoke(clazz, args); break; } else if ("valueOf".equalsIgnoreCase(m[i].getName())) { Object[] args = { value }; o = m[i].invoke(clazz, args); break; } } } catch (Exception e) { } if (o != null) { return o; } try { Constructor[] c = clazz.getConstructors(); for (int i = 0; i < c.length; i++) { Class[] param = c[i].getParameterTypes(); if (param != null && param.length == 1 && param[0].getName().equals("java.lang.String")) { Object[] args = { value }; o = c[i].newInstance(args); } } } catch (Exception e) { } if (o == null) { o = value; } return o; }
From source file:ips1ap101.lib.base.util.TimeUtils.java
public static Time newTime(java.util.Date date) { if (date == null) { return null; } else {//w w w. j a v a 2s .c om Calendar c = Calendar.getInstance(); c.setTimeInMillis(date.getTime()); c.set(Calendar.YEAR, 1970); c.set(Calendar.MONTH, Calendar.JANUARY); c.set(Calendar.DAY_OF_MONTH, 1); return new Time(c.getTimeInMillis()); } }
From source file:org.fatal1t.forexapp.spring.api.adapters.APISyncAdapter.java
public GetTradingHoursResp GetTradingHours(GetTradingHoursReq request) { List<String> symbols = request.getSymbols(); GetTradingHoursResp data = null;/*from w w w .ja v a 2s. c o m*/ try { TradingHoursResponse response = APICommandFactory.executeTradingHoursCommand(connector, symbols); data = new GetTradingHoursResp(); log.info("Prijata data: " + response.toString().substring(0, 10)); for (String symbol : response.getSymbols()) { SymbolTradingHours hours = new SymbolTradingHours(symbol); int index = response.getSymbols().indexOf(symbol); List<HoursRecord> respHours = response.getQuotes().get(index); if (respHours != null) { respHours.forEach((HoursRecord hour) -> { Long day = hour.getDay(); hours.getQuoteHours().add( new HourData(day.intValue(), new Time(hour.getFromT()), new Time(hour.getToT()))); }); } respHours = response.getTrading().get(index); if (respHours != null) { respHours.forEach((HoursRecord hour) -> { Long day = hour.getDay(); hours.getQuoteHours().add( new HourData(day.intValue(), new Time(hour.getFromT()), new Time(hour.getToT()))); }); } data.addSymbolTradingHours(hours); } } catch (APICommandConstructionException | APICommunicationException | APIReplyParseException | APIErrorResponse ex) { log.fatal("error v komunikaci "); log.fatal(ex); } return data; }