root / branches / v2_0_0_prep / libraries / libFMap_daldb / src / org / gvsig / fmap / dal / store / mysql / MySQLLibrary.java @ 32880
History | View | Annotate | Download (3.73 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.mysql; |
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 |
|
39 |
public class MySQLLibrary extends AbstractLibrary { |
40 |
|
41 |
|
42 |
static String DEFAULT_JDCB_DRIVER_NAME = "com.mysql.jdbc.Driver"; |
43 |
|
44 |
|
45 |
public static String getJdbcUrl(String host, Integer port, String db) { |
46 |
String url;
|
47 |
String sport = ""; |
48 |
if (port != null) { |
49 |
sport = ":" + port;
|
50 |
} |
51 |
url = "jdbc:mysql://" + host + sport + "/" + db; |
52 |
|
53 |
return url;
|
54 |
} |
55 |
|
56 |
@Override
|
57 |
protected void doInitialize() throws LibraryException { |
58 |
} |
59 |
|
60 |
|
61 |
@Override
|
62 |
protected void doPostInitialize() throws LibraryException { |
63 |
LibraryException ex=null;
|
64 |
|
65 |
new JDBCLibrary().postInitialize();
|
66 |
|
67 |
DBHelper.registerParametersDefinition( |
68 |
MySQLStoreParameters.PARAMETERS_DEFINITION_NAME, |
69 |
MySQLStoreParameters.class, |
70 |
"MySQLParameters.xml"
|
71 |
); |
72 |
DBHelper.registerParametersDefinition( |
73 |
MySQLNewStoreParameters.PARAMETERS_DEFINITION_NAME, |
74 |
MySQLNewStoreParameters.class, |
75 |
"MySQLParameters.xml"
|
76 |
); |
77 |
DBHelper.registerParametersDefinition( |
78 |
MySQLServerExplorerParameters.PARAMETERS_DEFINITION_NAME, |
79 |
MySQLServerExplorerParameters.class, |
80 |
"MySQLParameters.xml"
|
81 |
); |
82 |
DBHelper.registerParametersDefinition( |
83 |
MySQLResourceParameters.PARAMETERS_DEFINITION_NAME, |
84 |
MySQLResourceParameters.class, |
85 |
"MySQLParameters.xml"
|
86 |
); |
87 |
try {
|
88 |
DBHelper.registerMetadataDefinition( |
89 |
MySQLStoreProvider.METADATA_DEFINITION_NAME, |
90 |
MySQLStoreProvider.class, |
91 |
"MySQLMetadata.xml"
|
92 |
); |
93 |
} catch (MetadataException e) {
|
94 |
ex = new LibraryException(this.getClass(),e); |
95 |
} |
96 |
|
97 |
ResourceManagerProviderServices resman = (ResourceManagerProviderServices) DALLocator |
98 |
.getResourceManager(); |
99 |
|
100 |
|
101 |
if (!resman.getResourceProviders().contains(MySQLResource.NAME)) {
|
102 |
resman.register(MySQLResource.NAME, |
103 |
MySQLResource.DESCRIPTION, MySQLResource.class, |
104 |
MySQLResourceParameters.class); |
105 |
} |
106 |
|
107 |
|
108 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator |
109 |
.getDataManager(); |
110 |
|
111 |
if (!dataman.getStoreProviders().contains(MySQLStoreProvider.NAME)) {
|
112 |
dataman.registerStoreProvider(MySQLStoreProvider.NAME, |
113 |
MySQLStoreProvider.class, |
114 |
MySQLStoreParameters.class); |
115 |
} |
116 |
|
117 |
if (!dataman.getExplorerProviders().contains(
|
118 |
MySQLStoreProvider.NAME)) { |
119 |
dataman.registerExplorerProvider(MySQLServerExplorer.NAME, |
120 |
MySQLServerExplorer.class, |
121 |
MySQLServerExplorerParameters.class); |
122 |
} |
123 |
if( ex!=null ) { |
124 |
throw ex;
|
125 |
} |
126 |
} |
127 |
|
128 |
} |