svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_daldb / src / org / gvsig / fmap / dal / store / mysql / MySQLServerExplorer.java @ 33717
History | View | Annotate | Download (5.45 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 |
* 2009 IVER T.I {{Task}}
|
26 |
*/
|
27 |
|
28 |
/**
|
29 |
*
|
30 |
*/
|
31 |
package org.gvsig.fmap.dal.store.mysql; |
32 |
|
33 |
import java.sql.Connection; |
34 |
import java.sql.SQLException; |
35 |
import java.sql.Statement; |
36 |
|
37 |
import org.gvsig.fmap.dal.DataStoreParameters; |
38 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
39 |
import org.gvsig.fmap.dal.exception.DataException; |
40 |
import org.gvsig.fmap.dal.exception.InitializeException; |
41 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
42 |
import org.gvsig.fmap.dal.exception.RemoveException; |
43 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
44 |
import org.gvsig.fmap.dal.store.jdbc.JDBCHelper; |
45 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer; |
46 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
47 |
import org.gvsig.fmap.dal.store.jdbc.TransactionalAction; |
48 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCExecuteSQLException; |
49 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
50 |
import org.slf4j.Logger; |
51 |
import org.slf4j.LoggerFactory; |
52 |
|
53 |
/**
|
54 |
* @author jmvivo
|
55 |
*
|
56 |
*/
|
57 |
public class MySQLServerExplorer extends JDBCServerExplorer { |
58 |
final static private Logger logger = LoggerFactory |
59 |
.getLogger(MySQLServerExplorer.class); |
60 |
|
61 |
public static final String NAME = "MySQLExplorer"; |
62 |
|
63 |
|
64 |
|
65 |
public MySQLServerExplorer(
|
66 |
MySQLServerExplorerParameters parameters, |
67 |
DataServerExplorerProviderServices services) |
68 |
throws InitializeException {
|
69 |
super(parameters, services);
|
70 |
} |
71 |
|
72 |
private MySQLServerExplorerParameters getMySQLparameters() {
|
73 |
return (MySQLServerExplorerParameters) super.getParameters(); |
74 |
} |
75 |
|
76 |
|
77 |
protected JDBCHelper createHelper() throws InitializeException { |
78 |
return new MySQLHelper(this, getMySQLparameters()); |
79 |
} |
80 |
|
81 |
|
82 |
protected String getStoreName() { |
83 |
return MySQLStoreProvider.NAME;
|
84 |
} |
85 |
|
86 |
public String getProviderName() { |
87 |
return NAME;
|
88 |
} |
89 |
|
90 |
protected JDBCStoreParameters createStoreParams()
|
91 |
throws InitializeException, ProviderNotRegisteredException {
|
92 |
MySQLStoreParameters orgParams = (MySQLStoreParameters) super
|
93 |
.createStoreParams(); |
94 |
|
95 |
orgParams.setUseSSL(getMySQLparameters().getUseSSL()); |
96 |
|
97 |
return orgParams;
|
98 |
} |
99 |
|
100 |
|
101 |
// ****************************
|
102 |
|
103 |
|
104 |
public boolean canAdd() { |
105 |
return true; |
106 |
} |
107 |
|
108 |
protected void checkIsMine(DataStoreParameters dsp) { |
109 |
if (!(dsp instanceof MySQLStoreParameters)) { |
110 |
// FIXME Excpetion ???
|
111 |
throw new IllegalArgumentException( |
112 |
"not instance of MySQLStoreParameters");
|
113 |
} |
114 |
super.checkIsMine(dsp);
|
115 |
|
116 |
MySQLServerExplorerParameters myParameters = getMySQLparameters(); |
117 |
MySQLStoreParameters myp = (MySQLStoreParameters) dsp; |
118 |
if (myp.getUseSSL().booleanValue() != myParameters.getUseSSL()) {
|
119 |
throw new IllegalArgumentException("worng explorer: useSSL (mine:" |
120 |
+ myParameters.getUseSSL() + " other:" + myp.getUseSSL()
|
121 |
+ ")");
|
122 |
} |
123 |
} |
124 |
|
125 |
public void remove(DataStoreParameters dsp) throws RemoveException { |
126 |
final MySQLStoreParameters myParams =(MySQLStoreParameters) dsp;
|
127 |
|
128 |
TransactionalAction action = new TransactionalAction() {
|
129 |
public boolean continueTransactionAllowed() { |
130 |
return false; |
131 |
} |
132 |
public Object action(Connection conn) throws DataException { |
133 |
|
134 |
|
135 |
Statement st;
|
136 |
try{
|
137 |
st = conn.createStatement(); |
138 |
} catch (SQLException e) { |
139 |
throw new JDBCSQLException(e); |
140 |
} |
141 |
|
142 |
String sqlDrop = "Drop table " |
143 |
+ myParams.tableID(); |
144 |
|
145 |
try{
|
146 |
try{
|
147 |
st.execute(sqlDrop); |
148 |
} catch (SQLException e) { |
149 |
throw new JDBCExecuteSQLException(sqlDrop, e); |
150 |
} |
151 |
|
152 |
} finally{
|
153 |
try{ st.close(); } catch (SQLException e) {}; |
154 |
} |
155 |
return null; |
156 |
} |
157 |
}; |
158 |
try {
|
159 |
this.helper.doConnectionAction(action);
|
160 |
} catch (Exception e) { |
161 |
throw new RemoveException(this.getProviderName(), e); |
162 |
} |
163 |
} |
164 |
|
165 |
public NewDataStoreParameters getAddParameters() throws DataException { |
166 |
MySQLServerExplorerParameters parameters = getMySQLparameters(); |
167 |
MySQLNewStoreParameters params = new MySQLNewStoreParameters();
|
168 |
params.setHost(parameters.getHost()); |
169 |
params.setPort(parameters.getPort()); |
170 |
params.setDBName(parameters.getDBName()); |
171 |
params.setUser(parameters.getUser()); |
172 |
params.setPassword(parameters.getPassword()); |
173 |
params.setCatalog(parameters.getCatalog()); |
174 |
params.setSchema(parameters.getSchema()); |
175 |
params.setJDBCDriverClassName(parameters.getJDBCDriverClassName()); |
176 |
params.setUrl(parameters.getUrl()); |
177 |
params.setUseSSL(parameters.getUseSSL()); |
178 |
|
179 |
|
180 |
params.setDefaultFeatureType(this.getServerExplorerProviderServices()
|
181 |
.createNewFeatureType()); |
182 |
|
183 |
|
184 |
return params;
|
185 |
} |
186 |
|
187 |
|
188 |
|
189 |
// ***********************
|
190 |
// ***********************
|
191 |
|
192 |
|
193 |
public boolean hasGeometrySupport() { |
194 |
return true; |
195 |
} |
196 |
|
197 |
protected MySQLHelper getMyHelper() {
|
198 |
return (MySQLHelper) getHelper();
|
199 |
} |
200 |
|
201 |
} |