01: /*
02: * WbLoadPkMapping.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.SqlUtil;
24: import workbench.util.StringUtil;
25: import workbench.util.WbFile;
26:
27: /**
28: *
29: * @author support@sql-workbench.net
30: */
31: public class WbLoadPkMapping extends SqlCommand {
32: public final static String VERB = "WBLOADPKMAP";
33: public final static String FORMATTED_VERB = "WbLoadPKMap";
34:
35: public WbLoadPkMapping() {
36: cmdLine = new ArgumentParser();
37: cmdLine.addArgument("file");
38: }
39:
40: public String getVerb() {
41: return VERB;
42: }
43:
44: protected boolean isConnectionRequired() {
45: return false;
46: }
47:
48: public StatementRunnerResult execute(String aSql)
49: throws SQLException {
50: StatementRunnerResult result = new StatementRunnerResult();
51: String sql = SqlUtil.stripVerb(aSql);
52: cmdLine.parse(sql);
53: String file = cmdLine.getValue("file");
54: if (file == null) {
55: file = Settings.getInstance().getPKMappingFilename();
56: } else {
57: WbFile cd = new WbFile(Settings.getInstance()
58: .getConfigDir());
59: file = StringUtil.replace(file,
60: FileDialogUtil.CONFIG_DIR_KEY, cd.getFullPath());
61: }
62:
63: if (file == null) {
64: result.setFailure();
65: result.addMessage(ResourceMgr.getString("ErrPkDefNoFile"));
66: return result;
67: }
68:
69: PkMapping.getInstance().loadMapping(file);
70: String msg = ResourceMgr.getString("MsgPkMappingLoaded");
71: File f = new File(file);
72: msg = StringUtil
73: .replace(msg, "%filename%", f.getAbsolutePath());
74: result.addMessage(msg);
75: result.addMessage("");
76:
77: String info = PkMapping.getInstance().getMappingAsText();
78: if (info != null) {
79: result.addMessage(info);
80: result.addMessage(ResourceMgr
81: .getString("MsgPkDefinitionsEnd"));
82: }
83:
84: result.setSuccess();
85: return result;
86: }
87:
88: }
|