当前位置: 首页>>代码示例>>Java>>正文


Java JdbcUtils.lookupColumnName方法代码示例

本文整理汇总了Java中org.springframework.jdbc.support.JdbcUtils.lookupColumnName方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcUtils.lookupColumnName方法的具体用法?Java JdbcUtils.lookupColumnName怎么用?Java JdbcUtils.lookupColumnName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.jdbc.support.JdbcUtils的用法示例。


在下文中一共展示了JdbcUtils.lookupColumnName方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processRow

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * Implementation of ResultSetCallbackHandler.
 * Work out column size if this is the first row, otherwise just count rows.
 * <p>Subclasses can perform custom extraction or processing
 * by overriding the {@code processRow(ResultSet, int)} method.
 * @see #processRow(java.sql.ResultSet, int)
 */
@Override
public final void processRow(ResultSet rs) throws SQLException {
	if (this.rowCount == 0) {
		ResultSetMetaData rsmd = rs.getMetaData();
		this.columnCount = rsmd.getColumnCount();
		this.columnTypes = new int[this.columnCount];
		this.columnNames = new String[this.columnCount];
		for (int i = 0; i < this.columnCount; i++) {
			this.columnTypes[i] = rsmd.getColumnType(i + 1);
			this.columnNames[i] = JdbcUtils.lookupColumnName(rsmd, i + 1);
		}
		// could also get column names
	}
	processRow(rs, this.rowCount++);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:RowCountCallbackHandler.java

示例2: mapRow

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
@Override
public T mapRow(ResultSet rs, int rowNum) throws SQLException {
    T mappedObject = this.entityMapper.createInstance();
    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();
    Map<String, Class<?>> types = this.entityMapper.types();

    this.entityMapper.startMapping(mappedObject);
    for (int index = 1; index <= columnCount; index++) {
        String column = JdbcUtils.lookupColumnName(rsmd, index);
        Object value = JdbcUtils.getResultSetValue(rs, index, types.get(column));

        this.entityMapper.setValue(mappedObject, column, value);
    }
    this.entityMapper.finishMapping(mappedObject);
    return mappedObject;
}
 
开发者ID:cybozu,项目名称:spring-data-jdbc-template,代码行数:18,代码来源:EntityRowMapper.java

示例3: mapRow

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * <B>方法名称:</B>映射行数据<BR>
 * <B>概要说明:</B><BR>
 * 
 * @param rs 结果集
 * @param row 行号
 * @return JSONObject 数据
 * @throws SQLException SQL异常错误
 * @see RowMapper#mapRow(ResultSet,
 *      int)
 */
public JSONObject mapRow(ResultSet rs, int row) throws SQLException {
    String key = null;
    Object obj = null;
    JSONObject json = new JSONObject();
    ResultSetMetaData rsmd = rs.getMetaData();
    int count = rsmd.getColumnCount();
    for (int i = 1; i <= count; i++) {
        key = JdbcUtils.lookupColumnName(rsmd, i);
        obj = JdbcUtils.getResultSetValue(rs, i);
        try {
            json.put(key, obj);
        }
        catch (JSONException e) {
        }
    }
    return json;
}
 
开发者ID:craware,项目名称:webapp-tyust,代码行数:29,代码来源:JsonRowMapper.java

