Lines 48-58
Link Here
|
48 |
import java.io.IOException; |
48 |
import java.io.IOException; |
49 |
import java.io.OutputStream; |
49 |
import java.io.OutputStream; |
50 |
import java.io.OutputStreamWriter; |
50 |
import java.io.OutputStreamWriter; |
51 |
import java.text.MessageFormat; |
51 |
import java.util.List; |
52 |
import java.util.logging.Level; |
52 |
import java.util.logging.Level; |
53 |
import java.util.logging.Logger; |
53 |
import java.util.logging.Logger; |
54 |
import org.netbeans.api.db.explorer.DatabaseConnection; |
54 |
import org.netbeans.api.db.explorer.DatabaseConnection; |
55 |
import org.netbeans.modules.db.api.sql.execute.SQLExecuteCookie; |
55 |
import org.netbeans.modules.db.api.sql.execute.SQLExecuteCookie; |
|
|
56 |
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle; |
56 |
import org.netbeans.modules.db.spi.sql.editor.SQLEditorProvider; |
57 |
import org.netbeans.modules.db.spi.sql.editor.SQLEditorProvider; |
57 |
import org.openide.cookies.OpenCookie; |
58 |
import org.openide.cookies.OpenCookie; |
58 |
import org.openide.filesystems.FileLock; |
59 |
import org.openide.filesystems.FileLock; |
Lines 76-82
Link Here
|
76 |
private static final String CMD_FOLDER = "Databases/SQLCommands"; // NOI18N |
77 |
private static final String CMD_FOLDER = "Databases/SQLCommands"; // NOI18N |
77 |
|
78 |
|
78 |
@Override |
79 |
@Override |
79 |
public void openSQLEditor(DatabaseConnection dbconn, String sql, boolean execute) { |
80 |
public void openSQLEditor(DatabaseConnection dbconn, String sql, boolean execute, |
|
|
81 |
MetadataElementHandle<?> elementHandle) { |
80 |
FileObject tmpFo = FileUtil.getConfigFile(CMD_FOLDER); |
82 |
FileObject tmpFo = FileUtil.getConfigFile(CMD_FOLDER); |
81 |
if (tmpFo == null) { |
83 |
if (tmpFo == null) { |
82 |
try { |
84 |
try { |
Lines 90-97
Link Here
|
90 |
|
92 |
|
91 |
int i = 1; |
93 |
int i = 1; |
92 |
for (;;) { |
94 |
for (;;) { |
93 |
String nameFmt = NbBundle.getMessage(SQLEditorProviderImpl.class, "LBL_SQLCommandFileName"); |
95 |
String name = getFileName(dbconn, elementHandle, i); |
94 |
String name = MessageFormat.format(nameFmt, new Object[] { new Integer(i) }); |
|
|
95 |
try { |
96 |
try { |
96 |
sqlFo = tmpFo.createData(name); |
97 |
sqlFo = tmpFo.createData(name); |
97 |
} catch (IOException e) { |
98 |
} catch (IOException e) { |
Lines 143-146
Link Here
|
143 |
Logger.getLogger(SQLEditorProviderImpl.class.getName()).log(Level.INFO, "No SQLExecuteCookie found for " + sqlDo); |
144 |
Logger.getLogger(SQLEditorProviderImpl.class.getName()).log(Level.INFO, "No SQLExecuteCookie found for " + sqlDo); |
144 |
} |
145 |
} |
145 |
} |
146 |
} |
|
|
147 |
|
148 |
private String getFileName(DatabaseConnection dbconn, |
149 |
MetadataElementHandle<?> elementHandle, int number) { |
150 |
|
151 |
List<String> names = (elementHandle == null) ? null |
152 |
: elementHandle.getNonNullNames(); |
153 |
if (names != null && names.size() > 1) { |
154 |
String first = names.get(names.size() - 2); |
155 |
String second = names.get(names.size() - 1); |
156 |
if (isSafeTableName(first) && isSafeTableName(second)) { |
157 |
return NbBundle.getMessage(SQLEditorProviderImpl.class, |
158 |
"LBL_SQLCommandFileNameTwoElements", //NOI18N |
159 |
new Object[]{first, second, number}); |
160 |
} |
161 |
} else if (names != null && names.size() == 1 |
162 |
&& isSafeTableName(names.get(0))) { |
163 |
return NbBundle.getMessage(SQLEditorProviderImpl.class, |
164 |
"LBL_SQLCommandFileNameOneElement", //NOI18N |
165 |
new Object[]{names.get(0), number}); |
166 |
} |
167 |
if (isSafeTableName(dbconn.getDisplayName())) { |
168 |
return NbBundle.getMessage(SQLEditorProviderImpl.class, |
169 |
"LBL_SQLCommandFileNameOneElement", //NOI18N |
170 |
new Object[]{dbconn.getDisplayName(), number}); |
171 |
} |
172 |
return NbBundle.getMessage(SQLEditorProviderImpl.class, |
173 |
"LBL_SQLCommandFileName", new Object[]{number}); //NOI18N |
174 |
} |
175 |
|
176 |
private boolean isSafeTableName(String tableName) { |
177 |
return tableName != null && tableName.matches("\\w+"); //NOI18N |
178 |
} |
146 |
} |
179 |
} |