Revision 586

View differences:

tags/org.gvsig.postgresql-2.0.117/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/buildNumber.properties
1
#Mon Jan 20 22:17:20 CET 2020
2
buildNumber=2174
tags/org.gvsig.postgresql-2.0.117/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>org.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.117/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.117/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.117</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>org.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.117/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.117</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.117/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.117</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.264</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.117</connection>
20
      <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-postgresql/tags/org.gvsig.postgresql-2.0.117</developerConnection>
21
      <url>https://devel.gvsig.org/redmine/projects/gvsig-postgresql/repository/show/tags/org.gvsig.postgresql-2.0.117</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.117</version>
63
          </dependency>
64
          <dependency>
65
            <groupId>org.gvsig</groupId>
66
            <artifactId>org.gvsig.postgresql.app.mainplugin</artifactId>
67
            <version>2.0.117</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.117/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.117</version>
14
  </parent>
15
  <dependencies>
16
    <dependency>
17
      <groupId>com.googlecode.log4jdbc</groupId>
18
      <artifactId>log4jdbc</artifactId>
19
      <scope>compile</scope>
20
    </dependency>
21
    <dependency>
22
      <groupId>org.gvsig</groupId>
23
      <artifactId>org.gvsig.tools.lib</artifactId>
24
      <scope>compile</scope>
25
    </dependency>
26
    <dependency>
27
      <groupId>org.gvsig</groupId>
28
      <artifactId>org.gvsig.projection.api</artifactId>
29
      <scope>compile</scope>
30
    </dependency>
31
    <dependency>
32
      <groupId>org.gvsig</groupId>
33
      <artifactId>org.gvsig.fmap.dal.api</artifactId>
34
      <scope>compile</scope>
35
    </dependency>
36
    
37
    <dependency>
38
      <groupId>org.gvsig</groupId>
39
      <artifactId>org.gvsig.fmap.dal.db.jdbc</artifactId>
40
      <scope>compile</scope>
41
    </dependency>
42

  
43
    <dependency>
44
      <groupId>org.gvsig</groupId>
45
      <artifactId>org.gvsig.fmap.dal.db.lib</artifactId>
46
      <scope>compile</scope>
47
    </dependency>
48
    
49
    <dependency>
50
      <groupId>org.gvsig</groupId>
51
      <artifactId>org.gvsig.fmap.dal.spi</artifactId>
52
      <scope>compile</scope>
53
    </dependency>
54
    <dependency>
55
      <groupId>org.gvsig</groupId>
56
      <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
57
      <scope>compile</scope>
58
    </dependency>
59
    <dependency>
60
      <groupId>org.gvsig</groupId>
61
      <artifactId>org.gvsig.fmap.geometry.api</artifactId>
62
      <scope>compile</scope>
63
    </dependency>
64
    <!--
65
    <dependency>
66
        <groupId>org.gvsig</groupId>
67
        <artifactId>org.gvsig.fmap.geometry.operation</artifactId>
68
        <scope>compile</scope>
69
    </dependency>
70
    -->
71
    <dependency>
72
      <groupId>org.gvsig</groupId>
73
      <artifactId>org.gvsig.timesupport.lib.api</artifactId>
74
      <scope>compile</scope>
75
    </dependency>  
76
    <dependency>
77
      <groupId>org.gvsig</groupId>
78
      <artifactId>org.gvsig.utils</artifactId>
79
      <scope>compile</scope>
80
    </dependency>
81
    <dependency>
82
      <groupId>org.postgresql</groupId>
83
      <artifactId>postgresql</artifactId>
84
      <scope>compile</scope>
85
    </dependency>
86
    <dependency>
87
      <groupId>commons-dbcp</groupId>
88
      <artifactId>commons-dbcp</artifactId>
89
      <scope>compile</scope>
90
    </dependency>
91
    <dependency>
92
      <groupId>commons-collections</groupId>
93
      <artifactId>commons-collections</artifactId>
94
      <scope>compile</scope>
95
    </dependency>
96

  
97

  
98
    <!-- TESTS -->
99
    <dependency>
100
      <groupId>org.gvsig</groupId>
101
      <artifactId>org.gvsig.tools.lib</artifactId>
