📄 rowsutils.java
字号:
package org.speedframework.db.executor;
//~--- non-JDK imports --------------------------------------------------------
import org.speedframework.convert.OutDataConvertUtil;
import org.speedframework.exception.SpeedFrameworkException;
import org.speedframework.utilities.BeanAnalyzer;
import org.speedframework.utilities.PropertiesUtil;
//~--- JDK imports ------------------------------------------------------------
import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 类描述信息,描述类的主要职责和用处。
*
*
* @version $LastChangedRevision: 1945 $, 2007.09.29 at 02:14:24 CST
* @author <a href="mailto:falcon8848@gmail.com">piginzoo </a>
*/
public class RowsUtils
{
/**
* Constructs ...
*
*/
public RowsUtils() {}
/**
* copy db value from ResultSet
*
* @param rs ResultSet
* @param voclass Class or null
* @return List
* @throws SQLException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IntrospectionException
* @throws SpeedFrameworkException
*/
public static synchronized List copyRows(ResultSet rs, Class voclass)
throws SQLException, InstantiationException, IllegalAccessException, SpeedFrameworkException,
IntrospectionException, InvocationTargetException, NoSuchMethodException {
Object vo = null;
ResultSetMetaData rsm = null;
List relist = null;
rsm = rs.getMetaData();
relist = new ArrayList();
Map entity = null;
while (rs.next()) {
if (voclass != null) {
vo = voclass.newInstance();
} else {
entity = new HashMap(rsm.getColumnCount());
}
for (int i = 1; i <= rsm.getColumnCount(); i++) {
String columnName = rsm.getColumnName(i).toLowerCase();
Object value = null;
if (voclass != null) {
if (!columnName.equals("rownum") &&!columnName.equals("rownum_") &&!columnName.equals("count_")) {
String propertyname = BeanAnalyzer.getPropertyName(voclass, columnName);
value = OutDataConvertUtil.outPortData(rs, columnName, propertyname, voclass);
PropertiesUtil.setProperty(vo, propertyname, value);
}
} else {
value = rs.getObject(i);
entity.put(columnName, value);
}
}
if (voclass != null) {
relist.add(vo);
} else {
relist.add(entity);
}
}
return relist;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -