Revision 71

View differences:

tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.export/buildNumber.properties
1
#Tue Oct 08 20:52:46 CEST 2013
2
buildNumber=2077
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.export/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.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.export/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.exportto.swing.prov.postgresql.ExporttoV2PostgreSQLProviderLibrary
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.export/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
    <file>
17
      <source>src/main/resources-plugin/config.xml</source>
18
    </file>
19
  </files>
20

  
21
  <dependencySets>
22
  
23
    <dependencySet>
24
      <useProjectArtifact>false</useProjectArtifact>
25
      <useTransitiveDependencies>false</useTransitiveDependencies>
26
      <outputDirectory>lib</outputDirectory>
27
      <includes>
28
        <include>org.gvsig:org.gvsig.postgresql.provider</include>
29
      </includes>
30
    </dependencySet>
31
    
32
    <dependencySet>
33
      <useProjectArtifact>false</useProjectArtifact>
34
      <useTransitiveDependencies>false</useTransitiveDependencies>
35
      <outputDirectory>lib</outputDirectory>
36
      <includes>
37
		<include>postgresql:postgresql</include>
38
		<include>commons-dbcp:commons-dbcp</include>
39
		<include>commons-collections:commons-collections</include>
40
		<include>commons-pool:commons-pool</include>
41
      </includes>
42
    </dependencySet>
43
    
44
  </dependencySets>
45

  
46
</assembly>
47

  
48

  
49

  
50

  
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.export/src/main/java/org/gvsig/postgresql/exportto/ExporttoPostgreSQLProviderLibrary.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
package org.gvsig.postgresql.exportto;
25

  
26
import org.gvsig.tools.library.AbstractLibrary;
27
import org.gvsig.tools.library.LibraryException;
28
import org.gvsig.tools.service.spi.ProviderManager;
29
import org.gvsig.exportto.swing.ExporttoSwingLibrary;
30
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderLocator;
31

  
32
/**
33
 * Library to initialize and register the file Exporto provider
34
 * implementation.
35
 * 
36
 * @author gvSIG Team
37
 * @version $Id$
38
 */
39
public class ExporttoPostgreSQLProviderLibrary extends AbstractLibrary {
40

  
41
    @Override
42
    public void doRegistration() {
43
        registerAsServiceOf(ExporttoSwingLibrary.class);
44
    }
45

  
46
    @Override
47
    protected void doInitialize() throws LibraryException {
48
        // Nothing to do
49
    }
50

  
51
    @Override
52
    protected void doPostInitialize() throws LibraryException {
53
        ProviderManager providerManager =
54
            ExporttoSwingProviderLocator.getManager();
55
        providerManager
56
            .addProviderFactory(new ExporttoPostgreSQLProviderFactory());
57
    }
58

  
59
}
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.export/src/main/java/org/gvsig/postgresql/exportto/ExporttoPostgreSQLProviderFactory.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
package org.gvsig.postgresql.exportto;
25

  
26
import org.cresques.cts.IProjection;
27

  
28
import org.gvsig.exportto.swing.ExporttoSwingManager;
29
import org.gvsig.exportto.swing.spi.AbstractExporttoProviderFactory;
30
import org.gvsig.fmap.dal.feature.FeatureStore;
31
import org.gvsig.tools.dynobject.DynObject;
32
import org.gvsig.tools.service.ServiceException;
33
import org.gvsig.tools.service.spi.Provider;
34
import org.gvsig.tools.service.spi.ProviderServices;
35

  
36
/**
37
 * Factory of file {@link ExportoProvider} objects.
38
 * 
39
 * @author gvSIG Team
40
 * @version $Id$
41
 */
42
public class ExporttoPostgreSQLProviderFactory extends
43
    AbstractExporttoProviderFactory {
44

  
45
    private static final String PROVIDER_NAME = "PostgreSQLv2";
46

  
47
    public ExporttoPostgreSQLProviderFactory() {
48
        super(new int[] {
49
            ExporttoSwingManager.VECTORIAL_TABLE_WITHOUT_GEOMETRY,
50
            ExporttoSwingManager.VECTORIAL_TABLE_WITH_GEOMETRY });
51
    }
52

  
53
    public Provider create(DynObject parameters, ProviderServices services)
54
        throws ServiceException {
55
        return new ExporttoPostgreSQLProvider(services,
56
            (FeatureStore) parameters.getDynValue(PARAMETER_FEATURESTORE),
57
            (IProjection) parameters.getDynValue(PARAMETER_PROJECTION));
58
    }
59

  
60
    public String getName() {
61
        return PROVIDER_NAME;
62
    }
63
}
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.export/src/main/java/org/gvsig/postgresql/exportto/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 3
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
28
<html xmlns="http://www.w3.org/1999/xhtml">
29
<head>
30
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
31
<title>org.gvsig.exporto package documentation</title>
32
</head>
33
<body>
34

  
35
	<p>Exporto provider which gets Exporto from a file.</p>