102
      <type>test-jar</type>
103
      <scope>test</scope>
104
    </dependency>
105
    <dependency>
106
      <groupId>org.gvsig</groupId>
107
      <artifactId>org.gvsig.compat.se</artifactId>
108
      <scope>test</scope>
109
    </dependency>
110
    <dependency>
111
      <groupId>org.gvsig</groupId>
112
      <artifactId>org.gvsig.fmap.dal.impl</artifactId>
113
      <scope>test</scope>
114
    </dependency>
115
    <dependency>
116
      <groupId>org.gvsig</groupId>
117
      <artifactId>org.gvsig.fmap.dal.file.csv</artifactId>
118
      <scope>test</scope>
119
    </dependency>
120
    <dependency>
121
      <groupId>org.gvsig</groupId>
122
      <artifactId>org.gvsig.tools.util.impl</artifactId>
123
      <scope>test</scope>
124
    </dependency>
125
    <dependency>
126
      <groupId>org.gvsig</groupId>
127
      <artifactId>org.gvsig.tools.swing.impl</artifactId>
128
      <scope>test</scope>
129
    </dependency>
130
    <dependency>
131
      <groupId>org.gvsig</groupId>
132
      <artifactId>${org.gvsig.fmap.geometry.impl}</artifactId>
133
      <scope>test</scope>
134
    </dependency>    
135
    <dependency>
136
      <groupId>org.gvsig</groupId>
137
      <artifactId>org.gvsig.expressionevaluator.geometry.lib.impl</artifactId>
138
      <scope>test</scope>
139
    </dependency>    
140
    <dependency>
141
      <groupId>org.gvsig</groupId>
142
      <artifactId>${org.gvsig.proj.lib.impl}</artifactId>
143
      <scope>test</scope>
144
    </dependency>
145
    <dependency>
146
      <groupId>org.gvsig</groupId>
147
      <artifactId>org.gvsig.projection.cresques.impl</artifactId>
148
      <scope>test</scope>
149
    </dependency>
150
    <dependency>
151
      <groupId>org.gvsig</groupId>
152
      <artifactId>org.gvsig.timesupport.lib.impl</artifactId>
153
      <scope>test</scope>
154
    </dependency>
155
    <dependency>
156
      <groupId>org.gvsig</groupId>
157
      <artifactId>org.gvsig.metadata.lib.basic.impl</artifactId>
158
      <scope>test</scope>
159
    </dependency>      
160
    
161
    
162
    <dependency>
163
      <artifactId>junit</artifactId>
164
      <groupId>junit</groupId>
165
      <scope>test</scope>
166
    </dependency>
167
  </dependencies>
168

  
169
  <build>
170
    <plugins>
171

  
172
      <!-- Skip test execution ? -->
173
      <plugin>
174
        <groupId>org.apache.maven.plugins</groupId>
175
        <artifactId>maven-surefire-plugin</artifactId>
176
        <configuration>
177
          <skipTests>false</skipTests>
178
        </configuration>
179
      </plugin>
180
        
181
      <!-- Skip test compilation ? -->
182
      <plugin>
183
        <groupId>org.apache.maven.plugins</groupId>
184
        <artifactId>maven-compiler-plugin</artifactId>
185
        <executions>
186
          <execution>
187
            <id>default-testCompile</id>
188
            <phase>process-test-sources</phase>
189
            <goals>
190
              <goal>testCompile</goal>
191
            </goals>
192
            <configuration>
193
              <skip>false</skip>
194
            </configuration>
195
          </execution>
196
        </executions>
197
      </plugin>
198

  
199
      <!-- Ignore test execution failure ? -->
200
      <plugin>
201
        <groupId>org.apache.maven.plugins</groupId>
202
        <artifactId>maven-surefire-plugin</artifactId>
203
        <configuration>
204
          <testFailureIgnore>true</testFailureIgnore>
205
        </configuration>
206
      </plugin>
207

  
208
    </plugins>
209
  </build>
