View Javadoc

1   package migratool.datasources;
2   
3   import java.sql.ResultSet;
4   import java.sql.ResultSetMetaData;
5   import java.sql.SQLException;
6   import java.sql.Statement;
7   import java.util.Collection;
8   import java.util.Vector;
9   
10  import migratool.model.BDdescription;
11  
12  /**
13   * 
14   * MIGRATOOL Program to migrate spatial databsets.
15   * Copyright (C) 2007 Fábio Luiz Leite Júnior
16   * Universidade Federal de Campina Grande
17   * contact: fabioleite@gmail.com
18   *
19   * This program is free software; you can redistribute it and/or
20   * modify it under the terms of the GNU General Public License
21   * as published by the Free Software Foundation; either version 2
22   * of the License, or (at your option) any later version.
23   *
24   * This program is distributed in the hope that it will be useful,
25   * but WITHOUT ANY WARRANTY; without even the implied warranty of
26   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27   * GNU General Public License for more details.
28   *
29   * You should have received a copy of the GNU General Public License
30   * along with this program; if not, write to the Free Software
31   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
32   *
33   * @author fabio
34   *
35   */
36  
37  public class OriginDataSource extends AbstractOriginDataSource{
38  
39  	/**
40  	 * @param fromDescrition
41  	 */
42  	public OriginDataSource(BDdescription fromDescrition) {
43  		super(fromDescrition);
44  	}
45  	
46  	/**
47  	 * Retorna um Tabela l�gica contendo na os metadados e os dados
48  	 * @return logicTable contendo os resultados como atributos.
49  	 */
50  	public LogicTable getData(){
51  		ResultSet rs;
52  		Statement stmt;
53  		LogicTable results = new LogicTable();
54  		Vector nomeColunas = null;
55  		Vector linhas = null;
56  		try {
57  			stmt = dbConnection.createStatement();
58  			rs = stmt.executeQuery("select * from " + originDescription.getTableName());
59  			
60  			nomeColunas = new Vector();
61  			linhas = new Vector();
62  			ResultSetMetaData rsmd = rs.getMetaData();
63  
64  			for (int i =1; i <= rsmd.getColumnCount(); ++i)	           
65  				nomeColunas.addElement(rsmd.getColumnName(i));
66  			while (rs.next()){
67  				linhas.addElement(getProximaLinha(rs, nomeColunas));
68  			}
69  		} catch (SQLException e) {
70  			e.printStackTrace();
71  		}
72  		
73  		results.setNomeColunas(nomeColunas);
74  		results.setLinhas(linhas);
75  		
76  		return results;
77  	}
78  	
79  	public String toString(){
80  		return "OriginDataSource";
81  	}
82  
83  	public Collection getDataTable() throws DataSourceException, igis.datasources.DataSourceException {
84  		return null;
85  	}
86  }