Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_daldb / src / org / gvsig / fmap / dal / store / postgresql / PostgreSQLLibrary.java @ 34129

History | View | Annotate | Download (4.09 KB)

1 26790 jmvivo
/* 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
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27
28 27919 jmvivo
package org.gvsig.fmap.dal.store.postgresql;
29 26790 jmvivo
30
import org.gvsig.fmap.dal.DALLocator;
31 27525 jmvivo
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices;
32 26790 jmvivo
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
33 32880 jjdelcerro
import org.gvsig.fmap.dal.store.db.DBHelper;
34 30714 cordinyana
import org.gvsig.fmap.dal.store.jdbc.JDBCLibrary;
35 32880 jjdelcerro
import org.gvsig.metadata.exceptions.MetadataException;
36 30633 cordinyana
import org.gvsig.tools.library.AbstractLibrary;
37 30580 cordinyana
import org.gvsig.tools.library.LibraryException;
38 34128 fdiaz
import org.slf4j.Logger;
39
import org.slf4j.LoggerFactory;
40 26790 jmvivo
41 30633 cordinyana
public class PostgreSQLLibrary extends AbstractLibrary {
42 26790 jmvivo
43
44 34128 fdiaz
    private static final Logger LOG =
45
        LoggerFactory.getLogger(PostgreSQLLibrary.class);
46
47 27753 jmvivo
        static String DEFAULT_JDCB_DRIVER_NAME = "org.postgresql.Driver";
48 27595 jmvivo
49 26790 jmvivo
50 27906 jmvivo
        public static String getJdbcUrl(String host, Integer port, String db) {
51 34128 fdiaz
                String url = null;
52
                if(host != null){
53
                    String sport = "";
54
                    if (port != null) {
55
                        sport = ":" + port;
56
                    }
57
                    url = "jdbc:postgresql://" + host + sport + "/" + db;
58 27906 jmvivo
                }
59
                return url;
60
        }
61
62
63 30580 cordinyana
        @Override
64
        protected void doInitialize() throws LibraryException {
65 27525 jmvivo
        }
66
67 26790 jmvivo
68 30580 cordinyana
        @Override
69
        protected void doPostInitialize() throws LibraryException {
70 32880 jjdelcerro
                LibraryException ex=null;
71
72 30714 cordinyana
                new JDBCLibrary().postInitialize();
73
74 32880 jjdelcerro
                 DBHelper.registerParametersDefinition(
75
                                 PostgreSQLStoreParameters.PARAMETERS_DEFINITION_NAME,
76
                                 PostgreSQLStoreParameters.class,
77
                                 "PostgreSQLParameters.xml"
78
                );
79
                DBHelper.registerParametersDefinition(
80
                                PostgreSQLNewStoreParameters.PARAMETERS_DEFINITION_NAME,
81
                                PostgreSQLNewStoreParameters.class,
82
                                "PostgreSQLParameters.xml"
83
                );
84
                DBHelper.registerParametersDefinition(
85
                                PostgreSQLServerExplorerParameters.PARAMETERS_DEFINITION_NAME,
86
                                PostgreSQLServerExplorerParameters.class,
87
                                "PostgreSQLParameters.xml"
88
                );
89
                DBHelper.registerParametersDefinition(
90
                                PostgreSQLResourceParameters.PARAMETERS_DEFINITION_NAME,
91
                                PostgreSQLResourceParameters.class,
92
                                "PostgreSQLParameters.xml"
93
                );
94
                try {
95
                        DBHelper.registerMetadataDefinition(
96
                                        PostgreSQLStoreProvider.METADATA_DEFINITION_NAME,
97
                                        PostgreSQLStoreProvider.class,
98
                                        "PostgreSQLMetadata.xml"
99
                        );
100
                } catch (MetadataException e) {
101
                        ex = new LibraryException(this.getClass(),e);
102
                }
103
104
                ResourceManagerProviderServices resman = (ResourceManagerProviderServices) DALLocator
105 30580 cordinyana
                .getResourceManager();
106 26790 jmvivo
107 30580 cordinyana
108
                if (!resman.getResourceProviders().contains(PostgreSQLResource.NAME)) {
109 27525 jmvivo
                        resman.register(PostgreSQLResource.NAME,
110
                                        PostgreSQLResource.DESCRIPTION, PostgreSQLResource.class,
111
                                        PostgreSQLResourceParameters.class);
112
                }
113 30580 cordinyana
114
115
                DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator
116 26790 jmvivo
                                .getDataManager();
117 30580 cordinyana
118 26790 jmvivo
                if (!dataman.getStoreProviders().contains(PostgreSQLStoreProvider.NAME)) {
119
                        dataman.registerStoreProvider(PostgreSQLStoreProvider.NAME,
120
                                        PostgreSQLStoreProvider.class,
121
                                        PostgreSQLStoreParameters.class);
122
                }
123 30580 cordinyana
124 27906 jmvivo
                if (!dataman.getExplorerProviders().contains(
125
                                PostgreSQLStoreProvider.NAME)) {
126
                        dataman.registerExplorerProvider(PostgreSQLServerExplorer.NAME,
127
                                        PostgreSQLServerExplorer.class,
128
                                        PostgreSQLServerExplorerParameters.class);
129
                }
130 32880 jjdelcerro
                if( ex!=null ) {
131
                        throw ex;
132
                }
133 26790 jmvivo
        }
134
135 30580 cordinyana
}