This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 195880
Collapse All | Expand All

(-)a/db.metadata.model/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.db.metadata.model/1
2
OpenIDE-Module: org.netbeans.modules.db.metadata.model/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/db/metadata/model/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/db/metadata/model/resources/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.0
4
OpenIDE-Module-Specification-Version: 1.1
5
AutoUpdate-Show-In-Client: false
5
AutoUpdate-Show-In-Client: false
(-)a/db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/MetadataElementHandle.java (+16 lines)
Lines 162-167 Link Here
162
    }
162
    }
163
163
164
    /**
164
    /**
165
     * Get non null names of database objects that fully identify this element.
166
     *
167
     * @since db.metadata.model/1.1
168
     * @return List of names of DB objects, can be empty, contains no nulls.
169
     */
170
    public List<String> getNonNullNames() {
171
        List<String> nonNullNames = new ArrayList<String>(names.length);
172
        for (String name : names) {
173
            if (name != null) {
174
                nonNullNames.add(name);
175
            }
176
        }
177
        return nonNullNames;
178
    }
179
180
    /**
165
     * Resolves this handle to the corresponding metadata element, if any.
181
     * Resolves this handle to the corresponding metadata element, if any.
166
     *
182
     *
167
     * @param  metadata the {@link Metadata} instance to resolve this element against.
183
     * @param  metadata the {@link Metadata} instance to resolve this element against.
(-)a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/Bundle.properties (+6 lines)
Lines 46-51 Link Here
46
#{0} = command number
46
#{0} = command number
47
#PARTI18N - only localize "SQL Command" and do not add anything after ".sql"
47
#PARTI18N - only localize "SQL Command" and do not add anything after ".sql"
48
LBL_SQLCommandFileName=SQL Command {0}.sql
48
LBL_SQLCommandFileName=SQL Command {0}.sql
49
# {0} - schema or catalog, {1} - schema or table, {2} - number
50
#NOI18N - this probably shouldn't be localized
51
LBL_SQLCommandFileNameTwoElements=SQL {0}.{1}{2,choice,1#|1< ({2})}.sql
52
# {0} - schema or catalog or connection name, {1} - number
53
#NOI18N - this probably shouldn't be localized
54
LBL_SQLCommandFileNameOneElement=SQL {0}{1,choice,1#|1< ({1})}.sql
49
55
50
#options
56
#options
51
NAME_coloring_sql-whitespace=White Space
57
NAME_coloring_sql-whitespace=White Space
(-)a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/SQLEditorProviderImpl.java (-4 / +37 lines)
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
}
(-)a/db/nbproject/project.properties (-1 / +1 lines)
Lines 45-51 Link Here
45
javadoc.arch=${basedir}/arch.xml
45
javadoc.arch=${basedir}/arch.xml
46
javadoc.apichanges=${basedir}/apichanges.xml
46
javadoc.apichanges=${basedir}/apichanges.xml
47
47
48
spec.version.base=1.53
48
spec.version.base=1.54
49
49
50
extra.module.files=modules/ext/ddl.jar
50
extra.module.files=modules/ext/ddl.jar
51
51
(-)a/db/src/org/netbeans/modules/db/explorer/action/EditSourceCodeAction.java (-1 / +5 lines)
Lines 47-52 Link Here
47
import org.netbeans.modules.db.explorer.DatabaseConnection;
47
import org.netbeans.modules.db.explorer.DatabaseConnection;
48
import org.netbeans.modules.db.explorer.node.ProcedureNode;
48
import org.netbeans.modules.db.explorer.node.ProcedureNode;
49
import org.netbeans.modules.db.explorer.sql.editor.SQLEditorSupport;
49
import org.netbeans.modules.db.explorer.sql.editor.SQLEditorSupport;
50
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
50
import org.openide.nodes.Node;
51
import org.openide.nodes.Node;
51
import org.openide.util.HelpCtx;
52
import org.openide.util.HelpCtx;
52
import org.openide.util.NbBundle;
53
import org.openide.util.NbBundle;
Lines 78-84 Link Here
78
                        public void run() {
79
                        public void run() {
79
                            ProcedureNode pn = activatedNodes[0].getLookup().lookup(ProcedureNode.class);
80
                            ProcedureNode pn = activatedNodes[0].getLookup().lookup(ProcedureNode.class);
80
                            try {
81
                            try {
81
                                SQLEditorSupport.openSQLEditor(connection.getDatabaseConnection(), pn.getDDL(), false);
82
                                MetadataElementHandle<?> elementHandle =
83
                                        activatedNodes[0].getLookup().lookup(MetadataElementHandle.class);
84
                                SQLEditorSupport.openSQLEditor(connection.getDatabaseConnection(),
85
                                        pn.getDDL(), false, elementHandle);
82
                            } catch (Exception exc) {
86
                            } catch (Exception exc) {
83
                                Logger.getLogger(EditSourceCodeAction.class.getName()).log(Level.INFO, exc.getLocalizedMessage() + " while executing expression " + pn.getDDL(), exc); // NOI18N
87
                                Logger.getLogger(EditSourceCodeAction.class.getName()).log(Level.INFO, exc.getLocalizedMessage() + " while executing expression " + pn.getDDL(), exc); // NOI18N
84
                            }
88
                            }
(-)a/db/src/org/netbeans/modules/db/explorer/action/ExecuteCommandAction.java (-1 / +5 lines)
Lines 44-49 Link Here
44
44
45
import org.netbeans.modules.db.explorer.DatabaseConnection;
45
import org.netbeans.modules.db.explorer.DatabaseConnection;
46
import org.netbeans.modules.db.explorer.sql.editor.SQLEditorSupport;
46
import org.netbeans.modules.db.explorer.sql.editor.SQLEditorSupport;
47
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
47
import org.openide.nodes.Node;
48
import org.openide.nodes.Node;
48
import org.openide.util.HelpCtx;
49
import org.openide.util.HelpCtx;
49
import org.openide.util.NbBundle;
50
import org.openide.util.NbBundle;
Lines 72-78 Link Here
72
    public void performAction (Node[] activatedNodes) {
73
    public void performAction (Node[] activatedNodes) {
73
        if (activatedNodes != null && activatedNodes.length == 1) {
74
        if (activatedNodes != null && activatedNodes.length == 1) {
74
            DatabaseConnection dbconn = activatedNodes[0].getLookup().lookup(DatabaseConnection.class);
75
            DatabaseConnection dbconn = activatedNodes[0].getLookup().lookup(DatabaseConnection.class);
75
            SQLEditorSupport.openSQLEditor(dbconn.getDatabaseConnection(), "", false); // NOI18N
76
            MetadataElementHandle<?> elementHandle =
77
                    activatedNodes[0].getLookup().lookup(MetadataElementHandle.class);
78
            SQLEditorSupport.openSQLEditor(dbconn.getDatabaseConnection(),
79
                    "", false, elementHandle);                          //NOI18N
76
        }
80
        }
77
    }
81
    }
78
82
(-)a/db/src/org/netbeans/modules/db/explorer/action/ViewDataAction.java (-1 / +5 lines)
Lines 46-51 Link Here
46
import java.util.logging.Logger;
46
import java.util.logging.Logger;
47
import org.netbeans.modules.db.explorer.DatabaseConnection;
47
import org.netbeans.modules.db.explorer.DatabaseConnection;
48
import org.netbeans.modules.db.explorer.sql.editor.SQLEditorSupport;
48
import org.netbeans.modules.db.explorer.sql.editor.SQLEditorSupport;
49
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
49
import org.openide.DialogDisplayer;
50
import org.openide.DialogDisplayer;
50
import org.openide.NotifyDescriptor;
51
import org.openide.NotifyDescriptor;
51
import org.openide.nodes.Node;
52
import org.openide.nodes.Node;
Lines 81-87 Link Here
81
                        String expression = null;
82
                        String expression = null;
82
                        try {
83
                        try {
83
                            expression = getDefaultQuery(activatedNodes);
84
                            expression = getDefaultQuery(activatedNodes);
84
                            SQLEditorSupport.openSQLEditor(connection.getDatabaseConnection(), expression + ";\n", true); //NOI18N
85
                            MetadataElementHandle<?> elementHandle =
86
                                    activatedNodes[0].getLookup().lookup(MetadataElementHandle.class);
87
                            SQLEditorSupport.openSQLEditor(connection.getDatabaseConnection(),
88
                                    expression + ";\n", true, elementHandle); //NOI18N
85
                        } catch(Exception exc) {
89
                        } catch(Exception exc) {
86
                            Logger.getLogger(ViewDataAction.class.getName()).log(Level.INFO, exc.getLocalizedMessage() + " while executing expression " + expression, exc); // NOI18N
90
                            Logger.getLogger(ViewDataAction.class.getName()).log(Level.INFO, exc.getLocalizedMessage() + " while executing expression " + expression, exc); // NOI18N
87
                            String message = NbBundle.getMessage (ViewDataAction.class, "ShowDataError", exc.getMessage()); // NOI18N
91
                            String message = NbBundle.getMessage (ViewDataAction.class, "ShowDataError", exc.getMessage()); // NOI18N
(-)a/db/src/org/netbeans/modules/db/explorer/action/ViewSourceCodeAction.java (-1 / +5 lines)
Lines 47-52 Link Here
47
import org.netbeans.modules.db.explorer.dlg.ViewProcedureDialog;
47
import org.netbeans.modules.db.explorer.dlg.ViewProcedureDialog;
48
import org.netbeans.modules.db.explorer.node.ProcedureNode;
48
import org.netbeans.modules.db.explorer.node.ProcedureNode;
49
import org.netbeans.modules.db.explorer.sql.editor.SQLEditorSupport;
49
import org.netbeans.modules.db.explorer.sql.editor.SQLEditorSupport;
50
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
50
import org.openide.nodes.Node;
51
import org.openide.nodes.Node;
51
import org.openide.util.HelpCtx;
52
import org.openide.util.HelpCtx;
52
import org.openide.util.NbBundle;
53
import org.openide.util.NbBundle;
Lines 82-88 Link Here
82
                            ProcedureNode pn = activatedNodes[0].getLookup().lookup(ProcedureNode.class);
83
                            ProcedureNode pn = activatedNodes[0].getLookup().lookup(ProcedureNode.class);
83
                            try {
84
                            try {
84
                                expression = pn.getSource();
85
                                expression = pn.getSource();
85
                                SQLEditorSupport.openSQLEditor(connection.getDatabaseConnection(), expression, false);
86
                                MetadataElementHandle<?> elementHandle =
87
                                        activatedNodes[0].getLookup().lookup(MetadataElementHandle.class);
88
                                SQLEditorSupport.openSQLEditor(connection.getDatabaseConnection(),
89
                                        expression, false, elementHandle);
86
                            } catch (Exception exc) {
90
                            } catch (Exception exc) {
87
                                Logger.getLogger(ViewSourceCodeAction.class.getName()).log(Level.INFO, exc.getLocalizedMessage() + " while executing expression " + expression, exc); // NOI18N
91
                                Logger.getLogger(ViewSourceCodeAction.class.getName()).log(Level.INFO, exc.getLocalizedMessage() + " while executing expression " + expression, exc); // NOI18N
88
                            }
92
                            }
(-)a/db/src/org/netbeans/modules/db/explorer/sql/editor/SQLEditorSupport.java (-2 / +10 lines)
Lines 45-50 Link Here
45
package org.netbeans.modules.db.explorer.sql.editor;
45
package org.netbeans.modules.db.explorer.sql.editor;
46
46
47
import org.netbeans.api.db.explorer.DatabaseConnection;
47
import org.netbeans.api.db.explorer.DatabaseConnection;
48
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
48
import org.netbeans.modules.db.spi.sql.editor.SQLEditorProvider;
49
import org.netbeans.modules.db.spi.sql.editor.SQLEditorProvider;
49
import org.openide.util.Lookup;
50
import org.openide.util.Lookup;
50
51
Lines 54-63 Link Here
54
 */