示例4: mapRow

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
@Override
public T mapRow(ResultSet rs, int rowNum) throws SQLException {
	Assert.state(this.mappedClass != null, "Mapped class was not specified");
	T bean = BeanUtils.instantiate(this.mappedClass);
	ResultSetMetaData rsmd = rs.getMetaData();
	int columnCount = rsmd.getColumnCount();
	for (int index = 1; index <= columnCount; index++) {
		String columnName = JdbcUtils.lookupColumnName(rsmd, index);
		// System.err.println("column:" + column);
		columnName = columnName.replaceAll(" ", "").toLowerCase();
		columnName = columnName.replace("_", "");

		Field field = this.mappedFields.get(columnName);

		// if (field == null) {
		// this.mappedFields.get(underscoreName(column));
		// }
		// System.out.println("column:" + column + " field:" + field);

		if (field == null && columnName.endsWith("s")) {
			// TODO images转imageList的临时实现?
			String column2 = columnName.substring(0, columnName.length() - 1) + "list";
			field = this.mappedFields.get(column2);
			// System.out.println("column2:" + column2 + " field:" + field);
		}

		if (field != null) {
			this.loadFieldValue(bean, rs, index, rsmd, columnName, field);
		}
	}
	return bean;
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:33,代码来源:LeopardBeanPropertyRowMapper.java

示例5: createFieldIndex

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
private Map<String, Integer> createFieldIndex(ResultSet rs) throws SQLException {
	ResultSetMetaData rsmd = rs.getMetaData();
	int columnCount = rsmd.getColumnCount();
	Map<String, Integer> fieldIndex = new LinkedHashMap<String, Integer>(columnCount);

	for (int i = 1; i <= columnCount; i++) {
		String field = JdbcUtils.lookupColumnName(rsmd, i);
		fieldIndex.put(field, Integer.valueOf(i));
	}

	return fieldIndex;
}
 
开发者ID:sogou-biztech,项目名称:compass,代码行数:13,代码来源:AggregationResultSetExtractor.java

示例6: mapRow

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
@Override
public JsonNode mapRow(ResultSet rs, int rowNum) throws SQLException {
    ObjectNode objectNode = mapper.createObjectNode();
    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();
    for (int index = 1; index <= columnCount; index++) {
        String column = JdbcUtils.lookupColumnName(rsmd, index);
        Object value = rs.getObject(column);
        column = this.snakeCaseToCamelCase(column);
        if (value == null) {
            objectNode.putNull(column);
        } else if (value instanceof Integer) {
            objectNode.put(column, (Integer) value);
        } else if (value instanceof String) {
            objectNode.put(column, (String) value);
        } else if (value instanceof Boolean) {
            objectNode.put(column, (Boolean) value);
        } else if (value instanceof Date) {
            objectNode.put(column, ((Date) value).getTime());
        } else if (value instanceof Long) {
            objectNode.put(column, (Long) value);
        } else if (value instanceof Double) {
            objectNode.put(column, (Double) value);
        } else if (value instanceof Float) {
            objectNode.put(column, (Float) value);
        } else if (value instanceof BigDecimal) {
            objectNode.put(column, (BigDecimal) value);
        } else if (value instanceof Byte) {
            objectNode.put(column, (Byte) value);
        } else if (value instanceof byte[]) {
            objectNode.put(column, (byte[]) value);
        } else {
            throw new IllegalArgumentException("Unmappable object type: " + value.getClass());
        }
    }
    return objectNode;
}
 
开发者ID:OHDSI,项目名称:WebAPI,代码行数:38,代码来源:GenericRowMapper.java

示例7: processRow

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * Implementation of ResultSetCallbackHandler.
 * Work out column size if this is the first row, otherwise just count rows.
 * <p>Subclasses can perform custom extraction or processing
 * by overriding the {@code processRow(ResultSet, int)} method.
 * @see #processRow(java.sql.ResultSet, int)
 */
public final void processRow(ResultSet rs) throws SQLException {
	if (this.rowCount == 0) {
		ResultSetMetaData rsmd = rs.getMetaData();
		this.columnCount = rsmd.getColumnCount();
		this.columnTypes = new int[this.columnCount];
		this.columnNames = new String[this.columnCount];
		for (int i = 0; i < this.columnCount; i++) {
			this.columnTypes[i] = rsmd.getColumnType(i + 1);
			this.columnNames[i] = JdbcUtils.lookupColumnName(rsmd, i + 1);
		}
		// could also get column names
	}
	processRow(rs, this.rowCount++);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:22,代码来源:RowCountCallbackHandler.java

示例8: mapRow

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
    Assert.state(this.mappedClass != null, "Mapped class was not specified");
    T mappedObject = BeanUtils.instantiate(this.mappedClass);
    BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject);

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

    for (int index = 1; index <= columnCount; index++) {
        String column = JdbcUtils.lookupColumnName(metaData, index);

        String name = column.replaceAll(" ", "").toLowerCase();
        Object value = null;
        if (privateFields.containsKey(name)) {
            PropertyDescriptor pd = privateFields.get(name);
            value = getColumnValue(rs, index, pd.getPropertyType());
            if (logger.isDebugEnabled() && rowNumber == 0) {
                logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type " + pd.getPropertyType());
            }
            // TODO: care about assign null to primitive field. See BeanPropertyRowMapper
            bw.setPropertyValue(pd.getName(), value);
        } else if (publicFields.containsKey(name)) {
            Field field = this.publicFields.get(name);
            value = getColumnValue(rs, index, field.getType());
            if (logger.isDebugEnabled() && rowNumber == 0) {
                logger.debug("Mapping column '" + column + "' to property '" + field.getName() + "' of type " + field.getType());
            }
            try {
                field.set(mappedObject, value);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    }

    return mappedObject;
}
 
开发者ID:cero-t,项目名称:sqltemplate,代码行数:42,代码来源:BeanMapper.java

示例9: mapRow

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
@Override
public Map<String, String> mapRow(ResultSet rs, int rowNum) throws SQLException {
    Map<String, String> object = new HashMap<String, String>();
    ResultSetMetaData metaData = rs.getMetaData();
    for (int i = 1; i <= metaData.getColumnCount(); i++) {
        String columnName = JdbcUtils.lookupColumnName(metaData, i);
        object.put(columnName, rs.getString(i));
    }
    return object;
}
 
开发者ID:PkayJava,项目名称:pluggable,代码行数:11,代码来源:StringStringMapper.java

示例10: mapRow

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * Extract the values for all columns in the current row.
 * <p>Utilizes public setters and result set metadata.
 * @see java.sql.ResultSetMetaData
 */
@Override
public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
	Assert.state(this.mappedClass != null, "Mapped class was not specified");
	T mappedObject = BeanUtils.instantiate(this.mappedClass);
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject);
	initBeanWrapper(bw);

	ResultSetMetaData rsmd = rs.getMetaData();
	int columnCount = rsmd.getColumnCount();
	Set<String> populatedProperties = (isCheckFullyPopulated() ? new HashSet<String>() : null);

	for (int index = 1; index <= columnCount; index++) {
		String column = JdbcUtils.lookupColumnName(rsmd, index);
		PropertyDescriptor pd = this.mappedFields.get(column.replaceAll(" ", "").toLowerCase());
		if (pd != null) {
			try {
				Object value = getColumnValue(rs, index, pd);
				if (logger.isDebugEnabled() && rowNumber == 0) {
					logger.debug("Mapping column '" + column + "' to property '" +
							pd.getName() + "' of type " + pd.getPropertyType());
				}
				try {
					bw.setPropertyValue(pd.getName(), value);
				}
				catch (TypeMismatchException e) {
					if (value == null && primitivesDefaultedForNullValue) {
						logger.debug("Intercepted TypeMismatchException for row " + rowNumber +
								" and column '" + column + "' with value " + value +
								" when setting property '" + pd.getName() + "' of type " + pd.getPropertyType() +
								" on object: " + mappedObject);
					}
					else {
						throw e;
					}
				}
				if (populatedProperties != null) {
					populatedProperties.add(pd.getName());
				}
			}
			catch (NotWritablePropertyException ex) {
				throw new DataRetrievalFailureException(
						"Unable to map column " + column + " to property " + pd.getName(), ex);
			}
		}
	}

	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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:59,代码来源:BeanPropertyRowMapper.java

示例11: mapRow

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
@Override
public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
	Assert.state(this.mappedClass != null, "Mapped class was not specified");
	T mappedObject = BeanUtils.instantiate(this.mappedClass);
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject);

	ResultSetMetaData rsmd = rs.getMetaData();
	int columnCount = rsmd.getColumnCount();
	
	for (int index = 1; index <= columnCount; index++) {
		String column = JdbcUtils.lookupColumnName(rsmd, index);
		String dbFieldName = column.replaceAll(" ", "");
		FieldMapper fieldMapper = this.tableMapper.getFieldMapper(dbFieldName);
		PropertyDescriptor pd;
		if (fieldMapper != null && (pd=fieldMapper.getPropertyDescriptor()) != null ) {
			try {
				Object value = getColumnValue(rs, index, pd);
				if (logger.isDebugEnabled() && rowNumber == 0) {
					logger.debug("Mapping column '" + column + "' to property '" +pd.getName() + "' of type " + pd.getPropertyType());
				}
				try {
					bw.setPropertyValue(pd.getName(), value);
				}
				catch (TypeMismatchException e) {
					if (value == null) {
						logger.debug("Intercepted TypeMismatchException for row " + rowNumber +
								" and column '" + column + "' with value " + value +
								" when setting property '" + pd.getName() + "' of type " + pd.getPropertyType() +
								" on object: " + mappedObject);
					}
					else {
						throw e;
					}
				}
			}
			catch (NotWritablePropertyException ex) {
				throw new DataRetrievalFailureException("Unable to map column " + column + " to property " + pd.getName(), ex);
			}
		}
	}
	
	
	return mappedObject;
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:45,代码来源:EntityPropertyRowMapper.java

