root / tags / v1_0_2_Build_916 / extensions / extJDBC / src / com / iver / cit / gvsig / jdbc_spatial / JDBCLayerBuilder.java @ 12327
History | View | Annotate | Download (3.8 KB)
1 | 4797 | jorpiell | package com.iver.cit.gvsig.jdbc_spatial; |
---|---|---|---|
2 | |||
3 | import java.sql.Connection; |
||
4 | import java.sql.DriverManager; |
||
5 | import java.sql.SQLException; |
||
6 | import java.util.Map; |
||
7 | |||
8 | import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
||
9 | import com.iver.cit.gvsig.fmap.drivers.jdbc.postgis.PostGisDriver; |
||
10 | import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
||
11 | import com.iver.utiles.extensionPoints.IExtensionBuilder; |
||
12 | |||
13 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
14 | *
|
||
15 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
16 | *
|
||
17 | * This program is free software; you can redistribute it and/or
|
||
18 | * modify it under the terms of the GNU General Public License
|
||
19 | * as published by the Free Software Foundation; either version 2
|
||
20 | * of the License, or (at your option) any later version.
|
||
21 | *
|
||
22 | * This program is distributed in the hope that it will be useful,
|
||
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
25 | * GNU General Public License for more details.
|
||
26 | *
|
||
27 | * You should have received a copy of the GNU General Public License
|
||
28 | * along with this program; if not, write to the Free Software
|
||
29 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
30 | *
|
||
31 | * For more information, contact:
|
||
32 | *
|
||
33 | * Generalitat Valenciana
|
||
34 | * Conselleria d'Infraestructures i Transport
|
||
35 | * Av. Blasco Ib??ez, 50
|
||
36 | * 46010 VALENCIA
|
||
37 | * SPAIN
|
||
38 | *
|
||
39 | * +34 963862235
|
||
40 | * gvsig@gva.es
|
||
41 | * www.gvsig.gva.es
|
||
42 | *
|
||
43 | * or
|
||
44 | *
|
||
45 | * IVER T.I. S.A
|
||
46 | * Salamanca 50
|
||
47 | * 46005 Valencia
|
||
48 | * Spain
|
||
49 | *
|
||
50 | * +34 963163400
|
||
51 | * dac@iver.es
|
||
52 | */
|
||
53 | /* CVS MESSAGES:
|
||
54 | *
|
||
55 | * $Id$
|
||
56 | * $Log$
|
||
57 | 10271 | jmvivo | * Revision 1.2.4.3 2007-02-12 14:35:52 jmvivo
|
58 | * Quitado el soporte para Oracle spacial
|
||
59 | 10047 | fjp | *
|
60 | * Revision 1.2 2006/04/18 06:19:06 jorpiell
|
||
61 | 4842 | jorpiell | * Modificada la forma en la que se a?ade la clase que implementa la factor?a. Se tiene que pasar una instancia, y no una clase. Adem?s se la ha a?adido un constructor sin par?metros a la factoria.
|
62 | *
|
||
63 | * Revision 1.1 2006/04/11 11:54:38 jorpiell
|
||
64 | 4797 | jorpiell | * Nueva clase que se usa para cargar una capa Postgis usando el mecanismo de extensibilidad
|
65 | *
|
||
66 | *
|
||
67 | */
|
||
68 | /**
|
||
69 | * Creates a Postgis FLyrVect from a set of params
|
||
70 | * (URL, user name, password, ...). The catalog
|
||
71 | * extension uses this class to load a new layer
|
||
72 | * from a metadata.
|
||
73 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
74 | */
|
||
75 | public class JDBCLayerBuilder implements IExtensionBuilder{ |
||
76 | |||
77 | 4842 | jorpiell | public JDBCLayerBuilder(){
|
78 | super();
|
||
79 | } |
||
80 | |||
81 | 4797 | jorpiell | public Object create() { |
82 | // TODO Auto-generated method stub
|
||
83 | return null; |
||
84 | } |
||
85 | |||
86 | public Object create(Object[] args) { |
||
87 | // TODO Auto-generated method stub
|
||
88 | return null; |
||
89 | } |
||
90 | |||
91 | public Object create(Map args) { |
||
92 | String dbURL = (String) args.get("DBURL"); |
||
93 | String user = (String) args.get((String) "USER"); |
||
94 | String pwd = (String) args.get((String) "PASSWORD"); |
||
95 | String layerName = (String) args.get((String) "NAME"); |
||
96 | String fidField = (String) args.get((String) "ID"); |
||
97 | String sFields = (String) args.get((String) "FIELDS"); |
||
98 | String[] fields = sFields.split(","); |
||
99 | String geomField = (String) args.get((String) "GEOMFIELD"); |
||
100 | String tableName = (String) args.get((String) "TABLENAME"); |
||
101 | String whereClause = (String) args.get((String) "WHERECLAUSE"); |
||
102 | |||
103 | |||
104 | Connection conn;
|
||
105 | try {
|
||
106 | conn = DriverManager.getConnection(dbURL, user, pwd);
|
||
107 | conn.setAutoCommit(false);
|
||
108 | } catch (SQLException e) { |
||
109 | // TODO Auto-generated catch block
|
||
110 | e.printStackTrace(); |
||
111 | return null; |
||
112 | } |
||
113 | |||
114 | |||
115 | DBLayerDefinition lyrDef = new DBLayerDefinition();
|
||
116 | lyrDef.setName(layerName); |
||
117 | lyrDef.setTableName(tableName); |
||
118 | lyrDef.setWhereClause(whereClause); |
||
119 | lyrDef.setFieldNames(fields); |
||
120 | lyrDef.setFieldGeometry(geomField); |
||
121 | lyrDef.setFieldID(fidField); |
||
122 | |||
123 | PostGisDriver pgd = new PostGisDriver();
|
||
124 | pgd.setData(conn, lyrDef); |
||
125 | |||
126 | return LayerFactory.createDBLayer(pgd, layerName, null); |
||
127 | |||
128 | } |
||
129 | |||
130 | } |