Revision 47283 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.xml2db/org.gvsig.xml2db.lib/org.gvsig.xml2db.lib.impl/src/main/java/org/gvsig/xml2db/lib/impl/DefaultXml2dbManager.java
DefaultXml2dbManager.java | ||
---|---|---|
29 | 29 |
import java.io.InputStream; |
30 | 30 |
import java.io.Reader; |
31 | 31 |
import java.nio.charset.Charset; |
32 |
import org.apache.commons.io.FilenameUtils; |
|
33 |
import org.apache.commons.lang3.StringUtils; |
|
32 | 34 |
import org.cresques.cts.IProjection; |
33 | 35 |
import org.gvsig.fmap.dal.DALLocator; |
34 | 36 |
import org.gvsig.fmap.dal.DataManager; |
... | ... | |
40 | 42 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
41 | 43 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
42 | 44 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
45 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
43 | 46 |
import org.gvsig.tools.util.HasAFile; |
44 | 47 |
import org.gvsig.xml2db.lib.api.Xml2dbManager; |
45 | 48 |
import org.gvsig.xml2db.lib.api.xmlinfo.XMLInfo; |
... | ... | |
54 | 57 |
} |
55 | 58 |
|
56 | 59 |
@Override |
57 |
public XMLInfo extractStructure(File xml, Charset encoding, IProjection projection) throws IOException, FileNotFoundException { |
|
60 |
public XMLInfo extractStructure(File xml, Charset encoding, IProjection projection, SimpleTaskStatus status) throws IOException, FileNotFoundException {
|
|
58 | 61 |
StructureExtractorImpl extractor = new StructureExtractorImpl(); |
59 |
XMLInfo xmlinfo = extractor.extractStructure(xml, encoding); |
|
62 |
XMLInfo xmlinfo = extractor.extractStructure(xml, encoding, SimpleTaskStatus.get(status));
|
|
60 | 63 |
return xmlinfo; |
61 | 64 |
} |
62 | 65 |
|
63 | 66 |
@Override |
64 |
public XMLInfo extractStructure(InputStream xml, Charset encoding, IProjection projection) throws IOException { |
|
67 |
public XMLInfo extractStructure(InputStream xml, Charset encoding, IProjection projection, SimpleTaskStatus status) throws IOException {
|
|
65 | 68 |
StructureExtractorImpl extractor = new StructureExtractorImpl(); |
66 |
XMLInfo xmlinfo = extractor.extractStructure(xml, encoding); |
|
69 |
XMLInfo xmlinfo = extractor.extractStructure(xml, encoding, SimpleTaskStatus.get(status));
|
|
67 | 70 |
return xmlinfo; |
68 | 71 |
} |
69 | 72 |
|
70 | 73 |
@Override |
71 |
public XMLInfo extractStructure(Reader xml, IProjection projection) throws IOException { |
|
74 |
public XMLInfo extractStructure(Reader xml, IProjection projection, SimpleTaskStatus status) throws IOException {
|
|
72 | 75 |
StructureExtractorImpl extractor = new StructureExtractorImpl(); |
73 |
XMLInfo xmlinfo = extractor.extractStructure(xml); |
|
76 |
XMLInfo xmlinfo = extractor.extractStructure(xml, SimpleTaskStatus.get(status));
|
|
74 | 77 |
return xmlinfo; |
75 | 78 |
} |
76 | 79 |
|
77 | 80 |
@Override |
78 |
public void copyXml2Db(File xml, Charset encoding, JDBCServerExplorerParameters dbparams) { |
|
81 |
public void copyXml2Db(File xml, Charset encoding, JDBCServerExplorerParameters dbparams, SimpleTaskStatus taskStatus) {
|
|
79 | 82 |
CopyXML2dbImpl helper = new CopyXML2dbImpl(); |
80 |
helper.copyData(xml, encoding, dbparams); |
|
83 |
taskStatus = SimpleTaskStatus.get(taskStatus); |
|
84 |
helper.copyData(xml, encoding, dbparams, taskStatus); |
|
81 | 85 |
} |
82 | 86 |
|
83 | 87 |
@Override |
84 |
public void copyXml2Db(InputStream xml, Charset encoding, JDBCServerExplorerParameters dbparams) { |
|
88 |
public void copyXml2Db(InputStream xml, Charset encoding, JDBCServerExplorerParameters dbparams, SimpleTaskStatus taskStatus) {
|
|
85 | 89 |
CopyXML2dbImpl helper = new CopyXML2dbImpl(); |
86 |
helper.copyData(xml, encoding, dbparams); |
|
90 |
taskStatus = SimpleTaskStatus.get(taskStatus); |
|
91 |
helper.copyData(xml, encoding, dbparams, taskStatus); |
|
87 | 92 |
} |
88 | 93 |
|
89 | 94 |
@Override |
90 |
public JDBCServerExplorerParameters createDatabase(File dbfile, XMLInfo xmlinfo) { |
|
95 |
public JDBCServerExplorerParameters createDatabase(File dbfile, XMLInfo xmlinfo, SimpleTaskStatus taskStatus) {
|
|
91 | 96 |
try { |
97 |
taskStatus = SimpleTaskStatus.get(taskStatus); |
|
98 |
|
|
92 | 99 |
DataManager dataManager = DALLocator.getDataManager(); |
100 |
String repoID = xmlinfo.getRepositoryID(); |
|
101 |
if( StringUtils.isBlank(repoID) ) { |
|
102 |
repoID = FilenameUtils.getBaseName(dbfile.getName()); |
|
103 |
} |
|
93 | 104 |
|
105 |
taskStatus.message("Creating database..."); |
|
106 |
taskStatus.setIndeterminate(); |
|
107 |
|
|
94 | 108 |
JDBCServerExplorerParameters serverParams = (JDBCServerExplorerParameters) dataManager.createServerExplorerParameters(FeatureStore.H2SPATIAL_PROVIDER_NAME); |
95 | 109 |
((HasAFile)serverParams).setFile(dbfile); |
96 | 110 |
|
97 | 111 |
DatabaseWorkspaceManager dbworkspace = dataManager.createDatabaseWorkspaceManager(serverParams); |
98 |
dbworkspace.create(dbfile.getName(), null);
|
|
112 |
dbworkspace.create(repoID, null);
|
|
99 | 113 |
|
100 | 114 |
JDBCServerExplorer server = (JDBCServerExplorer) dbworkspace.getServerExplorer(); |
101 | 115 |
|
116 |
taskStatus.message("Creating tables..."); |
|
117 |
taskStatus.setRangeOfValues(0, xmlinfo.size()); |
|
102 | 118 |
for (XMLTableInfo tableInfo : xmlinfo) { |
103 | 119 |
String tablename = tableInfo.getName(); |
104 | 120 |
FeatureType ftype = tableInfo.getFeatureType(); |
... | ... | |
106 | 122 |
tableParams.setTable(tablename); |
107 | 123 |
tableParams.setDefaultFeatureType(ftype); |
108 | 124 |
server.add(tableParams.getProviderName(), tableParams, false); |
125 |
taskStatus.incrementCurrentValue(); |
|
109 | 126 |
} |
127 |
taskStatus.message("Registering tables in the repository..."); |
|
128 |
taskStatus.setRangeOfValues(0, xmlinfo.size()); |
|
110 | 129 |
for (DataStoreParameters storeParams : server.list()) { |
111 | 130 |
JDBCStoreParameters featureStoreParams = (JDBCStoreParameters)storeParams; |
112 | 131 |
if( xmlinfo.get(featureStoreParams.getTable())==null ) { |
113 | 132 |
continue; |
114 | 133 |
} |
115 | 134 |
dbworkspace.writeStoresRepositoryEntry(featureStoreParams.getTable(), featureStoreParams); |
135 |
taskStatus.incrementCurrentValue(); |
|
116 | 136 |
} |
117 | 137 |
return serverParams; |
118 | 138 |
} catch (Exception ex) { |
Also available in: Unified diff