root / trunk / org.gvsig.postgresql / org.gvsig.postgresql.provider / src / main / java / org / gvsig / fmap / dal / store / postgresql / PostgreSQLLibrary.java @ 294
History | View | Annotate | Download (4.14 KB)
1 | 5 | jldominguez | /* 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.DALLibrary; |
||
31 | import org.gvsig.fmap.dal.DALLocator; |
||
32 | import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
||
33 | import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
||
34 | import org.gvsig.fmap.dal.store.db.DBHelper; |
||
35 | import org.gvsig.fmap.dal.store.jdbc.JDBCLibrary; |
||
36 | import org.gvsig.metadata.exceptions.MetadataException; |
||
37 | import org.gvsig.tools.library.AbstractLibrary; |
||
38 | import org.gvsig.tools.library.LibraryException; |
||
39 | |||
40 | public class PostgreSQLLibrary extends AbstractLibrary { |
||
41 | |||
42 | 294 | jjdelcerro | static String DEFAULT_JDCB_DRIVER_NAME = "org.postgresql.Driver"; |
43 | public static final String NAME = "PostgreSQL"; |
||
44 | 5 | jldominguez | |
45 | @Override
|
||
46 | public void doRegistration() { |
||
47 | registerAsServiceOf(DALLibrary.class); |
||
48 | require(JDBCLibrary.class); |
||
49 | } |
||
50 | |||
51 | public static String getJdbcUrl(String host, Integer port, String db) { |
||
52 | String url = null; |
||
53 | if(host != null){ |
||
54 | String sport = ""; |
||
55 | if (port != null) { |
||
56 | sport = ":" + port;
|
||
57 | } |
||
58 | url = "jdbc:postgresql://" + host + sport + "/" + db; |
||
59 | } |
||
60 | return url;
|
||
61 | } |
||
62 | |||
63 | |||
64 | @Override
|
||
65 | protected void doInitialize() throws LibraryException { |
||
66 | } |
||
67 | |||
68 | |||
69 | @Override
|
||
70 | protected void doPostInitialize() throws LibraryException { |
||
71 | LibraryException ex=null;
|
||
72 | |||
73 | new JDBCLibrary().postInitialize();
|
||
74 | |||
75 | DBHelper.registerParametersDefinition( |
||
76 | PostgreSQLStoreParameters.PARAMETERS_DEFINITION_NAME, |
||
77 | PostgreSQLStoreParameters.class, |
||
78 | "PostgreSQLParameters.xml"
|
||
79 | ); |
||
80 | DBHelper.registerParametersDefinition( |
||
81 | PostgreSQLNewStoreParameters.PARAMETERS_DEFINITION_NAME, |
||
82 | PostgreSQLNewStoreParameters.class, |
||
83 | "PostgreSQLParameters.xml"
|
||
84 | ); |
||
85 | DBHelper.registerParametersDefinition( |
||
86 | PostgreSQLServerExplorerParameters.PARAMETERS_DEFINITION_NAME, |
||
87 | PostgreSQLServerExplorerParameters.class, |
||
88 | "PostgreSQLParameters.xml"
|
||
89 | ); |
||
90 | DBHelper.registerParametersDefinition( |
||
91 | PostgreSQLResourceParameters.PARAMETERS_DEFINITION_NAME, |
||
92 | PostgreSQLResourceParameters.class, |
||
93 | "PostgreSQLParameters.xml"
|
||
94 | ); |
||
95 | try {
|
||
96 | DBHelper.registerMetadataDefinition( |
||
97 | PostgreSQLStoreProvider.METADATA_DEFINITION_NAME, |
||
98 | PostgreSQLStoreProvider.class, |
||
99 | "PostgreSQLMetadata.xml"
|
||
100 | ); |
||
101 | } catch (MetadataException e) {
|
||
102 | ex = new LibraryException(this.getClass(),e); |
||
103 | } |
||
104 | |||
105 | ResourceManagerProviderServices resman = (ResourceManagerProviderServices) DALLocator |
||
106 | .getResourceManager(); |
||
107 | |||
108 | |||
109 | if (!resman.getResourceProviders().contains(PostgreSQLResource.NAME)) {
|
||
110 | resman.register(PostgreSQLResource.NAME, |
||
111 | PostgreSQLResource.DESCRIPTION, PostgreSQLResource.class, |
||
112 | PostgreSQLResourceParameters.class); |
||
113 | } |
||
114 | |||
115 | |||
116 | DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator |
||
117 | .getDataManager(); |
||
118 | |||
119 | if (!dataman.getStoreProviders().contains(PostgreSQLStoreProvider.NAME)) {
|
||
120 | 294 | jjdelcerro | dataman.registerStoreProviderFactory( |
121 | new PostgreSQLStoreProviderFactory()
|
||
122 | ); |
||
123 | 5 | jldominguez | } |
124 | |||
125 | if (!dataman.getExplorerProviders().contains(
|
||
126 | PostgreSQLStoreProvider.NAME)) { |
||
127 | 294 | jjdelcerro | dataman.registerServerExplorerFactory( |
128 | new PostgreSQLServerExplorerFactory()
|
||
129 | ); |
||
130 | 5 | jldominguez | } |
131 | if( ex!=null ) { |
||
132 | throw ex;
|
||
133 | } |
||
134 | } |
||
135 | |||
136 | } |