01: /*
02: * SqlExportWriter.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.db.exporter;
13:
14: import workbench.db.TableIdentifier;
15: import workbench.log.LogMgr;
16: import workbench.resource.Settings;
17:
18: /**
19: *
20: * @author support@sql-workbench.net
21: */
22: public class SqlExportWriter extends ExportWriter {
23:
24: /** Creates a new instance of SqlExportWriter
25: * @param exp The exporter to convert the rows for
26: */
27: public SqlExportWriter(DataExporter exp) {
28: super (exp);
29: }
30:
31: public RowDataConverter createConverter() {
32: return new SqlRowDataConverter(exporter.getConnection());
33: }
34:
35: public void configureConverter() {
36: super .configureConverter();
37: SqlRowDataConverter conv = (SqlRowDataConverter) this .converter;
38: conv.setIncludeTableOwner(Settings.getInstance()
39: .getIncludeOwnerInSqlExport());
40: conv.setCommitEvery(exporter.getCommitEvery());
41: conv.setChrFunction(exporter.getChrFunction());
42: conv.setConcatString(exporter.getConcatString());
43: conv.setConcatFunction(exporter.getConcatFunction());
44: conv.setSqlLiteralType(exporter.getDateLiteralType());
45:
46: BlobMode type = exporter.getBlobMode();
47: if (type == BlobMode.DbmsLiteral) {
48: conv.setBlobTypeDbmsLiteral();
49: } else if (type == BlobMode.AnsiLiteral) {
50: conv.setBlobTypeAnsiLiteral();
51: } else if (type == BlobMode.SaveToFile) {
52: conv.setBlobTypeFile();
53: } else {
54: conv.setBlobTypeNone();
55: }
56:
57: if (exporter.getWriteClobAsFile()) {
58: String encoding = exporter.getEncoding();
59: if (encoding == null)
60: encoding = Settings.getInstance()
61: .getDefaultFileEncoding();
62: conv.setClobAsFile(encoding);
63: }
64:
65: // the key columns need to be set before the createInsert flag!
66: conv.setKeyColumnsToUse(exporter.getKeyColumnsToUse());
67: try {
68: conv.setType(exporter.getSqlType());
69: } catch (IllegalArgumentException e) {
70: LogMgr.logError("SqlExportWriter.createConverter()",
71: "Illegal SQL type requested. Reverting to INSERT",
72: null);
73: conv.setCreateInsert();
74: }
75:
76: String table = exporter.getTableName();
77: if (table != null) {
78: conv.setAlternateUpdateTable(new TableIdentifier(table));
79: }
80: conv.setCreateTable(exporter.isIncludeCreateTable());
81:
82: }
83:
84: }
|