36

  
37
</body>
38
</html>
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.export/src/main/java/org/gvsig/postgresql/exportto/panel/SelectTableNamePanel.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
package org.gvsig.postgresql.exportto.panel;
25

  
26
import java.awt.BorderLayout;
27
import javax.swing.JTextField;
28
import org.gvsig.exportto.swing.ExporttoSwingLocator;
29
import org.gvsig.exportto.swing.ExporttoSwingManager;
30
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException;
31
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel;
32

  
33
/**
34
 * @author gvSIG Team
35
 * @version $Id$
36
 * 
37
 */
38
public class SelectTableNamePanel extends ExporttoSwingProviderPanel {
39

  
40
    private static final long serialVersionUID = 6269512983586358017L;
41

  
42
    private static final ExporttoSwingManager EXPORTTO_SWING_MANAGER =
43
        ExporttoSwingLocator.getSwingManager();
44

  
45
    protected JTextField textField = null;
46

  
47
    protected void initializeComponents() {
48
        this.setLayout(new BorderLayout());
49
        textField = new JTextField();
50
        add(textField, BorderLayout.NORTH);
51
    }
52

  
53
    public String getText() {
54
        String field = textField.getText();
55
        if ((field == null) || (field.equals(""))) {
56
            return null;
57
        }
58
        return field;
59
    }
60
    
61
    public String getPanelTitle() {
62
        return EXPORTTO_SWING_MANAGER.getTranslation("intro_tablename");
63
    }
64

  
65
    public boolean isValidPanel() throws ExporttoPanelValidationException {
66
        if (getText() == null || getText().equals("")) {
67
            throw new ExporttoPanelValidationException(
68
                "The table cannot be empty");
69
        }
70
        return true;
71
    }
72
}
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.export/src/main/java/org/gvsig/postgresql/exportto/panel/SelectPkPanel.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 modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.postgresql.exportto.panel;
24

  
25
import java.awt.BorderLayout;
26

  
27
import javax.swing.JLabel;
28
import javax.swing.JPanel;
29
import javax.swing.JTextField;
30

  
31
import org.gvsig.exportto.swing.ExporttoSwingLocator;
32
import org.gvsig.exportto.swing.ExporttoSwingManager;
33
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException;
34
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel;
35
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
36
import org.gvsig.fmap.dal.feature.FeatureType;
37

  
38
/**
39
 * @author gvSIG Team
40
 * @version $Id$
41
 *
42
 */
43
public class SelectPkPanel extends ExporttoSwingProviderPanel {
44

  
45
    private static final long serialVersionUID = 2652404227373508779L;
46

  
47
    private static final ExporttoSwingManager EXPORTTO_SWING_MANAGER
48
            = ExporttoSwingLocator.getSwingManager();
49

  
50
    private FeatureType featType = null;
51
    protected JTextField textField = null;
52

  
53
    public SelectPkPanel() {
54
        super();
55
    }
56

  
57
    public SelectPkPanel(FeatureType ft) {
58
        super();
59
        featType = ft;
60
    }
61

  
62
    protected void initializeComponents() {
63
        this.setLayout(new BorderLayout());
64

  
65
        JPanel topPanel = new JPanel(new BorderLayout());
66
        textField = new JTextField();
67

  
68
        String msg = EXPORTTO_SWING_MANAGER.getTranslation(
69
                "_Enter_new_field_name_for_primary_key_or_blank_to_not_add_primary_key");
70
        topPanel.add(new JLabel(msg + ":"), BorderLayout.NORTH);
71
        topPanel.add(textField, BorderLayout.CENTER);
72
        // ==============================================
73
        add(topPanel, BorderLayout.NORTH);
74
    }
75

  
76
    public String getText() {
77
        String field = textField.getText();
78
        if ((field == null) || (field.trim().equals(""))) {
79
            return null;
80
        }
81
        return field;
82
    }
83

  
84
    @Override
85
    public String getPanelTitle() {
86
        return EXPORTTO_SWING_MANAGER.getTranslation("_Primary_key");
87
    }
88

  
89
    @Override
90
    public boolean isValidPanel() throws ExporttoPanelValidationException {
91
        String txt = this.getText();
92
        if (isFieldName(txt, featType)) {
93
            throw new ExporttoPanelValidationException(
94
                    EXPORTTO_SWING_MANAGER.getTranslation(
95
                            "_Field_name_already_exists"));
96
        }
97
        return true;
98
    }
99

  
100
    private boolean isFieldName(String txt, FeatureType ft) {
101

  
102
        if (ft == null || txt == null) {
103
            return false;
104
        }
105

  
106
        FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors();
107
        for (int i = 0; i < atts.length; i++) {
108
            if (atts[i].getName().equals(txt)) {
109
                return true;
110
            }
111
        }
112
        return false;
113
    }
114

  
115
}
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.export/src/main/java/org/gvsig/postgresql/exportto/panel/DefaultConnectionPanel.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6

  
7
package org.gvsig.postgresql.exportto.panel;
8

  
9
import java.util.HashMap;
10
import java.util.Iterator;
11
import java.util.Map;
12
import javax.swing.JComponent;
13
import javax.swing.JPanel;
14
import org.gvsig.andami.PluginsLocator;
15
import org.gvsig.andami.PluginsManager;
16
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters;
17
import org.gvsig.tools.swing.api.Component;
18
import org.gvsig.geodb.ExtDB_Spatial;
19

  
20
/**
21
 *
22
 * @author jjdelcerro
23
 */
