All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tsc9526.monalisa.tools.csv.DataTableReader Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
/*******************************************************************************************
 *	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.csv;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.relique.io.DataReader;

import com.tsc9526.monalisa.tools.clazz.MelpClass;
import com.tsc9526.monalisa.tools.clazz.MelpClass.FGS;
import com.tsc9526.monalisa.tools.clazz.MelpClass.ClassHelper;
import com.tsc9526.monalisa.tools.datatable.DataColumn;
import com.tsc9526.monalisa.tools.datatable.DataTable;

/**
 * 
 * @author zzg.zhou([email protected])
 */
class DataTableReader extends DataReader {
	private String[] columnNames;
	private String[] columnTypes;
	private List columnValues;
	private int rowIndex;

	public DataTableReader(DataTable table){
		List hs=table.getHeaders();
		
		List  columnNames=new ArrayList();
		List  columnTypes=new ArrayList();
		 
		List columnValues=new ArrayList();

		for(DataColumn c:hs){
			columnNames.add(c.getName());
			columnTypes.add(c.getTypeString());
		}
	
		for(Object row:table){
			Object[] vs=new Object[columnNames.size()];
			
			int i=0;
			if(row instanceof Map){
				Map map=(Map)row;
				for(String name:columnNames){
					vs[i++]=map.get(name);
				}
			}else{
				if(row.getClass().isPrimitive() || row.getClass().getName().startsWith("java.")){
					vs[i++]=row;
				}else if(row.getClass().isArray()){
					Object[] xs=(Object[])row;
					for(int k=0;k getEnvironment() throws SQLException {
		HashMap retval = new HashMap();
		Object[] o = columnValues.get(rowIndex);
		for (int i = 0; i < columnNames.length; i++) {
			retval.put(columnNames[i].toUpperCase(), o[i]);
		}
		return retval;
	}

	 
	public String[] getColumnTypes() throws SQLException {
		return columnTypes;
	}

	 
	public int[] getColumnSizes() throws SQLException {
		int[] columnSizes = new int[columnTypes.length];
		Arrays.fill(columnSizes, DEFAULT_COLUMN_SIZE);
		return columnSizes;
	}

	public String getTableAlias() {
		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy