List of usage examples for java.sql Date getTime
public long getTime()
From source file:org.kuali.rice.krad.web.bind.UifDateTimeEditor.java
/** * {@inheritDoc}/*from w w w .j a v a 2s.c o m*/ * * This implementation converts the {@link Date} display string to a {@link DateTime} object using the * {@link DateTimeService}. */ @Override public void setAsText(String text) throws IllegalArgumentException { if (StringUtils.isBlank(text)) { setValue(null); return; } try { Date value = getDateTimeService().convertToSqlDate(text); Calendar calendar = Calendar.getInstance(); calendar.setTime(value); if (calendar.get(Calendar.YEAR) < 1000 && verbatimYear(text).length() < 4) { throw new FormatException("illegal year format", RiceKeyConstants.ERROR_DATE, text); } setValue(new DateTime(value.getTime())); } catch (ParseException e) { throw new FormatException("parsing", RiceKeyConstants.ERROR_DATE, text, e); } }
From source file:data.DefaultExchanger.java
protected void putDate(JsonGenerator generator, String fieldName, ResultSet rs, short index) throws SQLException, IOException { generator.writeFieldName(fieldName); Date date = rs.getDate(index); if (date == null) { generator.writeNull();/*from w ww. j av a 2 s . co m*/ } else { generator.writeNumber(date.getTime()); } }
From source file:org.geoserver.wms.dimension.RasterTimeDimensionDefaultValueTest.java
@Test public void testExplicitFixedTimeCoverageSelector() throws Exception { String fixedTimeStr = "2012-06-01T03:00:00.000Z"; // Use explicit default value strategy: DimensionDefaultValueSetting defaultValueSetting = new DimensionDefaultValueSetting(); defaultValueSetting.setStrategyType(Strategy.FIXED); defaultValueSetting.setReferenceValue(fixedTimeStr); setupCoverageTimeDimension(WATTEMP_FUTURE, defaultValueSetting); long fixedTime = DateUtil.parseDateTime(fixedTimeStr); CoverageInfo coverage = getCatalog().getCoverageByName(WATTEMP_FUTURE.getLocalPart()); java.util.Date d = wms.getDefaultTime(coverage); assertTrue("Returns a valid Default time", d != null); assertTrue("Default time should be the fixed one", d.getTime() == fixedTime); }
From source file:org.geoserver.wms.dimension.RasterTimeDimensionDefaultValueTest.java
@Test public void testExplicitMinTimeCoverageSelector() throws Exception { // Use explicit default value strategy: DimensionDefaultValueSetting defaultValueSetting = new DimensionDefaultValueSetting(); defaultValueSetting.setStrategyType(Strategy.MINIMUM); setupCoverageTimeDimension(WATTEMP_FUTURE, defaultValueSetting); //From src/test/resources/org/geoserver/wms/watertemp.zip: Date expected = Date.valueOf("2008-10-31"); CoverageInfo coverage = getCatalog().getCoverageByName(WATTEMP_FUTURE.getLocalPart()); java.util.Date d = wms.getDefaultTime(coverage); assertTrue("Returns a valid Default time", d != null); assertTrue("Default time should be the smallest one", d.getTime() == expected.getTime()); }
From source file:org.geoserver.wms.dimension.RasterTimeDimensionDefaultValueTest.java
@Test public void testDefaultTimeCoverageSelector() throws Exception { // Use default default value strategy: setupCoverageTimeDimension(WATTEMP_FUTURE, null); Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND)); long todayMidnight = cal.getTimeInMillis(); CoverageInfo coverage = getCatalog().getCoverageByName(WATTEMP_FUTURE.getLocalPart()); java.util.Date d = wms.getDefaultTime(coverage); assertTrue("Returns a valid Default time", d != null); assertTrue("Default time should be the closest one", d.getTime() == todayMidnight); }
From source file:org.geoserver.wms.dimension.RasterTimeDimensionDefaultValueTest.java
@Test public void testExplicitNearestToGivenTimeCoverageSelector() throws Exception { String preferredTimeStr = "2009-01-01T00:00:00.000Z"; // Use explicit default value strategy: DimensionDefaultValueSetting defaultValueSetting = new DimensionDefaultValueSetting(); defaultValueSetting.setStrategyType(Strategy.NEAREST); defaultValueSetting.setReferenceValue(preferredTimeStr); setupCoverageTimeDimension(WATTEMP_FUTURE, defaultValueSetting); //From src/test/resources/org/geoserver/wms/watertemp.zip: Date expected = Date.valueOf("2008-11-01"); CoverageInfo coverage = getCatalog().getCoverageByName(WATTEMP_FUTURE.getLocalPart()); java.util.Date d = wms.getDefaultTime(coverage); assertTrue("Returns a valid Default time", d != null); assertTrue("Default time should be the closest one", d.getTime() == expected.getTime()); }
From source file:org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm.java
public LocalDate getReceiptDateAsLocalDate() throws InvalidDateException { Date receiptDateStr = getDateAsSentFromBrowser(getReceiptDate()); return (receiptDateStr != null) ? new LocalDate(receiptDateStr.getTime()) : null; }
From source file:org.geoserver.wms.dimension.RasterTimeDimensionDefaultValueTest.java
@Test public void testExplicitCurrentTimeCoverageSelector() throws Exception { // Use explicit default value strategy: DimensionDefaultValueSetting defaultValueSetting = new DimensionDefaultValueSetting(); defaultValueSetting.setStrategyType(Strategy.NEAREST); defaultValueSetting.setReferenceValue(DimensionDefaultValueSetting.TIME_CURRENT); setupCoverageTimeDimension(WATTEMP_FUTURE, defaultValueSetting); Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND)); long todayMidnight = cal.getTimeInMillis(); CoverageInfo coverage = getCatalog().getCoverageByName(WATTEMP_FUTURE.getLocalPart()); java.util.Date d = wms.getDefaultTime(coverage); assertTrue("Returns a valid Default time", d != null); assertTrue("Default time should be the closest one", d.getTime() == todayMidnight); }
From source file:org.geoserver.wms.dimension.RasterTimeDimensionDefaultValueTest.java
@Test public void testExplicitMaxTimeCoverageSelector() throws Exception { // Use explicit default value strategy: DimensionDefaultValueSetting defaultValueSetting = new DimensionDefaultValueSetting(); defaultValueSetting.setStrategyType(Strategy.MAXIMUM); setupCoverageTimeDimension(WATTEMP_FUTURE, defaultValueSetting); Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND)); cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 1); long oneYearInFuture = cal.getTimeInMillis(); CoverageInfo coverage = getCatalog().getCoverageByName(WATTEMP_FUTURE.getLocalPart()); java.util.Date d = wms.getDefaultTime(coverage); assertTrue("Returns a valid Default time", d != null); assertTrue("Default time should be the biggest one", d.getTime() == oneYearInFuture); }
From source file:org.openlogics.gears.jdbc.map.BeanResultHandler.java
/** * * @param resultSet//from w ww.jav a 2 s.co m * @param useColumnLabel * @param instantiate * @return * @throws SQLException */ private T mapResultSet(ResultSet resultSet, boolean useColumnLabel, Initializer<T> instantiate) throws SQLException { try { //T obj = requiredType.newInstance(); if (instantiate == null || instantiate.getType() == null) { throw new IllegalArgumentException("Initializer can not be null neither the type to instantiate."); } ResultSetMetaData rsmd = resultSet.getMetaData(); Class requiredType = instantiate.getType(); if (!Map.class.isAssignableFrom(requiredType)) { T obj = instantiate.newInstance(resultSet); //Adecuate RESULTS to BEAN struct List<Field> fields = getInheritedFields(requiredType);//requiredType.getDeclaredFields(); for (Field field : fields) { String metName = getSetterName(field.getName()); Method method = null; String columnName = ""; try { method = requiredType.getMethod(metName, field.getType()); } catch (NoSuchMethodException ex) { //LOGGER.warn("Can't bind a result to method " + metName + " of class " + requiredType.getName()); continue; } catch (SecurityException ex) { //LOGGER.warn("Can't bind a result to method " + metName + " of class " + requiredType.getName()); continue; } Object value = null; try { ColumnRef c = field.getAnnotation(ColumnRef.class); if (c != null) { columnName = c.value().trim(); } columnName = columnName.length() > 0 ? columnName : field.getName(); value = resultSet.getObject(columnName); method.invoke(obj, value); } catch (IllegalArgumentException ex) { if (value == null) { continue; } logger.debug("Type found in database is '" + value.getClass().getName() + "', but target object requires '" + field.getType().getName() + "': " + ex.getLocalizedMessage()); //if this is thrown the try to fix this error using the following: //If is a big decimal, maybe pojo has double or float attributes try { if (value instanceof BigDecimal || value instanceof Number) { if (Double.class.isAssignableFrom(field.getType()) || double.class.isAssignableFrom(field.getType())) { method.invoke(obj, ((BigDecimal) value).doubleValue()); continue; } else if (Float.class.isAssignableFrom(field.getType()) || float.class.isAssignableFrom(field.getType())) { method.invoke(obj, ((BigDecimal) value).floatValue()); continue; } else if (Long.class.isAssignableFrom(field.getType()) || long.class.isAssignableFrom(field.getType())) { method.invoke(obj, ((BigDecimal) value).longValue()); continue; } else { logger.warn("Tried to fix the mismatch problem, but couldn't: " + "Trying to inject an object of class " + value.getClass().getName() + " to an object of class " + field.getType()); } } else if (value instanceof Date) { Date dd = (Date) value; if (java.sql.Date.class.isAssignableFrom(field.getType())) { method.invoke(obj, new java.sql.Date(dd.getTime())); continue; } else if (Timestamp.class.isAssignableFrom(field.getType())) { method.invoke(obj, new Timestamp(dd.getTime())); continue; } else if (Time.class.isAssignableFrom(field.getType())) { method.invoke(obj, new Time(dd.getTime())); continue; } } } catch (IllegalArgumentException x) { printIllegalArgumentException(x, field, value); } catch (InvocationTargetException x) { x.printStackTrace(); } //throw new DataSourceException("Can't execute method " + method.getName() + " due to "+ex.getMessage(), ex); logger.warn( "Can't execute method " + method.getName() + " due to: " + ex.getMessage() + "."); } catch (InvocationTargetException ex) { //throw new DataSourceException("Can't inject an object into method " + method.getName(), ex); logger.warn("Can't inject an object into method " + method.getName() + " due to: " + ex.getMessage()); } catch (SQLException ex) { logger.warn("Target object has a field '" + columnName + "', this was not found in query results, " + "this cause that attribute remains NULL or with default value."); } } return obj; } else { ImmutableMap.Builder<String, Object> obj = new ImmutableMap.Builder<String, Object>(); //Adecuate results to BEAN for (int i = 1; i <= rsmd.getColumnCount(); i++) { String column = useColumnLabel ? rsmd.getColumnLabel(i) : rsmd.getColumnName(i); Object value = resultSet.getObject(i); obj.put(column, value); } return (T) obj.build(); } } catch (IllegalAccessException ex) { throw new SQLException( "Object of class " + instantiate.getType().getName() + " doesn't provide a valid access. It's possible be private or protected access only.", ex); } }