210

  
211
</project>
tags/org.gvsig.postgresql-2.0.117/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.GeometryExpressionBuilderHelper.GeometrySupportType;
10
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
11
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters;
12
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters;
13
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
14
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
15
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCDriverClassNotFoundException;
16
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
17
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase;
18
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
19
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolverBase;
20
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolverDumb;
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
    /* friend */ 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() {
187
        super(null);
188
        this.srssolver = new SRSSolverDumb(this);
189
    }
190

  
191
    public PostgreSQLHelper(JDBCConnectionParameters connectionParameters) {
192
        super(connectionParameters);
193
        this.srssolver = new SRSSolverBase(this);
194
    }
195

  
196
    @Override
197
    public Connection getConnection() throws AccessResourceException {
198
        try {
199
            if (this.connectionProvider == null) {
200
              if( this.getConnectionParameters()==null ) {
201
                return null;
202
              }
203
              this.connectionProvider = new ConnectionProvider(this.getConnectionParameters());
204
            }
205
            return this.connectionProvider.getConnection();
206
        } catch (SQLException ex) {
207
            throw new AccessResourceException(PostgreSQLLibrary.NAME, ex);
208
        }
209
    }
210

  
211
    @Override
212
    public void closeConnection(Connection connection) {
213
      if( connection!=null ) { // In test ???
214
         this.connectionProvider.closeConnection(connection);
215
      }
216
    }
217
    
218
    @Override
219
    public PostgreSQLConnectionParameters getConnectionParameters() {
220
        return (PostgreSQLConnectionParameters) super.getConnectionParameters();
221
    }
222
    
223
    @Override
224
    public String getConnectionURL() {
225
        return getConnectionURL(this.getConnectionParameters());
226
    }
227

  
228
    @Override
229
    protected String getResourceType() {
230
        return PostgreSQLLibrary.NAME;
231
    }
232

  
233
    @Override
234
    public String getProviderName() {
235
        return PostgreSQLLibrary.NAME;
236
    }
237

  
238
    @Override
239
    public JDBCSQLBuilderBase createSQLBuilder() {
240
        return new PostgreSQLBuilder(this);
241
    }
242
    
243
    @Override
244
    public OperationsFactory getOperations() {
245
        if (this.operationsFactory == null) {
246
            this.operationsFactory = new PostgreSQLOperationsFactory(this);
247
        }
248
        return operationsFactory;
249
    }
250

  
251
    @Override
252
    public GeometrySupportType getGeometrySupportType() {
253
        return GeometrySupportType.WKB;
254
    }
255

  
256
    @Override
257
    public boolean hasSpatialFunctions() {
258
        return true;
259
    }
260

  
261
    @Override
262
    public boolean canWriteGeometry(int geometryType, int geometrySubtype) {
263
        return true;
264
    }
265

  
266
    @Override
267
    public String getQuoteForIdentifiers() {
268
        return "\"";
269
    }
270

  
271
    @Override
272
    public boolean allowAutomaticValues() {
273
        return true;
274
    }
275

  
276
    @Override
277
    public boolean supportOffsetInSelect() {
278
        return true;
279
    }
280

  
281
    @Override
282
    public String getQuoteForStrings() {
283
        return "'";
284
    }
285
    
286
    @Override
287
    public String getSourceId(JDBCStoreParameters parameters) {
288
        return parameters.getDBName() + "." + 
289
               parameters.getSchema()+ "." + 
290
               parameters.getTable();
291
    }
292

  
293
    @Override
294
    public JDBCNewStoreParameters createNewStoreParameters() {
295
        return new PostgreSQLNewStoreParameters();
296
    }
297

  
298
    @Override
299
    public JDBCStoreParameters createOpenStoreParameters() {
300
        return new PostgreSQLStoreParameters();
301
    }
302

  
303
    @Override
304
    public JDBCServerExplorerParameters createServerExplorerParameters() {
305
        return new PostgreSQLServerExplorerParameters();
306
    }