24
public class DefaultConnectionPanel extends JPanel implements Component {
25

  
26
    private String name = null;
27
    private DBServerExplorerParameters explorerParameters = null;
28
    private String explorerNameFilter = null;
29

  
30
    
31
    public DefaultConnectionPanel() {
32
        
33
    }
34
    
35
    public void setFilterByExplorerName(String explorerNameFilter) {
36
        this.explorerNameFilter = explorerNameFilter;
37
    }
38
    
39
    public JComponent asJComponent() {
40
        return this;
41
    }
42
    
43
    protected Map<String,DBServerExplorerParameters> getUserConections() {
44
        PluginsManager pluginsManager = PluginsLocator.getManager();
45
        ExtDB_Spatial geodbExtension = pluginsManager.getExtension(ExtDB_Spatial.class);
46
        Map<String, DBServerExplorerParameters> connections = geodbExtension.getUserConnections();
47
        if( this.explorerNameFilter == null ) {
48
            return connections;
49
        }
50
        Map<String,DBServerExplorerParameters> filteredConnections = new HashMap<String,DBServerExplorerParameters>();
51
        
52
        Iterator<Map.Entry<String,DBServerExplorerParameters>> it = connections.entrySet().iterator();
53
        while( it.hasNext() ) {
54
            Map.Entry<String,DBServerExplorerParameters> entry = it.next();
55
            if( this.explorerNameFilter.equalsIgnoreCase(entry.getValue().getExplorerName()) ) {
56
                filteredConnections.put(entry.getKey(), entry.getValue());
57
            }
58
        }
59
        return filteredConnections;
60
    }
61
    
62
    protected void initComponents() {
63
        
64
    }
65
    
66
    
67
}
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.export/src/main/java/org/gvsig/postgresql/exportto/ExporttoPostgreSQLProvider.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 modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.postgresql.exportto;
24

  
25
import org.cresques.cts.IProjection;
26
import org.gvsig.exportto.ExporttoService;
27
import org.gvsig.exportto.swing.prov.jdbc.ExporrtoJDBCService;
28
import org.gvsig.exportto.swing.prov.jdbc.panel.JDBCConnectionPanel;
29
import org.gvsig.exportto.swing.spi.ExporttoSwingProvider;
30
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel;
31
import org.gvsig.fmap.dal.feature.FeatureStore;
32
import org.gvsig.fmap.dal.feature.FeatureType;
33
import org.gvsig.tools.service.spi.AbstractProvider;
34
import org.gvsig.tools.service.spi.ProviderServices;
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37
import org.gvsig.postgresql.exportto.panel.SelectPkPanel;
38
import org.gvsig.postgresql.exportto.panel.SelectTableNamePanel;
39

  
40
        
41
/**
42
 * Exporto provider which gets Exporto from a file.
43
 *
44
 * @author gvSIG Team
45
 * @version $Id$
46
 */
47
public class ExporttoPostgreSQLProvider extends AbstractProvider
48
        implements ExporttoSwingProvider {
49

  
50
    private static Logger logger = LoggerFactory.getLogger(
51
            ExporttoPostgreSQLProvider.class);
52

  
53
    protected SelectTableNamePanel selectTableNamePanel = null;
54
    protected SelectPkPanel selectPkPanel = null;
55
    protected JDBCConnectionPanel jdbcConnectionPanel = null;
56

  
57
    protected FeatureStore featureStore;
58
    protected IProjection projection;
59

  
60
    /**
61
     * Constructor.
62
     *
63
     * @param providerServices the services for the provider
64
     * @param file to get the Exporto from
65
     */
66
    public ExporttoPostgreSQLProvider(ProviderServices providerServices,
67
            FeatureStore featureStore, IProjection projection) {
68
        super(providerServices);
69
        this.featureStore = featureStore;
70
        this.projection = projection;
71

  
72
        selectTableNamePanel = new SelectTableNamePanel();
73

  
74
        FeatureType ftype = null;
75
        try {
76
            ftype = featureStore.getDefaultFeatureType();
77
        } catch (Exception exc) {
78
            logger.error("While getting feature type.", exc);
79
        }
80
        selectPkPanel = new SelectPkPanel(ftype);
81
        jdbcConnectionPanel = new JDBCConnectionPanel();
82
    }
83

  
84
    public String getStoreName() {
85
        return "PostgreSQL";
86
    }
87

  
88
    public String getExplorerName() {
89
        return "PostgreSQLExplorer";
90
    }
91

  
92
    public int getPanelCount() {
93
        return 3;
94
    }
95

  
96
    public ExporttoSwingProviderPanel getPanelAt(int index) {
97
        switch (index) {
98
            case 0:
99
                return selectTableNamePanel;
100
            case 1:
101
                return selectPkPanel;
102
            case 2:
103
                return jdbcConnectionPanel;
104
        }
105
        return null;
106
    }
107

  
108
    public ExporttoService createExporttoService() {
109
        ConnectionSettings connectionSettings
110
                = jdbcConnectionPanel.getConnectionSettings();
111

  
112
        int port = -1;
113
        if (connectionSettings.getPort() != null
114
                && connectionSettings.getPort().length() > 0) {
115
            port = Integer.valueOf(connectionSettings.getPort());
116
        }
117

  
118
        String schema = null;
119
        if (connectionSettings.getSchema() != null
120
                && connectionSettings.getSchema().length() > 0) {
121
            schema = connectionSettings.getSchema();
122
        }
123

  
124
        return new ExporrtoJDBCService(featureStore,
125
                connectionSettings.getDb(), schema, selectTableNamePanel.getText(),
126
                selectPkPanel.getText(), connectionSettings.getUser(),
127
                connectionSettings.getPassw(), connectionSettings.getHost(), port,
128
                getExplorerName(), getStoreName(), this.projection);
129
    }
130
}
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.export/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.export</artifactId>
7
  <packaging>jar</packaging>
