List of usage examples for java.sql Time Time
public Time(long time)
Time
object using a milliseconds time value. From source file:org.kuali.kpme.core.calendar.entry.CalendarEntryBo.java
public Time getEndPeriodTime() { return endPeriodDateTime != null ? new Time(endPeriodDateTime.getTime()) : null; }
From source file:org.moqui.impl.context.L10nFacadeImpl.java
@Override public Time parseTime(String input, String format) { Locale curLocale = getLocale(); TimeZone curTz = getTimeZone(); if (format == null || format.isEmpty()) format = "HH:mm:ss.SSS"; Calendar cal = calendarValidator.validate(input, format, curLocale, curTz); if (cal == null) cal = calendarValidator.validate(input, "HH:mm:ss", curLocale, curTz); if (cal == null) cal = calendarValidator.validate(input, "HH:mm", curLocale, curTz); if (cal == null) cal = calendarValidator.validate(input, "h:mm a", curLocale, curTz); if (cal == null) cal = calendarValidator.validate(input, "h:mm:ss a", curLocale, curTz); // also try the full ISO-8601, times may come in that way (even if funny with a date of 1970-01-01) if (cal == null) cal = calendarValidator.validate(input, "yyyy-MM-dd'T'HH:mm:ssZ", curLocale, curTz); if (cal != null) { Time time = new Time(cal.getTimeInMillis()); // logger.warn("============== parseTime input=${input} cal=${cal} long=${cal.getTimeInMillis()} time=${time} time long=${time.getTime()} util date=${new java.util.Date(cal.getTimeInMillis())} timestamp=${new java.sql.Timestamp(cal.getTimeInMillis())}") return time; }/*from w w w . ja v a2s .c om*/ // try interpreting the String as a long try { Long lng = Long.valueOf(input); return new Time(lng); } catch (NumberFormatException e) { if (logger.isTraceEnabled()) logger.trace("Ignoring NumberFormatException for Time parse: " + e.toString()); } return null; }
From source file:com.facebook.presto.accumulo.model.Row.java
/** * Converts the given String into a Java object based on the given Presto type * * @param str String to convert//from w w w. j a v a 2 s. com * @param type Presto Type * @return Java object * @throws PrestoException If the type is not supported by this function */ public static Object valueFromString(String str, Type type) { if (str == null || str.isEmpty()) { return null; } else if (Types.isArrayType(type)) { Type elementType = Types.getElementType(type); ImmutableList.Builder<Object> listBuilder = ImmutableList.builder(); for (String element : Splitter.on(',').split(str)) { listBuilder.add(valueFromString(element, elementType)); } return AccumuloRowSerializer.getBlockFromArray(elementType, listBuilder.build()); } else if (Types.isMapType(type)) { Type keyType = Types.getKeyType(type); Type valueType = Types.getValueType(type); ImmutableMap.Builder<Object, Object> mapBuilder = ImmutableMap.builder(); for (String element : Splitter.on(',').split(str)) { ImmutableList.Builder<String> builder = ImmutableList.builder(); List<String> keyValue = builder.addAll(Splitter.on("->").split(element)).build(); checkArgument(keyValue.size() == 2, format("Map element %s has %d entries, not 2", element, keyValue.size())); mapBuilder.put(valueFromString(keyValue.get(0), keyType), valueFromString(keyValue.get(1), valueType)); } return AccumuloRowSerializer.getBlockFromMap(type, mapBuilder.build()); } else if (type.equals(BIGINT)) { return Long.parseLong(str); } else if (type.equals(BOOLEAN)) { return Boolean.parseBoolean(str); } else if (type.equals(DATE)) { return new Date(DATE_PARSER.parseDateTime(str).getMillis()); } else if (type.equals(DOUBLE)) { return Double.parseDouble(str); } else if (type.equals(INTEGER)) { return Integer.parseInt(str); } else if (type.equals(REAL)) { return Float.parseFloat(str); } else if (type.equals(SMALLINT)) { return Short.parseShort(str); } else if (type.equals(TIME)) { return new Time(TIME_PARSER.parseDateTime(str).getMillis()); } else if (type.equals(TIMESTAMP)) { return new Timestamp(TIMESTAMP_PARSER.parseDateTime(str).getMillis()); } else if (type.equals(TINYINT)) { return Byte.valueOf(str); } else if (type.equals(VARBINARY)) { return str.getBytes(UTF_8); } else if (type instanceof VarcharType) { return str; } else { throw new PrestoException(NOT_SUPPORTED, "Unsupported type " + type); } }
From source file:org.apache.phoenix.pig.util.TypeUtil.java
/** * This method encodes a value with Phoenix data type. It begins with checking whether an object is BINARY and makes * a call to {@link #castBytes(Object, PDataType)} to convert bytes to targetPhoenixType. It returns a {@link RuntimeException} * when object can not be coerced./* w w w . j av a 2s . c o m*/ * * @param o * @param targetPhoenixType * @return Object */ public static Object castPigTypeToPhoenix(Object o, byte objectType, PDataType targetPhoenixType) { PDataType inferredPType = getType(o, objectType); if (inferredPType == null) { return null; } if (inferredPType == PVarbinary.INSTANCE) { try { o = castBytes(o, targetPhoenixType); if (targetPhoenixType != PVarbinary.INSTANCE && targetPhoenixType != PBinary.INSTANCE) { inferredPType = getType(o, DataType.findType(o)); } } catch (IOException e) { throw new RuntimeException("Error while casting bytes for object " + o); } } if (inferredPType == PDate.INSTANCE) { int inferredSqlType = targetPhoenixType.getSqlType(); if (inferredSqlType == Types.DATE) { return new Date(((DateTime) o).getMillis()); } if (inferredSqlType == Types.TIME) { return new Time(((DateTime) o).getMillis()); } if (inferredSqlType == Types.TIMESTAMP) { return new Timestamp(((DateTime) o).getMillis()); } } if (targetPhoenixType == inferredPType || inferredPType.isCoercibleTo(targetPhoenixType)) { return inferredPType.toObject(o, targetPhoenixType); } throw new RuntimeException( o.getClass().getName() + " cannot be coerced to " + targetPhoenixType.toString()); }
From source file:org.ojbc.adapters.analyticaldatastore.processor.IncidentReportProcessor.java
@Transactional public void processReport(Document incidentReport) throws Exception { Incident incident = new Incident(); String rootElemntName = incidentReport.getDocumentElement().getLocalName(); if (INCIDENT_REPORT_ROOT_ELEMENT_NAME.equals(rootElemntName)) { incident.setRecordType('N'); } else if (INCIDENT_REPORT_UPDATE_ROOT_ELEMENT_NAME.equals(rootElemntName)) { incident.setRecordType('U'); }/* w ww. ja v a2 s. c o m*/ String reportingAgencyName = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DIGEST + "/lexsdigest:EntityOrganization/nc:Organization[@s:id= " + PATH_TO_LEXS_DIGEST + " /lexsdigest:Associations/nc:ActivityReportingOrganizationAssociation[nc:ActivityReference/@s:ref=" + PATH_TO_LEXS_DIGEST + "/lexsdigest:EntityActivity/nc:Activity[nc:ActivityCategoryText='Incident']/@s:id]/nc:OrganizationReference/@s:ref]/nc:OrganizationName"); log.debug("Agency Name: " + reportingAgencyName); String reportingAgencyORI = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DATA_ITEM_PACKAGE + "/lexs:PackageMetadata/lexs:DataOwnerMetadata/lexs:DataOwnerIdentifier/lexs:ORI"); log.debug("Agency ORI: " + reportingAgencyORI); Integer reportingAgencyId = null; if (StringUtils.isNotBlank(reportingAgencyORI)) { reportingAgencyId = analyticalDatastoreDAO.searchForAgenyIDbyAgencyORI(reportingAgencyORI); if (reportingAgencyId == null) { throw new Exception("Valid Agency ORI required for incident. Agency Name is: " + reportingAgencyName + ", Agency ORI is: " + reportingAgencyORI); } incident.setReportingAgencyID(reportingAgencyId); } else { throw new Exception("Valid Agency ORI required for incident. Agency Name is: " + StringUtils.trimToEmpty(reportingAgencyName) + ", Agency ORI is: " + StringUtils.trimToEmpty(reportingAgencyORI)); } String incidentCaseNumber = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DATA_ITEM_PACKAGE + "/lexs:PackageMetadata/lexs:DataItemID"); log.debug("Incident Case Number: " + incidentCaseNumber); if (StringUtils.isNotBlank(incidentCaseNumber)) { incident.setIncidentCaseNumber(incidentCaseNumber); } //Check to see if incident(s) already exists List<Incident> incidents = analyticalDatastoreDAO .searchForIncidentsByIncidentNumberAndReportingAgencyID(incidentCaseNumber, reportingAgencyId); //if incidents exist, delete them prior to inserting a new one if (incidents.size() > 1) { throw new IllegalStateException( "Error condition. Duplicate records with same incident number and agency ID exists in database"); } Integer incidentIDToReplace = null; if (incidents.size() == 1) { incidentIDToReplace = incidents.get(0).getIncidentID(); incident.setIncidentID(incidentIDToReplace); log.debug("Incident ID to replace: " + incidentIDToReplace); analyticalDatastoreDAO.deleteIncident(incidents.get(0).getIncidentID()); } String reportingSystem = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DATA_ITEM_PACKAGE + "/lexs:PackageMetadata/lexs:DataOwnerMetadata/lexs:DataOwnerIdentifier/lexs:SystemID"); incident.setReportingSystem(reportingSystem); //Look for either incident date/time or incident date field String incidentDateTimeAsString = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DIGEST + "/lexsdigest:EntityActivity/nc:Activity/nc:ActivityDateRange/nc:StartDate/nc:DateTime"); log.debug("Incident Date/Time: " + incidentDateTimeAsString); if (StringUtils.isNotEmpty(incidentDateTimeAsString)) { Calendar incidentDateTimeCal = DatatypeConverter.parseDateTime(incidentDateTimeAsString); Date incidentDateTime = incidentDateTimeCal.getTime(); if (incidentDateTime != null) { incident.setIncidentDate(incidentDateTime); } Time incidentTime = new Time(incidentDateTime.getTime()); log.debug("Incident Time: " + incidentTime.toString()); if (incidentTime != null) { incident.setIncidentTime(incidentTime); } } else { String incidentDateAsString = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DIGEST + "/lexsdigest:EntityActivity/nc:Activity/nc:ActivityDate/nc:Date"); log.debug("Incident Date: " + incidentDateAsString); Calendar incidentDateCal = DatatypeConverter.parseDate(incidentDateAsString); Date incidentDate = incidentDateCal.getTime(); if (incidentDate != null) { incident.setIncidentDate(incidentDate); } } String mapHorizontalCoordinateText = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DATA_ITEM_PACKAGE + "/lexs:StructuredPayload/inc-ext:IncidentReport/inc-ext:Location/nc:LocationMapLocation/nc:MapHorizontalCoordinateText"); if (StringUtils.isNotBlank(mapHorizontalCoordinateText)) { //TODO: put this into a strategy try { mapHorizontalCoordinateText = updatedCoordinate(mapHorizontalCoordinateText); log.debug("Map horizontal coordinate text: " + mapHorizontalCoordinateText); BigDecimal longitude = new BigDecimal(mapHorizontalCoordinateText); incident.setIncidentLocationLongitude(longitude); } catch (Exception ex) { log.warn("Unable to set map horizontal text coordinate"); } } String mapVerticalCoordinateText = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DATA_ITEM_PACKAGE + "/lexs:StructuredPayload/inc-ext:IncidentReport/inc-ext:Location/nc:LocationMapLocation/nc:MapVerticalCoordinateText"); if (StringUtils.isNotBlank(mapVerticalCoordinateText)) { //TODO: put this into a strategy try { mapVerticalCoordinateText = updatedCoordinate(mapVerticalCoordinateText); log.debug("Map vertical coordinate text: " + mapVerticalCoordinateText); BigDecimal latitude = new BigDecimal(mapVerticalCoordinateText); incident.setIncidentLocationLatitude(latitude); } catch (Exception ex) { log.warn("Unable to set map vertical text coordinate"); } } String incidentLocationReference = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DIGEST + "/lexsdigest:Associations/lexsdigest:IncidentLocationAssociation/nc:LocationReference/@s:ref"); if (StringUtils.isNotEmpty(incidentLocationReference)) { Node locationNode = XmlUtils.xPathNodeSearch(incidentReport, PATH_TO_LEXS_DIGEST + "/lexsdigest:EntityLocation/nc:Location[@s:id='" + incidentLocationReference + "']"); String streetFullText = XmlUtils.xPathStringSearch(locationNode, "nc:LocationAddress/nc:StructuredAddress/nc:LocationStreet/nc:StreetFullText"); log.debug("Street Full Text: " + streetFullText); if (StringUtils.isNotBlank(streetFullText)) { incident.setIncidentLocationStreetAddress(streetFullText); } else { String streetNumberText = XmlUtils.xPathStringSearch(locationNode, "nc:LocationAddress/nc:StructuredAddress/nc:LocationStreet/nc:StreetNumberText"); log.debug("Street Number Text: " + streetNumberText); String streetName = XmlUtils.xPathStringSearch(locationNode, "nc:LocationAddress/nc:StructuredAddress/nc:LocationStreet/nc:StreetName"); log.debug("Street Name Text: " + streetName); String streetCategoryText = XmlUtils.xPathStringSearch(locationNode, "nc:LocationAddress/nc:StructuredAddress/nc:LocationStreet/nc:StreetCategoryText"); log.debug("Street Category Text: " + streetCategoryText); streetFullText = streetNumberText + streetName + streetFullText; log.debug("Street Full Text built from number, name and category: " + streetFullText); if (StringUtils.isNotBlank(streetFullText)) { incident.setIncidentLocationStreetAddress(streetFullText); } } String cityTown = XmlUtils.xPathStringSearch(locationNode, "nc:LocationAddress/nc:StructuredAddress/nc:LocationCityName"); log.debug("City/Town: " + cityTown); if (StringUtils.isNotBlank(cityTown)) { incident.setIncidentLocationTown(cityTown); } } Integer incidentPk = analyticalDatastoreDAO.saveIncident(incident); //Add Incident Description Text processIncidentType(incidentReport, incidentPk); //Save circumstance codes processCircumstanceCodes(incidentReport, incidentPk); processArrests(incidentReport, incidentPk, reportingSystem); }
From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatExportHelper.java
private Object convertToSqoop(Object val, HCatFieldSchema.Type fieldType, String javaColType, String hCatTypeString) throws IOException { if (val == null) { return null; }// www. j a v a 2 s . c om switch (fieldType) { case INT: case TINYINT: case SMALLINT: case FLOAT: case DOUBLE: val = convertNumberTypes(val, javaColType); if (val != null) { return val; } break; case BOOLEAN: val = convertBooleanTypes(val, javaColType); if (val != null) { return val; } break; case BIGINT: if (javaColType.equals(DATE_TYPE)) { return new Date((Long) val); } else if (javaColType.equals(TIME_TYPE)) { return new Time((Long) val); } else if (javaColType.equals(TIMESTAMP_TYPE)) { return new Timestamp((Long) val); } else { val = convertNumberTypes(val, javaColType); if (val != null) { return val; } } break; case DATE: Date date = (Date) val; if (javaColType.equals(DATE_TYPE)) { return date; } else if (javaColType.equals(TIME_TYPE)) { return new Time(date.getTime()); } else if (javaColType.equals(TIMESTAMP_TYPE)) { return new Timestamp(date.getTime()); } break; case TIMESTAMP: Timestamp ts = (Timestamp) val; if (javaColType.equals(DATE_TYPE)) { return new Date(ts.getTime()); } else if (javaColType.equals(TIME_TYPE)) { return new Time(ts.getTime()); } else if (javaColType.equals(TIMESTAMP_TYPE)) { return ts; } break; case STRING: case VARCHAR: case CHAR: val = convertStringTypes(val, javaColType); if (val != null) { return val; } break; case BINARY: val = convertBinaryTypes(val, javaColType); if (val != null) { return val; } break; case DECIMAL: val = convertDecimalTypes(val, javaColType); if (val != null) { return val; } break; case ARRAY: case MAP: case STRUCT: default: throw new IOException("Cannot convert HCatalog type " + fieldType); } LOG.error("Cannot convert HCatalog object of " + " type " + hCatTypeString + " to java object type " + javaColType); return null; }
From source file:javadz.beanutils.locale.converters.SqlTimeLocaleConverter.java
/** * Convert the specified locale-sensitive input object into an output object of the * specified type./*from w ww . j ava 2 s . c o m*/ * * @param value The input object to be converted * @param pattern The pattern is used for the convertion * @return The converted value * * @exception org.apache.commons.beanutils.ConversionException if conversion * cannot be performed successfully * @throws ParseException if an error occurs parsing a String to a Number */ protected Object parse(Object value, String pattern) throws ParseException { return new Time(((java.util.Date) super.parse(value, pattern)).getTime()); }
From source file:org.saiku.reporting.backend.component.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 w w w . jav a2 s . co m if (rawValue == null) { return null; } if (targetType.isInstance(rawValue)) { return rawValue; } //TODO: // 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(Locale.getDefault())); 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(Locale.getDefault())); 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( "ReportPlugin.unableToConvertParameter " + parameter.getName() + " " + valueAsString); //$NON-NLS-1$ } } return rawValue; }
From source file:org.azkfw.datasource.xml.XmlDatasourceFactory.java
private static XmlRecord readData(final int aRowNum, final XmlRecordEntity aRecord, final List<XmlField> aFields) throws ParseException { Map<String, Object> data = new HashMap<String, Object>(); for (int i = 0; i < aFields.size(); i++) { XmlField field = aFields.get(i); XmlRecordDataEntity d = aRecord.data.get(i); String value = d.value;// w ww .jav a 2 s . co m if ("(NULL)".equals(value)) { data.put(field.name, null); } else { if (FieldType.String == field.type) { String obj = value; data.put(field.name, obj); } else if (FieldType.Boolean == field.type) { Boolean obj = Boolean.parseBoolean(value); data.put(field.name, obj); } else if (FieldType.Integer == field.type) { Double obj = Double.parseDouble(value); data.put(field.name, Integer.valueOf(obj.intValue())); } else if (FieldType.Long == field.type) { Double obj = Double.parseDouble(value); data.put(field.name, Long.valueOf(obj.longValue())); } else if (FieldType.Float == field.type) { Float obj = Float.parseFloat(value); data.put(field.name, obj); } else if (FieldType.Double == field.type) { Double obj = Double.parseDouble(value); data.put(field.name, obj); } else if (FieldType.Timestamp == field.type) { Timestamp obj = new Timestamp( new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(value).getTime()); data.put(field.name, obj); } else if (FieldType.Date == field.type) { Timestamp ts = new Timestamp(new SimpleDateFormat("yyyy/MM/dd").parse(value).getTime()); Date obj = new Date(ts.getTime()); data.put(field.name, obj); } else if (FieldType.Time == field.type) { Timestamp ts = new Timestamp(new SimpleDateFormat("HH:mm:ss").parse(value).getTime()); Time obj = new Time(ts.getTime()); data.put(field.name, obj); } else { throw new ParseException("Undefined type.[" + field.getType() + "]", aRowNum); } } } XmlRecord record = new XmlRecord(); record.data = data; return record; }
From source file:org.openlogics.gears.jdbc.map.BeanResultHandler.java
/** * * @param resultSet/* w w w . j a v a 2s. c o 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); } }