svn-gvsig-desktop / trunk / libraries / libGDBMS / src / main / java / com / hardcode / gdbms / driver / postgresql / PostgreSQLDriver.java @ 4851
History | View | Annotate | Download (6.98 KB)
1 |
package com.hardcode.gdbms.driver.postgresql; |
---|---|
2 |
|
3 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
4 |
import com.hardcode.gdbms.engine.data.db.JDBCSupport; |
5 |
import com.hardcode.gdbms.engine.data.driver.AlphanumericDBDriver; |
6 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
7 |
import com.hardcode.gdbms.engine.values.Value; |
8 |
|
9 |
import java.sql.Connection; |
10 |
import java.sql.Date; |
11 |
import java.sql.DriverManager; |
12 |
import java.sql.SQLException; |
13 |
import java.sql.Time; |
14 |
import java.sql.Timestamp; |
15 |
|
16 |
import java.util.HashMap; |
17 |
|
18 |
|
19 |
/**
|
20 |
*
|
21 |
*/
|
22 |
public class PostgreSQLDriver implements AlphanumericDBDriver { |
23 |
private static Exception driverException; |
24 |
|
25 |
static {
|
26 |
try {
|
27 |
Class.forName("org.postgresql.Driver").newInstance(); |
28 |
} catch (Exception ex) { |
29 |
driverException = ex; |
30 |
} |
31 |
} |
32 |
|
33 |
protected JDBCSupport jdbcSupport;
|
34 |
|
35 |
/**
|
36 |
* DOCUMENT ME!
|
37 |
*
|
38 |
* @param host DOCUMENT ME!
|
39 |
* @param port DOCUMENT ME!
|
40 |
* @param dbName DOCUMENT ME!
|
41 |
* @param user DOCUMENT ME!
|
42 |
* @param password DOCUMENT ME!
|
43 |
*
|
44 |
* @return DOCUMENT ME!
|
45 |
*
|
46 |
* @throws SQLException
|
47 |
* @throws RuntimeException DOCUMENT ME!
|
48 |
*
|
49 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#connect(java.lang.String)
|
50 |
*/
|
51 |
public Connection getConnection(String host, int port, String dbName, |
52 |
String user, String password) throws SQLException { |
53 |
if (driverException != null) { |
54 |
throw new RuntimeException(driverException); |
55 |
} |
56 |
|
57 |
String connectionString = "jdbc:postgresql://" + host; |
58 |
|
59 |
if (port != -1) { |
60 |
connectionString += (":" + port);
|
61 |
} |
62 |
|
63 |
connectionString += ("/" + dbName);
|
64 |
|
65 |
if (user != null) { |
66 |
connectionString += ("?user=" + user + "&password=" + password); |
67 |
} |
68 |
|
69 |
return DriverManager.getConnection(connectionString); |
70 |
} |
71 |
|
72 |
/**
|
73 |
* @see com.hardcode.driverManager.Driver#getName()
|
74 |
*/
|
75 |
public String getName() { |
76 |
return "postgresql"; |
77 |
} |
78 |
|
79 |
/**
|
80 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#executeSQL(java.sql.Connection,
|
81 |
* java.lang.String)
|
82 |
*/
|
83 |
public void open(Connection con, String sql) throws SQLException { |
84 |
jdbcSupport = JDBCSupport.newJDBCSupport(con, sql); |
85 |
} |
86 |
|
87 |
/**
|
88 |
* DOCUMENT ME!
|
89 |
*
|
90 |
* @return DOCUMENT ME!
|
91 |
*
|
92 |
* @throws DriverException DOCUMENT ME!
|
93 |
*/
|
94 |
public int getFieldCount() throws DriverException { |
95 |
return jdbcSupport.getFieldCount();
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* DOCUMENT ME!
|
100 |
*
|
101 |
* @param fieldId DOCUMENT ME!
|
102 |
*
|
103 |
* @return DOCUMENT ME!
|
104 |
*
|
105 |
* @throws DriverException DOCUMENT ME!
|
106 |
*/
|
107 |
public String getFieldName(int fieldId) throws DriverException { |
108 |
return jdbcSupport.getFieldName(fieldId);
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* DOCUMENT ME!
|
113 |
*
|
114 |
* @param i DOCUMENT ME!
|
115 |
*
|
116 |
* @return DOCUMENT ME!
|
117 |
*
|
118 |
* @throws DriverException DOCUMENT ME!
|
119 |
*/
|
120 |
public int getFieldType(int i) throws DriverException { |
121 |
return jdbcSupport.getFieldType(i);
|
122 |
} |
123 |
|
124 |
/**
|
125 |
* DOCUMENT ME!
|
126 |
*
|
127 |
* @param rowIndex DOCUMENT ME!
|
128 |
* @param fieldId DOCUMENT ME!
|
129 |
*
|
130 |
* @return DOCUMENT ME!
|
131 |
*
|
132 |
* @throws DriverException DOCUMENT ME!
|
133 |
*/
|
134 |
public Value getFieldValue(long rowIndex, int fieldId) |
135 |
throws DriverException {
|
136 |
return jdbcSupport.getFieldValue(rowIndex, fieldId);
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* DOCUMENT ME!
|
141 |
*
|
142 |
* @return DOCUMENT ME!
|
143 |
*
|
144 |
* @throws DriverException DOCUMENT ME!
|
145 |
*/
|
146 |
public long getRowCount() throws DriverException { |
147 |
return jdbcSupport.getRowCount();
|
148 |
} |
149 |
|
150 |
/**
|
151 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#close()
|
152 |
*/
|
153 |
public void close() throws SQLException { |
154 |
jdbcSupport.close(); |
155 |
} |
156 |
|
157 |
/**
|
158 |
* @see com.hardcode.gdbms.engine.data.driver.DriverCommons#getDriverProperties()
|
159 |
*/
|
160 |
public HashMap getDriverProperties() { |
161 |
return null; |
162 |
} |
163 |
|
164 |
/**
|
165 |
* @see com.hardcode.gdbms.engine.data.driver.DriverCommons#setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory)
|
166 |
*/
|
167 |
public void setDataSourceFactory(DataSourceFactory dsf) { |
168 |
} |
169 |
|
170 |
/**
|
171 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#execute(java.sql.Connection,
|
172 |
* java.lang.String, com.hardcode.gdbms.engine.data.HasProperties)
|
173 |
*/
|
174 |
public void execute(Connection con, String sql) throws SQLException { |
175 |
JDBCSupport.execute(con, sql); |
176 |
} |
177 |
|
178 |
/**
|
179 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#getInternalTableName(java.lang.String)
|
180 |
*/
|
181 |
public String getInternalTableName(String tableName) { |
182 |
return tableName;
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#getStatementString(long)
|
187 |
*/
|
188 |
public String getStatementString(long i) { |
189 |
// TODO Auto-generated method stub
|
190 |
return null; |
191 |
} |
192 |
|
193 |
/**
|
194 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#getStatementString(int,
|
195 |
* int)
|
196 |
*/
|
197 |
public String getStatementString(int i, int sqlType) { |
198 |
// TODO Auto-generated method stub
|
199 |
return null; |
200 |
} |
201 |
|
202 |
/**
|
203 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#getStatementString(double,
|
204 |
* int)
|
205 |
*/
|
206 |
public String getStatementString(double d, int sqlType) { |
207 |
// TODO Auto-generated method stub
|
208 |
return null; |
209 |
} |
210 |
|
211 |
/**
|
212 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#getStatementString(java.lang.String,
|
213 |
* int)
|
214 |
*/
|
215 |
public String getStatementString(String str, int sqlType) { |
216 |
// TODO Auto-generated method stub
|
217 |
return null; |
218 |
} |
219 |
|
220 |
/**
|
221 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#getStatementString(java.sql.Date)
|
222 |
*/
|
223 |
public String getStatementString(Date d) { |
224 |
// TODO Auto-generated method stub
|
225 |
return null; |
226 |
} |
227 |
|
228 |
/**
|
229 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#getStatementString(java.sql.Time)
|
230 |
*/
|
231 |
public String getStatementString(Time t) { |
232 |
// TODO Auto-generated method stub
|
233 |
return null; |
234 |
} |
235 |
|
236 |
/**
|
237 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#getStatementString(java.sql.Timestamp)
|
238 |
*/
|
239 |
public String getStatementString(Timestamp ts) { |
240 |
// TODO Auto-generated method stub
|
241 |
return null; |
242 |
} |
243 |
|
244 |
/**
|
245 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#getStatementString(byte[])
|
246 |
*/
|
247 |
public String getStatementString(byte[] binary) { |
248 |
// TODO Auto-generated method stub
|
249 |
return null; |
250 |
} |
251 |
|
252 |
/**
|
253 |
* @see com.hardcode.gdbms.engine.data.driver.DBDriver#getStatementString(boolean)
|
254 |
*/
|
255 |
public String getStatementString(boolean b) { |
256 |
// TODO Auto-generated method stub
|
257 |
return null; |
258 |
} |
259 |
|
260 |
/**
|
261 |
* @see com.hardcode.gdbms.engine.values.ValueWriter#getNullStatementString()
|
262 |
*/
|
263 |
public String getNullStatementString() { |
264 |
return null; |
265 |
} |
266 |
public int getFieldWidth(int i) throws DriverException { |
267 |
return jdbcSupport.getFieldWidth(i);
|
268 |
} |
269 |
} |