root / branches / v10 / extensions / extPublish / src / org / gvsig / publish / infoProject / datasources / PostGISTableInfo.java @ 13962
History | View | Annotate | Download (3.81 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004-2006 IVER T.I. 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 Iba?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 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.publish.infoProject.datasources; |
42 |
|
43 |
import java.sql.SQLException; |
44 |
|
45 |
|
46 |
import com.iver.cit.gvsig.fmap.core.FShape; |
47 |
import com.iver.cit.gvsig.fmap.drivers.ConnectionJDBC; |
48 |
import com.iver.cit.gvsig.fmap.drivers.DBException; |
49 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
50 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.postgis.PostGisDriver; |
51 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
52 |
|
53 |
public class PostGISTableInfo implements IDataBaseInfo, IVectorialDSInfo { |
54 |
private VectorialAdapter adapter = null; |
55 |
private PostGisDriver driver = null; |
56 |
private ConnectionJDBC connection = null; |
57 |
/**
|
58 |
* Constructor
|
59 |
* @param vectorialAdapter The adapter from gvSIG
|
60 |
*/
|
61 |
public PostGISTableInfo(VectorialAdapter vectorialAdapter) {
|
62 |
this.adapter = vectorialAdapter;
|
63 |
this.driver = (PostGisDriver) vectorialAdapter.getDriver();
|
64 |
this.connection = (ConnectionJDBC) driver.getConnection();
|
65 |
} |
66 |
/**
|
67 |
* @return datasource type, SHAPEFILE, POSTGIS_TABLE, ...
|
68 |
* @see IVectorialDSInfo
|
69 |
*/
|
70 |
public String getDataSourceType() { |
71 |
return IVectorialDSInfo.POSTGIS_TABLE;
|
72 |
} |
73 |
/**
|
74 |
* @return Geometry type of the table, POINT, POLYGON, ...
|
75 |
* @see IVectorialDSInfo
|
76 |
* TODO: Always returns MULTI !! I must do a query in table geometry_columns
|
77 |
* TODO: Exceptions
|
78 |
*/
|
79 |
public String getGeomType() { |
80 |
|
81 |
//int kk = ((ISpatialDB)adapter).getLyrDef().getShapeType();
|
82 |
try {
|
83 |
switch (adapter.getShapeType()){
|
84 |
case FShape.POINT:
|
85 |
return IVectorialDSInfo.POINT;
|
86 |
case FShape.POLYGON:
|
87 |
return IVectorialDSInfo.POLYGON;
|
88 |
case FShape.LINE:
|
89 |
return IVectorialDSInfo.LINE;
|
90 |
case FShape.MULTI:
|
91 |
return IVectorialDSInfo.MULTIGEOM;
|
92 |
} |
93 |
} catch (DriverIOException e) {
|
94 |
// TODO Auto-generated catch block
|
95 |
e.printStackTrace(); |
96 |
} |
97 |
return null; |
98 |
} |
99 |
/**
|
100 |
*
|
101 |
* @return connection host
|
102 |
* TODO: I think is not good idea to parse the URL with splits ...
|
103 |
* Exceptions
|
104 |
*/
|
105 |
public String getHost() { |
106 |
try {
|
107 |
String aux = connection.getURL().split("//")[1]; |
108 |
return aux.split(":")[0]; |
109 |
} catch (DBException e) {
|
110 |
// TODO Auto-generated catch block
|
111 |
e.printStackTrace(); |
112 |
} |
113 |
return null; |
114 |
} |
115 |
/**
|
116 |
* @return connection port
|
117 |
*/
|
118 |
public int getPort() { |
119 |
return driver.getDefaultPort();
|
120 |
} |
121 |
/**
|
122 |
* Gets the user of the connection
|
123 |
* @return connection user
|
124 |
* TODO: Exceptions ...
|
125 |
*/
|
126 |
public String getUser() { |
127 |
try {
|
128 |
return connection.getConnection().getMetaData().getUserName();
|
129 |
} catch (SQLException e) { |
130 |
// TODO Auto-generated catch block
|
131 |
e.printStackTrace(); |
132 |
} |
133 |
return null; |
134 |
} |
135 |
/**
|
136 |
* At the moment I can't know the password !
|
137 |
* @return
|
138 |
*/
|
139 |
public String getPassword(){ |
140 |
|
141 |
return null; |
142 |
} |
143 |
} |