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 |
/* 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 |
package org.gvsig.fmap.dal.store.postgresql; |
29 |
|
30 |
import org.gvsig.fmap.dal.DALLocator; |
31 |
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
32 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
33 |
import org.gvsig.fmap.dal.store.db.DBHelper; |
34 |
import org.gvsig.fmap.dal.store.jdbc.JDBCLibrary; |
35 |
import org.gvsig.metadata.exceptions.MetadataException; |
36 |
import org.gvsig.tools.library.AbstractLibrary; |
37 |
import org.gvsig.tools.library.LibraryException; |
38 |
import org.slf4j.Logger; |
39 |
import org.slf4j.LoggerFactory; |
40 |
|
41 |
public class PostgreSQLLibrary extends AbstractLibrary { |
42 |
|
43 |
|
44 |
private static final Logger LOG = |
45 |
LoggerFactory.getLogger(PostgreSQLLibrary.class); |
46 |
|
47 |
static String DEFAULT_JDCB_DRIVER_NAME = "org.postgresql.Driver"; |
48 |
|
49 |
|
50 |
public static String getJdbcUrl(String host, Integer port, String db) { |
51 |
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 |
} |
59 |
return url;
|
60 |
} |
61 |
|
62 |
|
63 |
@Override
|
64 |
protected void doInitialize() throws LibraryException { |
65 |
} |
66 |
|
67 |
|
68 |
@Override
|
69 |
protected void doPostInitialize() throws LibraryException { |
70 |
LibraryException ex=null;
|
71 |
|
72 |
new JDBCLibrary().postInitialize();
|
73 |
|
74 |
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 |
.getResourceManager(); |
106 |
|
107 |
|
108 |
if (!resman.getResourceProviders().contains(PostgreSQLResource.NAME)) {
|
109 |
resman.register(PostgreSQLResource.NAME, |
110 |
PostgreSQLResource.DESCRIPTION, PostgreSQLResource.class, |
111 |
PostgreSQLResourceParameters.class); |
112 |
} |
113 |
|
114 |
|
115 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator |
116 |
.getDataManager(); |
117 |
|
118 |
if (!dataman.getStoreProviders().contains(PostgreSQLStoreProvider.NAME)) {
|
119 |
dataman.registerStoreProvider(PostgreSQLStoreProvider.NAME, |
120 |
PostgreSQLStoreProvider.class, |
121 |
PostgreSQLStoreParameters.class); |
122 |
} |
123 |
|
124 |
if (!dataman.getExplorerProviders().contains(
|
125 |
PostgreSQLStoreProvider.NAME)) { |
126 |
dataman.registerExplorerProvider(PostgreSQLServerExplorer.NAME, |
127 |
PostgreSQLServerExplorer.class, |
128 |
PostgreSQLServerExplorerParameters.class); |
129 |
} |
130 |
if( ex!=null ) { |
131 |
throw ex;
|
132 |
} |
133 |
} |
134 |
|
135 |
} |