Revision 443
tags/org.gvsig.postgresql-2.0.91/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.91</version> |
|
13 |
</parent> |
|
14 |
|
|
15 |
<modules> |
|
16 |
<module>org.gvsig.postgresql.app.mainplugin</module> |
|
17 |
<!-- |
|
18 |
<module>org.gvsig.postgresql.app.export</module> |
|
19 |
--> |
|
20 |
</modules> |
|
21 |
|
|
22 |
</project> |
tags/org.gvsig.postgresql-2.0.91/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/buildNumber.properties | ||
---|---|---|
1 |
#Wed Nov 29 23:27:01 CET 2017 |
|
2 |
buildNumber=2148 |
tags/org.gvsig.postgresql-2.0.91/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.mainplugin"/> |
|
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.91/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 |
<file> |
|
17 |
<source>src/main/resources-plugin/config.xml</source> |
|
18 |
</file> |
|
19 |
</files> |
|
20 |
|
|
21 |
<dependencySets> |
|
22 |
|
|
23 |
<dependencySet> |
|
24 |
<useProjectArtifact>false</useProjectArtifact> |
|
25 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
26 |
<outputDirectory>lib</outputDirectory> |
|
27 |
<includes> |
|
28 |
<include>org.gvsig:org.gvsig.postgresql.provider</include> |
|
29 |
</includes> |
|
30 |
</dependencySet> |
|
31 |
|
|
32 |
<dependencySet> |
|
33 |
<useProjectArtifact>false</useProjectArtifact> |
|
34 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
35 |
<outputDirectory>lib</outputDirectory> |
|
36 |
<includes> |
|
37 |
<include>postgresql:postgresql</include> |
|
38 |
<include>commons-dbcp:commons-dbcp</include> |
|
39 |
<include>commons-pool:commons-pool</include> |
|
40 |
</includes> |
|
41 |
</dependencySet> |
|
42 |
|
|
43 |
</dependencySets> |
|
44 |
|
|
45 |
</assembly> |
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
tags/org.gvsig.postgresql-2.0.91/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>${project.artifactId}</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.91</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-pool</groupId> |
|
46 |
<artifactId>commons-pool</artifactId> |
|
47 |
<scope>runtime</scope> |
|
48 |
</dependency> |
|
49 |
|
|
50 |
</dependencies> |
|
51 |
|
|
52 |
<properties> |
|
53 |
<!-- Package info property values --> |
|
54 |
<!-- Default values in org.gvsig.desktop --> |
|
55 |
<gvsig.package.info.name>Formats: PostgreSQL support</gvsig.package.info.name> |
|
56 |
<gvsig.package.info.state>testing</gvsig.package.info.state> |
|
57 |
<gvsig.package.info.official>true</gvsig.package.info.official> |
|
58 |
<gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.0.1</gvsig.package.info.dependencies> |
|
59 |
<gvsig.package.info.categories>Formats,Vector,Database</gvsig.package.info.categories> |
|
60 |
<gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-postgresql/pool/</gvsig.package.info.poolURL> |
|
61 |
</properties> |
|
62 |
|
|
63 |
|
|
64 |
</project> |
|
0 | 65 |
tags/org.gvsig.postgresql-2.0.91/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.91</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.213</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.91</connection> |
|
20 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-postgresql/tags/org.gvsig.postgresql-2.0.91</developerConnection> |
|
21 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-postgresql/repository/show/tags/org.gvsig.postgresql-2.0.91</url> |
|
22 |
</scm> |
|
23 |
|
|
24 |
<repositories> |
|
25 |
<repository> |
|
26 |
<id>gvsig-public-http-repository</id> |
|
27 |
<name>gvSIG maven public HTTP repository</name> |
|
28 |
<url>http://devel.gvsig.org/m2repo/j2se</url> |
|
29 |
<releases> |
|
30 |
<enabled>true</enabled> |
|
31 |
<updatePolicy>daily</updatePolicy> |
|
32 |
<checksumPolicy>warn</checksumPolicy> |
|
33 |
</releases> |
|
34 |
<snapshots> |
|
35 |
<enabled>true</enabled> |
|
36 |
<updatePolicy>daily</updatePolicy> |
|
37 |
<checksumPolicy>warn</checksumPolicy> |
|
38 |
</snapshots> |
|
39 |
</repository> |
|
40 |
</repositories> |
|
41 |
|
|
42 |
|
|
43 |
<build> |
|
44 |
<plugins> |
|
45 |
<plugin> |
|
46 |
<groupId>org.apache.maven.plugins</groupId> |
|
47 |
<artifactId>maven-release-plugin</artifactId> |
|
48 |
<configuration> |
|
49 |
<tagBase>https://devel.gvsig.org/svn/gvsig-postgresql/tags/</tagBase> |
|
50 |
<goals>deploy</goals> |
|
51 |
</configuration> |
|
52 |
</plugin> |
|
53 |
</plugins> |
|
54 |
</build> |
|
55 |
|
|
56 |
|
|
57 |
<dependencyManagement> |
|
58 |
<dependencies> |
|
59 |
<dependency> |
|
60 |
<groupId>org.gvsig</groupId> |
|
61 |
<artifactId>org.gvsig.postgresql.provider</artifactId> |
|
62 |
<version>2.0.91</version> |
|
63 |
</dependency> |
|
64 |
<dependency> |
|
65 |
<groupId>org.gvsig</groupId> |
|
66 |
<artifactId>org.gvsig.postgresql.app.mainplugin</artifactId> |
|
67 |
<version>2.0.91</version> |
|
68 |
</dependency> |
|
69 |
</dependencies> |
|
70 |
</dependencyManagement> |
|
71 |
|
|
72 |
<dependencies> |
|
73 |
<dependency> |
|
74 |
<groupId>org.slf4j</groupId> |
|
75 |
<artifactId>slf4j-api</artifactId> |
|
76 |
<scope>compile</scope> |
|
77 |
</dependency> |
|
78 |
</dependencies> |
|
79 |
|
|
80 |
|
|
81 |
<modules> |
|
82 |
<module>org.gvsig.postgresql.app</module> |
|
83 |
<module>org.gvsig.postgresql.provider</module> |
|
84 |
</modules> |
|
85 |
|
|
86 |
|
|
87 |
</project> |
tags/org.gvsig.postgresql-2.0.91/org.gvsig.postgresql.provider/src/main/resources/org/gvsig/postgresql/dal/PostgreSQLMetadata.xml | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<definitions> |
|
3 |
<version>1.0.0</version> |
|
4 |
<classes> |
|
5 |
<class name="PostgreSQL" namespace="Metadata"> |
|
6 |
<extends> |
|
7 |
<class name="JDBC2" namespace="Metadata"/> |
|
8 |
</extends> |
|
9 |
<description>Metadata of a PostgreSQL store</description> |
|
10 |
<fields> |
|
11 |
</fields> |
|
12 |
</class> |
|
13 |
|
|
14 |
</classes> |
|
15 |
</definitions> |
tags/org.gvsig.postgresql-2.0.91/org.gvsig.postgresql.provider/src/main/resources/org/gvsig/postgresql/dal/PostgreSQLParameters.xml | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<definitions> |
|
3 |
<version>1.0.0</version> |
|
4 |
<classes> |
|
5 |
<class name="PostgreSQLResourceParameters"> |
|
6 |
<extends> |
|
7 |
<class>JDBC2ResourceParameters</class> |
|
8 |
</extends> |
|
9 |
<fields> |
|
10 |
<field name="JDBCDriverClass" type="string" mandatory="true" |
|
11 |
defaultValue="org.postgresql.Driver" group="Advanced"> |
|
12 |
<description>JDBC Driver class</description> |
|
13 |
</field> |
|
14 |
<field name="port" type="integer" mandatory="false" |
|
15 |
defaultValue="5432" group="Connection"> |
|
16 |
<description></description> |
|
17 |
</field> |
|
18 |
<field name="host" type="string" mandatory="false" |
|
19 |
defaultValue="127.0.0.1" group="Connection"> |
|
20 |
<description></description> |
|
21 |
</field> |
|
22 |
<field name="UseSSL" type="boolean" mandatory="false" |
|
23 |
defaultValue="false" group="Basic"> |
|
24 |
<description>Use SSL connetion</description> |
|
25 |
</field> |
|
26 |
<field name="maxIdle" type="integer" mandatory="false" |
|
27 |
defaultValue="8" group="Advanced"> |
|
28 |
<description>The maximum number of connections that can remail idle in the pool.</description> |
|
29 |
</field> |
|
30 |
</fields> |
|
31 |
</class> |
|
32 |
|
|
33 |
<class name="PostgreSQLStoreParameters"> |
|
34 |
<extends> |
|
35 |
<class>JDBC2StoreParameters</class> |
|
36 |
<class>PostgreSQLResourceParameters</class> |
|
37 |
</extends> |
|
38 |
<fields/> |
|
39 |
</class> |
|
40 |
|
|
41 |
<class name="PostgreSQLNewStoreParameters"> |
|
42 |
<extends> |
|
43 |
<class>JDBC2NewStoreParameters</class> |
|
44 |
<class>PostgreSQLResourceParameters</class> |
|
45 |
</extends> |
|
46 |
<fields/> |
|
47 |
</class> |
|
48 |
|
|
49 |
|
|
50 |
<class name="PostgreSQLServerExplorerParameters"> |
|
51 |
<extends> |
|
52 |
<class>PostgreSQLResourceParameters</class> |
|
53 |
<class>JDBC2ServerExplorerParameters</class> |
|
54 |
</extends> |
|
55 |
<fields/> |
|
56 |
</class> |
|
57 |
|
|
58 |
|
|
59 |
</classes> |
|
60 |
</definitions> |
tags/org.gvsig.postgresql-2.0.91/org.gvsig.postgresql.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.postgresql.dal.PostgreSQLLibrary |
tags/org.gvsig.postgresql-2.0.91/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLBuilder.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.postgresql.dal; |
|
26 |
|
|
27 |
import java.text.MessageFormat; |
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.List; |
|
30 |
import org.apache.commons.lang3.StringUtils; |
|
31 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
32 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
|
33 |
|
|
34 |
public class PostgreSQLBuilder extends JDBCSQLBuilderBase { |
|
35 |
|
|
36 |
private final JDBCHelper helper; |
|
37 |
|
|
38 |
public PostgreSQLBuilder(JDBCHelper helper) { |
|
39 |
super(); |
|
40 |
|
|
41 |
this.helper = helper; |
|
42 |
|
|
43 |
config.set(SQLConfig.default_schema, "public"); |
|
44 |
config.set(SQLConfig.allowAutomaticValues, true); |
|
45 |
config.set(SQLConfig.geometry_type_support, this.helper.getGeometrySupportType()); |
|
46 |
config.set(SQLConfig.has_spatial_functions, this.helper.hasSpatialFunctions()); |
|
47 |
config.set(SQLConfig.constant_true, "true"); |
|
48 |
config.set(SQLConfig.constant_false, "false"); |
|
49 |
|
|
50 |
config.remove_functionality(SQLConfig.DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table); |
|
51 |
config.remove_functionality(SQLConfig.DELETE_GEOMETRY_COLUMN_FROM_TABLE_table); |
|
52 |
|
|
53 |
config.set(SQLConfig.UPDATE_TABLE_STATISTICS_table,"ANALYZE {0}"); |
|
54 |
|
|
55 |
config.set(SQLConfig.ST_GeomFromEWKB, "ST_GeomFromEWKB({0}, {1})"); |
|
56 |
config.set(SQLConfig.ST_AsEWKB, "ST_AsEWKB(({0}))"); |
|
57 |
config.set(SQLConfig.ST_ExtentAggregate, "ST_Extent({0})"); |
|
58 |
config.set(SQLConfig.ST_UnionAggregate, "ST_Union({0})"); |
|
59 |
|
|
60 |
config.set(SQLConfig.lcase, "lower({0})"); |
|
61 |
config.set(SQLConfig.ucase, "upper({0})"); |
|
62 |
config.set(SQLConfig.operator_ILIKE, "({0}) ILIKE ({1})"); |
|
63 |
config.set(SQLConfig.isNull, "( ({0}) ISNULL )"); |
|
64 |
config.set(SQLConfig.notIsNull, "( ({0}) NOT NULL )"); |
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
public class PostgreSQLUpdateTableStatisticsBuilderBase extends UpdateTableStatisticsBuilderBase { |
|
69 |
@Override |
|
70 |
public List<String> toStrings() { |
|
71 |
List<String> sqls = new ArrayList<>(); |
|
72 |
|
|
73 |
if( config.has_functionality(SQLConfig.UPDATE_TABLE_STATISTICS_table) ) { |
|
74 |
// In postGIS, UpdateLayerStatistics function, don't allow to |
|
75 |
// use the database name in the table name. |
|
76 |
String name = identifier(this.table.getName()); |
|
77 |
if( table.has_schema()) { |
|
78 |
name = identifier(this.table.getSchema()) + "." + name; |
|
79 |
} |
|
80 |
String sql = MessageFormat.format( |
|
81 |
config.getString(SQLConfig.UPDATE_TABLE_STATISTICS_table), |
|
82 |
name |
|
83 |
); |
|
84 |
if( !StringUtils.isEmpty(sql) ) { |
|
85 |
sqls.add(sql); |
|
86 |
} |
|
87 |
} |
|
88 |
return sqls; |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
protected class PostgreSQLCreateTableBuilder extends CreateTableBuilderBase { |
|
93 |
|
|
94 |
@Override |
|
95 |
public List<String> toStrings() { |
|
96 |
// |
|
97 |
// https://www.postgresql.org/docs/9.1/static/sql-createtable.html |
|
98 |
// |
|
99 |
List<String> sqls = new ArrayList<>(); |
|
100 |
StringBuilder builder = new StringBuilder(); |
|
101 |
|
|
102 |
builder.append("CREATE TABLE "); |
|
103 |
builder.append(this.table.toString()); |
|
104 |
builder.append(" ("); |
|
105 |
boolean first = true; |
|
106 |
for (ColumnDescriptorBuilder column : columns) { |
|
107 |
if( column.isGeometry() ) { |
|
108 |
continue; |
|
109 |
} |
|
110 |
if (first) { |
|
111 |
first = false; |
|
112 |
} else { |
|
113 |
builder.append(", "); |
|
114 |
} |
|
115 |
builder.append(identifier(column.getName())); |
|
116 |
builder.append(" "); |
|
117 |
if( column.isAutomatic() ) { |
|
118 |
builder.append(" SERIAL"); |
|
119 |
} else { |
|
120 |
builder.append(sqltype(column.getType(), column.getPrecision(), column.getSize())); |
|
121 |
if (column.getDefaultValue() == null) { |
|
122 |
if (column.allowNulls()) { |
|
123 |
builder.append(" DEFAULT NULL"); |
|
124 |
} |
|
125 |
} else { |
|
126 |
builder.append(" DEFAULT '"); |
|
127 |
builder.append(column.getDefaultValue().toString()); |
|
128 |
builder.append("'"); |
|
129 |
} |
|
130 |
if (column.allowNulls()) { |
|
131 |
builder.append(" NULL"); |
|
132 |
} else { |
|
133 |
builder.append(" NOT NULL"); |
|
134 |
} |
|
135 |
} |
|
136 |
if (column.isPrimaryKey()) { |
|
137 |
builder.append(" PRIMARY KEY"); |
|
138 |
} |
|
139 |
} |
|
140 |
builder.append(" )"); |
|
141 |
sqls.add(builder.toString()); |
|
142 |
|
|
143 |
String AddGeometryColumn = "SELECT AddGeometryColumn({0} , {1} , {2}, {3,number,#######} , {4} , {5}, {6})"; |
|
144 |
for (ColumnDescriptorBuilderBase column : columns) { |
|
145 |
if( column.isGeometry() ) { |
|
146 |
String sql = MessageFormat.format( |
|
147 |
AddGeometryColumn, |
|
148 |
constant(this.table.getSchema()), |
|
149 |
constant(this.table.getName()), |
|
150 |
constant(column.getName()), |
|
151 |
column.getGeometrySRSId(), |
|
152 |
constant(sqlgeometrytype(column.getGeometryType(), column.getGeometrySubtype())), |
|
153 |
constant(sqlgeometrydimension(column.getGeometryType(), column.getGeometrySubtype())), |
|
154 |
constant(column.allowNulls()) |
|
155 |
); |
|
156 |
sqls.add(sql); |
|
157 |
} |
|
158 |
} |
|
159 |
for (ColumnDescriptorBuilderBase column : columns) { |
|
160 |
if( column.isIndexed() ) { |
|
161 |
String sql; |
|
162 |
String name = "idx_" + this.table().getName() + "_" + column.getName(); |
|
163 |
if( column.isGeometry() ) { |
|
164 |
sql = MessageFormat.format( |
|
165 |
config.getString(SQLConfig.CREATE_INDEX_name_ON_table_USING_GIST_column), |
|
166 |
name, |
|
167 |
this.table().toString(), |
|
168 |
column.getName() |
|
169 |
); |
|
170 |
} else { |
|
171 |
sql = MessageFormat.format( |
|
172 |
config.getString(SQLConfig.CREATE_INDEX_name_ON_table_column), |
|
173 |
name, |
|
174 |
this.table().toString(), |
|
175 |
column.getName() |
|
176 |
); |
|
177 |
} |
|
178 |
sqls.add(sql); |
|
179 |
} |
|
180 |
} |
|
181 |
return sqls; |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 |
public class PostgreSQLSelectBuilderBase extends SelectBuilderBase { |
|
186 |
|
|
187 |
@Override |
|
188 |
protected boolean isValid(StringBuilder message) { |
|
189 |
if( message == null ) { |
|
190 |
message = new StringBuilder(); |
|
191 |
} |
|
192 |
if( this.has_offset() && !this.has_order_by() ) { |
|
193 |
// Algunos gestores de BBDD requieren que se especifique un |
|
194 |
// orden para poder usar OFFSET. Como eso parece buena idea para |
|
195 |
// asegurar que siempre tengamos los mismo resultados, lo exijimos |
|
196 |
// siempre. |
|
197 |
message.append("Can't use OFFSET without an ORDER BY."); |
|
198 |
return false; |
|
199 |
} |
|
200 |
return true; |
|
201 |
} |
|
202 |
|
|
203 |
@Override |
|
204 |
public String toString() { |
|
205 |
// |
|
206 |
// https://www.postgresql.org/docs/9.1/static/sql-select.html |
|
207 |
// |
|
208 |
StringBuilder builder = new StringBuilder(); |
|
209 |
if( !isValid(builder) ) { |
|
210 |
throw new IllegalStateException(builder.toString()); |
|
211 |
} |
|
212 |
builder.append("SELECT "); |
|
213 |
if( this.distinct ) { |
|
214 |
builder.append("DISTINCT "); |
|
215 |
} |
|
216 |
boolean first = true; |
|
217 |
for (SelectColumnBuilder column : columns) { |
|
218 |
if (first) { |
|
219 |
first = false; |
|
220 |
} else { |
|
221 |
builder.append(", "); |
|
222 |
} |
|
223 |
builder.append(column.toString()); |
|
224 |
} |
|
225 |
|
|
226 |
if ( this.has_from() ) { |
|
227 |
builder.append(" FROM "); |
|
228 |
builder.append(this.from.toString()); |
|
229 |
} |
|
230 |
if ( this.has_where() ) { |
|
231 |
builder.append(" WHERE "); |
|
232 |
builder.append(this.where.toString()); |
|
233 |
} |
|
234 |
|
|
235 |
if( this.has_order_by() ) { |
|
236 |
builder.append(" ORDER BY "); |
|
237 |
first = true; |
|
238 |
for (OrderByBuilder item : this.order_by) { |
|
239 |
if (first) { |
|
240 |
first = false; |
|
241 |
} else { |
|
242 |
builder.append(", "); |
|
243 |
} |
|
244 |
builder.append(item.toString()); |
|
245 |
} |
|
246 |
} |
|
247 |
|
|
248 |
if ( this.has_limit() && this.has_offset() ) { |
|
249 |
builder.append(" OFFSET "); |
|
250 |
builder.append(this.offset); |
|
251 |
builder.append(" FETCH NEXT "); |
|
252 |
builder.append(this.limit); |
|
253 |
builder.append(" ROWS ONLY"); |
|
254 |
|
|
255 |
} else if ( this.has_limit()) { |
|
256 |
builder.append(" LIMIT "); |
|
257 |
builder.append(this.limit); |
|
258 |
|
|
259 |
} else if ( this.has_offset() ) { |
|
260 |
builder.append(" LIMIT ALL OFFSET "); |
|
261 |
builder.append(this.offset); |
|
262 |
} |
|
263 |
return builder.toString(); |
|
264 |
|
|
265 |
} |
|
266 |
} |
|
267 |
|
|
268 |
@Override |
|
269 |
public String bytearray(byte[] data) { |
|
270 |
return "decode('"+bytearray_hex(data)+"','hex')"; |
|
271 |
} |
|
272 |
|
|
273 |
@Override |
|
274 |
protected CreateTableBuilder createCreateTableBuilder() { |
|
275 |
return new PostgreSQLCreateTableBuilder(); |
|
276 |
} |
|
277 |
|
|
278 |
@Override |
|
279 |
protected SelectBuilder createSelectBuilder() { |
|
280 |
return new PostgreSQLSelectBuilderBase(); |
|
281 |
} |
|
282 |
|
|
283 |
@Override |
|
284 |
protected UpdateTableStatisticsBuilder createUpdateTableStatisticsBuilder() { |
|
285 |
return new PostgreSQLUpdateTableStatisticsBuilderBase(); |
|
286 |
} |
|
287 |
} |
tags/org.gvsig.postgresql-2.0.91/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLNewStoreParameters.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 |
package org.gvsig.postgresql.dal; |
|
23 |
|
|
24 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
25 |
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
|
26 |
|
|
27 |
public class PostgreSQLNewStoreParameters |
|
28 |
extends |
|
29 |
JDBCNewStoreParameters |
|
30 |
implements |
|
31 |
PostgreSQLConnectionParameters |
|
32 |
{ |
|
33 |
|
|
34 |
private final PostgreSQLConnectionParametersHelper helper; |
|
35 |
|
|
36 |
public PostgreSQLNewStoreParameters() { |
|
37 |
super( |
|
38 |
PostgreSQLLibrary.NAME + "NewStoreParameters", |
|
39 |
PostgreSQLLibrary.NAME |
|
40 |
); |
|
41 |
this.helper = new PostgreSQLConnectionParametersHelper(this); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public String getUrl() { |
|
46 |
return this.helper.getUrl(); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public void validate() throws ValidateDataParametersException { |
|
51 |
this.helper.validate(); |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public boolean getUseSSL() { |
|
56 |
return this.helper.getUseSSL(); |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public int getMaxIdle() { |
|
61 |
return this.helper.getMaxIdle(); |
|
62 |
} |
|
63 |
|
|
64 |
public void setUseSSL(boolean v) { |
|
65 |
this.helper.setUseSSL(v); |
|
66 |
} |
|
67 |
|
|
68 |
} |
tags/org.gvsig.postgresql-2.0.91/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLServerExplorerParameters.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 |
*/ |
|
25 |
package org.gvsig.postgresql.dal; |
|
26 |
|
|
27 |
import org.apache.commons.lang3.StringUtils; |
|
28 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
29 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
30 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
31 |
|
|
32 |
|
|
33 |
public class PostgreSQLServerExplorerParameters extends |
|
34 |
JDBCServerExplorerParameters |
|
35 |
implements |
|
36 |
PostgreSQLConnectionParameters |
|
37 |
{ |
|
38 |
|
|
39 |
private final PostgreSQLConnectionParametersHelper helper; |
|
40 |
|
|
41 |
public PostgreSQLServerExplorerParameters() { |
|
42 |
super( |
|
43 |
PostgreSQLLibrary.NAME + "ServerExplorerParameters", |
|
44 |
PostgreSQLLibrary.NAME |
|
45 |
); |
|
46 |
this.helper = new PostgreSQLConnectionParametersHelper(this); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public String getUrl() { |
|
51 |
return this.helper.getUrl(); |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public void validate() throws ValidateDataParametersException { |
|
56 |
// Esto seria para convertir los parametros de gvSIG 2.3 a 2.4. |
|
57 |
// if( !StringUtils.equalsIgnoreCase(PostgreSQLLibrary.NAME, (CharSequence) getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME)) ) { |
|
58 |
// setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, PostgreSQLLibrary.NAME); |
|
59 |
// } |
|
60 |
this.helper.validate(); |
|
61 |
super.validate(); |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public boolean getUseSSL() { |
|
66 |
return this.helper.getUseSSL(); |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
public int getMaxIdle() { |
|
71 |
return this.helper.getMaxIdle(); |
|
72 |
} |
|
73 |
|
|
74 |
public void setUseSSL(boolean v) { |
|
75 |
this.helper.setUseSSL(v); |
|
76 |
} |
|
77 |
} |
tags/org.gvsig.postgresql-2.0.91/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLHelper.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.postgresql.dal; |
|
3 |
|
|
4 |
import java.sql.Connection; |
|
5 |
import java.sql.PreparedStatement; |
|
6 |
import java.sql.SQLException; |
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.List; |
|
9 |
import org.apache.commons.dbcp.BasicDataSource; |
|
10 |
import org.apache.commons.lang3.BooleanUtils; |
|
11 |
import org.apache.commons.lang3.StringUtils; |
|
12 |
import org.gvsig.fmap.dal.DataTypes; |
|
13 |
import org.gvsig.fmap.dal.ExpressionBuilder; |
|
14 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
15 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
16 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
17 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
18 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
|
19 |
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters; |
|
20 |
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
|
21 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
22 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
23 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCDriverClassNotFoundException; |
|
24 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
|
25 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase; |
|
26 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
|
27 |
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolverBase; |
|
28 |
import org.gvsig.fmap.geom.Geometry; |
|
29 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
|
30 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
|
31 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
|
32 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
33 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
34 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
35 |
import org.gvsig.postgresql.dal.operations.PostgreSQLOperationsFactory; |
|
36 |
import org.gvsig.tools.dispose.Disposable; |
|
37 |
import org.slf4j.Logger; |
|
38 |
import org.slf4j.LoggerFactory; |
|
39 |
|
|
40 |
public class PostgreSQLHelper extends JDBCHelperBase { |
|
41 |
|
|
42 |
static final Logger logger = LoggerFactory.getLogger(PostgreSQLHelper.class); |
|
43 |
|
|
44 |
public static final String POSTGRESQL_JDBC_DRIVER = "org.postgresql.Driver"; |
|
45 |
|
|
46 |
public static String getConnectionURL(PostgreSQLConnectionParameters params) { |
|
47 |
return getConnectionURL( |
|
48 |
params.getHost(), |
|
49 |
params.getPort(), |
|
50 |
params.getDBName() |
|
51 |
); |
|
52 |
} |
|
53 |
|
|
54 |
public static String getConnectionURL(String host, Integer port, String db) { |
|
55 |
if( StringUtils.isEmpty(host) ) { |
|
56 |
throw new IllegalArgumentException("Parameter 'host' can't be null."); |
|
57 |
} |
|
58 |
String connectionURL = "jdbc:postgresql://" + host; |
|
59 |
if (port != null) { |
|
60 |
connectionURL = connectionURL + ":" + port; |
|
61 |
} |
|
62 |
connectionURL = connectionURL + "/" + db; |
|
63 |
logger.debug("connectionURL: {}", connectionURL); |
|
64 |
return connectionURL; |
|
65 |
} |
|
66 |
|
|
67 |
private static class ConnectionProvider { |
|
68 |
|
|
69 |
private static boolean needRegisterDriver = true; |
|
70 |
|
|
71 |
private BasicDataSource dataSource = null; |
|
72 |
|
|
73 |
private final PostgreSQLConnectionParameters connectionParameters; |
|
74 |
|
|
75 |
public ConnectionProvider(PostgreSQLConnectionParameters connectionParameters) { |
|
76 |
this.connectionParameters = connectionParameters; |
|
77 |
} |
|
78 |
|
|
79 |
public Connection getConnection() throws SQLException { |
|
80 |
if (this.dataSource == null) { |
|
81 |
this.dataSource = this.createDataSource(); |
|
82 |
} |
|
83 |
if( logger.isDebugEnabled() ) { |
|
84 |
logger.debug("getConnection:\n" + getStatusInformation()); |
|
85 |
} |
|
86 |
Connection conn; |
|
87 |
try { |
|
88 |
conn = this.dataSource.getConnection(); |
|
89 |
} catch(Throwable ex) { |
|
90 |
logger.debug("Error getting connection from pool.",ex); |
|
91 |
throw ex; |
|
92 |
} |
|
93 |
if( logger.isDebugEnabled() ) { |
|
94 |
logger.debug("Created connection: {}\n NumActive: {}\n NumIdle: {}", |
|
95 |
new Object[] { |
|
96 |
conn.hashCode(), |
|
97 |
this.dataSource.getNumActive(), |
|
98 |
this.dataSource.getNumIdle() |
|
99 |
} |
|
100 |
); |
|
101 |
} |
|
102 |
return conn; |
|
103 |
} |
|
104 |
|
|
105 |
public void closeConnection(Connection connection) { |
|
106 |
if( connection != null ) { |
|
107 |
int connectionId = connection.hashCode(); |
|
108 |
try { |
|
109 |
connection.close(); |
|
110 |
} catch(Throwable ex) { |
|
111 |
logger.warn("Can't close connection.", ex); |
|
112 |
} |
|
113 |
if( logger.isDebugEnabled() ) { |
|
114 |
Boolean isClosed; |
|
115 |
try { |
|
116 |
isClosed = connection.isClosed(); |
|
117 |
} catch(Throwable th) { |
|
118 |
isClosed = null; |
|
119 |
} |
|
120 |
logger.debug("Closed connection: {}\n isClosed: {}\n NumActive: {}\n NumIdle: {}", |
|
121 |
new Object[] { |
|
122 |
connectionId, |
|
123 |
isClosed, |
|
124 |
this.dataSource.getNumActive(), |
|
125 |
this.dataSource.getNumIdle() |
|
126 |
} |
|
127 |
); |
|
128 |
} |
|
129 |
} else if( logger.isDebugEnabled() ) { |
|
130 |
logger.debug("Close connection: null"); |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
public String getStatusInformation() { |
|
135 |
StringBuilder builder = new StringBuilder(); |
|
136 |
builder.append("BasicDataSource pool status:\n"); |
|
137 |
builder.append(" Connection URL: '").append(this.dataSource.getUrl()).append("'\n"); |
|
138 |
if( this.dataSource.getInitialSize()>0 ) { |
|
139 |
builder.append(" InitialSize: ").append(this.dataSource.getInitialSize()).append(" (The initial number of connections that are created when the pool is started)\n"); |
|
140 |
} |
|
141 |
if( this.dataSource.isPoolPreparedStatements() ) { |
|
142 |
builder.append(" PoolPreparedStatements: ").append(this.dataSource.isPoolPreparedStatements()).append("\n"); |
|
143 |
builder.append(" MaxOpenPreparedStatements: ").append(this.dataSource.getMaxOpenPreparedStatements()).append(" (The maximum number of open statements that can be allocated from the statement pool at the same time, or non-positive for no limit)\n"); |
|
144 |
} |
|
145 |
builder.append(" MaxActive: ").append(this.dataSource.getMaxActive()).append(" (The maximum number of active connections that can be allocated from this pool at the same time)\n"); |
|
146 |
builder.append(" MaxIdle: ").append(this.dataSource.getMaxIdle()).append(" (The maximum number of connections that can remain idle in the pool)\n"); |
|
147 |
builder.append(" NumActive:").append(this.dataSource.getNumActive()).append(" (the current number of active connections)\n"); |
|
148 |
builder.append(" NumIdle:").append(this.dataSource.getNumIdle()).append(" (the current number of idle connections)\n"); |
|
149 |
return builder.toString(); |
|
150 |
} |
|
151 |
|
|
152 |
private BasicDataSource createDataSource() throws SQLException { |
|
153 |
if (!this.isRegistered()) { |
|
154 |
this.registerDriver(); |
|
155 |
} |
|
156 |
PostgreSQLConnectionParameters params = connectionParameters; |
|
157 |
|
|
158 |
BasicDataSource ds = new BasicDataSource(); |
|
159 |
ds.setMaxIdle(params.getMaxIdle()); |
|
160 |
ds.setDriverClassName(params.getJDBCDriverClassName()); |
|
161 |
if( params.getUseSSL() ) { |
|
162 |
String s = BooleanUtils.toStringTrueFalse(params.getUseSSL()); |
|
163 |
ds.addConnectionProperty("ssl", s ); |
|
164 |
} |
|
165 |
if( !StringUtils.isEmpty(params.getUser()) ) { |
|
166 |
ds.setUsername(params.getUser()); |
|
167 |
} |
|
168 |
if( !StringUtils.isEmpty(params.getPassword()) ) { |
|
169 |
ds.setPassword(params.getPassword()); |
|
170 |
} |
|
171 |
ds.setUrl(params.getUrl()); |
|
172 |
|
|
173 |
ds.setMaxWait(60L * 1000); |
|
174 |
return ds; |
|
175 |
} |
|
176 |
|
|
177 |
private boolean isRegistered() { |
|
178 |
return needRegisterDriver; |
|
179 |
} |
|
180 |
|
|
181 |
public void registerDriver() throws SQLException { |
|
182 |
String className = this.connectionParameters.getJDBCDriverClassName(); |
|
183 |
if (className == null) { |
|
184 |
return; |
|
185 |
} |
|
186 |
try { |
|
187 |
Class theClass = Class.forName(className); |
|
188 |
if (theClass == null) { |
|
189 |
throw new JDBCDriverClassNotFoundException(PostgreSQLLibrary.NAME, className); |
|
190 |
} |
|
191 |
} catch (Exception e) { |
|
192 |
throw new SQLException("Can't register JDBC driver '" + className + "'.", e); |
|
193 |
} |
|
194 |
needRegisterDriver = false; |
|
195 |
} |
|
196 |
|
|
197 |
} |
|
198 |
|
|
199 |
private ConnectionProvider connectionProvider = null; |
|
200 |
|
|
201 |
public PostgreSQLHelper(JDBCConnectionParameters connectionParameters) { |
|
202 |
super(connectionParameters); |
|
203 |
this.srssolver = new SRSSolverBase(this); |
|
204 |
} |
|
205 |
|
|
206 |
@Override |
|
207 |
public Connection getConnection() throws AccessResourceException { |
|
208 |
try { |
|
209 |
if (this.connectionProvider == null) { |
|
210 |
this.connectionProvider = new ConnectionProvider(this.getConnectionParameters()); |
|
211 |
} |
|
212 |
return this.connectionProvider.getConnection(); |
|
213 |
} catch (SQLException ex) { |
|
214 |
throw new AccessResourceException(PostgreSQLLibrary.NAME, ex); |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
@Override |
|
219 |
public void closeConnection(Connection connection) { |
|
220 |
this.connectionProvider.closeConnection(connection); |
|
221 |
} |
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
@Override |
|
226 |
public PostgreSQLConnectionParameters getConnectionParameters() { |
|
227 |
return (PostgreSQLConnectionParameters) super.getConnectionParameters(); |
|
228 |
} |
|
229 |
|
|
230 |
@Override |
|
231 |
public String getConnectionURL() { |
|
232 |
return getConnectionURL(this.getConnectionParameters()); |
|
233 |
} |
|
234 |
|
|
235 |
@Override |
|
236 |
protected String getResourceType() { |
|
237 |
return PostgreSQLLibrary.NAME; |
|
238 |
} |
|
239 |
|
|
240 |
@Override |
|
241 |
public String getProviderName() { |
|
242 |
return PostgreSQLLibrary.NAME; |
|
243 |
} |
|
244 |
|
|
245 |
@Override |
|
246 |
public JDBCSQLBuilderBase createSQLBuilder() { |
|
247 |
return new PostgreSQLBuilder(this); |
|
248 |
} |
|
249 |
|
|
250 |
@Override |
|
251 |
public OperationsFactory getOperations() { |
|
252 |
if (this.operationsFactory == null) { |
|
253 |
this.operationsFactory = new PostgreSQLOperationsFactory(this); |
|
254 |
} |
|
255 |
return operationsFactory; |
|
256 |
} |
|
257 |
|
|
258 |
@Override |
|
259 |
public SQLBuilder.GeometrySupportType getGeometrySupportType() { |
|
260 |
return SQLBuilder.GeometrySupportType.WKB; |
|
261 |
} |
|
262 |
|
|
263 |
@Override |
|
264 |
public boolean hasSpatialFunctions() { |
|
265 |
return true; |
|
266 |
} |
|
267 |
|
|
268 |
@Override |
|
269 |
public boolean canWriteGeometry(int geometryType, int geometrySubtype) { |
|
270 |
return true; |
|
271 |
} |
|
272 |
|
|
273 |
@Override |
|
274 |
public String getQuoteForIdentifiers() { |
|
275 |
return "\""; |
|
276 |
} |
|
277 |
|
|
278 |
@Override |
|
279 |
public boolean allowAutomaticValues() { |
|
280 |
return true; |
|
281 |
} |
|
282 |
|
|
283 |
@Override |
|
284 |
public boolean supportOffsetInSelect() { |
|
285 |
return true; |
|
286 |
} |
|
287 |
|
|
288 |
@Override |
|
289 |
public String getQuoteForStrings() { |
|
290 |
return "'"; |
|
291 |
} |
|
292 |
|
|
293 |
@Override |
|
294 |
public String getSourceId(JDBCStoreParameters parameters) { |
|
295 |
return parameters.getDBName() + "." + |
|
296 |
parameters.getSchema()+ "." + |
|
297 |
parameters.getTable(); |
|
298 |
} |
|
299 |
|
|
300 |
@Override |
|
301 |
public JDBCNewStoreParameters createNewStoreParameters() { |
|
302 |
return new PostgreSQLNewStoreParameters(); |
|
303 |
} |
|
304 |
|
|
305 |
@Override |
|
306 |
public JDBCStoreParameters createOpenStoreParameters() { |
|
307 |
return new PostgreSQLStoreParameters(); |
|
308 |
} |
|
309 |
|
|
310 |
@Override |
|
311 |
public JDBCServerExplorerParameters createServerExplorerParameters() { |
|
312 |
return new PostgreSQLServerExplorerParameters(); |
|
313 |
} |
|
314 |
|
|
315 |
public Disposable setPreparedStatementParameters(PreparedStatement st, JDBCSQLBuilderBase sqlbuilder, FeatureType type, FeatureProvider feature) { |
|
316 |
try { |
|
317 |
List<Object> values = new ArrayList<>(); |
|
318 |
for (ExpressionBuilder.Parameter parameter : sqlbuilder.getParameters()) { |
|
319 |
Object value; |
|
320 |
if (parameter.is_constant()) { |
|
321 |
value = parameter.getValue(); |
|
322 |
} else { |
|
323 |
String name = parameter.getName(); |
|
324 |
value = feature.get(name); |
|
325 |
FeatureAttributeDescriptor attr = type.getAttributeDescriptor(name); |
|
326 |
if( attr.getType()==DataTypes.GEOMETRY ) { |
|
327 |
value = forceGeometry(attr.getGeomType(), (Geometry) value); |
|
328 |
} |
|
329 |
} |
|
330 |
values.add(value); |
|
331 |
} |
|
332 |
return sqlbuilder.setStatementParameters(st, values, sqlbuilder.geometry_support_type()); |
|
333 |
} catch (Exception ex) { |
|
334 |
String f = "unknow"; |
|
335 |
try { |
|
336 |
f = feature.toString(); |
|
337 |
} catch (Exception ex2) { |
|
338 |
// Do nothing |
|
339 |
} |
|
340 |
throw new RuntimeException("Can't set parameters to prepared statement from the feature (" + f + ")", ex); |
|
341 |
} |
|
342 |
} |
|
343 |
|
|
344 |
private Geometry forceGeometry(GeometryType geomtype, Geometry geom) throws CreateGeometryException { |
|
345 |
if( geom == null ) { |
|
346 |
return null; |
|
347 |
} |
|
348 |
switch( geomtype.getType() ) { |
|
349 |
case Geometry.TYPES.MULTIPOLYGON: |
|
350 |
if( geom.getType()==Geometry.TYPES.POLYGON ) { |
|
351 |
MultiPolygon x = getGeometryManager().createMultiPolygon(geomtype.getSubType()); |
|
352 |
x.addPrimitive((Primitive) geom); |
|
353 |
geom = x; |
|
354 |
} |
|
355 |
break; |
|
356 |
case Geometry.TYPES.MULTILINE: |
|
357 |
if( geom.getType()==Geometry.TYPES.LINE ) { |
|
358 |
MultiLine x = getGeometryManager().createMultiLine(geomtype.getSubType()); |
|
359 |
x.addPrimitive((Primitive) geom); |
|
360 |
geom = x; |
|
361 |
} |
|
362 |
break; |
|
363 |
case Geometry.TYPES.MULTIPOINT: |
|
364 |
if( geom.getType()==Geometry.TYPES.POINT ) { |
|
365 |
MultiLine x = getGeometryManager().createMultiLine(geomtype.getSubType()); |
|
366 |
x.addPrimitive((Primitive) geom); |
|
367 |
geom = x; |
|
368 |
} |
|
369 |
break; |
|
370 |
case Geometry.TYPES.POLYGON: |
|
371 |
if( geom.getType()==Geometry.TYPES.MULTIPOLYGON ) { |
|
372 |
MultiPolygon x = (MultiPolygon) geom; |
|
373 |
if( x.getPrimitivesNumber()==1 ) { |
|
374 |
geom = x.getPrimitiveAt(0); |
|
375 |
} |
|
376 |
} |
|
377 |
break; |
|
378 |
case Geometry.TYPES.LINE: |
|
379 |
if( geom.getType()==Geometry.TYPES.MULTILINE ) { |
|
380 |
MultiLine x = (MultiLine) geom; |
|
381 |
if( x.getPrimitivesNumber()==1 ) { |
|
382 |
geom = x.getPrimitiveAt(0); |
|
383 |
} |
|
384 |
} |
|
385 |
break; |
|
386 |
case Geometry.TYPES.POINT: |
|
387 |
if( geom.getType()==Geometry.TYPES.MULTIPOINT ) { |
|
388 |
MultiPoint x = (MultiPoint) geom; |
|
389 |
if( x.getPrimitivesNumber()==1 ) { |
|
390 |
geom = x.getPrimitiveAt(0); |
|
391 |
} |
|
392 |
} |
|
393 |
} |
|
394 |
return geom; |
|
395 |
} |
|
396 |
|
|
397 |
|
|
398 |
} |
tags/org.gvsig.postgresql-2.0.91/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLServerExplorerFactory.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.postgresql.dal; |
|
3 |
|
|
4 |
import org.apache.commons.lang3.StringUtils; |
|
5 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
6 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
7 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
|
8 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
9 |
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters; |
|
10 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
11 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
12 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
|
13 |
import org.gvsig.fmap.dal.store.jdbc2.impl.JDBCServerExplorerFactory; |
|
14 |
|
|
15 |
|
|
16 |
public class PostgreSQLServerExplorerFactory extends JDBCServerExplorerFactory { |
|
17 |
|
|
18 |
private static final String NAME = PostgreSQLLibrary.NAME; |
|
19 |
|
|
20 |
public PostgreSQLServerExplorerFactory() { |
|
21 |
super( |
|
22 |
NAME, |
|
23 |
"PostgreSQL Server" |
|
24 |
); |
|
25 |
} |
|
26 |
|
|
27 |
public PostgreSQLServerExplorerFactory(String name) { |
|
28 |
// Cuando se instancia la factoria con un "name" que no es el de por |
|
29 |
// defecto, es para declarar "alias" para el ServerExplorer, normalmente |
|
30 |
// para mantener compatibilidad con versiones anteriores. |
|
31 |
// Marcaremos la factoria como "hidden" para que no aparezca |
|
32 |
// en el interface de usuario. |
|
33 |
super( |
|
34 |
name, |
|
35 |
"PostgreSQL Server (for compatibility)", |
|
36 |
true |
|
37 |
); |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public JDBCServerExplorer create( |
|
42 |
DataServerExplorerParameters parameters, |
|
43 |
DataServerExplorerProviderServices providerServices |
|
44 |
) throws InitializeException { |
|
45 |
// Esto seria para convertir los parametros de gvSIG 2.3 a 2.4. |
|
46 |
// if( !StringUtils.equalsIgnoreCase(NAME, (CharSequence) parameters.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME)) ) { |
|
47 |
// parameters.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, NAME); |
|
48 |
// } |
|
49 |
JDBCHelper helper = new PostgreSQLHelper((JDBCConnectionParameters) parameters); |
|
50 |
JDBCServerExplorer server = helper.createServerExplorer( |
|
51 |
(JDBCServerExplorerParameters) parameters, |
|
52 |
providerServices |
|
53 |
); |
|
54 |
return server; |
|
55 |
} |
|
56 |
|
|
57 |
|
|
58 |
@Override |
|
59 |
public JDBCServerExplorerParameters createParameters() { |
|
60 |
JDBCServerExplorerParameters params = new PostgreSQLServerExplorerParameters(); |
|
61 |
return params; |
|
62 |
} |
|
63 |
|
|
64 |
} |
tags/org.gvsig.postgresql-2.0.91/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLStoreProviderFactory.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.postgresql.dal; |
|
3 |
|
|
4 |
import org.gvsig.fmap.dal.DataParameters; |
|
5 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
6 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
7 |
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters; |
|
8 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
9 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
10 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCStoreProvider; |
|
11 |
import org.gvsig.fmap.dal.store.jdbc2.impl.JDBCStoreProviderFactory; |
|
12 |
|
|
13 |
|
|
14 |
public class PostgreSQLStoreProviderFactory extends JDBCStoreProviderFactory { |
|
15 |
|
|
16 |
public PostgreSQLStoreProviderFactory() { |
|
17 |
super( |
|
18 |
PostgreSQLLibrary.NAME, |
|
19 |
"PostgreSQL store" |
|
20 |
); |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
public JDBCStoreProvider createProvider( |
|
25 |
DataParameters parameters, |
|
26 |
DataStoreProviderServices providerServices |
|
27 |
) throws InitializeException { |
|
28 |
JDBCHelper helper = new PostgreSQLHelper((JDBCConnectionParameters) parameters); |
|
29 |
JDBCStoreProvider provider = helper.createProvider( |
|
30 |
(JDBCStoreParameters) parameters, |
|
31 |
providerServices |
|
32 |
); |
|
33 |
return provider; |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public JDBCStoreParameters createParameters() { |
|
38 |
JDBCStoreParameters params = new PostgreSQLStoreParameters(); |
|
39 |
return params; |
|
40 |
} |
|
41 |
|
|
42 |
} |
tags/org.gvsig.postgresql-2.0.91/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/operations/PostgreSQLAppendOperation.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.postgresql.dal.operations; |
|
3 |
|
|
4 |
import org.gvsig.fmap.dal.exception.DataException; |
|
5 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
6 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
7 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
8 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
|
9 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.AppendOperation; |
|
10 |
import org.gvsig.postgresql.dal.PostgreSQLHelper; |
|
11 |
|
|
12 |
|
|
13 |
public class PostgreSQLAppendOperation extends AppendOperation { |
|
14 |
|
|
15 |
public PostgreSQLAppendOperation( |
|
16 |
JDBCHelper helper, |
|
17 |
String database, |
|
18 |
String schema, |
|
19 |
String table, |
|
20 |
FeatureType type |
|
21 |
) { |
|
22 |
super(helper, database, schema, table, type); |
|
23 |
} |
|
24 |
|
|
25 |
|
|
26 |
private PostgreSQLHelper getHelper() { |
|
27 |
return (PostgreSQLHelper) this.helper; |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public void append(FeatureProvider feature) throws DataException { |
|
32 |
int n; |
|
33 |
try { |
|
34 |
getHelper().setPreparedStatementParameters(preparedStatement, sqlbuilder, type, feature); |
|
35 |
n = JDBCUtils.executeUpdate(this.preparedStatement,this.sql); |
|
36 |
} catch(Exception ex) { |
|
37 |
throw new RuntimeException("Can't insert feature.", ex); |
|
38 |
} |
|
39 |
if( n<1 ) { |
|
40 |
throw new RuntimeException("Can't insert feature (n="+n+")."); |
|
41 |
} |
|
42 |
} |
|
43 |
|
|
44 |
} |
tags/org.gvsig.postgresql-2.0.91/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/operations/PostgreSQLFetchFeatureTypeOperation.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.postgresql.dal.operations; |
|
3 |
|
|
4 |
import java.sql.Connection; |
|
5 |
import java.sql.ResultSet; |
|
6 |
import java.sql.ResultSetMetaData; |
|
7 |
import java.sql.SQLException; |
|
8 |
import java.sql.Statement; |
|
9 |
import java.util.HashMap; |
|
10 |
import java.util.List; |
|
11 |
import java.util.Map; |
|
12 |
import org.apache.commons.lang3.StringUtils; |
|
13 |
import org.cresques.cts.IProjection; |
|
14 |
import org.gvsig.fmap.dal.DataTypes; |
|
15 |
import org.gvsig.fmap.dal.exception.DataException; |
|
16 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
17 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
18 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
19 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
|
20 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
|
21 |
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolver; |
|
22 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.FetchFeatureTypeOperation; |
|
23 |
import org.gvsig.fmap.geom.Geometry; |
|
24 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
25 |
import org.gvsig.fmap.geom.GeometryManager; |
|
26 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
27 |
|
|
28 |
public class PostgreSQLFetchFeatureTypeOperation extends FetchFeatureTypeOperation { |
|
29 |
|
|
30 |
private static Map<String,GeometryType>databaseGeometryTypes = null; |
|
31 |
|
|
32 |
public PostgreSQLFetchFeatureTypeOperation( |
|
33 |
JDBCHelper helper |
|
34 |
) { |
|
35 |
super(helper); |
|
36 |
} |
|
37 |
|
|
38 |
private GeometryType getGT( |
|
39 |
GeometryManager manager, |
|
40 |
int type, |
|
41 |
int subtype |
|
42 |
) { |
|
43 |
try { |
|
44 |
return manager.getGeometryType(type, subtype); |
|
45 |
} catch (Exception ex) { |
|
46 |
return null; |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
public PostgreSQLFetchFeatureTypeOperation( |
|
51 |
JDBCHelper helper, |
|
52 |
EditableFeatureType featureType, |
|
53 |
String dbname, |
|
54 |
String schema, |
|
55 |
String table, |
|
56 |
List<String> primaryKeys, |
|
57 |
String defaultGeometryColumn, |
|
58 |
IProjection crs |
|
59 |
) { |
|
60 |
super(helper, featureType, dbname, schema, table, primaryKeys, defaultGeometryColumn, crs); |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public void fetch(EditableFeatureType featureType, Connection conn, String dbname, String schema, String table, List<String> pks, String defaultGeometryColumn, IProjection crs) throws DataException { |
|
65 |
super.fetch(featureType, conn, dbname, schema, table, pks, defaultGeometryColumn, crs); |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
protected int getDataTypeFromMetadata( |
|
70 |
ResultSetMetaData rsMetadata, |
|
71 |
int colIndex |
|
72 |
) throws SQLException { |
|
73 |
|
|
74 |
return super.getDataTypeFromMetadata(rsMetadata, colIndex); |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
protected void fetchGeometryTypeAndSRS( |
|
79 |
EditableFeatureAttributeDescriptor attr, |
|
80 |
ResultSetMetaData rsMetadata, |
|
81 |
int colIndex |
|
82 |
) { |
|
83 |
if( attr.getType()!=DataTypes.GEOMETRY ) { |
|
84 |
return; |
|
85 |
} |
|
86 |
try { |
|
87 |
JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder(); |
|
88 |
sqlbuilder.select().column().name("f_table_catalog"); |
|
89 |
sqlbuilder.select().column().name("f_table_schema"); |
|
90 |
sqlbuilder.select().column().name("f_table_name"); |
|
91 |
sqlbuilder.select().column().name("f_geometry_column"); |
|
92 |
sqlbuilder.select().column().name("coord_dimension"); |
|
93 |
sqlbuilder.select().column().name("srid"); |
|
94 |
sqlbuilder.select().column().name("type"); |
|
95 |
sqlbuilder.select().where().set( |
|
96 |
sqlbuilder.eq( |
|
97 |
sqlbuilder.column("f_table_name"), |
|
98 |
sqlbuilder.constant(this.getTablename()) |
|
99 |
) |
|
100 |
); |
|
101 |
sqlbuilder.select().where().and( |
|
102 |
sqlbuilder.eq( |
|
103 |
sqlbuilder.column("f_geometry_column"), |
|
104 |
sqlbuilder.constant(attr.getName()) |
|
105 |
) |
|
106 |
); |
|
107 |
sqlbuilder.select().from().table().name("geometry_columns"); |
|
108 |
Statement st = null; |
|
109 |
ResultSet rs = null; |
|
110 |
|
|
111 |
String srsid = null; |
|
112 |
String geometryTypeName = null; |
|
113 |
try { |
|
114 |
st = this.getConnection().createStatement(); |
|
115 |
rs = JDBCUtils.executeQuery(st, sqlbuilder.toString()); |
|
116 |
if (rs.next()) { |
|
117 |
srsid = rs.getString("srid"); |
|
118 |
geometryTypeName = rs.getString("type"); |
Also available in: Unified diff