svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.h2spatial / org.gvsig.h2spatial.h2gis132 / org.gvsig.h2spatial.h2gis132.app / org.gvsig.h2spatial.h2gis132.app.mainplugin / src / main / java / org / gvsig / h2spatial / ShutdownCompact.java @ 46230
History | View | Annotate | Download (2.78 KB)
1 |
package org.gvsig.h2spatial; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.List; |
5 |
import javax.swing.JComboBox; |
6 |
import org.apache.commons.lang3.StringUtils; |
7 |
import org.gvsig.fmap.dal.DALLocator; |
8 |
import org.gvsig.fmap.dal.DataManager; |
9 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
10 |
import org.gvsig.fmap.dal.DataServerExplorerPool; |
11 |
import org.gvsig.fmap.dal.DataServerExplorerPoolEntry; |
12 |
import org.gvsig.fmap.dal.DataStore; |
13 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer; |
14 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
15 |
import org.gvsig.tools.util.LabeledValue; |
16 |
import org.gvsig.tools.util.LabeledValueImpl; |
17 |
import org.slf4j.Logger; |
18 |
import org.slf4j.LoggerFactory; |
19 |
|
20 |
/**
|
21 |
*
|
22 |
* @author jjdelcerro
|
23 |
*/
|
24 |
public class ShutdownCompact extends ShutdownCompactView { |
25 |
|
26 |
private static Logger LOGGER = LoggerFactory.getLogger(ShutdownCompact.class); |
27 |
|
28 |
public ShutdownCompact() {
|
29 |
this.initComponents();
|
30 |
} |
31 |
|
32 |
private void initComponents() { |
33 |
fillConnections(cboCconnections); |
34 |
} |
35 |
|
36 |
private void fillConnections(JComboBox combo) { |
37 |
DataManager dataManager = DALLocator.getDataManager(); |
38 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
39 |
|
40 |
DataServerExplorerParameters params; |
41 |
combo.removeAllItems(); |
42 |
|
43 |
List<DataServerExplorerPoolEntry> entries = new ArrayList<>(); |
44 |
pool.iterator().forEachRemaining((DataServerExplorerPoolEntry e) -> { |
45 |
entries.add(e); |
46 |
}); |
47 |
entries.sort((DataServerExplorerPoolEntry o1, DataServerExplorerPoolEntry o2) -> { |
48 |
return StringUtils.compare(o1.getName(), o2.getName());
|
49 |
}); |
50 |
|
51 |
for (DataServerExplorerPoolEntry entry : entries) {
|
52 |
if (StringUtils.equalsIgnoreCase(DataStore.H2SPATIAL_PROVIDER_NAME, entry.getExplorerParameters().getProviderName())) {
|
53 |
JDBCServerExplorerParameters dbParams = (JDBCServerExplorerParameters) entry.getExplorerParameters(); |
54 |
combo.addItem( |
55 |
new LabeledValueImpl<>(entry.getName(), dbParams)
|
56 |
); |
57 |
} |
58 |
} |
59 |
combo.setSelectedIndex(-1);
|
60 |
} |
61 |
|
62 |
public void shutdownAndCompact() { |
63 |
LabeledValue<JDBCServerExplorerParameters> value = (LabeledValue<JDBCServerExplorerParameters>) this.cboCconnections.getSelectedItem();
|
64 |
if (value == null) { |
65 |
return;
|
66 |
} |
67 |
try {
|
68 |
DataManager dataManager = DALLocator.getManager(); |
69 |
JDBCServerExplorer server = (JDBCServerExplorer) dataManager.openServerExplorer( |
70 |
DataStore.H2SPATIAL_PROVIDER_NAME, |
71 |
value.getValue() |
72 |
); |
73 |
server.execute("!SHUTDOWN");
|
74 |
} catch (Exception ex) { |
75 |
LOGGER.warn("Can't shutdown/compact database",ex);
|
76 |
} |
77 |
|
78 |
} |
79 |
} |