307
}
tags/org.gvsig.postgresql-2.0.117/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.117/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.117/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.117/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(Connection conn) throws DataException {
67
        super.fetch(conn);
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
    public String getSQLToRetrievePrimaryKeysFromInformationSchema() throws SQLException {
81
        PostgreSQLBuilder sqlbuilder = (PostgreSQLBuilder) this.createSQLBuilder();
82
        ExpressionBuilder expbuilder = sqlbuilder.expression();
83
        
84
        String column_COLUMN_NAME = "column_name";
85
        String column_CONSTRAINT_TYPE = "constraint_type";
86
        
87
        if( sqlbuilder.getDatabaseVersion().getMajor()<10 ) {
88
            column_COLUMN_NAME = "COLUMN_NAME";
89
            column_CONSTRAINT_TYPE = "CONSTRAINT_TYPE";
90
        }
91
        sqlbuilder.select().column().name(column_COLUMN_NAME);
92
        sqlbuilder.select().column().name(column_CONSTRAINT_TYPE);
93
        sqlbuilder.select().from().custom(
94
                "INFORMATION_SCHEMA.table_constraints t_cons "
95
                + "inner join INFORMATION_SCHEMA.key_column_usage c on "
96
                + "c.constraint_catalog = t_cons.constraint_catalog and "
97
                + "c.table_schema = t_cons.table_schema and "
98
                + "c.table_name = t_cons.table_name and "
99
                + "c.constraint_name = t_cons.constraint_name "
100
        );
101
        sqlbuilder.select().where().set(
102
                expbuilder.like(
103
                        expbuilder.custom("c.TABLE_NAME"), 
104
                        expbuilder.constant(table.getTable())
105
                )
106
        );
107
        if (table.hasSchema()) {
108
            sqlbuilder.select().where().and(
109
                    expbuilder.like(
110
                            expbuilder.custom("c.TABLE_SCHEMA"),
111
                            expbuilder.constant(table.getSchema())
112
                    )
113
            );
114
        }
115
//        if (catalog != null) {
116
//            sqlbuilder.select().where().and(
117
//                    expbuilder.like(
118
//                            expbuilder.custom("c.CONSTRAINT_CATALOG"),
119
//                            expbuilder.constant(catalog)
120
//                    )
121
//            );
122
//        }
123
        sqlbuilder.select().where().and(
124
                expbuilder.eq(
125
                        expbuilder.column(column_CONSTRAINT_TYPE),
126
                        expbuilder.constant("PRIMARY KEY")
127
                )
128
        );
129
        return sqlbuilder.toString();
130
    }
131
        
132
    @Override
133
    protected void fetchGeometryTypeAndSRS(
134
            EditableFeatureAttributeDescriptor attr,
135
            ResultSetMetaData rsMetadata,
136
            int colIndex
137
        ) {
138
        if( attr.getType()!=DataTypes.GEOMETRY ) {
139
            return;
140
        }
141
        try {
142
            JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
143
            ExpressionBuilder expbuilder = sqlbuilder.expression();
144
            
145
            sqlbuilder.select().column().name("f_table_catalog");
146
            sqlbuilder.select().column().name("f_table_schema");
147
            sqlbuilder.select().column().name("f_table_name");
148
            sqlbuilder.select().column().name("f_geometry_column");
149
            sqlbuilder.select().column().name("coord_dimension");
150
            sqlbuilder.select().column().name("srid");
151
            sqlbuilder.select().column().name("type");
152
            sqlbuilder.select().where().set(
153
                    expbuilder.eq(
154
                            expbuilder.column("f_table_name"),
155
                            expbuilder.constant(this.getTable().getTable())
156
                    )
157
            );                
158
            sqlbuilder.select().where().and(
159
                    expbuilder.eq(
160
                            expbuilder.column("f_geometry_column"),
161
                            expbuilder.constant(attr.getName())
162
                    )
163
            );         
164
            sqlbuilder.select().from().table().name("geometry_columns");
165
            Statement st = null;
166
            ResultSet rs = null;
167
            
168
            Integer srsid = null;
169
            String geometryTypeName = null;
170
            try {
171
                st = this.getConnection().createStatement();
172
                rs = JDBCUtils.executeQuery(st, sqlbuilder.toString());
173
                if (rs.next()) {
174
                    srsid = rs.getInt("srid");
175
                    geometryTypeName = rs.getString("type");
176
                }
177
            } finally {
178
                JDBCUtils.closeQuietly(rs);
179
                JDBCUtils.closeQuietly(st);
180
            }
181
            if( !StringUtils.isEmpty(geometryTypeName) ) {
182
                GeometryType gt = getGeometryTypeFromDatabaseTypeName(geometryTypeName);
183
                attr.setGeometryType(gt);
184
            }
185
            if( srsid!=null ) {
186
                SRSSolver srssolver = this.helper.getSRSSolver();
187
                attr.setSRS(srssolver.getProjection(this.getConnection(),srsid));
188
            }
189
        } catch (Exception ex) {
190
            LOGGER.debug("Can't get geometry type and srs from column '"+attr.getName()+"'.",ex);
191
        }
192
    }
193

  
194
    private GeometryType getGeometryTypeFromDatabaseTypeName(String typeName) {
195
        if( databaseGeometryTypes==null ) {
196
            GeometryManager manager = GeometryLocator.getGeometryManager();
197
            databaseGeometryTypes = new HashMap<>();
198
            databaseGeometryTypes.put("POINT", getGT(manager, Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM2D));
199
            databaseGeometryTypes.put("POINTZ", getGT(manager, Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM3D));
200
            databaseGeometryTypes.put("POINTM", getGT(manager, Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM2DM));
201
            databaseGeometryTypes.put("POINTZM", getGT(manager, Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM3DM));
202
            
203
            databaseGeometryTypes.put("LINESTRING", getGT(manager, Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM2D));
204
            databaseGeometryTypes.put("LINESTRINGZ", getGT(manager, Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM3D));
205
            databaseGeometryTypes.put("LINESTRINGM", getGT(manager, Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM2DM));
206
            databaseGeometryTypes.put("LINESTRINGZM", getGT(manager, Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM3DM));
207
            
208
            databaseGeometryTypes.put("POLYGON", getGT(manager, Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM2D));
209
            databaseGeometryTypes.put("POLYGONZ", getGT(manager, Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM3D));
210
            databaseGeometryTypes.put("POLYGONM", getGT(manager, Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM2DM));
211
            databaseGeometryTypes.put("POLYGONZM", getGT(manager, Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM3DM));
212

  
213
            databaseGeometryTypes.put("MULTIPOINT", getGT(manager, Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM2D));
214
            databaseGeometryTypes.put("MULTIPOINTZ", getGT(manager, Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM3D));
215
            databaseGeometryTypes.put("MULTIPOINTM", getGT(manager, Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM2DM));
216
            databaseGeometryTypes.put("MULTIPOINTZM", getGT(manager, Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM3DM));
217

  
218
            databaseGeometryTypes.put("MULTILINESTRING", getGT(manager, Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM2D));
219
            databaseGeometryTypes.put("MULTILINESTRINGZ", getGT(manager, Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM3D));
220
            databaseGeometryTypes.put("MULTILINESTRINGM", getGT(manager, Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM2DM));
221
            databaseGeometryTypes.put("MULTILINESTRINGZM", getGT(manager, Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM3DM));
222

  
223
            databaseGeometryTypes.put("MULTIPOLYGON", getGT(manager, Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM2D));
224
            databaseGeometryTypes.put("MULTIPOLYGONZ", getGT(manager, Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM3D));
225
            databaseGeometryTypes.put("MULTIPOLYGONM", getGT(manager, Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM2DM));
226
            databaseGeometryTypes.put("MULTIPOLYGONZM", getGT(manager, Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM3DM));
227

  
228
            databaseGeometryTypes.put("GEOMETRY", getGT(manager, Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM2D));
229
            databaseGeometryTypes.put("GEOMETRYZ", getGT(manager, Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM3D));
230
            databaseGeometryTypes.put("GEOMETRYM", getGT(manager, Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM2DM));
231
            databaseGeometryTypes.put("GEOMETRYZM", getGT(manager, Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM3DM));
232
        }
233
        return databaseGeometryTypes.get(typeName);
234
    }
235
    
236
}
tags/org.gvsig.postgresql-2.0.117/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.117/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.117/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.117/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.117/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
@SuppressWarnings("UseSpecificCatch")
39
public class PostgreSQLBuilder extends JDBCSQLBuilderBase {
40

  
41
    protected Formatter formatter = null;
42
    
43
    public static class Version {
44

  
45
        private final int major;
46
        private final int minor;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff