プロパティの型に変換した値を取得

@param type 変換対象の型
@param rs ResultSet
@param columnIndex 変換対象データのカラムIndex
@return プロパティの型に変換した値
@throws SQLException SQL例外
515478
public Object getValue(final JavaType type, final ResultSet rs, final int columnIndex) throws SQLException {
		Class<?> rawType = type.getRawType();
		for (PropertyMapper<?> propertyMapper : this.mappers) {
			if (propertyMapper.canAccept(rawType) && propertyMapper.canAcceptTest(type, rs, columnIndex, this)) {
				return propertyMapper.getValue(type, rs, columnIndex, this);
			}
		}

		if (String.class.equals(rawType)) {
			return rs.getString(columnIndex);
		}
		if (Boolean.class.equals(rawType)) {
			boolean result = rs.getBoolean(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (boolean.class.equals(rawType)) {
			return rs.getBoolean(columnIndex);
		}
		if (Byte.class.equals(rawType)) {
			byte result = rs.getByte(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (byte.class.equals(rawType)) {
			return rs.getByte(columnIndex);
		}
		if (Short.class.equals(rawType)) {
			short result = rs.getShort(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (short.class.equals(rawType)) {
			return rs.getShort(columnIndex);
		}
		if (Integer.class.equals(rawType)) {
			int result = rs.getInt(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (int.class.equals(rawType)) {
			return rs.getInt(columnIndex);
		}
		if (Long.class.equals(rawType)) {
			long result = rs.getLong(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (long.class.equals(rawType)) {
			return rs.getLong(columnIndex);
		}
		if (Float.class.equals(rawType)) {
			float result = rs.getFloat(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (float.class.equals(rawType)) {
			return rs.getFloat(columnIndex);
		}
		if (Double.class.equals(rawType)) {
			double result = rs.getDouble(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (double.class.equals(rawType)) {
			return rs.getDouble(columnIndex);
		}
		if (BigDecimal.class.equals(rawType)) {
			return rs.getBigDecimal(columnIndex);
		}
		if (byte[].class.equals(rawType)) {
			return rs.getBytes(columnIndex);
		}
		if (java.sql.Timestamp.class.equals(rawType)) {
			return rs.getTimestamp(columnIndex);
		}
		if (java.sql.Time.class.equals(rawType)) {
			return rs.getTime(columnIndex);
		}
		if (java.sql.Date.class.equals(rawType)) {
			return rs.getDate(columnIndex);
		}
		if (Date.class.equals(rawType)) {
			return rs.getTimestamp(columnIndex);
		}
		if (java.sql.Array.class.equals(rawType)) {
			return rs.getArray(columnIndex);
		}
		if (java.sql.Blob.class.equals(rawType)) {
			return rs.getBlob(columnIndex);
		}
		if (java.sql.Clob.class.equals(rawType)) {
			return rs.getClob(columnIndex);
		}
		if (java.sql.NClob.class.equals(rawType)) {
			return rs.getNClob(columnIndex);
		}
		if (java.sql.Ref.class.equals(rawType)) {
			return rs.getRef(columnIndex);
		}
		if (java.sql.SQLXML.class.equals(rawType)) {
			return rs.getSQLXML(columnIndex);
		}
		for (PropertyMapper<?> propertyMapper : DEFAULT_MAPPERS) {
			if (propertyMapper.canAccept(rawType) && propertyMapper.canAcceptTest(type, rs, columnIndex, this)) {
				return propertyMapper.getValue(type, rs, columnIndex, this);
			}
		}
		return rs.getObject(columnIndex);
	}
870520
public <T> T  sqlObject(Class<T> beanType,  String entity ) throws ElasticSearchException {
		SQLRestResponse result = this.client.executeRequest("/_xpack/sql",entity,   new SQLRestResponseHandler());
		return ResultUtil.buildSQLObject(result,beanType);
	}
331390
private QueryParameters convertResultSetCurrentLine(ResultSet rs) throws SQLException {
        ResultSetMetaData rsmd = rs.getMetaData();
        int cols = rsmd.getColumnCount();
        String columnName = null;
        QueryParameters result = new QueryParameters();

        for (int i = 1; i <= cols; i++) {

            columnName = rsmd.getColumnLabel(i);
            if (null == columnName || 0 == columnName.length()) {
                columnName = rsmd.getColumnName(i);
            }

            result.set(columnName, rs.getObject(i));
            result.updatePosition(columnName, i - 1);
        }

        if (result != null) {
            result = typeHandler.processOutput(stmt, result);
        }

        return result;
    }
278787
public static int resultSetTypeToSqlLite(int columnType) {

		int type;

		switch (columnType) {
		case Types.INTEGER:
		case Types.BIGINT:
		case Types.SMALLINT:
		case Types.TINYINT:
		case Types.BOOLEAN:
			type = ResultUtils.FIELD_TYPE_INTEGER;
			break;
		case Types.VARCHAR:
		case Types.DATE:
			type = ResultUtils.FIELD_TYPE_STRING;
			break;
		case Types.REAL:
		case Types.FLOAT:
		case Types.DOUBLE:
			type = ResultUtils.FIELD_TYPE_FLOAT;
			break;
		case Types.BLOB:
			type = ResultUtils.FIELD_TYPE_BLOB;
			break;
		case Types.NULL:
			type = ResultUtils.FIELD_TYPE_NULL;
			break;
		default:
			throw new GeoPackageException(
					"Unsupported ResultSet Metadata Column Type: " + columnType);
		}

		return type;
	}
454944
public SQLXML getSQLXML(int columnIndex) throws SQLException {
        try {
            SQLXML xml = rsetImpl.getSQLXML(columnIndex); 
            if (xml != null && freeResourcesOnClose)
                xmls.add(xml); 
            return xml; 
        } catch (SQLException sqlX) {
            FFDCFilter.processException(
                                        sqlX, getClass().getName() + ".getSQLXML", "2115", this);
            throw WSJdbcUtil.mapException(this, sqlX);
        } catch (NullPointerException nullX) {
            // No FFDC code needed; we might be closed.
            throw runtimeXIfNotClosed(nullX);
        } catch (AbstractMethodError methError) {
            // No FFDC code needed; wrong JDBC level.
            throw AdapterUtil.notSupportedX("ResultSet.getSQLXML", methError);
        } catch (RuntimeException runX) {
            FFDCFilter.processException(
                                        runX, getClass().getName() + ".getSQLXML", "2131", this);
            if (tc.isDebugEnabled())
                Tr.debug(this, tc, "getSQLXML", runX);
            throw runX;
        } catch (Error err) {
            FFDCFilter.processException(
                                        err, getClass().getName() + ".getSQLXML", "2138", this);
            if (tc.isDebugEnabled())
                Tr.debug(this, tc, "getSQLXML", err);
            throw err;
        }
    }
1132041
public static <T> List<T> buildSQLResult(SQLRestResponse result,Class<T> type){
		if(result == null || result.getRows() == null || result.getRows().size() == 0)
			return null;
		if(result.getRows() != null && result.getRows().size() > 0) {
			List<Object[]> rows = result.getRows();
			List<T> datas = new ArrayList<T>(rows.size());
			ColumnMeta[] metas = result.getColumns();
			if (Map.class.isAssignableFrom(type)) {
				Map<String,Object> data = null;
				for(int i = 0; i < rows.size(); i ++) {
					Object[] row = rows.get(i);
					data = new HashMap<String,Object>(metas.length);
					for (int j = 0; j < metas.length; j++) {
						data.put(metas[j].getName(),row[j]);
					}
					datas.add((T)data);
				}

			} else {
				DateFormat defaultDateFormat = SerialUtil.getDateFormateMeta().toDateFormat();
				T valueObject = null;
				for(int i = 0; i < rows.size(); i ++) {
					Object[] row = rows.get(i);
					valueObject = buildObject(type,  metas,  row,defaultDateFormat);
					datas.add(valueObject);
				}
			}
			return datas;
		}
		else {
			return null;
		}

	}
935399
private void updateResultSetCurrentLine(ResultSet rs, QueryParameters params) throws SQLException {
        Object value = null;
        Object prevValue = null;

        int columnIndex = -1;
        boolean readOnly = false;
        QueryParameters prevParams = get(this.currentIndex);
        ResultSetMetaData rsmd = rs.getMetaData();

        QueryParameters processedParams = typeHandler.processInput(stmt, params);

        for (String parameterName : processedParams.keySet()) {
            value = processedParams.getValue(parameterName);
            prevValue = prevParams.getValue(parameterName);

            // no need to update value if it is the same
            if (value == prevValue || (value != null && prevValue != null && value.equals(prevValue) == true)) {
                continue;
            }

            columnIndex = rs.findColumn(parameterName);
            readOnly = rsmd.isReadOnly(columnIndex) || rsmd.isAutoIncrement(columnIndex);

            if (readOnly == false) {
                rs.updateObject(parameterName, value);
            }
        }
    }
153960
protected void checkIndex(int parameterIndex, int type, String getName) throws SQLException {
    checkIndex(parameterIndex);
    if (type != this.testReturn[parameterIndex - 1]) {
      throw new PSQLException(
          GT.tr("Parameter of type {0} was registered, but call to get{1} (sqltype={2}) was made.",
              "java.sql.Types=" + testReturn[parameterIndex - 1], getName,
                  "java.sql.Types=" + type),
          PSQLState.MOST_SPECIFIC_TYPE_DOES_NOT_MATCH);
    }
  }
708604
public static <E, T extends Collection<E>> T handleRsToBeanList(ResultSet rs, T collection, Class<E> elementBeanType) throws SQLException {
		final ResultSetMetaData meta = rs.getMetaData();
		final int columnCount = meta.getColumnCount();

		while (rs.next()) {
			collection.add(handleRow(columnCount, meta, rs, elementBeanType));
		}

		return collection;
	}
484494
public Object convertToDynamicBean(ResultSet rs) throws SQLException{
		ResultSetMetaData rsmd = rs.getMetaData();
		
		Map<String, ColumnMetaData> columnToPropertyMappings = createColumnToPropertyMappings(rsmd);
		
		Class<?> beanClass = reuseOrBuildBeanClass(rsmd, columnToPropertyMappings);
		BeanProcessor beanProcessor = new BeanProcessor(simpleColumnToPropertyMappings(columnToPropertyMappings));
		return beanProcessor.toBean(rs, beanClass);
	}
823436
public static Object getValueByColumnType(final ResultSet resultSet, final int columnIndex) throws SQLException {
        ResultSetMetaData metaData = resultSet.getMetaData();
        switch (metaData.getColumnType(columnIndex)) {
            case Types.BIT:
            case Types.BOOLEAN:
                return resultSet.getBoolean(columnIndex);
            case Types.TINYINT:
                return resultSet.getByte(columnIndex);
            case Types.SMALLINT:
                return resultSet.getShort(columnIndex);
            case Types.INTEGER:
                return resultSet.getInt(columnIndex);
            case Types.BIGINT:
                return resultSet.getLong(columnIndex);
            case Types.NUMERIC:
            case Types.DECIMAL:
                return resultSet.getBigDecimal(columnIndex);
            case Types.FLOAT:
            case Types.DOUBLE:
                return resultSet.getDouble(columnIndex);
            case Types.CHAR:
            case Types.VARCHAR:
            case Types.LONGVARCHAR:
                return resultSet.getString(columnIndex);
            case Types.BINARY:
            case Types.VARBINARY:
            case Types.LONGVARBINARY:
                return resultSet.getBytes(columnIndex);
            case Types.DATE:
                return resultSet.getDate(columnIndex);
            case Types.TIME:
                return resultSet.getTime(columnIndex);
            case Types.TIMESTAMP:
                return resultSet.getTimestamp(columnIndex);
            case Types.CLOB:
                return resultSet.getClob(columnIndex);
            case Types.BLOB:
                return resultSet.getBlob(columnIndex);
            default:
                return resultSet.getObject(columnIndex);
        }
    }
1254651
public int getColumnType( int index ) throws OdaException
	{
		//return Types.JAVA_OBJECT;//Any OrientDB field may be NULL
		///*
		String fieldName = getColumnName(index);
		OType fieldType = rowDoc.fieldType(fieldName);
		if (fieldType!=null){
			return typesSqlTypes.get(fieldType);
		}else{
			return Types.VARCHAR;
			//throw new OdaException("Unknown OType of field "+fieldName+" with index "+index);
		}
		//*/
	}
311478
public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
        // spring's : Object mappedObject = BeanUtils.instantiateClass(this.mappedClass);
        // jade's : private Object instantiateClass(this.mappedClass);
        // why: 经过简单的笔记本测试，mappedClass.newInstrance性能比BeanUtils.instantiateClass(mappedClass)快1个数量级
        Object mappedObject = instantiateClass(this.mappedClass);
        BeanWrapper bw = new BeanWrapperImpl(mappedObject);

        ResultSetMetaData rsmd = rs.getMetaData();
        int columnCount = rsmd.getColumnCount();

        boolean warnEnabled = logger.isWarnEnabled();
        boolean debugEnabled = logger.isDebugEnabled();
        Set<String> populatedProperties = (checkProperties ? new HashSet<String>() : null);

        for (int index = 1; index <= columnCount; index++) {
            String column = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase();
            PropertyDescriptor pd = this.mappedFields.get(column);
            if (pd != null) {
                try {
                    Object value = JdbcUtils.getResultSetValue(rs, index, pd.getPropertyType());
                    if (debugEnabled && rowNumber == 0) {
                        logger.debug("Mapping column '" + column + "' to property '" + pd.getName()
                                + "' of type " + pd.getPropertyType());
                    }
                    bw.setPropertyValue(pd.getName(), value);
                    if (populatedProperties != null) {
                        populatedProperties.add(pd.getName());
                    }
                } catch (NotWritablePropertyException ex) {
                    throw new DataRetrievalFailureException("Unable to map column " + column
                            + " to property " + pd.getName(), ex);
                }
            } else {
                if (checkColumns) {
                    throw new InvalidDataAccessApiUsageException("Unable to map column '" + column
                            + "' to any properties of bean " + this.mappedClass.getName());
                }
                if (warnEnabled && rowNumber == 0) {
                    logger.warn("Unable to map column '" + column + "' to any properties of bean "
                            + this.mappedClass.getName());
                }
            }
        }

        if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) {
            throw new InvalidDataAccessApiUsageException(
                    "Given ResultSet does not contain all fields "
                            + "necessary to populate object of class [" + this.mappedClass + "]: "
                            + this.mappedProperties);
        }

        return mappedObject;
    }
961190
@SuppressWarnings("unchecked")
    @Override
    protected K createKey(ResultSet rs) throws SQLException {
        return (columnName == null) ?
                (K) rs.getObject(columnIndex) :
                (K) rs.getObject(columnName);
    }
1043739
public <S> S queryOne(Class<S> type, String sql, Object[] params) {
        Connection conn = getConn();
        try {
            Query query = conn.createQuery(sql)
                    .withParams(params)
                    .setAutoDeriveColumnNames(true)
                    .throwOnMappingFailure(false);

            return ifReturn(AnimaUtils.isBasicType(type),
                    () -> query.executeScalar(type),
                    () -> query.executeAndFetchFirst(type));
        } finally {
            this.closeConn(conn);
            this.clean(null);
        }
    }
1143446
public int columnIndex(final int _tableIndex, final String _columnName)
    {
        final Optional<Column> colOpt = getColumns().stream()
                        .filter(column -> column.tableIndex == _tableIndex && column.columnName.equals(_columnName))
                        .findFirst();
        final int ret;
        if (colOpt.isPresent()) {
            ret = getColumns().indexOf(colOpt.get());
        } else {
            columns.add(new Column(tablePrefix, _tableIndex, _columnName));
            ret = getColumnIdx();
        }
        return ret;
    }
162299
public <T> T page(Connection conn, Collection<String> fields, Entity where, Page page, RsHandler<T> rsh) throws SQLException {
		checkConn(conn);
		if(null == page){
			return this.find(conn, fields, where, rsh);
		}
		
		final Query query = new Query(SqlUtil.buildConditions(where), where.getTableName());
		query.setFields(fields);
		query.setPage(page);
		return SqlExecutor.queryAndClosePs(dialect.psForPage(conn, query), rsh);
	}