1
2
3
4 package migratool.datasources;
5
6 import java.sql.Connection;
7 import java.sql.ResultSet;
8 import java.sql.ResultSetMetaData;
9 import java.sql.SQLException;
10 import java.sql.Statement;
11 import java.util.Collection;
12 import java.util.Iterator;
13 import java.util.Vector;
14
15 import migratool.access.Connector;
16 import migratool.model.BDdescription;
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public abstract class AbstractOriginDataSource {
44
45 protected Connector dbAccess;
46 protected Connection dbConnection;
47 protected BDdescription originDescription;
48
49
50
51
52 public AbstractOriginDataSource(BDdescription fromDescrition) {
53 this.originDescription = fromDescrition;
54 dbAccess = Connector.getInstance();
55 dbConnection = dbAccess.getConnection(originDescription);
56 }
57
58 public boolean testDataBase() {
59 boolean success = true;
60 ResultSet rs = null;
61 Statement stmt = null;
62 if (dbConnection == null)
63 success = false;
64
65 try {
66 stmt = dbConnection.createStatement();
67 rs =
68 stmt.executeQuery(
69 "select * from " + originDescription.getTableName());
70 } catch (SQLException e) {
71 e.printStackTrace();
72 success = false;
73 }
74 if (rs == null)
75 success = false;
76
77 try {
78 rs.close();
79 stmt.close();
80 } catch (SQLException e1) {
81 e1.printStackTrace();
82 success = false;
83 }
84
85 return success;
86 }
87
88
89
90
91 public abstract LogicTable getData();
92
93
94
95
96
97 public abstract Collection getDataTable() throws DataSourceException, igis.datasources.DataSourceException;
98
99 protected static Vector getProximaLinha(ResultSet rs, Vector rsmd)
100 throws SQLException {
101 Vector linhaCorrente = new Vector();
102
103 Iterator itRsmd = rsmd.iterator();
104 while (itRsmd.hasNext()) {
105 linhaCorrente.addElement(rs.getObject((String) itRsmd.next()));
106 }
107 return linhaCorrente;
108 }
109
110
111
112
113 public void closeConnection() throws SQLException {
114 dbConnection.close();
115 }
116
117 public ResultSetMetaData getTableMetaData() {
118 ResultSet rs = null;
119 Statement stmt = null;
120 ResultSetMetaData rsmd = null;
121
122 try {
123 stmt = dbConnection.createStatement();
124 rs =
125 stmt.executeQuery(
126 "select * from " + originDescription.getTableName());
127 rsmd = rs.getMetaData();
128 } catch (SQLException e) {
129 e.printStackTrace();
130 }
131 return rsmd;
132 }
133
134 }