示例12: mapRow

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * Extract the values for all columns in the current row.
 * <p>Utilizes public setters and result set metadata.
 * @see java.sql.ResultSetMetaData
 */
public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
	Assert.state(this.mappedClass != null, "Mapped class was not specified");
	T mappedObject = BeanUtils.instantiate(this.mappedClass);
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject);
	initBeanWrapper(bw);

	ResultSetMetaData rsmd = rs.getMetaData();
	int columnCount = rsmd.getColumnCount();
	Set<String> populatedProperties = (isCheckFullyPopulated() ? new HashSet<String>() : null);

	for (int index = 1; index <= columnCount; index++) {
		String column = JdbcUtils.lookupColumnName(rsmd, index);
		PropertyDescriptor pd = this.mappedFields.get(column.replaceAll(" ", "").toLowerCase());
		if (pd != null) {
			try {
				Object value = getColumnValue(rs, index, pd);
				if (logger.isDebugEnabled() && rowNumber == 0) {
					logger.debug("Mapping column '" + column + "' to property '" +
							pd.getName() + "' of type " + pd.getPropertyType());
				}
				try {
					bw.setPropertyValue(pd.getName(), value);
				}
				catch (TypeMismatchException e) {
					if (value == null && primitivesDefaultedForNullValue) {
						logger.debug("Intercepted TypeMismatchException for row " + rowNumber +
								" and column '" + column + "' with value " + value +
								" when setting property '" + pd.getName() + "' of type " + pd.getPropertyType() +
								" on object: " + mappedObject);
					}
					else {
						throw e;
					}
				}
				if (populatedProperties != null) {
					populatedProperties.add(pd.getName());
				}
			}
			catch (NotWritablePropertyException ex) {
				throw new DataRetrievalFailureException(
						"Unable to map column " + column + " to property " + pd.getName(), ex);
			}
		}
	}

	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;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:58,代码来源:BeanPropertyRowMapper.java