8
  <name>Export: PostgreSQL support</name>
9
  <description>Export support for PostgreSQL</description>
10

  
11
  <parent>
12
      <groupId>org.gvsig</groupId>
13
      <artifactId>org.gvsig.postgresql.app</artifactId>
14
      <version>2.0.21-SNAPSHOT</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.exportto.lib.api</artifactId>
31
      <scope>compile</scope>
32
    </dependency>
33
    <dependency>
34
      <groupId>org.gvsig</groupId>
35
      <artifactId>org.gvsig.exportto.swing.api</artifactId>
36
      <scope>compile</scope>
37
    </dependency>
38
    <dependency>
39
      <groupId>org.gvsig</groupId>
40
      <artifactId>org.gvsig.exportto.swing.spi</artifactId>
41
      <scope>compile</scope>
42
    </dependency>
43
    <dependency>
44
      <groupId>org.gvsig</groupId>
45
      <artifactId>org.gvsig.exportto.swing.prov.jdbc</artifactId>
46
      <scope>compile</scope>
47
    </dependency>
48
    <dependency>
49
      <groupId>org.gvsig</groupId>
50
      <artifactId>org.gvsig.geodb.app.mainplugin</artifactId>
51
      <scope>compile</scope>
52
    </dependency>
53
    
54
    
55
    <dependency>
56
      <groupId>postgresql</groupId>
57
      <artifactId>postgresql</artifactId>
58
      <scope>runtime</scope>
59
    </dependency>
60
    <dependency>
61
      <groupId>commons-dbcp</groupId>
62
      <artifactId>commons-dbcp</artifactId>
63
      <scope>runtime</scope>
64
    </dependency>
65
    <dependency>
66
      <groupId>commons-collections</groupId>
67
      <artifactId>commons-collections</artifactId>
68
      <scope>runtime</scope>
69
    </dependency>
70
    <dependency>
71
      <groupId>commons-pool</groupId>
72
      <artifactId>commons-pool</artifactId>
73
      <scope>runtime</scope>
74
    </dependency>
75
    
76
  </dependencies>
77
  
78
    <properties>
79
        <!-- Package info property values -->
80
        <!-- Default values in org.gvsig.desktop -->
81
        <gvsig.package.info.state>testing</gvsig.package.info.state>
82
        <gvsig.package.info.official>true</gvsig.package.info.official>
83
        <gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.0.1</gvsig.package.info.dependencies>
84
        <gvsig.package.info.categories>Formats,Vector,Database</gvsig.package.info.categories>
85
        <gvsig.package.info.poolURL>http://devel.gvsig.org/download/projects/gvsig-postgresql/pool/</gvsig.package.info.poolURL>
86
    </properties>
87
  
88

  
89
</project>
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4

  
5
  <modelVersion>4.0.0</modelVersion>
6
  <artifactId>org.gvsig.postgresql.app.mainplugin</artifactId>
7
  <packaging>jar</packaging>
8
  <name>Formats: PostgreSQL support</name>
9
  <description>PostgreSQL file format support</description>
10

  
11
  <parent>
12
      <groupId>org.gvsig</groupId>
13
      <artifactId>org.gvsig.postgresql.app</artifactId>
14
      <version>2.0.21</version>
15
  </parent>
16

  
17
  <dependencies>
18
    <dependency>
19
        <groupId>org.gvsig</groupId>
20
        <artifactId>org.gvsig.tools.lib</artifactId>
21
        <scope>compile</scope>
