Statistics
| Revision:

root / branches / v10 / extensions / extOracleSpatial / src / es / prodevelop / cit / gvsig / jdbc_spatial / JDBCLayerBuilder.java @ 13996

History | View | Annotate | Download (3.6 KB)

1 13991 jldominguez@prodevelop.es
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Prodevelop Integraci?n de Tecnolog?as SL
34
 *   Conde Salvatierra de ?lava , 34-10
35
 *   46004 Valencia
36
 *   Spain
37
 *
38
 *   +34 963 510 612
39
 *   +34 963 510 968
40
 *   gis@prodevelop.es
41
 *   http://www.prodevelop.es
42
 */
43
package es.prodevelop.cit.gvsig.jdbc_spatial;
44
45
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition;
46
import com.iver.cit.gvsig.fmap.drivers.jdbc.postgis.PostGisDriver;
47
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
48
49
import com.iver.utiles.extensionPoints.IExtensionBuilder;
50
51
import java.sql.Connection;
52
import java.sql.DriverManager;
53
import java.sql.SQLException;
54
55
import java.util.Map;
56
57
58
/**
59
 * Creates a Postgis FLyrVect from a set of params
60
 * (URL, user name, password, ...). The catalog
61
 * extension uses this class to load a new layer
62
 * from a metadata.
63
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
64
 */
65
public class JDBCLayerBuilder implements IExtensionBuilder {
66
    public JDBCLayerBuilder() {
67
        super();
68
    }
69
70
    public Object create() {
71
        // TODO Auto-generated method stub
72
        return null;
73
    }
74
75
    public Object create(Object[] args) {
76
        // TODO Auto-generated method stub
77
        return null;
78
    }
79
80
    public Object create(Map args) {
81
        String dbURL = (String) args.get("DBURL");
82
        String user = (String) args.get((String) "USER");
83
        String pwd = (String) args.get((String) "PASSWORD");
84
        String layerName = (String) args.get((String) "NAME");
85
        String fidField = (String) args.get((String) "ID");
86
        String sFields = (String) args.get((String) "FIELDS");
87
        String[] fields = sFields.split(",");
88
        String geomField = (String) args.get((String) "GEOMFIELD");
89
        String tableName = (String) args.get((String) "TABLENAME");
90
        String whereClause = (String) args.get((String) "WHERECLAUSE");
91
92
        Connection conn;
93
94
        try {
95
            conn = DriverManager.getConnection(dbURL, user, pwd);
96
            conn.setAutoCommit(false);
97
        }
98
        catch (SQLException e) {
99
            // TODO Auto-generated catch block
100
            e.printStackTrace();
101
102
            return null;
103
        }
104
105
        DBLayerDefinition lyrDef = new DBLayerDefinition();
106
        lyrDef.setName(layerName);
107
        lyrDef.setTableName(tableName);
108
        lyrDef.setWhereClause(whereClause);
109
        lyrDef.setFieldNames(fields);
110
        lyrDef.setFieldGeometry(geomField);
111
        lyrDef.setFieldID(fidField);
112
113
        PostGisDriver pgd = new PostGisDriver();
114
        pgd.setData(conn, lyrDef);
115
116
        return LayerFactory.createDBLayer(pgd, layerName, null);
117
    }
118
}