01: package com.vividsolutions.jump.datastore.postgis;
02:
03: import java.sql.*;
04:
05: import com.vividsolutions.jump.datastore.*;
06:
07: import com.vividsolutions.jump.parameter.ParameterList;
08: import com.vividsolutions.jump.parameter.ParameterListSchema;
09:
10: import org.postgresql.PGConnection;
11:
12: /**
13: * A driver for supplying {@link PostgisDSConnection}s
14: */
15: public class PostgisDataStoreDriver implements DataStoreDriver {
16: public static final String DRIVER_NAME = "PostGIS";
17: public static final String JDBC_CLASS = "org.postgresql.Driver";
18: public static final String URL_PREFIX = "jdbc:postgresql://";
19:
20: public static final String PARAM_Server = "Server";
21: public static final String PARAM_Port = "Port";
22: public static final String PARAM_Instance = "Instance";
23: public static final String PARAM_User = "User";
24: public static final String PARAM_Password = "Password";
25:
26: private static final String[] paramNames = new String[] {
27: PARAM_Server, PARAM_Port, PARAM_Instance, PARAM_User,
28: PARAM_Password };
29: private static final Class[] paramClasses = new Class[] {
30: String.class, Integer.class, String.class, String.class,
31: String.class };
32: private final ParameterListSchema schema = new ParameterListSchema(
33: paramNames, paramClasses);;
34:
35: public PostgisDataStoreDriver() {
36: }
37:
38: public String getName() {
39: return DRIVER_NAME;
40: }
41:
42: public ParameterListSchema getParameterListSchema() {
43: return schema;
44: }
45:
46: public DataStoreConnection createConnection(ParameterList params)
47: throws Exception {
48: String host = params.getParameterString(PARAM_Server);
49: int port = params.getParameterInt(PARAM_Port);
50: String database = params.getParameterString(PARAM_Instance);
51: String user = params.getParameterString(PARAM_User);
52: String password = params.getParameterString(PARAM_Password);
53:
54: String url = String.valueOf(new StringBuffer(URL_PREFIX)
55: .append(host).append(":").append(port).append("/")
56: .append(database));
57:
58: Driver driver = (Driver) Class.forName(JDBC_CLASS)
59: .newInstance();
60: DriverManager.registerDriver(driver);
61:
62: Connection conn = DriverManager.getConnection(url, user,
63: password);
64: return new PostgisDSConnection(conn);
65: }
66:
67: public boolean isAdHocQuerySupported() {
68: return true;
69: }
70:
71: }
|