Revision 553
tags/org.gvsig.postgresql-2.0.111/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.111</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.251</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.111</connection> |
|
20 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-postgresql/tags/org.gvsig.postgresql-2.0.111</developerConnection> |
|
21 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-postgresql/repository/show/tags/org.gvsig.postgresql-2.0.111</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.111</version> |
|
63 |
</dependency> |
|
64 |
<dependency> |
|
65 |
<groupId>org.gvsig</groupId> |
|
66 |
<artifactId>org.gvsig.postgresql.app.mainplugin</artifactId> |
|
67 |
<version>2.0.111</version> |
|
68 |
</dependency> |
|
69 |
<dependency> |
|
70 |
<groupId>org.postgresql</groupId> |
|
71 |
<artifactId>postgresql</artifactId> |
|
72 |
<version>42.2.6</version> |
|
73 |
</dependency> |
|
74 |
</dependencies> |
|
75 |
</dependencyManagement> |
|
76 |
|
|
77 |
<modules> |
|
78 |
<module>org.gvsig.postgresql.app</module> |
|
79 |
<module>org.gvsig.postgresql.provider</module> |
|
80 |
</modules> |
|
81 |
|
|
82 |
</project> |
tags/org.gvsig.postgresql-2.0.111/org.gvsig.postgresql.provider/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.provider</artifactId> |
|
7 |
<packaging>jar</packaging> |
|
8 |
<name>${project.artifactId}</name> |
|
9 |
<description>DAL provider for PostgeSQL files</description> |
|
10 |
<parent> |
|
11 |
<groupId>org.gvsig</groupId> |
|
12 |
<artifactId>org.gvsig.postgresql</artifactId> |
|
13 |
<version>2.0.111</version> |
|
14 |
</parent> |
|
15 |
<build> |
|
16 |
<plugins> |
|
17 |
<plugin> |
|
18 |
<groupId>org.apache.maven.plugins</groupId> |
|
19 |
<artifactId>maven-surefire-plugin</artifactId> |
|
20 |
<version>2.15</version> |
|
21 |
</plugin> |
|
22 |
</plugins> |
|
23 |
</build> |
|
24 |
<dependencies> |
|
25 |
<dependency> |
|
26 |
<groupId>com.googlecode.log4jdbc</groupId> |
|
27 |
<artifactId>log4jdbc</artifactId> |
|
28 |
<scope>compile</scope> |
|
29 |
</dependency> |
|
30 |
<dependency> |
|
31 |
<groupId>org.gvsig</groupId> |
|
32 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
33 |
<scope>compile</scope> |
|
34 |
</dependency> |
|
35 |
<dependency> |
|
36 |
<groupId>org.gvsig</groupId> |
|
37 |
<artifactId>org.gvsig.projection.api</artifactId> |
|
38 |
<scope>compile</scope> |
|
39 |
</dependency> |
|
40 |
<dependency> |
|
41 |
<groupId>org.gvsig</groupId> |
|
42 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
43 |
<scope>compile</scope> |
|
44 |
</dependency> |
|
45 |
|
|
46 |
<dependency> |
|
47 |
<groupId>org.gvsig</groupId> |
|
48 |
<artifactId>org.gvsig.fmap.dal.db.jdbc</artifactId> |
|
49 |
<scope>compile</scope> |
|
50 |
</dependency> |
|
51 |
|
|
52 |
<dependency> |
|
53 |
<groupId>org.gvsig</groupId> |
|
54 |
<artifactId>org.gvsig.fmap.dal.db.lib</artifactId> |
|
55 |
<scope>compile</scope> |
|
56 |
</dependency> |
|
57 |
|
|
58 |
<dependency> |
|
59 |
<groupId>org.gvsig</groupId> |
|
60 |
<artifactId>org.gvsig.fmap.dal.spi</artifactId> |
|
61 |
<scope>compile</scope> |
|
62 |
</dependency> |
|
63 |
<dependency> |
|
64 |
<groupId>org.gvsig</groupId> |
|
65 |
<artifactId>org.gvsig.metadata.lib.basic.api</artifactId> |
|
66 |
<scope>compile</scope> |
|
67 |
</dependency> |
|
68 |
<dependency> |
|
69 |
<groupId>org.gvsig</groupId> |
|
70 |
<artifactId>org.gvsig.fmap.geometry.api</artifactId> |
|
71 |
<scope>compile</scope> |
|
72 |
</dependency> |
|
73 |
<!-- |
|
74 |
<dependency> |
|
75 |
<groupId>org.gvsig</groupId> |
|
76 |
<artifactId>org.gvsig.fmap.geometry.operation</artifactId> |
|
77 |
<scope>compile</scope> |
|
78 |
</dependency> |
|
79 |
--> |
|
80 |
<dependency> |
|
81 |
<groupId>org.gvsig</groupId> |
|
82 |
<artifactId>org.gvsig.timesupport.lib.api</artifactId> |
|
83 |
<scope>compile</scope> |
|
84 |
</dependency> |
|
85 |
<dependency> |
|
86 |
<groupId>org.gvsig</groupId> |
|
87 |
<artifactId>org.gvsig.utils</artifactId> |
|
88 |
<scope>compile</scope> |
|
89 |
</dependency> |
|
90 |
<dependency> |
|
91 |
<groupId>org.postgresql</groupId> |
|
92 |
<artifactId>postgresql</artifactId> |
|
93 |
<scope>compile</scope> |
|
94 |
</dependency> |
|
95 |
<dependency> |
|
96 |
<groupId>commons-dbcp</groupId> |
|
97 |
<artifactId>commons-dbcp</artifactId> |
|
98 |
<scope>compile</scope> |
|
99 |
</dependency> |
|
100 |
<dependency> |
|
101 |
<groupId>commons-collections</groupId> |
|
102 |
<artifactId>commons-collections</artifactId> |
|
103 |
<scope>compile</scope> |
|
104 |
</dependency> |
|
105 |
|
|
106 |
|
|
107 |
<!-- TESTS --> |
|
108 |
<dependency> |
|
109 |
<groupId>org.gvsig</groupId> |
|
110 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
111 |
<type>test-jar</type> |
|
112 |
<scope>test</scope> |
|
113 |
</dependency> |
|
114 |
<dependency> |
|
115 |
<groupId>org.gvsig</groupId> |
|
116 |
<artifactId>org.gvsig.compat.se</artifactId> |
|
117 |
<scope>test</scope> |
|
118 |
</dependency> |
|
119 |
<dependency> |
|
120 |
<groupId>org.gvsig</groupId> |
|
121 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
122 |
<type>test-jar</type> |
|
123 |
<scope>test</scope> |
|
124 |
</dependency> |
|
125 |
<dependency> |
|
126 |
<groupId>org.gvsig</groupId> |
|
127 |
<artifactId>${org.gvsig.fmap.geometry.impl}</artifactId> |
|
128 |
<scope>test</scope> |
|
129 |
</dependency> |
|
130 |
<dependency> |
|
131 |
<groupId>org.gvsig</groupId> |
|
132 |
<artifactId>org.gvsig.expressionevaluator.lib.impl</artifactId> |
|
133 |
<scope>test</scope> |
|
134 |
</dependency> |
|
135 |
<dependency> |
|
136 |
<groupId>org.gvsig</groupId> |
|
137 |
<artifactId>${org.gvsig.proj.lib.impl}</artifactId> |
|
138 |
<scope>test</scope> |
|
139 |
</dependency> |
|
140 |
<dependency> |
|
141 |
<groupId>org.gvsig</groupId> |
|
142 |
<artifactId>org.gvsig.projection.cresques.impl</artifactId> |
|
143 |
<scope>test</scope> |
|
144 |
</dependency> |
|
145 |
<dependency> |
|
146 |
<groupId>org.gvsig</groupId> |
|
147 |
<artifactId>org.gvsig.timesupport.lib.impl</artifactId> |
|
148 |
<scope>test</scope> |
|
149 |
</dependency> |
|
150 |
<dependency> |
|
151 |
<artifactId>junit</artifactId> |
|
152 |
<groupId>junit</groupId> |
|
153 |
<version>4.11</version> |
|
154 |
</dependency> |
|
155 |
</dependencies> |
|
156 |
|
|
157 |
</project> |
tags/org.gvsig.postgresql-2.0.111/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.111/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.111/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.111/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.SQLException; |
|
6 |
import org.apache.commons.dbcp.BasicDataSource; |
|
7 |
import org.apache.commons.lang3.BooleanUtils; |
|
8 |
import org.apache.commons.lang3.StringUtils; |
|
9 |
import org.gvsig.expressionevaluator.ExpressionBuilder.GeometrySupportType; |
|
10 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
11 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
|
12 |
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters; |
|
13 |
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
|
14 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
15 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
16 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCDriverClassNotFoundException; |
|
17 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
|
18 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase; |
|
19 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
|
20 |
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolverBase; |
|
21 |
import org.gvsig.postgresql.dal.operations.PostgreSQLOperationsFactory; |
|
22 |
import org.slf4j.Logger; |
|
23 |
import org.slf4j.LoggerFactory; |
|
24 |
|
|
25 |
public class PostgreSQLHelper extends JDBCHelperBase { |
|
26 |
|
|
27 |
static final Logger logger = LoggerFactory.getLogger(PostgreSQLHelper.class); |
|
28 |
|
|
29 |
public static final String POSTGRESQL_JDBC_DRIVER = "org.postgresql.Driver"; |
|
30 |
|
|
31 |
public static String getConnectionURL(PostgreSQLConnectionParameters params) { |
|
32 |
return getConnectionURL( |
|
33 |
params.getHost(), |
|
34 |
params.getPort(), |
|
35 |
params.getDBName() |
|
36 |
); |
|
37 |
} |
|
38 |
|
|
39 |
public static String getConnectionURL(String host, Integer port, String db) { |
|
40 |
if( StringUtils.isEmpty(host) ) { |
|
41 |
throw new IllegalArgumentException("Parameter 'host' can't be null."); |
|
42 |
} |
|
43 |
String connectionURL = "jdbc:postgresql://" + host; |
|
44 |
if (port != null) { |
|
45 |
connectionURL = connectionURL + ":" + port; |
|
46 |
} |
|
47 |
connectionURL = connectionURL + "/" + db; |
|
48 |
logger.debug("connectionURL: {}", connectionURL); |
|
49 |
return connectionURL; |
|
50 |
} |
|
51 |
|
|
52 |
private static class ConnectionProvider { |
|
53 |
|
|
54 |
private static boolean needRegisterDriver = true; |
|
55 |
|
|
56 |
private BasicDataSource dataSource = null; |
|
57 |
|
|
58 |
private final PostgreSQLConnectionParameters connectionParameters; |
|
59 |
|
|
60 |
public ConnectionProvider(PostgreSQLConnectionParameters connectionParameters) { |
|
61 |
this.connectionParameters = connectionParameters; |
|
62 |
} |
|
63 |
|
|
64 |
public Connection getConnection() throws SQLException { |
|
65 |
if (this.dataSource == null) { |
|
66 |
this.dataSource = this.createDataSource(); |
|
67 |
} |
|
68 |
if( logger.isDebugEnabled() ) { |
|
69 |
logger.debug("getConnection:\n" + getStatusInformation()); |
|
70 |
} |
|
71 |
Connection conn; |
|
72 |
try { |
|
73 |
conn = this.dataSource.getConnection(); |
|
74 |
} catch(Throwable ex) { |
|
75 |
logger.debug("Error getting connection from pool.",ex); |
|
76 |
throw ex; |
|
77 |
} |
|
78 |
if( logger.isDebugEnabled() ) { |
|
79 |
logger.debug("Created connection: {}\n NumActive: {}\n NumIdle: {}", |
|
80 |
new Object[] { |
|
81 |
conn.hashCode(), |
|
82 |
this.dataSource.getNumActive(), |
|
83 |
this.dataSource.getNumIdle() |
|
84 |
} |
|
85 |
); |
|
86 |
} |
|
87 |
return conn; |
|
88 |
} |
|
89 |
|
|
90 |
public void closeConnection(Connection connection) { |
|
91 |
if( connection != null ) { |
|
92 |
int connectionId = connection.hashCode(); |
|
93 |
try { |
|
94 |
connection.close(); |
|
95 |
} catch(Throwable ex) { |
|
96 |
logger.warn("Can't close connection.", ex); |
|
97 |
} |
|
98 |
if( logger.isDebugEnabled() ) { |
|
99 |
Boolean isClosed; |
|
100 |
try { |
|
101 |
isClosed = connection.isClosed(); |
|
102 |
} catch(Throwable th) { |
|
103 |
isClosed = null; |
|
104 |
} |
|
105 |
logger.debug("Closed connection: {}\n isClosed: {}\n NumActive: {}\n NumIdle: {}", |
|
106 |
new Object[] { |
|
107 |
connectionId, |
|
108 |
isClosed, |
|
109 |
this.dataSource.getNumActive(), |
|
110 |
this.dataSource.getNumIdle() |
|
111 |
} |
|
112 |
); |
|
113 |
} |
|
114 |
} else if( logger.isDebugEnabled() ) { |
|
115 |
logger.debug("Close connection: null"); |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
public String getStatusInformation() { |
|
120 |
StringBuilder builder = new StringBuilder(); |
|
121 |
builder.append("BasicDataSource pool status:\n"); |
|
122 |
builder.append(" Connection URL: '").append(this.dataSource.getUrl()).append("'\n"); |
|
123 |
if( this.dataSource.getInitialSize()>0 ) { |
|
124 |
builder.append(" InitialSize: ").append(this.dataSource.getInitialSize()).append(" (The initial number of connections that are created when the pool is started)\n"); |
|
125 |
} |
|
126 |
if( this.dataSource.isPoolPreparedStatements() ) { |
|
127 |
builder.append(" PoolPreparedStatements: ").append(this.dataSource.isPoolPreparedStatements()).append("\n"); |
|
128 |
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"); |
|
129 |
} |
|
130 |
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"); |
|
131 |
builder.append(" MaxIdle: ").append(this.dataSource.getMaxIdle()).append(" (The maximum number of connections that can remain idle in the pool)\n"); |
|
132 |
builder.append(" NumActive:").append(this.dataSource.getNumActive()).append(" (the current number of active connections)\n"); |
|
133 |
builder.append(" NumIdle:").append(this.dataSource.getNumIdle()).append(" (the current number of idle connections)\n"); |
|
134 |
return builder.toString(); |
|
135 |
} |
|
136 |
|
|
137 |
private BasicDataSource createDataSource() throws SQLException { |
|
138 |
if (!this.isRegistered()) { |
|
139 |
this.registerDriver(); |
|
140 |
} |
|
141 |
PostgreSQLConnectionParameters params = connectionParameters; |
|
142 |
|
|
143 |
BasicDataSource ds = new BasicDataSource(); |
|
144 |
ds.setMaxIdle(params.getMaxIdle()); |
|
145 |
ds.setDriverClassName(params.getJDBCDriverClassName()); |
|
146 |
if( params.getUseSSL() ) { |
|
147 |
String s = BooleanUtils.toStringTrueFalse(params.getUseSSL()); |
|
148 |
ds.addConnectionProperty("ssl", s ); |
|
149 |
} |
|
150 |
if( !StringUtils.isEmpty(params.getUser()) ) { |
|
151 |
ds.setUsername(params.getUser()); |
|
152 |
} |
|
153 |
if( !StringUtils.isEmpty(params.getPassword()) ) { |
|
154 |
ds.setPassword(params.getPassword()); |
|
155 |
} |
|
156 |
ds.setUrl(params.getUrl()); |
|
157 |
|
|
158 |
ds.setMaxWait(60L * 1000); |
|
159 |
return ds; |
|
160 |
} |
|
161 |
|
|
162 |
private boolean isRegistered() { |
|
163 |
return needRegisterDriver; |
|
164 |
} |
|
165 |
|
|
166 |
public void registerDriver() throws SQLException { |
|
167 |
String className = this.connectionParameters.getJDBCDriverClassName(); |
|
168 |
if (className == null) { |
|
169 |
return; |
|
170 |
} |
|
171 |
try { |
|
172 |
Class theClass = Class.forName(className); |
|
173 |
if (theClass == null) { |
|
174 |
throw new JDBCDriverClassNotFoundException(PostgreSQLLibrary.NAME, className); |
|
175 |
} |
|
176 |
} catch (Exception e) { |
|
177 |
throw new SQLException("Can't register JDBC driver '" + className + "'.", e); |
|
178 |
} |
|
179 |
needRegisterDriver = false; |
|
180 |
} |
|
181 |
|
|
182 |
} |
|
183 |
|
|
184 |
private ConnectionProvider connectionProvider = null; |
|
185 |
|
|
186 |
public PostgreSQLHelper(JDBCConnectionParameters connectionParameters) { |
|
187 |
super(connectionParameters); |
|
188 |
this.srssolver = new SRSSolverBase(this); |
|
189 |
} |
|
190 |
|
|
191 |
@Override |
|
192 |
public Connection getConnection() throws AccessResourceException { |
|
193 |
try { |
|
194 |
if (this.connectionProvider == null) { |
|
195 |
this.connectionProvider = new ConnectionProvider(this.getConnectionParameters()); |
|
196 |
} |
|
197 |
return this.connectionProvider.getConnection(); |
|
198 |
} catch (SQLException ex) { |
|
199 |
throw new AccessResourceException(PostgreSQLLibrary.NAME, ex); |
|
200 |
} |
|
201 |
} |
|
202 |
|
|
203 |
@Override |
|
204 |
public void closeConnection(Connection connection) { |
|
205 |
this.connectionProvider.closeConnection(connection); |
|
206 |
} |
|
207 |
|
|
208 |
@Override |
|
209 |
public PostgreSQLConnectionParameters getConnectionParameters() { |
|
210 |
return (PostgreSQLConnectionParameters) super.getConnectionParameters(); |
|
211 |
} |
|
212 |
|
|
213 |
@Override |
|
214 |
public String getConnectionURL() { |
|
215 |
return getConnectionURL(this.getConnectionParameters()); |
|
216 |
} |
|
217 |
|
|
218 |
@Override |
|
219 |
protected String getResourceType() { |
|
220 |
return PostgreSQLLibrary.NAME; |
|
221 |
} |
|
222 |
|
|
223 |
@Override |
|
224 |
public String getProviderName() { |
|
225 |
return PostgreSQLLibrary.NAME; |
|
226 |
} |
|
227 |
|
|
228 |
@Override |
|
229 |
public JDBCSQLBuilderBase createSQLBuilder() { |
|
230 |
return new PostgreSQLBuilder(this); |
|
231 |
} |
|
232 |
|
|
233 |
@Override |
|
234 |
public OperationsFactory getOperations() { |
|
235 |
if (this.operationsFactory == null) { |
|
236 |
this.operationsFactory = new PostgreSQLOperationsFactory(this); |
|
237 |
} |
|
238 |
return operationsFactory; |
|
239 |
} |
|
240 |
|
|
241 |
@Override |
|
242 |
public GeometrySupportType getGeometrySupportType() { |
|
243 |
return GeometrySupportType.WKB; |
|
244 |
} |
|
245 |
|
|
246 |
@Override |
|
247 |
public boolean hasSpatialFunctions() { |
|
248 |
return true; |
|
249 |
} |
|
250 |
|
|
251 |
@Override |
|
252 |
public boolean canWriteGeometry(int geometryType, int geometrySubtype) { |
|
253 |
return true; |
|
254 |
} |
|
255 |
|
|
256 |
@Override |
|
257 |
public String getQuoteForIdentifiers() { |
|
258 |
return "\""; |
|
259 |
} |
|
260 |
|
|
261 |
@Override |
|
262 |
public boolean allowAutomaticValues() { |
|
263 |
return true; |
|
264 |
} |
|
265 |
|
|
266 |
@Override |
|
267 |
public boolean supportOffsetInSelect() { |
|
268 |
return true; |
|
269 |
} |
|
270 |
|
|
271 |
@Override |
|
272 |
public String getQuoteForStrings() { |
|
273 |
return "'"; |
|
274 |
} |
|
275 |
|
|
276 |
@Override |
|
277 |
public String getSourceId(JDBCStoreParameters parameters) { |
|
278 |
return parameters.getDBName() + "." + |
|
279 |
parameters.getSchema()+ "." + |
|
280 |
parameters.getTable(); |
|
281 |
} |
|
282 |
|
|
283 |
@Override |
|
284 |
public JDBCNewStoreParameters createNewStoreParameters() { |
|
285 |
return new PostgreSQLNewStoreParameters(); |
|
286 |
} |
|
287 |
|
|
288 |
@Override |
|
289 |
public JDBCStoreParameters createOpenStoreParameters() { |
|
290 |
return new PostgreSQLStoreParameters(); |
|
291 |
} |
|
292 |
|
|
293 |
@Override |
|
294 |
public JDBCServerExplorerParameters createServerExplorerParameters() { |
|
295 |
return new PostgreSQLServerExplorerParameters(); |
|
296 |
} |
|
297 |
} |
tags/org.gvsig.postgresql-2.0.111/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.111/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.111/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.expressionevaluator.ExpressionBuilder; |
|
15 |
import org.gvsig.fmap.dal.DataTypes; |
|
16 |
import org.gvsig.fmap.dal.exception.DataException; |
|
17 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
18 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
19 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
20 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
|
21 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
|
22 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
|
23 |
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolver; |
|
24 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.FetchFeatureTypeOperation; |
|
25 |
import org.gvsig.fmap.geom.Geometry; |
|
26 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
27 |
import org.gvsig.fmap.geom.GeometryManager; |
|
28 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
29 |
import org.gvsig.postgresql.dal.PostgreSQLBuilder; |
|
30 |
|
|
31 |
@SuppressWarnings("UseSpecificCatch") |
|
32 |
public class PostgreSQLFetchFeatureTypeOperation extends FetchFeatureTypeOperation { |
|
33 |
|
|
34 |
private static Map<String,GeometryType>databaseGeometryTypes = null; |
|
35 |
|
|
36 |
public PostgreSQLFetchFeatureTypeOperation( |
|
37 |
JDBCHelper helper |
|
38 |
) { |
|
39 |
super(helper); |
|
40 |
} |
|
41 |
|
|
42 |
private GeometryType getGT( |
|
43 |
GeometryManager manager, |
|
44 |
int type, |
|
45 |
int subtype |
|
46 |
) { |
|
47 |
try { |
|
48 |
return manager.getGeometryType(type, subtype); |
|
49 |
} catch (Exception ex) { |
|
50 |
return null; |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
public PostgreSQLFetchFeatureTypeOperation( |
|
55 |
JDBCHelper helper, |
|
56 |
EditableFeatureType featureType, |
|
57 |
TableReference table, |
|
58 |
List<String> primaryKeys, |
|
59 |
String defaultGeometryColumn, |
|
60 |
IProjection crs |
|
61 |
) { |
|
62 |
super(helper, featureType, table, primaryKeys, defaultGeometryColumn, crs); |
|
63 |
} |
|
64 |
|
|
65 |
@Override |
|
66 |
public void fetch(EditableFeatureType featureType, Connection conn, TableReference table, List<String> pks, String defaultGeometryColumn, IProjection crs) throws DataException { |
|
67 |
super.fetch(featureType, conn, table, pks, defaultGeometryColumn, crs); |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
protected int getDataTypeFromMetadata( |
|
72 |
ResultSetMetaData rsMetadata, |
|
73 |
int colIndex |
|
74 |
) throws SQLException { |
|
75 |
|
|
76 |
return super.getDataTypeFromMetadata(rsMetadata, colIndex); |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
protected String getSQLToRetrievePrimaryKeysFromInformationSchema( |
|
81 |
String catalog, |
|
82 |
String schema, |
|
83 |
String table |
|
84 |
) throws SQLException { |
|
85 |
PostgreSQLBuilder sqlbuilder = (PostgreSQLBuilder) this.createSQLBuilder(); |
|
86 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
87 |
|
|
88 |
String column_COLUMN_NAME = "column_name"; |
|
89 |
String column_CONSTRAINT_TYPE = "constraint_type"; |
|
90 |
|
|
91 |
if( sqlbuilder.getDatabaseVersion().getMajor()<10 ) { |
|
92 |
column_COLUMN_NAME = "COLUMN_NAME"; |
|
93 |
column_CONSTRAINT_TYPE = "CONSTRAINT_TYPE"; |
|
94 |
} |
|
95 |
sqlbuilder.select().column().name(column_COLUMN_NAME); |
|
96 |
sqlbuilder.select().column().name(column_CONSTRAINT_TYPE); |
|
97 |
sqlbuilder.select().from().custom( |
|
98 |
"INFORMATION_SCHEMA.table_constraints t_cons " |
|
99 |
+ "inner join INFORMATION_SCHEMA.key_column_usage c on " |
|
100 |
+ "c.constraint_catalog = t_cons.constraint_catalog and " |
|
101 |
+ "c.table_schema = t_cons.table_schema and " |
|
102 |
+ "c.table_name = t_cons.table_name and " |
|
103 |
+ "c.constraint_name = t_cons.constraint_name " |
|
104 |
); |
|
105 |
sqlbuilder.select().where().set( |
|
106 |
expbuilder.like( |
|
107 |
expbuilder.custom("c.TABLE_NAME"), |
|
108 |
expbuilder.constant(table) |
|
109 |
) |
|
110 |
); |
|
111 |
if (schema != null) { |
|
112 |
sqlbuilder.select().where().and( |
|
113 |
expbuilder.like( |
|
114 |
expbuilder.custom("c.TABLE_SCHEMA"), |
|
115 |
expbuilder.constant(schema) |
|
116 |
) |
|
117 |
); |
|
118 |
} |
|
119 |
if (catalog != null) { |
|
120 |
sqlbuilder.select().where().and( |
|
121 |
expbuilder.like( |
|
122 |
expbuilder.custom("c.CONSTRAINT_CATALOG"), |
|
123 |
expbuilder.constant(catalog) |
|
124 |
) |
|
125 |
); |
|
126 |
} |
|
127 |
sqlbuilder.select().where().and( |
|
128 |
expbuilder.eq( |
|
129 |
expbuilder.column(column_CONSTRAINT_TYPE), |
|
130 |
expbuilder.constant("PRIMARY KEY") |
|
131 |
) |
|
132 |
); |
|
133 |
return sqlbuilder.toString(); |
|
134 |
} |
|
135 |
|
|
136 |
@Override |
|
137 |
protected void fetchGeometryTypeAndSRS( |
|
138 |
EditableFeatureAttributeDescriptor attr, |
|
139 |
ResultSetMetaData rsMetadata, |
|
140 |
int colIndex |
|
141 |
) { |
|
142 |
if( attr.getType()!=DataTypes.GEOMETRY ) { |
|
143 |
return; |
|
144 |
} |
|
145 |
try { |
|
146 |
JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder(); |
|
147 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
148 |
|
|
149 |
sqlbuilder.select().column().name("f_table_catalog"); |
|
150 |
sqlbuilder.select().column().name("f_table_schema"); |
|
151 |
sqlbuilder.select().column().name("f_table_name"); |
|
152 |
sqlbuilder.select().column().name("f_geometry_column"); |
|
153 |
sqlbuilder.select().column().name("coord_dimension"); |
|
154 |
sqlbuilder.select().column().name("srid"); |
|
155 |
sqlbuilder.select().column().name("type"); |
|
156 |
sqlbuilder.select().where().set( |
|
157 |
expbuilder.eq( |
|
158 |
expbuilder.column("f_table_name"), |
|
159 |
expbuilder.constant(this.getTable().getTable()) |
|
160 |
) |
|
161 |
); |
|
162 |
sqlbuilder.select().where().and( |
|
163 |
expbuilder.eq( |
|
164 |
expbuilder.column("f_geometry_column"), |
|
165 |
expbuilder.constant(attr.getName()) |
|
166 |
) |
|
167 |
); |
|
168 |
sqlbuilder.select().from().table().name("geometry_columns"); |
|
169 |
Statement st = null; |
|
170 |
ResultSet rs = null; |
|
171 |
|
|
172 |
Integer srsid = null; |
|
173 |
String geometryTypeName = null; |
|
174 |
try { |
|
175 |
st = this.getConnection().createStatement(); |
|
176 |
rs = JDBCUtils.executeQuery(st, sqlbuilder.toString()); |
|
177 |
if (rs.next()) { |
|
178 |
srsid = rs.getInt("srid"); |
|
179 |
geometryTypeName = rs.getString("type"); |
|
180 |
} |
|
181 |
} finally { |
|
182 |
JDBCUtils.closeQuietly(rs); |
|
183 |
JDBCUtils.closeQuietly(st); |
|
184 |
} |
|
185 |
if( !StringUtils.isEmpty(geometryTypeName) ) { |
|
186 |
GeometryType gt = getGeometryTypeFromDatabaseTypeName(geometryTypeName); |
|
187 |
attr.setGeometryType(gt); |
|
188 |
} |
|
189 |
if( srsid!=null ) { |
|
190 |
SRSSolver srssolver = this.helper.getSRSSolver(); |
|
191 |
attr.setSRS(srssolver.getProjection(this.getConnection(),srsid)); |
|
192 |
} |
|
193 |
} catch (Exception ex) { |
|
194 |
LOGGER.debug("Can't get geometry type and srs from column '"+attr.getName()+"'.",ex); |
|
195 |
} |
|
196 |
} |
|
197 |
|
|
198 |
private GeometryType getGeometryTypeFromDatabaseTypeName(String typeName) { |
|
199 |
if( databaseGeometryTypes==null ) { |
|
200 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
201 |
databaseGeometryTypes = new HashMap<>(); |
|
202 |
databaseGeometryTypes.put("POINT", getGT(manager, Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM2D)); |
|
203 |
databaseGeometryTypes.put("POINTZ", getGT(manager, Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM3D)); |
|
204 |
databaseGeometryTypes.put("POINTM", getGT(manager, Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM2DM)); |
|
205 |
databaseGeometryTypes.put("POINTZM", getGT(manager, Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM3DM)); |
|
206 |
|
|
207 |
databaseGeometryTypes.put("LINESTRING", getGT(manager, Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM2D)); |
|
208 |
databaseGeometryTypes.put("LINESTRINGZ", getGT(manager, Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM3D)); |
|
209 |
databaseGeometryTypes.put("LINESTRINGM", getGT(manager, Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM2DM)); |
|
210 |
databaseGeometryTypes.put("LINESTRINGZM", getGT(manager, Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM3DM)); |
|
211 |
|
|
212 |
databaseGeometryTypes.put("POLYGON", getGT(manager, Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM2D)); |
|
213 |
databaseGeometryTypes.put("POLYGONZ", getGT(manager, Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM3D)); |
|
214 |
databaseGeometryTypes.put("POLYGONM", getGT(manager, Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM2DM)); |
|
215 |
databaseGeometryTypes.put("POLYGONZM", getGT(manager, Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM3DM)); |
|
216 |
|
|
217 |
databaseGeometryTypes.put("MULTIPOINT", getGT(manager, Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM2D)); |
|
218 |
databaseGeometryTypes.put("MULTIPOINTZ", getGT(manager, Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM3D)); |
|
219 |
databaseGeometryTypes.put("MULTIPOINTM", getGT(manager, Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM2DM)); |
|
220 |
databaseGeometryTypes.put("MULTIPOINTZM", getGT(manager, Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM3DM)); |
|
221 |
|
|
222 |
databaseGeometryTypes.put("MULTILINESTRING", getGT(manager, Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM2D)); |
|
223 |
databaseGeometryTypes.put("MULTILINESTRINGZ", getGT(manager, Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM3D)); |
|
224 |
databaseGeometryTypes.put("MULTILINESTRINGM", getGT(manager, Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM2DM)); |
|
225 |
databaseGeometryTypes.put("MULTILINESTRINGZM", getGT(manager, Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM3DM)); |
|
226 |
|
|
227 |
databaseGeometryTypes.put("MULTIPOLYGON", getGT(manager, Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM2D)); |
|
228 |
databaseGeometryTypes.put("MULTIPOLYGONZ", getGT(manager, Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM3D)); |
|
229 |
databaseGeometryTypes.put("MULTIPOLYGONM", getGT(manager, Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM2DM)); |
|
230 |
databaseGeometryTypes.put("MULTIPOLYGONZM", getGT(manager, Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM3DM)); |
|
231 |
|
|
232 |
databaseGeometryTypes.put("GEOMETRY", getGT(manager, Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM2D)); |
|
233 |
databaseGeometryTypes.put("GEOMETRYZ", getGT(manager, Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM3D)); |
|
234 |
databaseGeometryTypes.put("GEOMETRYM", getGT(manager, Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM2DM)); |
|
235 |
databaseGeometryTypes.put("GEOMETRYZM", getGT(manager, Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM3DM)); |
|
236 |
} |
|
237 |
return databaseGeometryTypes.get(typeName); |
|
238 |
} |
|
239 |
|
|
240 |
} |
tags/org.gvsig.postgresql-2.0.111/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/operations/PostgreSQLOperationsFactory.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.postgresql.dal.operations; |
|
3 |
|
|
4 |
import java.util.List; |
|
5 |
import org.cresques.cts.IProjection; |
|
6 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
7 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
8 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.FetchFeatureTypeOperation; |
|
9 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase; |
|
10 |
|
|
11 |
|
|
12 |
public class PostgreSQLOperationsFactory extends OperationsFactoryBase { |
|
13 |
|
|
14 |
public PostgreSQLOperationsFactory(JDBCHelper helper) { |
|
15 |
super(helper); |
|
16 |
} |
|
17 |
|
|
18 |
@Override |
|
19 |
public FetchFeatureTypeOperation createFetchFeatureType(EditableFeatureType type, TableReference table, List<String> primaryKeys, String defaultGeometryField, IProjection crs) { |
|
20 |
return new PostgreSQLFetchFeatureTypeOperation( |
|
21 |
helper, type, table, primaryKeys, |
|
22 |
defaultGeometryField, crs |
|
23 |
); |
|
24 |
} |
|
25 |
|
|
26 |
} |
tags/org.gvsig.postgresql-2.0.111/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLStoreParameters.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.JDBCStoreParameters; |
|
26 |
|
|
27 |
public class PostgreSQLStoreParameters extends JDBCStoreParameters implements PostgreSQLConnectionParameters { |
|
28 |
|
|
29 |
private final PostgreSQLConnectionParametersHelper helper; |
|
30 |
|
|
31 |
public PostgreSQLStoreParameters() { |
|
32 |
super( |
|
33 |
PostgreSQLLibrary.NAME + "StoreParameters", |
|
34 |
PostgreSQLLibrary.NAME |
|
35 |
); |
|
36 |
this.helper = new PostgreSQLConnectionParametersHelper(this); |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public String getUrl() { |
|
41 |
return this.helper.getUrl(); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public void validate() throws ValidateDataParametersException { |
|
46 |
this.helper.validate(); |
|
47 |
super.validate(); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public boolean getUseSSL() { |
|
52 |
return this.helper.getUseSSL(); |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public int getMaxIdle() { |
|
57 |
return this.helper.getMaxIdle(); |
|
58 |
} |
|
59 |
|
|
60 |
public void setUseSSL(boolean v) { |
|
61 |
this.helper.setUseSSL(v); |
|
62 |
} |
|
63 |
|
|
64 |
|
|
65 |
} |
tags/org.gvsig.postgresql-2.0.111/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLConnectionParameters.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.postgresql.dal; |
|
3 |
|
|
4 |
import org.gvsig.fmap.dal.resource.db.DBParameters; |
|
5 |
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters; |
|
6 |
|
|
7 |
public interface PostgreSQLConnectionParameters extends JDBCConnectionParameters, DBParameters { |
|
8 |
public static final String USESSL_PARAMTER_NAME = "UseSSL"; |
|
9 |
public static final String MAXIDLE_PARAMTER_NAME = "maxIdle"; |
|
10 |
|
|
11 |
public boolean getUseSSL(); |
|
12 |
|
|
13 |
public int getMaxIdle(); |
|
14 |
} |
tags/org.gvsig.postgresql-2.0.111/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLConnectionParametersHelper.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.postgresql.dal; |
|
3 |
|
|
4 |
import org.apache.commons.lang3.StringUtils; |
|
5 |
import org.gvsig.fmap.dal.DataParameters; |
|
6 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
7 |
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters; |
|
8 |
|
|
9 |
|
|
10 |
public class PostgreSQLConnectionParametersHelper { |
|
11 |
|
|
12 |
private final JDBCConnectionParameters parameters; |
|
13 |
|
|
14 |
public PostgreSQLConnectionParametersHelper(JDBCConnectionParameters parameters) { |
|
15 |
this.parameters = parameters; |
|
16 |
} |
|
17 |
|
|
18 |
public String getUrl() { |
|
19 |
String url = (String) this.getDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME); |
|
20 |
if( StringUtils.isEmpty(url) ) { |
|
21 |
url = PostgreSQLHelper.getConnectionURL((PostgreSQLConnectionParameters) this.parameters); |
|
22 |
this.setDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME,url); |
|
23 |
} |
|
24 |
return url; |
|
25 |
} |
|
26 |
|
|
27 |
public void validate() throws ValidateDataParametersException { |
|
28 |
if (this.getDynValue(JDBCConnectionParameters.JDBC_DRIVER_CLASS_PARAMTER_NAME) == null) { |
|
29 |
this.setDynValue( |
|
30 |
JDBCConnectionParameters.JDBC_DRIVER_CLASS_PARAMTER_NAME, |
|
31 |
PostgreSQLHelper.POSTGRESQL_JDBC_DRIVER |
|
32 |
); |
|
33 |
} |
|
34 |
if( this.getDynValue(JDBCConnectionParameters.PORT_PARAMTER_NAME)==null ) { |
|
35 |
this.setDynValue(JDBCConnectionParameters.PORT_PARAMTER_NAME, 5432); |
|
36 |
} |
|
37 |
if ( StringUtils.isEmpty((CharSequence) this.getDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME))) { |
|
38 |
String url = PostgreSQLHelper.getConnectionURL( |
|
39 |
parameters.getHost(), |
|
40 |
parameters.getPort(), |
|
41 |
parameters.getDBName() |
|
42 |
); |
|
43 |
this.setDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME, url); |
|
44 |
} |
|
45 |
} |
|
46 |
|
|
47 |
private Object getDynValue(String name) { |
|
48 |
return ((DataParameters)this.parameters).getDynValue(name); |
|
49 |
} |
|
50 |
|
|
51 |
private void setDynValue(String name, Object value) { |
|
52 |
((DataParameters)this.parameters).setDynValue(name,value); |
|
53 |
} |
|
54 |
|
|
55 |
public int getMaxIdle() { |
|
56 |
return (int) this.getDynValue(PostgreSQLConnectionParameters.MAXIDLE_PARAMTER_NAME); |
|
57 |
} |
|
58 |
|
|
59 |
public boolean getUseSSL() { |
|
60 |
return (boolean) this.getDynValue(PostgreSQLConnectionParameters.USESSL_PARAMTER_NAME); |
|
61 |
} |
|
62 |
|
|
63 |
public void setUseSSL(boolean v) { |
|
64 |
this.setDynValue(PostgreSQLConnectionParameters.USESSL_PARAMTER_NAME, v); |
|
65 |
} |
|
66 |
|
|
67 |
} |
tags/org.gvsig.postgresql-2.0.111/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLLibrary.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.postgresql.dal; |
|
3 |
|
|
4 |
import org.gvsig.fmap.dal.DALLibrary; |
|
5 |
import org.gvsig.fmap.dal.DALLocator; |
|
6 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
7 |
import org.gvsig.fmap.dal.store.db.DBHelper; |
|
8 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCLibrary; |
|
9 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCStoreProviderBase; |
|
10 |
import org.gvsig.metadata.exceptions.MetadataException; |
|
11 |
import org.gvsig.tools.library.AbstractLibrary; |
|
12 |
import org.gvsig.tools.library.LibraryException; |
|
13 |
|
|
14 |
|
|
15 |
public class PostgreSQLLibrary extends AbstractLibrary { |
|
16 |
|
|
17 |
public static final String NAME = "PostgreSQL"; |
|
18 |
|
|
19 |
@Override |
|
20 |
public void doRegistration() { |
|
21 |
registerAsServiceOf(DALLibrary.class); |
|
22 |
require(JDBCLibrary.class); |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
protected void doInitialize() throws LibraryException { |
|
27 |
} |
|
28 |
|
|
29 |
@Override |
|
30 |
protected void doPostInitialize() throws LibraryException { |
|
31 |
LibraryException ex = null; |
|
32 |
|
|
33 |
DataManagerProviderServices dataman = |
|
34 |
(DataManagerProviderServices) DALLocator.getDataManager(); |
|
35 |
|
|
36 |
try { |
|
37 |
Class.forName(PostgreSQLHelper.POSTGRESQL_JDBC_DRIVER); |
|
38 |
} catch(Throwable th) { |
|
39 |
PostgreSQLHelper.logger.warn("Can't load PostgreSQL JDBC Driver.",th); |
|
40 |
} |
|
41 |
|
|
42 |
DBHelper.registerParametersDefinition( |
|
43 |
NAME + "StoreParameters", |
|
44 |
PostgreSQLStoreParameters.class, |
|
45 |
dataman.getResourceAsStream(this, NAME + "Parameters.xml") |
|
46 |
); |
|
47 |
DBHelper.registerParametersDefinition( |
|
48 |
NAME + "NewStoreParameters", |
|
49 |
PostgreSQLNewStoreParameters.class, |
|
50 |
dataman.getResourceAsStream(this, NAME + "Parameters.xml") |
|
51 |
); |
|
52 |
DBHelper.registerParametersDefinition( |
|
53 |
NAME + "ServerExplorerParameters", |
|
54 |
PostgreSQLServerExplorerParameters.class, |
|
55 |
dataman.getResourceAsStream(this, NAME + "Parameters.xml") |
|
56 |
); |
|
57 |
// DBHelper.registerParametersDefinition( |
|
58 |
// NAME + "ResourceParameters", |
|
59 |
// PostgreSQLResourceParameters.class, |
|
60 |
// dataman.getResourceAsStream(this, NAME + "Parameters.xml") |
|
61 |
// ); |
|
62 |
try { |
|
63 |
DBHelper.registerMetadataDefinition( |
|
64 |
NAME, |
|
65 |
JDBCStoreProviderBase.class, |
|
66 |
dataman.getResourceAsStream(this, NAME + "Metadata.xml") |
|
67 |
); |
|
68 |
} catch (MetadataException e) { |
|
69 |
ex = new LibraryException(this.getClass(), e); |
|
70 |
} |
|
71 |
|
|
72 |
// ResourceManagerProviderServices resman = (ResourceManagerProviderServices) DALLocator |
|
73 |
// .getResourceManager(); |
|
74 |
// |
|
75 |
// if (!resman.getResourceProviders().contains(NAME)) { |
|
76 |
// resman.register(NAME, |
|
77 |
// "Resource for " + NAME, |
|
78 |
// PostgreSQLResource.class, |
|
79 |
// PostgreSQLResourceParameters.class |
|
80 |
// ); |
|
81 |
// } |
|
82 |
|
|
83 |
if (!dataman.getStoreProviderRegister().exits(NAME)) { |
|
84 |
dataman.registerStoreProviderFactory(new PostgreSQLStoreProviderFactory()); |
|
85 |
} |
|
86 |
|
|
87 |
if (!dataman.getServerExplorerRegister().exits(NAME)) { |
|
88 |
dataman.registerServerExplorerFactory(new PostgreSQLServerExplorerFactory()); |
|
89 |
} |
|
90 |
|
|
91 |
// Por compatibilidad con gvSIG 2.3 registramos otra vez la factoria con |
|
92 |
// el nombre que tenia antes. |
|
93 |
if (!dataman.getServerExplorerRegister().exits("PostgreSQLExplorer")) { |
|
94 |
dataman.registerServerExplorerFactory(new PostgreSQLServerExplorerFactory("PostgreSQLExplorer")); |
|
95 |
} |
|
96 |
|
|
97 |
if (ex != null) { |
|
98 |
throw ex; |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
} |
tags/org.gvsig.postgresql-2.0.111/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.sql.Connection; |
|
28 |
import java.sql.DatabaseMetaData; |
|
29 |
import java.text.MessageFormat; |
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.List; |
|
32 |
import org.apache.commons.lang3.StringUtils; |
|
33 |
import org.gvsig.expressionevaluator.Formatter; |
|
34 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
35 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
|
36 |
import org.gvsig.postgresql.dal.expressionbuilderformatter.PostgreSQLFormatter; |
|
37 |
|
|
38 |
public class PostgreSQLBuilder extends JDBCSQLBuilderBase { |
|
39 |
|
|
40 |
protected Formatter formatter = null; |
|
41 |
|
|
42 |
public static class Version { |
|
43 |
|
|
44 |
private final int major; |
|
45 |
private final int minor; |
|
46 |
|
|
47 |
public Version(int major, int minor) { |
|
48 |
this.major = major; |
|
49 |
this.minor = minor; |
|
50 |
} |
|
51 |
|
|
52 |
public int getMajor() { |
|
53 |
return major; |
|
54 |
} |
|
55 |
|
|
56 |
public int getMinor() { |
|
57 |
return minor; |
|
58 |
} |
|
59 |
|
|
60 |
} |
|
61 |
private Version databaseVersion = null; |
|
62 |
|
|
63 |
public Version getDatabaseVersion() { |
|
64 |
if( databaseVersion == null ) { |
|
65 |
Connection conn = null; |
|
66 |
try { |
|
67 |
conn = this.getHelper().getConnection(); |
|
68 |
DatabaseMetaData metadata = conn.getMetaData(); |
|
69 |
databaseVersion = new Version( |
|
70 |
metadata.getDatabaseMajorVersion(), |
|
71 |
metadata.getDatabaseMinorVersion() |
|
72 |
); |
|
73 |
} catch (Exception ex) { |
|
74 |
databaseVersion = new Version(0,0); |
|
75 |
} finally { |
|
76 |
this.getHelper().closeConnectionQuietly(conn); |
|
77 |
} |
|
78 |
} |
|
79 |
return databaseVersion; |
|
80 |
} |
|
81 |
|
|
82 |
public PostgreSQLBuilder(JDBCHelper helper) { |
|
83 |
super(helper); |
|
84 |
this.defaultSchema = "public"; |
|
85 |
this.supportSchemas = true; |
|
86 |
this.allowAutomaticValues = true; |
|
87 |
this.geometrySupportType = this.helper.getGeometrySupportType(); |
|
88 |
this.hasSpatialFunctions = this.helper.hasSpatialFunctions(); |
|
89 |
|
|
90 |
this.STMT_DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table = null; |
|
91 |
this.STMT_DELETE_GEOMETRY_COLUMN_FROM_TABLE_table = null; |
|
92 |
|
|
93 |
this.STMT_UPDATE_TABLE_STATISTICS_table = "ANALYZE {0}"; |
|
94 |
|
|
95 |
// config.set(SQLConfig.ST_GeomFromEWKB, "ST_GeomFromEWKB({0}, {1})"); |
|
96 |
// config.set(SQLConfig.ST_AsEWKB, "ST_AsEWKB(({0}))"); |
|
97 |
// config.set(SQLConfig.ST_ExtentAggregate, "ST_Extent({0})"); |
|
98 |
// config.set(SQLConfig.ST_UnionAggregate, "ST_Union({0})"); |
|
99 |
|
|
100 |
// config.set(SQLConfig.isNull, "( ({0}) ISNULL )"); |
|
101 |
// config.set(SQLConfig.notIsNull, "( ({0}) NOT NULL )"); |
|
102 |
|
|
103 |
} |
|
104 |
|
|
105 |
public class PostgreSQLUpdateTableStatisticsBuilderBase extends UpdateTableStatisticsBuilderBase { |
|
106 |
@Override |
|
107 |
public List<String> toStrings() { |
|
108 |
List<String> sqls = new ArrayList<>(); |
|
109 |
|
|
110 |
if( !StringUtils.isBlank(STMT_UPDATE_TABLE_STATISTICS_table) ) { |
|
111 |
// In postGIS, UpdateLayerStatistics function, don't allow to |
|
112 |
// use the database name in the table name. |
|
113 |
String name = as_identifier(this.table.getName()); |
|
114 |
if( table.has_schema()) { |
|
115 |
name = as_identifier(this.table.getSchema()) + "." + name; |
|
116 |
} |
|
117 |
String sql = MessageFormat.format( |
|
118 |
STMT_UPDATE_TABLE_STATISTICS_table, |
|
119 |
name |
|
120 |
); |
|
121 |
if( !StringUtils.isEmpty(sql) ) { |
|
122 |
sqls.add(sql); |
|
123 |
} |
|
124 |
} |
|
125 |
return sqls; |
|
126 |
} |
|
127 |
} |
|
128 |
protected class PostgreSQLCreateIndexBuilder extends CreateIndexBuilderBase { |
|
129 |
|
|
130 |
@Override |
|
131 |
public List<String> toStrings(Formatter formatter) { |
|
132 |
StringBuilder builder = new StringBuilder(); |
|
133 |
builder.append("CREATE "); |
|
134 |
// if( this.isUnique ) { |
|
135 |
// builder.append("UNIQUE "); |
|
136 |
// } |
|
137 |
builder.append("INDEX "); |
|
138 |
if( this.ifNotExist ) { |
|
139 |
Version version = getDatabaseVersion(); |
|
140 |
if( version.getMajor()>=9 && version.getMinor()>=5 ) { |
|
141 |
builder.append("IF NOT EXISTS "); |
|
142 |
} |
|
143 |
} |
|
144 |
builder.append(as_identifier(this.indexName)); |
|
145 |
builder.append(" ON "); |
|
146 |
builder.append(this.table.toString(formatter)); |
|
147 |
if( this.isSpatial ) { |
|
148 |
builder.append(" USING GIST "); |
|
149 |
} |
|
150 |
builder.append(" ( "); |
|
151 |
boolean is_first_column = true; |
|
152 |
for( String column : this.columns) { |
|
153 |
if( is_first_column ) { |
|
154 |
is_first_column = false; |
|
155 |
} else { |
|
156 |
builder.append(", "); |
|
157 |
} |
|
158 |
builder.append(as_identifier(column)); |
|
159 |
} |
|
160 |
builder.append(" )"); |
|
161 |
|
|
162 |
List<String> sqls = new ArrayList<>(); |
|
163 |
sqls.add(builder.toString()); |
|
164 |
return sqls; |
|
165 |
} |
|
166 |
|
|
167 |
} |
|
168 |
|
|
169 |
protected class PostgreSQLCreateTableBuilder extends CreateTableBuilderBase { |
|
170 |
|
|
171 |
@Override |
|
172 |
public List<String> toStrings(Formatter formatter) { |
|
173 |
// |
|
174 |
// https://www.postgresql.org/docs/9.1/static/sql-createtable.html |
|
175 |
// |
|
176 |
List<String> sqls = new ArrayList<>(); |
|
177 |
StringBuilder builder = new StringBuilder(); |
|
178 |
|
|
179 |
builder.append("CREATE TABLE "); |
|
180 |
builder.append(this.table.toString(formatter)); |
|
181 |
builder.append(" ("); |
|
182 |
boolean first = true; |
|
183 |
for (ColumnDescriptor column : columns) { |
|
184 |
if( column.isGeometry() ) { |
|
185 |
continue; |
|
186 |
} |
|
187 |
if (first) { |
|
188 |
first = false; |
|
189 |
} else { |
|
190 |
builder.append(", "); |
|
191 |
} |
|
192 |
builder.append(as_identifier(column.getName())); |
|
193 |
builder.append(" "); |
Also available in: Unified diff