Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************************
* Copyright (c) 2016, zzg.zhou([email protected])
*
* Monalisa is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*******************************************************************************************/
package com.tsc9526.monalisa.tools.datatable;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import com.google.gson.stream.JsonWriter;
import com.tsc9526.monalisa.orm.annotation.Column;
import com.tsc9526.monalisa.orm.datasource.DbProp;
import com.tsc9526.monalisa.tools.clazz.MelpClass;
import com.tsc9526.monalisa.tools.clazz.MelpClass.ClassHelper;
import com.tsc9526.monalisa.tools.clazz.MelpClass.FGS;
import com.tsc9526.monalisa.tools.clazz.MelpLib;
import com.tsc9526.monalisa.tools.json.MelpJson;
import com.tsc9526.monalisa.tools.misc.MelpException;
import com.tsc9526.monalisa.tools.string.MelpSQL;
import com.tsc9526.monalisa.tools.string.MelpString;
/**
*
* @author zzg.zhou([email protected])
*/
public class DataTable extends ArrayList {
private static final long serialVersionUID = 6839964505006290332L;
public static DataTable fromCsv(InputStream csvInputStream) {
return MelpLib.createCsv().fromCsv(csvInputStream, CsvOptions.createDefaultOptions());
}
public static DataTable fromCsv(String csvString){
return MelpLib.createCsv().fromCsv(csvString, CsvOptions.createDefaultOptions());
}
public static DataTable fromResultSet(ResultSet rs){
DataTable table=new DataTable();
List headers=new ArrayList();
try{
ResultSetMetaData rsmd=rs.getMetaData();
for(int i=1;i<=rsmd.getColumnCount();i++){
String title = rsmd.getColumnLabel(i);
if(MelpString.isEmpty(title)){
title = rsmd.getColumnName(i);
}
headers.add(new DataColumn(title,rsmd.getColumnType(i)));
}
table.setHeaders(headers);
while (rs.next()) {
DataMap row=new DataMap();
for(int i=1;i<=rsmd.getColumnCount();i++){
row.put(headers.get(i-1).getName(), rs.getObject(i));
}
table.add(row);
}
return table;
}catch(SQLException e){
return MelpException.throwRuntimeException(e);
}
}
protected List headers=new ArrayList();
public DataTable() {
}
public DataTable(Collection extends E> cs) {
super(cs);
}
public void saveCsv(OutputStream csvOutputStream){
MelpLib.createCsv().writeToCsv(this, csvOutputStream,CsvOptions.createDefaultOptions());
}
/**
* 获取指定列数据
*
* @param column 列名称
* @return 返回指定列名的整列数据
*/
public List