01: /*
02: * WbSavePkMapping.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.sql.wbcommands;
13:
14: import java.io.File;
15: import java.sql.SQLException;
16: import workbench.resource.ResourceMgr;
17: import workbench.resource.Settings;
18: import workbench.sql.SqlCommand;
19: import workbench.sql.StatementRunnerResult;
20: import workbench.storage.PkMapping;
21: import workbench.util.ArgumentParser;
22: import workbench.util.FileDialogUtil;
23: import workbench.util.StringUtil;
24: import workbench.util.WbFile;
25:
26: /**
27: *
28: * @author support@sql-workbench.net
29: */
30: public class WbSavePkMapping extends SqlCommand {
31: public static final String VERB = "WBSAVEPKMAP";
32: public static final String FORMATTED_VERB = "WbSavePKMap";
33:
34: public WbSavePkMapping() {
35: cmdLine = new ArgumentParser();
36: cmdLine.addArgument("file");
37: }
38:
39: public String getVerb() {
40: return VERB;
41: }
42:
43: protected boolean isConnectionRequired() {
44: return false;
45: }
46:
47: public StatementRunnerResult execute(final String sql)
48: throws SQLException {
49: StatementRunnerResult result = new StatementRunnerResult();
50: cmdLine.parse(getCommandLine(sql));
51: String file = cmdLine.getValue("file");
52: if (file == null) {
53: file = Settings.getInstance().getPKMappingFilename();
54: } else {
55: WbFile cd = new WbFile(Settings.getInstance()
56: .getConfigDir());
57: file = StringUtil.replace(file,
58: FileDialogUtil.CONFIG_DIR_KEY, cd.getFullPath());
59: }
60:
61: if (file == null) {
62: result.setFailure();
63: result.addMessage(ResourceMgr.getString("ErrPkDefNoFile"));
64: return result;
65: }
66:
67: PkMapping.getInstance().saveMapping(file);
68: String msg = ResourceMgr.getString("MsgPkMappingSaved");
69: File f = new File(file);
70: msg = StringUtil
71: .replace(msg, "%filename%", f.getAbsolutePath());
72: result.addMessage(msg);
73: result.setSuccess();
74: return result;
75: }
76:
77: }
|