Revision 37
tags/org.gvsig.postgresql-2.0.17/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/buildNumber.properties | ||
---|---|---|
1 |
#Tue Oct 08 20:52:46 CEST 2013 |
|
2 |
buildNumber=2073 |
tags/org.gvsig.postgresql-2.0.17/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/resources-plugin/config.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<plugin-config> |
|
3 |
<libraries library-dir="lib/"/> |
|
4 |
<depends plugin-name="org.gvsig.app"/> |
|
5 |
<resourceBundle name="text"/> |
|
6 |
<extensions> |
|
7 |
<extension class-name="org.gvsig.andami.LibraryExtension" active="false"/> |
|
8 |
</extensions> |
|
9 |
</plugin-config> |
tags/org.gvsig.postgresql-2.0.17/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<assembly> |
|
2 |
<id>gvsig-plugin-package</id> |
|
3 |
<formats> |
|
4 |
<format>zip</format> |
|
5 |
</formats> |
|
6 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
7 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
8 |
<files> |
|
9 |
<file> |
|
10 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
11 |
<outputDirectory>lib</outputDirectory> |
|
12 |
</file> |
|
13 |
<file> |
|
14 |
<source>target/package.info</source> |
|
15 |
</file> |
|
16 |
</files> |
|
17 |
|
|
18 |
<fileSets> |
|
19 |
<fileSet> |
|
20 |
<directory>src/main/resources-plugin</directory> |
|
21 |
<outputDirectory>.</outputDirectory> |
|
22 |
</fileSet> |
|
23 |
</fileSets> |
|
24 |
|
|
25 |
<dependencySets> |
|
26 |
|
|
27 |
<dependencySet> |
|
28 |
<useProjectArtifact>false</useProjectArtifact> |
|
29 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
30 |
<outputDirectory>lib</outputDirectory> |
|
31 |
<includes> |
|
32 |
<include>org.gvsig:org.gvsig.postgresql.provider</include> |
|
33 |
</includes> |
|
34 |
</dependencySet> |
|
35 |
|
|
36 |
<dependencySet> |
|
37 |
<useProjectArtifact>false</useProjectArtifact> |
|
38 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
39 |
<outputDirectory>lib</outputDirectory> |
|
40 |
<includes> |
|
41 |
<include>postgresql:postgresql</include> |
|
42 |
<include>commons-dbcp:commons-dbcp</include> |
|
43 |
<include>commons-collections:commons-collections</include> |
|
44 |
<include>commons-pool:commons-pool</include> |
|
45 |
</includes> |
|
46 |
</dependencySet> |
|
47 |
|
|
48 |
</dependencySets> |
|
49 |
|
|
50 |
</assembly> |
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
tags/org.gvsig.postgresql-2.0.17/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.postgresql.app.mainplugin</artifactId> |
|
7 |
<packaging>jar</packaging> |
|
8 |
<name>Formats: PostgreSQL support</name> |
|
9 |
<description>PostgreSQL file format support</description> |
|
10 |
|
|
11 |
<parent> |
|
12 |
<groupId>org.gvsig</groupId> |
|
13 |
<artifactId>org.gvsig.postgresql.app</artifactId> |
|
14 |
<version>2.0.17</version> |
|
15 |
</parent> |
|
16 |
|
|
17 |
<dependencies> |
|
18 |
<dependency> |
|
19 |
<groupId>org.gvsig</groupId> |
|
20 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
21 |
<scope>compile</scope> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>org.gvsig</groupId> |
|
25 |
<artifactId>org.gvsig.andami</artifactId> |
|
26 |
<scope>compile</scope> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>org.gvsig</groupId> |
|
30 |
<artifactId>org.gvsig.postgresql.provider</artifactId> |
|
31 |
<scope>compile</scope> |
|
32 |
</dependency> |
|
33 |
|
|
34 |
<dependency> |
|
35 |
<groupId>postgresql</groupId> |
|
36 |
<artifactId>postgresql</artifactId> |
|
37 |
<scope>runtime</scope> |
|
38 |
</dependency> |
|
39 |
<dependency> |
|
40 |
<groupId>commons-dbcp</groupId> |
|
41 |
<artifactId>commons-dbcp</artifactId> |
|
42 |
<scope>runtime</scope> |
|
43 |
</dependency> |
|
44 |
<dependency> |
|
45 |
<groupId>commons-collections</groupId> |
|
46 |
<artifactId>commons-collections</artifactId> |
|
47 |
<scope>runtime</scope> |
|
48 |
</dependency> |
|
49 |
<dependency> |
|
50 |
<groupId>commons-pool</groupId> |
|
51 |
<artifactId>commons-pool</artifactId> |
|
52 |
<scope>runtime</scope> |
|
53 |
</dependency> |
|
54 |
|
|
55 |
</dependencies> |
|
56 |
|
|
57 |
<properties> |
|
58 |
<!-- Package info property values --> |
|
59 |
<!-- Default values in org.gvsig.desktop --> |
|
60 |
<gvsig.package.info.state>testing</gvsig.package.info.state> |
|
61 |
<gvsig.package.info.official>true</gvsig.package.info.official> |
|
62 |
<gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.0.1</gvsig.package.info.dependencies> |
|
63 |
<gvsig.package.info.categories>Formats,Vector,Database</gvsig.package.info.categories> |
|
64 |
<gvsig.package.info.poolURL>http://devel.gvsig.org/download/projects/gvsig-postgresql/pool/</gvsig.package.info.poolURL> |
|
65 |
</properties> |
|
66 |
|
|
67 |
|
|
68 |
</project> |
tags/org.gvsig.postgresql-2.0.17/org.gvsig.postgresql.app/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.postgresql.app</artifactId> |
|
7 |
<packaging>pom</packaging> |
|
8 |
<name>${project.artifactId}</name> |
|
9 |
<parent> |
|
10 |
<groupId>org.gvsig</groupId> |
|
11 |
<artifactId>org.gvsig.postgresql</artifactId> |
|
12 |
<version>2.0.17</version> |
|
13 |
</parent> |
|
14 |
|
|
15 |
<modules> |
|
16 |
<module>org.gvsig.postgresql.app.mainplugin</module> |
|
17 |
</modules> |
|
18 |
|
|
19 |
</project> |
tags/org.gvsig.postgresql-2.0.17/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.postgresql</artifactId> |
|
7 |
<version>2.0.17</version> |
|
8 |
<packaging>pom</packaging> |
|
9 |
<name>${project.artifactId}</name> |
|
10 |
<description>PostgreSQL support fort DAL and gvSIG</description> |
|
11 |
<parent> |
|
12 |
<groupId>org.gvsig</groupId> |
|
13 |
<artifactId>org.gvsig.desktop</artifactId> |
|
14 |
<version>2.0.21</version> |
|
15 |
</parent> |
|
16 |
|
|
17 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-postgresql</url> |
|
18 |
<scm> |
|
19 |
<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-postgresql/tags/org.gvsig.postgresql-2.0.17</connection> |
|
20 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-postgresql/tags/org.gvsig.postgresql-2.0.17</developerConnection> |
|
21 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-postgresql/repository/show/tags/org.gvsig.postgresql-2.0.17</url> |
|
22 |
</scm> |
|
23 |
|
|
24 |
|
|
25 |
<build> |
|
26 |
<plugins> |
|
27 |
<plugin> |
|
28 |
<groupId>org.apache.maven.plugins</groupId> |
|
29 |
<artifactId>maven-release-plugin</artifactId> |
|
30 |
<configuration> |
|
31 |
<tagBase>https://devel.gvsig.org/svn/gvsig-postgresql/tags/</tagBase> |
|
32 |
<goals>deploy</goals> |
|
33 |
</configuration> |
|
34 |
</plugin> |
|
35 |
</plugins> |
|
36 |
</build> |
|
37 |
|
|
38 |
|
|
39 |
<dependencyManagement> |
|
40 |
<dependencies> |
|
41 |
<dependency> |
|
42 |
<groupId>org.gvsig</groupId> |
|
43 |
<artifactId>org.gvsig.postgresql.provider</artifactId> |
|
44 |
<version>2.0.17</version> |
|
45 |
</dependency> |
|
46 |
<dependency> |
|
47 |
<groupId>org.gvsig</groupId> |
|
48 |
<artifactId>org.gvsig.postgresql.app.mainplugin</artifactId> |
|
49 |
<version>2.0.17</version> |
|
50 |
</dependency> |
|
51 |
</dependencies> |
|
52 |
</dependencyManagement> |
|
53 |
|
|
54 |
<dependencies> |
|
55 |
<dependency> |
|
56 |
<groupId>org.slf4j</groupId> |
|
57 |
<artifactId>slf4j-api</artifactId> |
|
58 |
<scope>compile</scope> |
|
59 |
</dependency> |
|
60 |
</dependencies> |
|
61 |
|
|
62 |
|
|
63 |
<modules> |
|
64 |
<module>org.gvsig.postgresql.app</module> |
|
65 |
<module>org.gvsig.postgresql.provider</module> |
|
66 |
</modules> |
|
67 |
|
|
68 |
|
|
69 |
</project> |
tags/org.gvsig.postgresql-2.0.17/org.gvsig.postgresql.provider/src/test/java/org/gvsig/fmap/dal/store/postgresql/DatabaseMetadataChecks.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package org.gvsig.fmap.dal.store.postgresql; |
|
5 |
|
|
6 |
import java.sql.Connection; |
|
7 |
import java.sql.DatabaseMetaData; |
|
8 |
import java.sql.DriverManager; |
|
9 |
import java.sql.ResultSet; |
|
10 |
import java.sql.ResultSetMetaData; |
|
11 |
import java.sql.SQLException; |
|
12 |
|
|
13 |
/** |
|
14 |
* @author cordin |
|
15 |
* |
|
16 |
*/ |
|
17 |
public class DatabaseMetadataChecks { |
|
18 |
|
|
19 |
// Columns as specified by the DatabaseMetadata.getTables javadoc |
|
20 |
private static final String[] COLUMNS = new String[] { |
|
21 |
// Metadata resultset column names |
|
22 |
"TABLE_CAT", // String => table catalog (may be null) |
|
23 |
"TABLE_SCHEM", // String => table schema (may be null) |
|
24 |
"TABLE_NAME", // String => table name |
|
25 |
"TABLE_TYPE", // String => table type. Typical types are "TABLE", |
|
26 |
// "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", |
|
27 |
// "LOCAL TEMPORARY", "ALIAS", "SYNONYM". |
|
28 |
"REMARKS", // String => explanatory comment on the table |
|
29 |
"TYPE_CAT", // String => the types catalog (may be null) |
|
30 |
"TYPE_SCHEM", // String => the types schema (may be null) |
|
31 |
"TYPE_NAME", // String => type name (may be null) |
|
32 |
"SELF_REFERENCING_COL_NAME", // String => name of the designated |
|
33 |
// "identifier" column of a typed |
|
34 |
// table (may be null) |
|
35 |
"REF_GENERATION", // String => specifies how values in |
|
36 |
// SELF_REFERENCING_COL_NAME are created. Values |
|
37 |
// are "SYSTEM", "USER", "DERIVED". (may be |
|
38 |
// null) |
|
39 |
}; |
|
40 |
|
|
41 |
public void showTables() throws Exception { |
|
42 |
|
|
43 |
Connection conn = DriverManager.getConnection( |
|
44 |
"jdbc:postgresql://localhost/gvsigDB", "gvsig", "gvsig"); |
|
45 |
|
|
46 |
try { |
|
47 |
// Statement st = conn.createStatement(); |
|
48 |
// String sql = "select tablename from pg_tables"; |
|
49 |
// ResultSet result = st.executeQuery(sql); |
|
50 |
|
|
51 |
DatabaseMetaData metadata = conn.getMetaData(); |
|
52 |
ResultSet result = metadata.getTables(null, null, null, |
|
53 |
new String[] { "TABLE", "VIEW" }); |
|
54 |
ResultSetMetaData resultMD = result.getMetaData(); |
|
55 |
String[] columns = new String[resultMD.getColumnCount()]; |
|
56 |
for (int i = 0; i < columns.length; i++) { |
|
57 |
columns[i] = resultMD.getColumnName(i + 1); |
|
58 |
} |
|
59 |
|
|
60 |
for (int i = 0; i < columns.length; i++) { |
|
61 |
System.out.print(columns[i]); |
|
62 |
System.out.print(";"); |
|
63 |
} |
|
64 |
System.out.println(); |
|
65 |
while (result.next()) { |
|
66 |
|
|
67 |
for (int i = 0; i < columns.length; i++) { |
|
68 |
System.out.print(result.getString(columns[i])); |
|
69 |
System.out.print(";"); |
|
70 |
} |
|
71 |
System.out.println(); |
|
72 |
} |
|
73 |
|
|
74 |
} finally { |
|
75 |
try { |
|
76 |
conn.close(); |
|
77 |
} catch (SQLException e) { |
|
78 |
e.printStackTrace(); |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* @param args |
|
86 |
*/ |
|
87 |
public static void main(String[] args) { |
|
88 |
try { |
|
89 |
new DatabaseMetadataChecks().showTables(); |
|
90 |
} catch (Exception e) { |
|
91 |
e.printStackTrace(); |
|
92 |
System.exit(-1); |
|
93 |
} |
|
94 |
System.exit(0); |
|
95 |
} |
|
96 |
|
|
97 |
} |
tags/org.gvsig.postgresql-2.0.17/org.gvsig.postgresql.provider/src/test/java/org/gvsig/fmap/dal/store/postgresql/TestPostgreSQLWrite.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
*/ |
|
31 |
package org.gvsig.fmap.dal.store.postgresql; |
|
32 |
|
|
33 |
import java.util.Iterator; |
|
34 |
|
|
35 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
36 |
import org.gvsig.fmap.dal.exception.DataException; |
|
37 |
import org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore; |
|
38 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
39 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
40 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
41 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
42 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
43 |
import org.gvsig.fmap.dal.feature.FeatureStoreTransform; |
|
44 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
45 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
46 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer; |
|
47 |
import org.gvsig.fmap.geom.Geometry; |
|
48 |
import org.gvsig.fmap.geom.operation.towkt.ToWKT; |
|
49 |
import org.gvsig.tools.evaluator.Evaluator; |
|
50 |
import org.gvsig.tools.evaluator.EvaluatorData; |
|
51 |
import org.gvsig.tools.evaluator.EvaluatorException; |
|
52 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
/** |
|
57 |
* @author jmvivo |
|
58 |
* |
|
59 |
*/ |
|
60 |
// public class TestPostgreSQL extends BaseTestEditableFeatureStore { |
|
61 |
public class TestPostgreSQLWrite extends BaseTestEditableFeatureStore { |
|
62 |
|
|
63 |
|
|
64 |
private JDBCServerExplorer myExplorer; |
|
65 |
private PostgreSQLNewStoreParameters newParams; |
|
66 |
|
|
67 |
@Override |
|
68 |
protected void doSetUp() throws Exception { |
|
69 |
// Initialize wkt geom operation |
|
70 |
int wktCode = ToWKT.CODE; |
|
71 |
} |
|
72 |
|
|
73 |
public DataStoreParameters getDefaultDataStoreParameters() |
|
74 |
throws DataException { |
|
75 |
PostgreSQLStoreParameters pgParameters = null; |
|
76 |
pgParameters = (PostgreSQLStoreParameters) dataManager |
|
77 |
.createStoreParameters(PostgreSQLStoreProvider.NAME); |
|
78 |
|
|
79 |
pgParameters.setHost("localhost"); |
|
80 |
pgParameters.setUser("postgres"); |
|
81 |
pgParameters.setPassword("postgres"); |
|
82 |
pgParameters.setDBName("gis"); |
|
83 |
pgParameters.setTable("muni10000_peq"); |
|
84 |
|
|
85 |
return pgParameters; |
|
86 |
} |
|
87 |
|
|
88 |
public boolean hasExplorer() { |
|
89 |
return true; |
|
90 |
} |
|
91 |
|
|
92 |
public void testLoadMetadata() throws Exception { |
|
93 |
DataStoreParameters params = this.getDefaultDataStoreParameters(); |
|
94 |
|
|
95 |
FeatureStore store = null; |
|
96 |
store = (FeatureStore) dataManager.createStore(params); |
|
97 |
FeatureType fType = store.getDefaultFeatureType(); |
|
98 |
FeatureAttributeDescriptor geomAttr; |
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
if (fType.getDefaultGeometryAttributeIndex() >= 0) { |
|
103 |
assertNotNull(store.getEnvelope()); |
|
104 |
geomAttr = fType.getAttributeDescriptor(fType |
|
105 |
.getDefaultGeometryAttributeIndex()); |
|
106 |
assertTrue(geomAttr.getGeometryType() == Geometry.TYPES.MULTISURFACE); |
|
107 |
assertTrue(geomAttr.getGeometrySubType() == Geometry.SUBTYPES.GEOM2D); |
|
108 |
assertNotNull(store.getDynValue("CRS")); |
|
109 |
|
|
110 |
} |
|
111 |
|
|
112 |
} |
|
113 |
|
|
114 |
public void testCloserConnection() throws Exception { |
|
115 |
|
|
116 |
DataStoreParameters params = this.getDefaultDataStoreParameters(); |
|
117 |
|
|
118 |
FeatureStore store = null; |
|
119 |
store = (FeatureStore) dataManager.createStore(params); |
|
120 |
|
|
121 |
FeatureQuery query = store.createFeatureQuery(); |
|
122 |
|
|
123 |
query.getOrder().add("gid", true); |
|
124 |
|
|
125 |
query.setFilter(new Evaluator() { |
|
126 |
|
|
127 |
public Object evaluate(EvaluatorData data) |
|
128 |
throws EvaluatorException { |
|
129 |
// TODO Auto-generated method stub |
|
130 |
return Boolean.TRUE; |
|
131 |
} |
|
132 |
|
|
133 |
public String getSQL() { |
|
134 |
return "true = true"; |
|
135 |
} |
|
136 |
|
|
137 |
public String getDescription() { |
|
138 |
// TODO Auto-generated method stub |
|
139 |
return null; |
|
140 |
} |
|
141 |
|
|
142 |
public String getName() { |
|
143 |
return "AlwaysTrue"; |
|
144 |
} |
|
145 |
|
|
146 |
public EvaluatorFieldsInfo getFieldsInfo() { |
|
147 |
// TODO Auto-generated method stub |
|
148 |
return null; |
|
149 |
} |
|
150 |
|
|
151 |
}); |
|
152 |
|
|
153 |
FeatureStoreTransform transform = new StringsToLowerTransform(); |
|
154 |
transform.setFeatureStore(store); |
|
155 |
|
|
156 |
store.getTransforms().add(transform); |
|
157 |
|
|
158 |
transform = new StringsToLowerTransform(); |
|
159 |
transform.setFeatureStore(store); |
|
160 |
|
|
161 |
store.getTransforms().add(transform); |
|
162 |
|
|
163 |
transform = new StringsToLowerTransform(); |
|
164 |
transform.setFeatureStore(store); |
|
165 |
|
|
166 |
store.getTransforms().add(transform); |
|
167 |
|
|
168 |
for (int i = 0; i < 30; i++) { |
|
169 |
// this.fullStoreIteratorTest(store); |
|
170 |
|
|
171 |
this.testIterationFastAndStandart(store, query); |
|
172 |
} |
|
173 |
|
|
174 |
|
|
175 |
store.dispose(); |
|
176 |
|
|
177 |
} |
|
178 |
|
|
179 |
public boolean usesResources() { |
|
180 |
return true; |
|
181 |
} |
|
182 |
|
|
183 |
public NewFeatureStoreParameters getDefaultNewDataStoreParameters() |
|
184 |
throws Exception { |
|
185 |
PostgreSQLStoreParameters parameters = (PostgreSQLStoreParameters) this |
|
186 |
.getDefaultDataStoreParameters(); |
|
187 |
|
|
188 |
FeatureStore store = null; |
|
189 |
|
|
190 |
if (this.myExplorer == null) { |
|
191 |
store = (FeatureStore) dataManager.createStore(parameters); |
|
192 |
myExplorer = (JDBCServerExplorer) store.getExplorer(); |
|
193 |
} |
|
194 |
if (this.newParams == null) { |
|
195 |
if (store == null){ |
|
196 |
store = (FeatureStore) dataManager.createStore(parameters); |
|
197 |
} |
|
198 |
|
|
199 |
newParams = (PostgreSQLNewStoreParameters) myExplorer |
|
200 |
.getAddParameters(); |
|
201 |
|
|
202 |
newParams.setTable(parameters.getTable() + "_test"); |
|
203 |
FeatureType ftOrg = store.getDefaultFeatureType(); |
|
204 |
EditableFeatureType ftTrg = (EditableFeatureType) newParams |
|
205 |
.getDefaultFeatureType(); |
|
206 |
FeatureAttributeDescriptor org; |
|
207 |
EditableFeatureAttributeDescriptor trg; |
|
208 |
Iterator iter = ftOrg.iterator(); |
|
209 |
while (iter.hasNext()) { |
|
210 |
org = (FeatureAttributeDescriptor) iter.next(); |
|
211 |
trg = ftTrg.add(org.getName(), org.getType()); |
|
212 |
trg.setAllowNull(org.allowNull()); |
|
213 |
trg.setDefaultValue(org.getDefaultValue()); |
|
214 |
trg.setGeometrySubType(org.getGeometrySubType()); |
|
215 |
trg.setGeometryType(org.getGeometryType()); |
|
216 |
trg.setIsAutomatic(org.isAutomatic()); |
|
217 |
trg.setIsPrimaryKey(org.isPrimaryKey()); |
|
218 |
trg.setIsReadOnly(org.isReadOnly()); |
|
219 |
trg.setMaximumOccurrences(org.getMaximumOccurrences()); |
|
220 |
trg.setMinimumOccurrences(org.getMinimumOccurrences()); |
|
221 |
trg.setPrecision(org.getPrecision()); |
|
222 |
trg.setSize(org.getSize()); |
|
223 |
trg.setSRS(org.getSRS()); |
|
224 |
} |
|
225 |
ftTrg.setDefaultGeometryAttributeName(ftOrg |
|
226 |
.getDefaultGeometryAttributeName()); |
|
227 |
ftTrg.setHasOID(ftOrg.hasOID()); |
|
228 |
|
|
229 |
} |
|
230 |
if (store != null){ |
|
231 |
store.dispose(); |
|
232 |
} |
|
233 |
|
|
234 |
return this.newParams; |
|
235 |
} |
|
236 |
|
|
237 |
public boolean resourcesNotifyChanges() { |
|
238 |
return false; |
|
239 |
} |
|
240 |
} |
tags/org.gvsig.postgresql-2.0.17/org.gvsig.postgresql.provider/src/test/java/org/gvsig/fmap/dal/store/postgresql/TestReadAndWriteGeom.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.store.postgresql; |
|
29 |
|
|
30 |
import java.sql.Connection; |
|
31 |
import java.sql.DriverManager; |
|
32 |
import java.sql.PreparedStatement; |
|
33 |
import java.sql.ResultSet; |
|
34 |
import java.sql.SQLException; |
|
35 |
import java.sql.Statement; |
|
36 |
import java.text.MessageFormat; |
|
37 |
|
|
38 |
import org.gvsig.fmap.geom.Geometry; |
|
39 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
40 |
import org.gvsig.fmap.geom.GeometryManager; |
|
41 |
import org.gvsig.fmap.geom.operation.fromwkb.FromWKB; |
|
42 |
import org.gvsig.fmap.geom.operation.fromwkb.FromWKBGeometryOperationContext; |
|
43 |
import org.gvsig.fmap.geom.operation.towkb.ToWKB; |
|
44 |
import org.gvsig.fmap.geom.operation.towkt.ToWKT; |
|
45 |
import org.gvsig.fmap.geom.primitive.impl.Point2D; |
|
46 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
47 |
|
|
48 |
public class TestReadAndWriteGeom extends AbstractLibraryAutoInitTestCase { |
|
49 |
private static final int FEATURES_TO_INSERT = 12000; |
|
50 |
private static final String TABLE_NAME_INSERT = "testReadadnwritegeom_testcase"; |
|
51 |
private static final String FIELD_NAME_INSERT = "geom"; |
|
52 |
private Connection conn; |
|
53 |
private GeometryManager geoManager; |
|
54 |
private static String SQL_FOR_READ_TEST = "Select {0} from medio_ejes"; |
|
55 |
|
|
56 |
@Override |
|
57 |
protected void doSetUp() throws Exception { |
|
58 |
geoManager = GeometryLocator.getGeometryManager(); |
|
59 |
|
|
60 |
Class klass = Class.forName(PostgreSQLLibrary.DEFAULT_JDCB_DRIVER_NAME); |
|
61 |
if (klass == null) { |
|
62 |
throw new Exception("Driver not found: " |
|
63 |
+ PostgreSQLLibrary.DEFAULT_JDCB_DRIVER_NAME); |
|
64 |
} |
|
65 |
|
|
66 |
// inicializamos operaciones de geometrias de las que dependemos |
|
67 |
int code = FromWKB.CODE; |
|
68 |
code = ToWKB.CODE; |
|
69 |
code = ToWKT.CODE; |
|
70 |
conn = DriverManager.getConnection(PostgreSQLLibrary.getJdbcUrl( |
|
71 |
"localhost", 5432, "gis"), "postgres", "postgres"); |
|
72 |
} |
|
73 |
|
|
74 |
public void testInsertWKB() throws Exception { |
|
75 |
PreparedStatement pst = null; |
|
76 |
try { |
|
77 |
crearTablaTest(); |
|
78 |
Point2D geom = (Point2D) geoManager.createPoint(0, 0, |
|
79 |
Geometry.SUBTYPES.GEOM2D); |
|
80 |
pst = conn.prepareStatement( |
|
81 |
"Insert into " |
|
82 |
+ TABLE_NAME_INSERT.toLowerCase() + |
|
83 |
" (" |
|
84 |
+ FIELD_NAME_INSERT + ") Values (GeomFromWKB(?))"); |
|
85 |
|
|
86 |
|
|
87 |
int i; |
|
88 |
for (i = 1; i <= FEATURES_TO_INSERT; i++) { |
|
89 |
pst.clearParameters(); |
|
90 |
geom.setX(i); |
|
91 |
geom.setY(i); |
|
92 |
pst.setBytes(1, |
|
93 |
(byte[]) geom.invokeOperation( |
|
94 |
ToWKB.CODE, |
|
95 |
null) |
|
96 |
); |
|
97 |
|
|
98 |
pst.executeUpdate(); |
|
99 |
} |
|
100 |
|
|
101 |
System.out |
|
102 |
.println("TestReadAndWriteGeom.testInsertPostgis() Inserteds= i"); |
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
} finally { |
|
108 |
if (pst != null) { |
|
109 |
try {pst.close();} catch (SQLException e) {e.printStackTrace();} |
|
110 |
} |
|
111 |
|
|
112 |
} |
|
113 |
|
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
private void crearTablaTest() throws SQLException { |
|
118 |
execute("DROP TABLE IF EXISTS " + TABLE_NAME_INSERT.toLowerCase()); |
|
119 |
execute("Delete from geometry_columns where f_table_name = '" |
|
120 |
+ TABLE_NAME_INSERT.toLowerCase() + "'"); |
|
121 |
execute("CREATE TABLE " + TABLE_NAME_INSERT.toLowerCase() |
|
122 |
+ " (id serial PRIMARY KEY)"); |
|
123 |
execute("Select AddGeometryColumn('" + TABLE_NAME_INSERT.toLowerCase() |
|
124 |
+ "','" |
|
125 |
+ FIELD_NAME_INSERT + "',-1,'GEOMETRY',2)"); |
|
126 |
} |
|
127 |
|
|
128 |
private void execute(String sql) throws SQLException { |
|
129 |
Statement st = null; |
|
130 |
try { |
|
131 |
st = conn.createStatement(); |
|
132 |
st.execute(sql); |
|
133 |
} finally { |
|
134 |
if (st != null) { |
|
135 |
try {st.close();} catch (SQLException e) {e.printStackTrace();} |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
} |
|
140 |
|
|
141 |
public String getSQLForRead(String geoColumn) { |
|
142 |
return MessageFormat.format(SQL_FOR_READ_TEST, geoColumn); |
|
143 |
|
|
144 |
} |
|
145 |
|
|
146 |
public void testReadBinary() throws Exception { |
|
147 |
// st.execute("declare " + getTableName() + myCursorId + |
|
148 |
// "_wkb_cursor binary scroll cursor with hold for " + sqlAux); |
|
149 |
// rs = st.executeQuery("fetch forward " + FETCH_SIZE+ " in " + |
|
150 |
// getTableName() + myCursorId + "_wkb_cursor"); |
|
151 |
|
|
152 |
Statement st = null; |
|
153 |
ResultSet rs = null; |
|
154 |
long count = 0; |
|
155 |
Geometry geom; |
|
156 |
Geometry nullGeom = geoManager.createNullGeometry(Geometry.SUBTYPES.GEOM2D); |
|
157 |
|
|
158 |
try { |
|
159 |
st = conn.createStatement(); |
|
160 |
String cursorName = "myCursor___xxx"; |
|
161 |
st.execute("declare " + cursorName |
|
162 |
+ "_wkb_cursor binary scroll cursor with hold for " |
|
163 |
+ getSQLForRead("the_geom")); |
|
164 |
rs = st.executeQuery("fetch forward all in " + cursorName |
|
165 |
+ "_wkb_cursor"); |
|
166 |
byte[] buff; |
|
167 |
FromWKBGeometryOperationContext opContext = new FromWKBGeometryOperationContext(); |
|
168 |
while (rs.next()) { |
|
169 |
count++; |
|
170 |
buff = rs.getBytes(1); |
|
171 |
// if (buff != null) { |
|
172 |
// opContext.setData(buff); |
|
173 |
// geom = (Geometry) nullGeom.invokeOperation(FromWKB.CODE, |
|
174 |
// opContext); |
|
175 |
// assertNotNull(geom); |
|
176 |
// } |
|
177 |
} |
|
178 |
|
|
179 |
System.out |
|
180 |
.println("TestReadAndWriteGeom.testReadPostgis() Count = " |
|
181 |
+ count); |
|
182 |
|
|
183 |
} finally { |
|
184 |
if (st != null) { |
|
185 |
try { |
|
186 |
st.close(); |
|
187 |
} catch (SQLException e) { |
|
188 |
e.printStackTrace(); |
|
189 |
} |
|
190 |
} |
|
191 |
if (rs != null) { |
|
192 |
try { |
|
193 |
rs.close(); |
|
194 |
} catch (SQLException e) { |
|
195 |
e.printStackTrace(); |
|
196 |
} |
|
197 |
} |
|
198 |
} |
|
199 |
|
|
200 |
} |
|
201 |
|
|
202 |
public void testReadWKB() throws Exception { |
|
203 |
Statement st = null; |
|
204 |
ResultSet rs = null; |
|
205 |
long count = 0; |
|
206 |
Geometry geom; |
|
207 |
Geometry nullGeom = geoManager |
|
208 |
.createNullGeometry(Geometry.SUBTYPES.GEOM2D); |
|
209 |
byte[] buff; |
|
210 |
FromWKBGeometryOperationContext opContext = new FromWKBGeometryOperationContext(); |
|
211 |
try { |
|
212 |
st = conn.createStatement(); |
|
213 |
rs = st.executeQuery(getSQLForRead("asBinary(the_geom)")); |
|
214 |
while (rs.next()) { |
|
215 |
count++; |
|
216 |
buff = rs.getBytes(1); |
|
217 |
// if (buff != null) { |
|
218 |
// opContext.setData(buff); |
|
219 |
// geom = (Geometry) nullGeom.invokeOperation(FromWKB.CODE, |
|
220 |
// opContext); |
|
221 |
// assertNotNull(geom); |
|
222 |
// } |
|
223 |
} |
|
224 |
|
|
225 |
System.out |
|
226 |
.println("TestReadAndWriteGeom.testReadPostgis() Count = " |
|
227 |
+ count); |
|
228 |
|
|
229 |
|
|
230 |
} finally { |
|
231 |
if (st != null) { |
|
232 |
try { |
|
233 |
st.close(); |
|
234 |
} catch (SQLException e) { |
|
235 |
e.printStackTrace(); |
|
236 |
} |
|
237 |
} |
|
238 |
if (rs != null) { |
|
239 |
try { |
|
240 |
rs.close(); |
|
241 |
} catch (SQLException e) { |
|
242 |
e.printStackTrace(); |
|
243 |
} |
|
244 |
} |
|
245 |
} |
|
246 |
} |
|
247 |
|
|
248 |
// public void testReadPostgis() throws Exception { |
|
249 |
// Statement st = null; |
|
250 |
// ResultSet rs = null; |
|
251 |
// long count = 0; |
|
252 |
// Geometry geom; |
|
253 |
// PGgeometry pgGeom; |
|
254 |
// PostGIS2Geometry converter = new PostGIS2Geometry(); |
|
255 |
// try { |
|
256 |
// st = conn.createStatement(); |
|
257 |
// rs = st.executeQuery(getSQLForRead("the_geom")); |
|
258 |
// while (rs.next()) { |
|
259 |
// count++; |
|
260 |
// pgGeom = (PGgeometry) rs.getObject(1); |
|
261 |
// if (pgGeom != null) { |
|
262 |
// geom = converter.getGeometry(pgGeom); |
|
263 |
// assertNotNull(geom); |
|
264 |
// } |
|
265 |
// } |
|
266 |
// |
|
267 |
// |
|
268 |
// System.out |
|
269 |
// .println("TestReadAndWriteGeom.testReadPostgis() Count = " |
|
270 |
// + count); |
|
271 |
// |
|
272 |
// |
|
273 |
// } finally { |
|
274 |
// if (st != null) { |
|
275 |
// try { |
|
276 |
// st.close(); |
|
277 |
// } catch (SQLException e) { |
|
278 |
// e.printStackTrace(); |
|
279 |
// } |
|
280 |
// } |
|
281 |
// if (rs != null) { |
|
282 |
// try { |
|
283 |
// rs.close(); |
|
284 |
// } catch (SQLException e) { |
|
285 |
// e.printStackTrace(); |
|
286 |
// } |
|
287 |
// } |
|
288 |
// } |
|
289 |
// } |
|
290 |
|
|
291 |
|
|
292 |
protected void tearDown() throws Exception { |
|
293 |
super.tearDown(); |
|
294 |
conn.close(); |
|
295 |
} |
|
296 |
|
|
297 |
} |
tags/org.gvsig.postgresql-2.0.17/org.gvsig.postgresql.provider/src/test/java/org/gvsig/fmap/dal/store/postgresql/TestPostgreSQL.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
*/ |
|
31 |
package org.gvsig.fmap.dal.store.postgresql; |
|
32 |
|
|
33 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
34 |
import org.gvsig.fmap.dal.exception.DataException; |
|
35 |
import org.gvsig.fmap.dal.feature.BaseTestFeatureStore; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
39 |
import org.gvsig.fmap.dal.feature.FeatureStoreTransform; |
|
40 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
41 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
42 |
import org.gvsig.fmap.geom.Geometry; |
|
43 |
import org.gvsig.tools.evaluator.Evaluator; |
|
44 |
import org.gvsig.tools.evaluator.EvaluatorData; |
|
45 |
import org.gvsig.tools.evaluator.EvaluatorException; |
|
46 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
|
47 |
|
|
48 |
/** |
|
49 |
* @author jmvivo |
|
50 |
* |
|
51 |
*/ |
|
52 |
// public class TestPostgreSQL extends BaseTestEditableFeatureStore { |
|
53 |
public class TestPostgreSQL extends BaseTestFeatureStore { |
|
54 |
|
|
55 |
@Override |
|
56 |
protected void doSetUp() throws Exception { |
|
57 |
super.doSetUp(); |
|
58 |
} |
|
59 |
|
|
60 |
public DataStoreParameters getDefaultDataStoreParameters() |
|
61 |
throws DataException { |
|
62 |
PostgreSQLStoreParameters pgParameters = null; |
|
63 |
pgParameters = (PostgreSQLStoreParameters) dataManager |
|
64 |
.createStoreParameters(PostgreSQLStoreProvider.NAME); |
|
65 |
|
|
66 |
pgParameters.setHost("localhost"); |
|
67 |
pgParameters.setUser("postgres"); |
|
68 |
pgParameters.setPassword("postgres"); |
|
69 |
pgParameters.setDBName("gis"); |
|
70 |
pgParameters.setTable("muni10000_peq"); |
|
71 |
|
|
72 |
return pgParameters; |
|
73 |
} |
|
74 |
|
|
75 |
public boolean hasExplorer() { |
|
76 |
return true; |
|
77 |
} |
|
78 |
|
|
79 |
public void testLoadMetadata() throws Exception { |
|
80 |
DataStoreParameters params = this.getDefaultDataStoreParameters(); |
|
81 |
|
|
82 |
FeatureStore store = null; |
|
83 |
store = (FeatureStore) dataManager.createStore(params); |
|
84 |
FeatureType fType = store.getDefaultFeatureType(); |
|
85 |
FeatureAttributeDescriptor geomAttr; |
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
if (fType.getDefaultGeometryAttributeIndex() >= 0) { |
|
90 |
assertNotNull(store.getEnvelope()); |
|
91 |
geomAttr = fType.getAttributeDescriptor(fType |
|
92 |
.getDefaultGeometryAttributeIndex()); |
|
93 |
assertTrue(geomAttr.getGeometryType() == Geometry.TYPES.MULTISURFACE); |
|
94 |
assertTrue(geomAttr.getGeometrySubType() == Geometry.SUBTYPES.GEOM2D); |
|
95 |
assertNotNull(store.getDynValue("CRS")); |
|
96 |
|
|
97 |
} |
|
98 |
|
|
99 |
} |
|
100 |
|
|
101 |
public void testCloserConnection() throws Exception { |
|
102 |
|
|
103 |
DataStoreParameters params = this.getDefaultDataStoreParameters(); |
|
104 |
|
|
105 |
FeatureStore store = null; |
|
106 |
store = (FeatureStore) dataManager.createStore(params); |
|
107 |
|
|
108 |
FeatureQuery query = store.createFeatureQuery(); |
|
109 |
|
|
110 |
query.getOrder().add("gid", true); |
|
111 |
|
|
112 |
query.setFilter(new Evaluator() { |
|
113 |
|
|
114 |
public Object evaluate(EvaluatorData data) |
|
115 |
throws EvaluatorException { |
|
116 |
// TODO Auto-generated method stub |
|
117 |
return Boolean.TRUE; |
|
118 |
} |
|
119 |
|
|
120 |
public String getSQL() { |
|
121 |
return "true = true"; |
|
122 |
} |
|
123 |
|
|
124 |
public String getDescription() { |
|
125 |
// TODO Auto-generated method stub |
|
126 |
return null; |
|
127 |
} |
|
128 |
|
|
129 |
public String getName() { |
|
130 |
return "AlwaysTrue"; |
|
131 |
} |
|
132 |
|
|
133 |
public EvaluatorFieldsInfo getFieldsInfo() { |
|
134 |
// TODO Auto-generated method stub |
|
135 |
return null; |
|
136 |
} |
|
137 |
|
|
138 |
}); |
|
139 |
|
|
140 |
FeatureStoreTransform transform = new StringsToLowerTransform(); |
|
141 |
transform.setFeatureStore(store); |
|
142 |
|
|
143 |
store.getTransforms().add(transform); |
|
144 |
|
|
145 |
transform = new StringsToLowerTransform(); |
|
146 |
transform.setFeatureStore(store); |
|
147 |
|
|
148 |
store.getTransforms().add(transform); |
|
149 |
|
|
150 |
transform = new StringsToLowerTransform(); |
|
151 |
transform.setFeatureStore(store); |
|
152 |
|
|
153 |
store.getTransforms().add(transform); |
|
154 |
|
|
155 |
for (int i = 0; i < 30; i++) { |
|
156 |
// this.fullStoreIteratorTest(store); |
|
157 |
|
|
158 |
this.testIterationFastAndStandart(store, query); |
|
159 |
} |
|
160 |
|
|
161 |
|
|
162 |
store.dispose(); |
|
163 |
|
|
164 |
} |
|
165 |
|
|
166 |
public boolean usesResources() { |
|
167 |
return true; |
|
168 |
} |
|
169 |
|
|
170 |
public NewFeatureStoreParameters getDefaultNewDataStoreParameters() |
|
171 |
throws Exception { |
|
172 |
// TODO Auto-generated method stub |
|
173 |
return null; |
|
174 |
} |
|
175 |
} |
tags/org.gvsig.postgresql-2.0.17/org.gvsig.postgresql.provider/src/main/java/org/gvsig/fmap/dal/store/postgresql/PostgreSQLResource.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.store.postgresql; |
|
29 |
|
|
30 |
import java.sql.SQLException; |
|
31 |
import java.text.MessageFormat; |
|
32 |
|
|
33 |
import javax.sql.DataSource; |
|
34 |
|
|
35 |
import org.apache.commons.dbcp.BasicDataSource; |
|
36 |
import org.gvsig.fmap.dal.exception.DataException; |
|
37 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
38 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
|
39 |
import org.gvsig.fmap.dal.store.jdbc.JDBCResource; |
|
40 |
import org.gvsig.fmap.dal.store.jdbc.JDBCResourceParameters; |
|
41 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCDriverClassNotFoundException; |
|
42 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
|
43 |
import org.slf4j.Logger; |
|
44 |
import org.slf4j.LoggerFactory; |
|
45 |
|
|
46 |
public class PostgreSQLResource extends JDBCResource { |
|
47 |
|
|
48 |
final static private Logger logger = LoggerFactory |
|
49 |
.getLogger(PostgreSQLResource.class); |
|
50 |
|
|
51 |
public final static String NAME = "PostgreSQLResource"; |
|
52 |
public static final String DESCRIPTION = "PostgreSQL Connection"; |
|
53 |
|
|
54 |
public PostgreSQLResource(PostgreSQLResourceParameters parameters) |
|
55 |
throws InitializeException { |
|
56 |
super(parameters); |
|
57 |
} |
|
58 |
|
|
59 |
public String getName() throws AccessResourceException { |
|
60 |
PostgreSQLResourceParameters params = (PostgreSQLResourceParameters) this.getParameters(); |
|
61 |
return MessageFormat.format("PostgreSQLResource({0},{1})", |
|
62 |
new Object[] { params.getUrl(),params.getUser() }); |
|
63 |
} |
|
64 |
|
|
65 |
protected void connectToDB() throws DataException { |
|
66 |
if (this.dataSource != null) { |
|
67 |
return; |
|
68 |
} |
|
69 |
JDBCResourceParameters jdbcParams = (JDBCResourceParameters) this |
|
70 |
.getParameters(); |
|
71 |
BasicDataSource dataSource = new BasicDataSource(); |
|
72 |
dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName()); |
|
73 |
dataSource.setUsername(jdbcParams.getUser()); |
|
74 |
dataSource.setPassword(jdbcParams.getPassword()); |
|
75 |
dataSource.setUrl(jdbcParams.getUrl()); |
|
76 |
|
|
77 |
dataSource.setMaxWait(60L * 1000); // FIXME |
|
78 |
|
|
79 |
// FIXME Set Pool parameters: |
|
80 |
/* |
|
81 |
dataSource.setMaxActive(maxActive); |
|
82 |
dataSource.setMaxIdle(maxActive); |
|
83 |
dataSource.setMaxOpenPreparedStatements(maxActive); |
|
84 |
dataSource.setMaxWait(maxActive); |
|
85 |
dataSource.setInitialSize(initialSize); |
|
86 |
dataSource.setDefaultReadOnly(defaultReadOnly); |
|
87 |
dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); |
|
88 |
dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); |
|
89 |
dataSource.setMinIdle(minIdle); |
|
90 |
dataSource.setTestOnBorrow(testOnBorrow); |
|
91 |
dataSource.setTestOnReturn(testOnReturn); |
|
92 |
dataSource.setTestWhileIdle(testOnReturn); |
|
93 |
dataSource |
|
94 |
.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); |
|
95 |
|
|
96 |
dataSource.setAccessToUnderlyingConnectionAllowed(allow); |
|
97 |
dataSource.setLoginTimeout(seconds); |
|
98 |
dataSource.setLogWriter(out); |
|
99 |
*/ |
|
100 |
|
|
101 |
this.dataSource = dataSource; |
|
102 |
} |
|
103 |
protected void registerJDBCDriver() throws InitializeException { |
|
104 |
String className = ((JDBCResourceParameters) getParameters()) |
|
105 |
.getJDBCDriverClassName(); |
|
106 |
if (className == null) { |
|
107 |
return; |
|
108 |
} |
|
109 |
|
|
110 |
Class theClass = null; |
|
111 |
try { |
|
112 |
theClass = Class.forName(className); |
|
113 |
} catch (Exception e){ |
|
114 |
throw new InitializeException(e); |
|
115 |
} |
|
116 |
if (theClass == null) { |
|
117 |
try { |
|
118 |
throw new JDBCDriverClassNotFoundException(this.getName(), |
|
119 |
className); |
|
120 |
} catch (AccessResourceException e) { |
|
121 |
throw new InitializeException(e); |
|
122 |
|
|
123 |
} |
|
124 |
} |
|
125 |
} |
|
126 |
|
|
127 |
protected DataSource createDataSource() { |
|
128 |
PostgreSQLResourceParameters jdbcParams = (PostgreSQLResourceParameters) this |
|
129 |
.getParameters(); |
|
130 |
BasicDataSource dataSource = new BasicDataSource(); |
|
131 |
dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName()); |
|
132 |
dataSource.setUsername(jdbcParams.getUser()); |
|
133 |
dataSource.setPassword(jdbcParams.getPassword()); |
|
134 |
dataSource.setUrl(jdbcParams.getUrl()); |
|
135 |
|
|
136 |
dataSource.setMaxWait(60L * 1000); // FIXME |
|
137 |
|
|
138 |
// FIXME Set Pool parameters: |
|
139 |
/* |
|
140 |
dataSource.setMaxActive(maxActive); |
|
141 |
dataSource.setMaxIdle(maxActive); |
|
142 |
dataSource.setMaxOpenPreparedStatements(maxActive); |
|
143 |
dataSource.setMaxWait(maxActive); |
|
144 |
dataSource.setInitialSize(initialSize); |
|
145 |
dataSource.setDefaultReadOnly(defaultReadOnly); |
|
146 |
dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); |
|
147 |
dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); |
|
148 |
dataSource.setMinIdle(minIdle); |
|
149 |
dataSource.setTestOnBorrow(testOnBorrow); |
|
150 |
dataSource.setTestOnReturn(testOnReturn); |
|
151 |
dataSource.setTestWhileIdle(testOnReturn); |
|
152 |
dataSource |
|
153 |
.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); |
|
154 |
|
|
155 |
dataSource.setAccessToUnderlyingConnectionAllowed(allow); |
|
156 |
dataSource.setLoginTimeout(seconds); |
|
157 |
dataSource.setLogWriter(out); |
|
158 |
*/ |
|
159 |
return dataSource; |
|
160 |
} |
|
161 |
|
|
162 |
|
|
163 |
public boolean isConnected() { |
|
164 |
if (dataSource == null) { |
|
165 |
return false; |
|
166 |
} |
|
167 |
if (dataSource instanceof BasicDataSource) { |
|
168 |
return ((BasicDataSource) dataSource).getNumActive() > 0 |
|
169 |
|| ((BasicDataSource) dataSource).getNumIdle() > 0; |
|
170 |
} |
|
171 |
return true; |
|
172 |
} |
|
173 |
|
|
174 |
private void logPoolStatus(String src) { |
|
175 |
if (logger.isDebugEnabled() && dataSource instanceof BasicDataSource) { |
|
176 |
BasicDataSource ds = (BasicDataSource) dataSource; |
|
177 |
logger.debug(src + " actives:" + ds.getNumActive() + "(" |
|
178 |
+ ds.getMaxActive() + ") idle:" + ds.getNumIdle() + "(" |
|
179 |
+ ds.getMaxIdle() + ")"); |
|
180 |
} |
|
181 |
|
|
182 |
} |
|
183 |
|
|
184 |
protected synchronized Object getTheConnection() throws DataException { |
|
185 |
try { |
|
186 |
Object conn = this.dataSource.getConnection(); |
|
187 |
logPoolStatus("getTheConnection"); |
|
188 |
return conn; |
|
189 |
} catch (SQLException e) { |
|
190 |
throw new JDBCSQLException(e); |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 |
} |
tags/org.gvsig.postgresql-2.0.17/org.gvsig.postgresql.provider/src/main/java/org/gvsig/fmap/dal/store/postgresql/PostgreSQLServerExplorer.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
*/ |
|
31 |
package org.gvsig.fmap.dal.store.postgresql; |
|
32 |
|
|
33 |
import java.sql.Connection; |
|
34 |
import java.sql.SQLException; |
|
35 |
import java.sql.Statement; |
|
36 |
import java.util.ArrayList; |
|
37 |
import java.util.List; |
|
38 |
|
|
39 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
40 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
41 |
import org.gvsig.fmap.dal.exception.DataException; |
|
42 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
43 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
44 |
import org.gvsig.fmap.dal.exception.RemoveException; |
|
45 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
|
46 |
import org.gvsig.fmap.dal.store.jdbc.JDBCHelper; |
|
47 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer; |
|
48 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
49 |
import org.gvsig.fmap.dal.store.jdbc.TransactionalAction; |
|
50 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCExecuteSQLException; |
|
51 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
|
52 |
import org.slf4j.Logger; |
|
53 |
import org.slf4j.LoggerFactory; |
|
54 |
|
|
55 |
/** |
|
56 |
* @author jmvivo |
|
57 |
* |
|
58 |
*/ |
|
59 |
public class PostgreSQLServerExplorer extends JDBCServerExplorer { |
|
60 |
final static private Logger logger = LoggerFactory |
|
61 |
.getLogger(PostgreSQLServerExplorer.class); |
|
62 |
|
|
63 |
public static final String NAME = "PostgreSQLExplorer"; |
|
64 |
|
|
65 |
|
|
66 |
public PostgreSQLServerExplorer( |
|
67 |
PostgreSQLServerExplorerParameters parameters, |
|
68 |
DataServerExplorerProviderServices services) |
|
69 |
throws InitializeException { |
|
70 |
super(parameters, services); |
|
71 |
} |
|
72 |
|
|
73 |
private PostgreSQLServerExplorerParameters getPostgreSQLParameters() { |
|
74 |
return (PostgreSQLServerExplorerParameters) getParameters(); |
|
75 |
} |
|
76 |
|
|
77 |
|
|
78 |
protected JDBCHelper createHelper() throws InitializeException { |
|
79 |
return new PostgreSQLHelper(this, getPostgreSQLParameters()); |
|
80 |
} |
|
81 |
|
|
82 |
|
|
83 |
protected String getStoreName() { |
|
84 |
return PostgreSQLStoreProvider.NAME; |
|
85 |
} |
|
86 |
|
|
87 |
public String getProviderName() { |
|
88 |
return NAME; |
|
89 |
} |
|
90 |
|
|
91 |
protected JDBCStoreParameters createStoreParams() |
|
92 |
throws InitializeException, ProviderNotRegisteredException { |
|
93 |
PostgreSQLStoreParameters orgParams = (PostgreSQLStoreParameters) super |
|
94 |
.createStoreParams(); |
|
95 |
|
|
96 |
orgParams.setUseSSL(getPostgreSQLParameters().getUseSSL()); |
|
97 |
|
|
98 |
return orgParams; |
|
99 |
} |
|
100 |
|
|
101 |
|
|
102 |
// **************************** |
|
103 |
|
|
104 |
|
|
105 |
public boolean canAdd() { |
|
106 |
return true; |
|
107 |
} |
|
108 |
|
|
109 |
protected void checkIsMine(DataStoreParameters dsp) { |
|
110 |
if (!(dsp instanceof PostgreSQLStoreParameters)) { |
|
111 |
// FIXME Excpetion ??? |
|
112 |
throw new IllegalArgumentException( |
|
113 |
"not instance of PostgreSQLStoreParameters"); |
|
114 |
} |
|
115 |
super.checkIsMine(dsp); |
|
116 |
|
|
117 |
PostgreSQLStoreParameters pgp = (PostgreSQLStoreParameters) dsp; |
|
118 |
if (pgp.getUseSSL().booleanValue() != getPostgreSQLParameters() |
|
119 |
.getUseSSL()) { |
|
120 |
throw new IllegalArgumentException("worng explorer: Host"); |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
public void remove(DataStoreParameters dsp) throws RemoveException { |
|
125 |
final PostgreSQLStoreParameters pgParams =(PostgreSQLStoreParameters) dsp; |
|
126 |
|
|
127 |
TransactionalAction action = new TransactionalAction() { |
|
128 |
public boolean continueTransactionAllowed() { |
|
129 |
return false; |
|
130 |
} |
|
131 |
public Object action(Connection conn) throws DataException { |
|
132 |
|
|
133 |
|
|
134 |
Statement st; |
|
135 |
try{ |
|
136 |
st = conn.createStatement(); |
|
137 |
} catch (SQLException e) { |
|
138 |
throw new JDBCSQLException(e); |
|
139 |
} |
|
140 |
|
|
141 |
String sqlDrop = "Drop table " |
|
142 |
+ pgParams.tableID(); |
|
143 |
|
|
144 |
StringBuilder strb = new StringBuilder(); |
|
145 |
strb.append("Delete from GEOMETRY_COLUMNS where f_table_schema = "); |
|
146 |
if (pgParams.getSchema() == null || pgParams.getSchema().length() == 0) { |
|
147 |
strb.append("current_schema() "); |
|
148 |
} else { |
|
149 |
strb.append('\''); |
|
150 |
strb.append(pgParams.getSchema()); |
|
151 |
strb.append("' "); |
|
152 |
} |
|
153 |
strb.append("and f_table_name = '"); |
|
154 |
strb.append(pgParams.getTable()); |
|
155 |
strb.append('\''); |
|
156 |
|
|
157 |
String sqlDeleteFromGeometry_column = strb.toString(); |
|
158 |
try{ |
|
159 |
try{ |
|
160 |
st.execute(sqlDrop); |
|
161 |
} catch (SQLException e) { |
|
162 |
throw new JDBCExecuteSQLException(sqlDrop, e); |
|
163 |
} |
|
164 |
|
|
165 |
try { |
|
166 |
st.execute(sqlDeleteFromGeometry_column); |
|
167 |
} catch (SQLException e) { |
|
168 |
throw new JDBCExecuteSQLException( |
|
169 |
sqlDeleteFromGeometry_column, e); |
|
170 |
} |
|
171 |
|
|
172 |
} finally{ |
|
173 |
try{ st.close(); } catch (SQLException e) {}; |
|
174 |
} |
|
175 |
return null; |
|
176 |
} |
|
177 |
}; |
|
178 |
try { |
|
179 |
this.helper.doConnectionAction(action); |
|
180 |
} catch (Exception e) { |
|
181 |
throw new RemoveException(this.getProviderName(), e); |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 |
public NewDataStoreParameters getAddParameters() throws DataException { |
|
186 |
PostgreSQLServerExplorerParameters parameters = getPostgreSQLParameters(); |
|
187 |
PostgreSQLNewStoreParameters params = new PostgreSQLNewStoreParameters(); |
|
188 |
params.setHost(parameters.getHost()); |
|
189 |
params.setPort(parameters.getPort()); |
|
190 |
params.setDBName(parameters.getDBName()); |
|
191 |
params.setUser(parameters.getUser()); |
|
192 |
params.setPassword(parameters.getPassword()); |
|
193 |
params.setCatalog(parameters.getCatalog()); |
|
194 |
params.setSchema(parameters.getSchema()); |
|
195 |
params.setJDBCDriverClassName(parameters.getJDBCDriverClassName()); |
|
196 |
params.setUrl(parameters.getUrl()); |
|
197 |
params.setUseSSL(parameters.getUseSSL()); |
|
198 |
|
|
199 |
|
|
200 |
params.setDefaultFeatureType(this.getServerExplorerProviderServices() |
|
201 |
.createNewFeatureType()); |
|
202 |
|
|
203 |
|
|
204 |
return params; |
|
205 |
} |
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
// *********************** |
|
210 |
// *********************** |
|
211 |
|
|
212 |
|
|
213 |
public boolean hasGeometrySupport() { |
|
214 |
return true; |
|
215 |
} |
|
216 |
|
|
217 |
protected PostgreSQLHelper getPgHelper() { |
Also available in: Unified diff