r12968 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12967‎ | r12968 | r12969 >
Date:03:42, 7 February 2006
Author:vibber
Status:old
Tags:
Comment:
Add table prefix support to direct SQL output (not in CLI options yet)
Modified paths:
  • /trunk/mwdumper/src/org/mediawiki/dumper/gui/DumperGui.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/dumper/gui/DumperWindow.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/SqlWriter.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/SqlWriter14.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/SqlWriter15.java (modified) (history)

Diff [purge]

Index: trunk/mwdumper/src/org/mediawiki/importer/SqlWriter14.java
@@ -36,6 +36,10 @@
3737 super(output);
3838 }
3939
 40+ public SqlWriter14(SqlStream output, String prefix) {
 41+ super(output, prefix);
 42+ }
 43+
4044 public void writeStartPage(Page page) {
4145 currentPage = page;
4246 lastRevision = null;
Index: trunk/mwdumper/src/org/mediawiki/importer/SqlWriter15.java
@@ -37,6 +37,10 @@
3838 super(output);
3939 }
4040
 41+ public SqlWriter15(SqlStream output, String prefix) {
 42+ super(output, prefix);
 43+ }
 44+
4145 public void writeEndWiki() throws IOException {
4246 flushInsertBuffers();
4347 super.writeEndWiki();
Index: trunk/mwdumper/src/org/mediawiki/importer/SqlWriter.java
@@ -37,6 +37,7 @@
3838
3939 public abstract class SqlWriter implements DumpWriter {
4040 private SqlStream stream;
 41+ private String tablePrefix = "";
4142
4243 protected static final Integer ONE = new Integer(1);
4344 protected static final Integer ZERO = new Integer(0);
@@ -51,6 +52,11 @@
5253 stream = output;
5354 }
5455
 56+ public SqlWriter(SqlStream output, String prefix) {
 57+ stream = output;
 58+ tablePrefix = prefix;
 59+ }
 60+
5561 public void close() throws IOException {
5662 stream.close();
5763 }
@@ -133,9 +139,9 @@
134140 stream.writeStatement(sql);
135141 }
136142
137 - private static void appendInsertStatement(StringBuffer sql, String table, Object[][] row) {
 143+ private void appendInsertStatement(StringBuffer sql, String table, Object[][] row) {
138144 sql.append("INSERT INTO ");
139 - //sql.append(tablePrefix);
 145+ sql.append(tablePrefix);
140146 sql.append(table);
141147 sql.append(" (");
142148
@@ -164,7 +170,7 @@
165171 StringBuffer sql = new StringBuffer(65536);
166172 synchronized (sql) { //only for StringBuffer
167173 sql.append("UPDATE ");
168 - //sql.append(tablePrefix);
 174+ sql.append(tablePrefix);
169175 sql.append(table);
170176 sql.append(" SET ");
171177
Index: trunk/mwdumper/src/org/mediawiki/dumper/gui/DumperGui.java
@@ -11,6 +11,7 @@
1212 import org.mediawiki.dumper.Tools;
1313 import org.mediawiki.importer.DumpWriter;
1414 import org.mediawiki.importer.SqlServerStream;
 15+import org.mediawiki.importer.SqlWriter14;
1516 import org.mediawiki.importer.SqlWriter15;
1617 import org.mediawiki.importer.XmlDumpReader;
1718
@@ -96,6 +97,11 @@
9798 checkSchema();
9899 }
99100
 101+ void setPrefix(String prefix) {
 102+ this.prefix = prefix;
 103+ checkSchema();
 104+ }
 105+
100106 void checkSchema() {
101107 schemaReady = false;
102108 if (connected) {
@@ -141,8 +147,7 @@
142148 final InputStream stream = Tools.openInputFile(inputFile);
143149 //DumpWriter writer = new MultiWriter();
144150 conn.setCatalog(dbname);
145 - SqlServerStream sqlStream = new SqlServerStream(conn);
146 - DumpWriter writer = new SqlWriter15(sqlStream);
 151+ DumpWriter writer = openWriter();
147152 DumpWriter progress = gui.getProgressWriter(writer, 1000);
148153 reader = new XmlDumpReader(stream, progress);
149154 new Thread() {
@@ -163,6 +168,14 @@
164169 }.start();
165170 }
166171
 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+
167180 void abort() {
168181 // Request an abort!
169182 gui.setProgress("Aborting import...");
Index: trunk/mwdumper/src/org/mediawiki/dumper/gui/DumperWindow.java
@@ -31,6 +31,8 @@
3232 public DumperWindow(DumperGui aBackend) {
3333 super();
3434 backend = aBackend;
 35+
 36+ // For some reason the Netbeans GUI editor doesn't offer these events
3537 dbnameText.getDocument().addDocumentListener(new DocumentListener() {
3638 public void changedUpdate(DocumentEvent e) {
3739 backend.setDbname(dbnameText.getText());
@@ -42,6 +44,20 @@
4345 backend.setDbname(dbnameText.getText());
4446 }
4547 });
 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();
4662 }
4763
4864 public DumpWriter getProgressWriter(DumpWriter sink, int interval) {
@@ -80,6 +96,7 @@
8197
8298 void showSchemaFields() {
8399 enableFields(new Component[] {
 100+ schemaLabel,
84101 schema14Radio,
85102 schema15Radio,
86103 prefixLabel,
@@ -164,6 +181,8 @@
165182 }
166183
167184 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...
168187 backend.setDbname(dbnameText.getText());
169188 }
170189

Status & tagging log