示例13: mapRow2SubObj

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * Extract the values for all columns in the current row.
 * <p>Utilizes public setters and result set metadata.
 * @see java.sql.ResultSetMetaData
 */
@SuppressWarnings("rawtypes")
public Object mapRow2SubObj(ResultSet rs, int rowNumber,Class subClz) throws SQLException {
	Assert.state(subClz != null, "Mapped class was not specified");
	Object mappedObject = BeanUtils.instantiate(subClz);
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject);
	initBeanWrapper(bw);
	
	ResultSetMetaData rsmd = rs.getMetaData();
	int columnCount = rsmd.getColumnCount();
	Set<String> populatedProperties = (isCheckFullyPopulated() ? new HashSet<String>() : null);
	
	for (int index = 1; index <= columnCount; index++) {
		String column = JdbcUtils.lookupColumnName(rsmd, index);
		PropertyDescriptor pd = this.subMappedFields.get(column.replaceAll(" ", "").toLowerCase());
		Class clz = this.subMappedFieldsSuperClz.get(column.replaceAll(" ", "").toLowerCase());
		if (pd != null&&clz==subClz) {
			try {
				Object value = getColumnValue(rs, index, pd);
				if (logger.isDebugEnabled() && rowNumber == 0) {
					//logger.debug("Mapping column '" + column + "' to property '" +
					//		pd.getName() + "' of type " + pd.getPropertyType());
				}
				try {
					bw.setPropertyValue(pd.getName(), value);
				}catch (TypeMismatchException e) {
					if (value == null && primitivesDefaultedForNullValue) {
						logger.debug("Intercepted TypeMismatchException for row " + rowNumber +
								" and column '" + column + "' with value " + value +
								" when setting property '" + pd.getName() + "' of type " + pd.getPropertyType() +
								" on object: " + mappedObject);
					}
					else {
						throw e;
					}
				}
				if (populatedProperties != null) {
					populatedProperties.add(pd.getName());
				}
			}
			catch (NotWritablePropertyException ex) {
				throw new DataRetrievalFailureException(
						"Unable to map column " + column + " to property " + pd.getName(), ex);
			}
		} 
	}
	
	if (populatedProperties != null && !populatedProperties.equals(this.subMappedProperties)) {
		throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields " +
				"necessary to populate object of class [" + subClz+ "]: " + this.subMappedProperties);
	}
	
	return mappedObject;
}
 
开发者ID:zhanggh,项目名称:mtools,代码行数:59,代码来源:BeanPropRowMap.java


注:本文中的org.springframework.jdbc.support.JdbcUtils.lookupColumnName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。