22
    </dependency>
23
    <dependency>
24
        <groupId>org.gvsig</groupId>
25
        <artifactId>org.gvsig.andami</artifactId>
26
        <scope>compile</scope>
27
    </dependency>
28
    <dependency>
29
        <groupId>org.gvsig</groupId>
30
        <artifactId>org.gvsig.postgresql.provider</artifactId>
31
        <scope>compile</scope>
32
    </dependency>
33
    
34
    <dependency>
35
      <groupId>postgresql</groupId>
36
      <artifactId>postgresql</artifactId>
37
      <scope>runtime</scope>
38
    </dependency>
39
    <dependency>
40
      <groupId>commons-dbcp</groupId>
41
      <artifactId>commons-dbcp</artifactId>
42
      <scope>runtime</scope>
43
    </dependency>
44
    <dependency>
45
      <groupId>commons-collections</groupId>
46
      <artifactId>commons-collections</artifactId>
47
      <scope>runtime</scope>
48
    </dependency>
49
    <dependency>
50
      <groupId>commons-pool</groupId>
51
      <artifactId>commons-pool</artifactId>
52
      <scope>runtime</scope>
53
    </dependency>
54
    
55
  </dependencies>
56
  
57
    <properties>
58
        <!-- Package info property values -->
59
        <!-- Default values in org.gvsig.desktop -->
60
        <gvsig.package.info.state>testing</gvsig.package.info.state>
61
        <gvsig.package.info.official>true</gvsig.package.info.official>
62
        <gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.0.1</gvsig.package.info.dependencies>
63
        <gvsig.package.info.categories>Formats,Vector,Database</gvsig.package.info.categories>
64
        <gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-postgresql/pool/</gvsig.package.info.poolURL>
65
    </properties>
66
  
67

  
68
</project>
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/buildNumber.properties
1
#Tue Oct 08 20:52:46 CEST 2013
2
buildNumber=2078
tags/org.gvsig.postgresql-2.0.21/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.21/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
    <file>
17
      <source>src/main/resources-plugin/config.xml</source>
18
    </file>
19
  </files>
20

  
21
  <dependencySets>
22
  
23
    <dependencySet>
24
      <useProjectArtifact>false</useProjectArtifact>
25
      <useTransitiveDependencies>false</useTransitiveDependencies>
26
      <outputDirectory>lib</outputDirectory>
27
      <includes>
28
        <include>org.gvsig:org.gvsig.postgresql.provider</include>
29
      </includes>
30
    </dependencySet>
31
    
32
    <dependencySet>
33
      <useProjectArtifact>false</useProjectArtifact>
34
      <useTransitiveDependencies>false</useTransitiveDependencies>
35
      <outputDirectory>lib</outputDirectory>
36
      <includes>
37
		<include>postgresql:postgresql</include>
38
		<include>commons-dbcp:commons-dbcp</include>
39
		<include>commons-collections:commons-collections</include>
40
		<include>commons-pool:commons-pool</include>
41
      </includes>
42
    </dependencySet>
43
    
44
  </dependencySets>
45

  
46
</assembly>
47

  
48

  
49

  
50

  
0 51

  
tags/org.gvsig.postgresql-2.0.21/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.21</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.21/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.21</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.42</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.21</connection>
20
      <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-postgresql/tags/org.gvsig.postgresql-2.0.21</developerConnection>
21
      <url>https://devel.gvsig.org/redmine/projects/gvsig-postgresql/repository/show/tags/org.gvsig.postgresql-2.0.21</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.21</version>
63
          </dependency>
64
          <dependency>
65
            <groupId>org.gvsig</groupId>
66
            <artifactId>org.gvsig.postgresql.app.mainplugin</artifactId>
67
            <version>2.0.21</version>
68
          </dependency>
69
      </dependencies>
70
  </dependencyManagement>
71

  
72
  <dependencies>
73
        <dependency>
74
            <groupId>org.slf4j</groupId>
75
            <artifactId>slf4j-api</artifactId>
76
            <scope>compile</scope>
77
        </dependency>
78
  </dependencies>
79

  
80
  
81
  <modules>
82
    <module>org.gvsig.postgresql.app</module>
83
    <module>org.gvsig.postgresql.provider</module>
84
  </modules>
85

  
86

  
87
</project>
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.provider/src/test/java/org/gvsig/fmap/dal/store/postgresql/TestPostgreSQLWrite.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
/**
29
 *
30
 */
