Index: trunk/mwdumper/src/org/mediawiki/importer/SqlWriter14.java |
— | — | @@ -36,6 +36,10 @@ |
37 | 37 | super(output); |
38 | 38 | } |
39 | 39 | |
| 40 | + public SqlWriter14(SqlStream output, String prefix) { |
| 41 | + super(output, prefix); |
| 42 | + } |
| 43 | + |
40 | 44 | public void writeStartPage(Page page) { |
41 | 45 | currentPage = page; |
42 | 46 | lastRevision = null; |
Index: trunk/mwdumper/src/org/mediawiki/importer/SqlWriter15.java |
— | — | @@ -37,6 +37,10 @@ |
38 | 38 | super(output); |
39 | 39 | } |
40 | 40 | |
| 41 | + public SqlWriter15(SqlStream output, String prefix) { |
| 42 | + super(output, prefix); |
| 43 | + } |
| 44 | + |
41 | 45 | public void writeEndWiki() throws IOException { |
42 | 46 | flushInsertBuffers(); |
43 | 47 | super.writeEndWiki(); |
Index: trunk/mwdumper/src/org/mediawiki/importer/SqlWriter.java |
— | — | @@ -37,6 +37,7 @@ |
38 | 38 | |
39 | 39 | public abstract class SqlWriter implements DumpWriter { |
40 | 40 | private SqlStream stream; |
| 41 | + private String tablePrefix = ""; |
41 | 42 | |
42 | 43 | protected static final Integer ONE = new Integer(1); |
43 | 44 | protected static final Integer ZERO = new Integer(0); |
— | — | @@ -51,6 +52,11 @@ |
52 | 53 | stream = output; |
53 | 54 | } |
54 | 55 | |
| 56 | + public SqlWriter(SqlStream output, String prefix) { |
| 57 | + stream = output; |
| 58 | + tablePrefix = prefix; |
| 59 | + } |
| 60 | + |
55 | 61 | public void close() throws IOException { |
56 | 62 | stream.close(); |
57 | 63 | } |
— | — | @@ -133,9 +139,9 @@ |
134 | 140 | stream.writeStatement(sql); |
135 | 141 | } |
136 | 142 | |
137 | | - private static void appendInsertStatement(StringBuffer sql, String table, Object[][] row) { |
| 143 | + private void appendInsertStatement(StringBuffer sql, String table, Object[][] row) { |
138 | 144 | sql.append("INSERT INTO "); |
139 | | - //sql.append(tablePrefix); |
| 145 | + sql.append(tablePrefix); |
140 | 146 | sql.append(table); |
141 | 147 | sql.append(" ("); |
142 | 148 | |
— | — | @@ -164,7 +170,7 @@ |
165 | 171 | StringBuffer sql = new StringBuffer(65536); |
166 | 172 | synchronized (sql) { //only for StringBuffer |
167 | 173 | sql.append("UPDATE "); |
168 | | - //sql.append(tablePrefix); |
| 174 | + sql.append(tablePrefix); |
169 | 175 | sql.append(table); |
170 | 176 | sql.append(" SET "); |
171 | 177 | |
Index: trunk/mwdumper/src/org/mediawiki/dumper/gui/DumperGui.java |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | import org.mediawiki.dumper.Tools; |
13 | 13 | import org.mediawiki.importer.DumpWriter; |
14 | 14 | import org.mediawiki.importer.SqlServerStream; |
| 15 | +import org.mediawiki.importer.SqlWriter14; |
15 | 16 | import org.mediawiki.importer.SqlWriter15; |
16 | 17 | import org.mediawiki.importer.XmlDumpReader; |
17 | 18 | |
— | — | @@ -96,6 +97,11 @@ |
97 | 98 | checkSchema(); |
98 | 99 | } |
99 | 100 | |
| 101 | + void setPrefix(String prefix) { |
| 102 | + this.prefix = prefix; |
| 103 | + checkSchema(); |
| 104 | + } |
| 105 | + |
100 | 106 | void checkSchema() { |
101 | 107 | schemaReady = false; |
102 | 108 | if (connected) { |
— | — | @@ -141,8 +147,7 @@ |
142 | 148 | final InputStream stream = Tools.openInputFile(inputFile); |
143 | 149 | //DumpWriter writer = new MultiWriter(); |
144 | 150 | conn.setCatalog(dbname); |
145 | | - SqlServerStream sqlStream = new SqlServerStream(conn); |
146 | | - DumpWriter writer = new SqlWriter15(sqlStream); |
| 151 | + DumpWriter writer = openWriter(); |
147 | 152 | DumpWriter progress = gui.getProgressWriter(writer, 1000); |
148 | 153 | reader = new XmlDumpReader(stream, progress); |
149 | 154 | new Thread() { |
— | — | @@ -163,6 +168,14 @@ |
164 | 169 | }.start(); |
165 | 170 | } |
166 | 171 | |
| 172 | + DumpWriter openWriter() { |
| 173 | + SqlServerStream sqlStream = new SqlServerStream(conn); |
| 174 | + if (schema.equals("1.4")) |
| 175 | + return new SqlWriter14(sqlStream, prefix); |
| 176 | + else |
| 177 | + return new SqlWriter15(sqlStream, prefix); |
| 178 | + } |
| 179 | + |
167 | 180 | void abort() { |
168 | 181 | // Request an abort! |
169 | 182 | gui.setProgress("Aborting import..."); |
Index: trunk/mwdumper/src/org/mediawiki/dumper/gui/DumperWindow.java |
— | — | @@ -31,6 +31,8 @@ |
32 | 32 | public DumperWindow(DumperGui aBackend) { |
33 | 33 | super(); |
34 | 34 | backend = aBackend; |
| 35 | + |
| 36 | + // For some reason the Netbeans GUI editor doesn't offer these events |
35 | 37 | dbnameText.getDocument().addDocumentListener(new DocumentListener() { |
36 | 38 | public void changedUpdate(DocumentEvent e) { |
37 | 39 | backend.setDbname(dbnameText.getText()); |
— | — | @@ -42,6 +44,20 @@ |
43 | 45 | backend.setDbname(dbnameText.getText()); |
44 | 46 | } |
45 | 47 | }); |
| 48 | + |
| 49 | + prefixText.getDocument().addDocumentListener(new DocumentListener() { |
| 50 | + public void changedUpdate(DocumentEvent e) { |
| 51 | + backend.setPrefix(prefixText.getText()); |
| 52 | + } |
| 53 | + public void insertUpdate(DocumentEvent e) { |
| 54 | + backend.setPrefix(prefixText.getText()); |
| 55 | + } |
| 56 | + public void removeUpdate(DocumentEvent e) { |
| 57 | + backend.setPrefix(prefixText.getText()); |
| 58 | + } |
| 59 | + }); |
| 60 | + |
| 61 | + showFields(); |
46 | 62 | } |
47 | 63 | |
48 | 64 | public DumpWriter getProgressWriter(DumpWriter sink, int interval) { |
— | — | @@ -80,6 +96,7 @@ |
81 | 97 | |
82 | 98 | void showSchemaFields() { |
83 | 99 | enableFields(new Component[] { |
| 100 | + schemaLabel, |
84 | 101 | schema14Radio, |
85 | 102 | schema15Radio, |
86 | 103 | prefixLabel, |
— | — | @@ -164,6 +181,8 @@ |
165 | 182 | } |
166 | 183 | |
167 | 184 | protected void onDbnameTextActionPerformed(java.awt.event.ActionEvent evt) { |
| 185 | + // This gets called if you hit enter in the field while the import |
| 186 | + // button is still disabled. Check the db again... |
168 | 187 | backend.setDbname(dbnameText.getText()); |
169 | 188 | } |
170 | 189 | |