55
 */
55
public class SQLEditorSupport {
56
public class SQLEditorSupport {
56
57
57
    public static void openSQLEditor(DatabaseConnection dbconn, String sql, boolean execute) {
58
    public static void openSQLEditor(DatabaseConnection dbconn, String sql,
59
            boolean execute) {
60
        openSQLEditor(dbconn, sql, execute, null);
61
    }
62
63
    public static void openSQLEditor(DatabaseConnection dbconn, String sql, boolean execute,
64
            MetadataElementHandle<?> elementHandle) {
65
58
        SQLEditorProvider provider = (SQLEditorProvider)Lookup.getDefault().lookup(SQLEditorProvider.class);
66
        SQLEditorProvider provider = (SQLEditorProvider)Lookup.getDefault().lookup(SQLEditorProvider.class);
59
        if (provider != null) {
67
        if (provider != null) {
60
            provider.openSQLEditor(dbconn, sql, execute);
68
            provider.openSQLEditor(dbconn, sql, execute, elementHandle);
61
        }
69
        }
62
    }
70
    }
63
}
71
}
(-)a/db/src/org/netbeans/modules/db/spi/sql/editor/SQLEditorProvider.java (-1 / +6 lines)
Lines 45-50 Link Here
45
package org.netbeans.modules.db.spi.sql.editor;
45
package org.netbeans.modules.db.spi.sql.editor;
46
46
47
import org.netbeans.api.db.explorer.DatabaseConnection;
47
import org.netbeans.api.db.explorer.DatabaseConnection;
48
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
49
import org.openide.util.Lookup;
48
50
49
/**
51
/**
50
 * This interface provides an SQL editor. It is used every time the Database
52
 * This interface provides an SQL editor. It is used every time the Database
Lines 63-68 Link Here
63
     *        statements are also executed against this connection.
65
     *        statements are also executed against this connection.
64
     * @param sql the SQL statements to be put in the editor
66
     * @param sql the SQL statements to be put in the editor
65
     * @param execute whether to execute the SQL statements.
67
     * @param execute whether to execute the SQL statements.
68
     * @param elementHandle Handle for element for which the editor should be
69
     * opened, can be null.
66
     */
70
     */
67
    public void openSQLEditor(DatabaseConnection dbconn, String sql, boolean execute);
71
    public void openSQLEditor(DatabaseConnection dbconn, String sql, boolean execute,
72
            MetadataElementHandle<?> elementHandle);
68
}
73
}

Return to bug 195880