31
package org.gvsig.fmap.dal.store.postgresql;
32

  
33
import java.util.Iterator;
34

  
35
import org.gvsig.fmap.dal.DataStoreParameters;
36
import org.gvsig.fmap.dal.exception.DataException;
37
import org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore;
38
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
39
import org.gvsig.fmap.dal.feature.EditableFeatureType;
40
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
41
import org.gvsig.fmap.dal.feature.FeatureQuery;
42
import org.gvsig.fmap.dal.feature.FeatureStore;
43
import org.gvsig.fmap.dal.feature.FeatureStoreTransform;
44
import org.gvsig.fmap.dal.feature.FeatureType;
45
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
46
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer;
47
import org.gvsig.fmap.geom.Geometry;
48
import org.gvsig.fmap.geom.operation.towkt.ToWKT;
49
import org.gvsig.tools.evaluator.Evaluator;
50
import org.gvsig.tools.evaluator.EvaluatorData;
51
import org.gvsig.tools.evaluator.EvaluatorException;
52
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo;
53

  
54

  
55

  
56
/**
57
 * @author jmvivo
58
 *
59
 */
60
// public class TestPostgreSQL extends BaseTestEditableFeatureStore {
61
public class TestPostgreSQLWrite extends BaseTestEditableFeatureStore {
62

  
63

  
64
	private JDBCServerExplorer myExplorer;
65
	private PostgreSQLNewStoreParameters newParams;
66

  
67
	@Override
68
	protected void doSetUp() throws Exception {
69
		// Initialize wkt geom operation
70
		int wktCode = ToWKT.CODE;
71
	}
72

  
73
	public DataStoreParameters getDefaultDataStoreParameters()
74
			throws DataException {
75
		PostgreSQLStoreParameters pgParameters = null;
76
		pgParameters = (PostgreSQLStoreParameters) dataManager
77
				.createStoreParameters(PostgreSQLStoreProvider.NAME);
78

  
79
		pgParameters.setHost("localhost");
80
		pgParameters.setUser("postgres");
81
		pgParameters.setPassword("postgres");
82
		pgParameters.setDBName("gis");
83
		pgParameters.setTable("muni10000_peq");
84

  
85
		return pgParameters;
86
	}
87

  
88
	public boolean hasExplorer() {
89
		return true;
90
	}
91

  
92
	public void testLoadMetadata() throws Exception {
93
		DataStoreParameters params = this.getDefaultDataStoreParameters();
94

  
95
		FeatureStore store = null;
96
		store = (FeatureStore) dataManager.createStore(params);
97
		FeatureType fType = store.getDefaultFeatureType();
98
		FeatureAttributeDescriptor geomAttr;
99

  
100

  
101

  
102
		if (fType.getDefaultGeometryAttributeIndex() >= 0) {
103
			assertNotNull(store.getEnvelope());
104
			geomAttr = fType.getAttributeDescriptor(fType
105
					.getDefaultGeometryAttributeIndex());
106
			assertTrue(geomAttr.getGeometryType() == Geometry.TYPES.MULTISURFACE);
107
			assertTrue(geomAttr.getGeometrySubType() == Geometry.SUBTYPES.GEOM2D);
108
			assertNotNull(store.getDynValue("CRS"));
109

  
110
		}
111

  
112
	}
113

  
114
	public void testCloserConnection() throws Exception {
115

  
116
		DataStoreParameters params = this.getDefaultDataStoreParameters();
117

  
118
		FeatureStore store = null;
119
		store = (FeatureStore) dataManager.createStore(params);
120

  
121
		FeatureQuery query = store.createFeatureQuery();
122

  
123
		query.getOrder().add("gid", true);
124

  
125
		query.setFilter(new Evaluator() {
126

  
127
			public Object evaluate(EvaluatorData data)
128
					throws EvaluatorException {
129
				// TODO Auto-generated method stub
130
				return Boolean.TRUE;
131
			}
132

  
133
			public String getSQL() {
134
				return "true = true";
135
			}
136

  
137
			public String getDescription() {
138
				// TODO Auto-generated method stub
139
				return null;
140
			}
141

  
142
			public String getName() {
143
				return "AlwaysTrue";
144
			}
145

  
146
			public EvaluatorFieldsInfo getFieldsInfo() {
147
				// TODO Auto-generated method stub
148
				return null;
149
			}
150

  
151
		});
152

  
153
		FeatureStoreTransform transform = new StringsToLowerTransform();
154
		transform.setFeatureStore(store);
155

  
156
		store.getTransforms().add(transform);
157

  
158
		transform = new StringsToLowerTransform();
159
		transform.setFeatureStore(store);
160

  
161
		store.getTransforms().add(transform);
162

  
163
		transform = new StringsToLowerTransform();
164
		transform.setFeatureStore(store);
165

  
166
		store.getTransforms().add(transform);
167

  
168
		for (int i = 0; i < 30; i++) {
169
			// this.fullStoreIteratorTest(store);
170

  
171
			this.testIterationFastAndStandart(store, query);
172
		}
173

  
174

  
175
		store.dispose();
176

  
177
	}
178

  
179
	public boolean usesResources() {
180
		return true;
181
	}
182

  
183
	public NewFeatureStoreParameters getDefaultNewDataStoreParameters()
184
			throws Exception {
185
		PostgreSQLStoreParameters parameters = (PostgreSQLStoreParameters) this
186
				.getDefaultDataStoreParameters();
187

  
188
		FeatureStore store = null;
189

  
190
		if (this.myExplorer == null) {
191
			store = (FeatureStore) dataManager.createStore(parameters);
192
			myExplorer = (JDBCServerExplorer) store.getExplorer();
193
		}
194
		if (this.newParams == null) {
195
			if (store == null){
196
				store = (FeatureStore) dataManager.createStore(parameters);
197
			}
198

  
199
			newParams = (PostgreSQLNewStoreParameters) myExplorer
200
					.getAddParameters();
201

  
202
			newParams.setTable(parameters.getTable() + "_test");
203
			FeatureType ftOrg = store.getDefaultFeatureType();
204
			EditableFeatureType ftTrg = (EditableFeatureType) newParams
205
					.getDefaultFeatureType();
206
			FeatureAttributeDescriptor org;
207
			EditableFeatureAttributeDescriptor trg;
208
			Iterator iter = ftOrg.iterator();
209
			while (iter.hasNext()) {
210
				org = (FeatureAttributeDescriptor) iter.next();
211
				trg = ftTrg.add(org.getName(), org.getType());
212
				trg.setAllowNull(org.allowNull());
213
				trg.setDefaultValue(org.getDefaultValue());
214
				trg.setGeometrySubType(org.getGeometrySubType());
215
				trg.setGeometryType(org.getGeometryType());
216
				trg.setIsAutomatic(org.isAutomatic());
217
				trg.setIsPrimaryKey(org.isPrimaryKey());
218
				trg.setIsReadOnly(org.isReadOnly());
219
				trg.setMaximumOccurrences(org.getMaximumOccurrences());
220
				trg.setMinimumOccurrences(org.getMinimumOccurrences());
221
				trg.setPrecision(org.getPrecision());
222
				trg.setSize(org.getSize());
223
				trg.setSRS(org.getSRS());
224
			}
225
			ftTrg.setDefaultGeometryAttributeName(ftOrg
226
					.getDefaultGeometryAttributeName());
227
			ftTrg.setHasOID(ftOrg.hasOID());
228

  
229
		}
230
		if (store != null){
231
			store.dispose();
232
		}
233

  
234
		return this.newParams;
235
	}
236

  
237
	public boolean resourcesNotifyChanges() {
238
		return false;
239
	}
240
}
tags/org.gvsig.postgresql-2.0.21/org.gvsig.postgresql.provider/src/test/java/org/gvsig/fmap/dal/store/postgresql/TestReadAndWriteGeom.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal.store.postgresql;
29

  
30
import java.sql.Connection;
31
import java.sql.DriverManager;
32
import java.sql.PreparedStatement;
33
import java.sql.ResultSet;
34
import java.sql.SQLException;
35
import java.sql.Statement;
36
import java.text.MessageFormat;
37

  
38
import org.gvsig.fmap.geom.Geometry;
39
import org.gvsig.fmap.geom.GeometryLocator;
40
import org.gvsig.fmap.geom.GeometryManager;
41
import org.gvsig.fmap.geom.operation.fromwkb.FromWKB;
42
import org.gvsig.fmap.geom.operation.fromwkb.FromWKBGeometryOperationContext;
43
import org.gvsig.fmap.geom.operation.towkb.ToWKB;
44
import org.gvsig.fmap.geom.operation.towkt.ToWKT;
45
import org.gvsig.fmap.geom.primitive.impl.Point2D;
46
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
47

  
48
public class TestReadAndWriteGeom extends AbstractLibraryAutoInitTestCase {
49
	private static final int FEATURES_TO_INSERT = 12000;
50
	private static final String TABLE_NAME_INSERT = "testReadadnwritegeom_testcase";
51
	private static final String FIELD_NAME_INSERT = "geom";
52
	private Connection conn;
53
	private GeometryManager geoManager;
54
	private static String SQL_FOR_READ_TEST = "Select {0} from medio_ejes";
55

  
56
	@Override
57
	protected void doSetUp() throws Exception {
58
		geoManager = GeometryLocator.getGeometryManager();
59

  
60
		Class klass = Class.forName(PostgreSQLLibrary.DEFAULT_JDCB_DRIVER_NAME);
61
		if (klass == null) {
62
			throw new Exception("Driver not found: "
63
					+ PostgreSQLLibrary.DEFAULT_JDCB_DRIVER_NAME);
64
		}
65

  
66
		// inicializamos operaciones de geometrias de las que dependemos
67
		int code = FromWKB.CODE;
68
		code = ToWKB.CODE;
69
		code = ToWKT.CODE;
70
		conn = DriverManager.getConnection(PostgreSQLLibrary.getJdbcUrl(
71
				"localhost", 5432, "gis"), "postgres", "postgres");
72
	}
73

  
74
	public void testInsertWKB() throws Exception {
75
		PreparedStatement pst = null;
76
		try {
77
			crearTablaTest();
78
			Point2D geom = (Point2D) geoManager.createPoint(0, 0,
79
					Geometry.SUBTYPES.GEOM2D);
80
			pst = conn.prepareStatement(
81
					"Insert into "
82
					+ TABLE_NAME_INSERT.toLowerCase() +
83
					"  ("
84
					+ FIELD_NAME_INSERT + ") Values (GeomFromWKB(?))");
85

  
86

  
87
			int i;
88
			for (i = 1; i <= FEATURES_TO_INSERT; i++) {
89
				pst.clearParameters();
90
				geom.setX(i);
91
				geom.setY(i);
92
				pst.setBytes(1,
93
					(byte[]) geom.invokeOperation(
94
							ToWKB.CODE,
95
							null)
96
					);
97

  
98
				pst.executeUpdate();
99
			}
100

  
101
			System.out
102
					.println("TestReadAndWriteGeom.testInsertPostgis() Inserteds= i");
103

  
104

  
105

  
106

  
107
		} finally {
108
			if (pst != null) {
109
				try {pst.close();} catch (SQLException e) {e.printStackTrace();}
110
			}
111

  
112
		}
113

  
114

  
115
	}
116

  
117
	private void crearTablaTest() throws SQLException {
118
		execute("DROP TABLE IF EXISTS " + TABLE_NAME_INSERT.toLowerCase());
119
		execute("Delete from geometry_columns  where  f_table_name = '"
120
				+ TABLE_NAME_INSERT.toLowerCase() + "'");
121
		execute("CREATE TABLE " + TABLE_NAME_INSERT.toLowerCase()
122
				+ " (id serial PRIMARY KEY)");
123
		execute("Select AddGeometryColumn('" + TABLE_NAME_INSERT.toLowerCase()
124
				+ "','"
125
				+ FIELD_NAME_INSERT + "',-1,'GEOMETRY',2)");
126
	}
127

  
128
	private void execute(String sql) throws SQLException {
129
		Statement st = null;
130
		try {
131
			st = conn.createStatement();
132
			st.execute(sql);
133
		} finally {
134
			if (st != null) {
135
				try {st.close();} catch (SQLException e) {e.printStackTrace();}
136
			}
137
		}
138

  
139
	}
140

  
141
	public String getSQLForRead(String geoColumn) {
142
		return MessageFormat.format(SQL_FOR_READ_TEST, geoColumn);
143

  
144
	}
145

  
146
	public void testReadBinary() throws Exception {
147
		// st.execute("declare " + getTableName() + myCursorId +
148
		// "_wkb_cursor binary scroll cursor with hold for " + sqlAux);
149
		// rs = st.executeQuery("fetch forward " + FETCH_SIZE+ " in " +
150
		// getTableName() + myCursorId + "_wkb_cursor");
151

  
152
		Statement st = null;
153
		ResultSet rs = null;
154
		long count = 0;
155
		Geometry geom;
156
		Geometry nullGeom = geoManager.createNullGeometry(Geometry.SUBTYPES.GEOM2D);
157

  
158
		try {
159
			st = conn.createStatement();
160
			String cursorName = "myCursor___xxx";
161
			st.execute("declare " + cursorName
162
					+ "_wkb_cursor binary scroll cursor with hold for "
163
					+ getSQLForRead("the_geom"));
164
			rs = st.executeQuery("fetch forward all in " + cursorName
165
					+ "_wkb_cursor");
166
			byte[] buff;
167
			FromWKBGeometryOperationContext opContext = new FromWKBGeometryOperationContext();
168
			while (rs.next()) {
169
				count++;
170
				buff = rs.getBytes(1);
171
//				if (buff != null) {
172
//					opContext.setData(buff);
173
//					geom = (Geometry) nullGeom.invokeOperation(FromWKB.CODE,
174
//							opContext);
175
//					assertNotNull(geom);
176
//				}
177
			}
178

  
179
			System.out
180
					.println("TestReadAndWriteGeom.testReadPostgis() Count = "
181
							+ count);
182

  
183
		} finally {
184
			if (st != null) {
185
				try {
186
					st.close();
187
				} catch (SQLException e) {
188
					e.printStackTrace();
189
				}
190
			}
191
			if (rs != null) {
192
				try {
193
					rs.close();
194
				} catch (SQLException e) {
195
					e.printStackTrace();
196
				}
197
			}
198
		}
199

  
200
	}
201

  
202
	public void testReadWKB() throws Exception {
203
		Statement st = null;
204
		ResultSet rs = null;
205
		long count = 0;
206
		Geometry geom;
207
		Geometry nullGeom = geoManager
208
				.createNullGeometry(Geometry.SUBTYPES.GEOM2D);
209
		byte[] buff;
210
		FromWKBGeometryOperationContext opContext = new FromWKBGeometryOperationContext();
211
		try {
212
			st = conn.createStatement();
213
			rs = st.executeQuery(getSQLForRead("asBinary(the_geom)"));
214
			while (rs.next()) {
215
				count++;
216
				buff = rs.getBytes(1);
217
//				if (buff != null) {
218
//					opContext.setData(buff);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff