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 156304
Collapse All | Expand All

(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/MetadataAccessor.java (+4 lines)
Lines 46-51 Link Here
46
import org.netbeans.modules.db.metadata.model.api.Column;
46
import org.netbeans.modules.db.metadata.model.api.Column;
47
import org.netbeans.modules.db.metadata.model.api.ForeignKey;
47
import org.netbeans.modules.db.metadata.model.api.ForeignKey;
48
import org.netbeans.modules.db.metadata.model.api.ForeignKeyColumn;
48
import org.netbeans.modules.db.metadata.model.api.ForeignKeyColumn;
49
import org.netbeans.modules.db.metadata.model.api.Function;
49
import org.netbeans.modules.db.metadata.model.api.Index;
50
import org.netbeans.modules.db.metadata.model.api.Index;
50
import org.netbeans.modules.db.metadata.model.api.IndexColumn;
51
import org.netbeans.modules.db.metadata.model.api.IndexColumn;
51
import org.netbeans.modules.db.metadata.model.api.Metadata;
52
import org.netbeans.modules.db.metadata.model.api.Metadata;
Lines 61-66 Link Here
61
import org.netbeans.modules.db.metadata.model.spi.ColumnImplementation;
62
import org.netbeans.modules.db.metadata.model.spi.ColumnImplementation;
62
import org.netbeans.modules.db.metadata.model.spi.ForeignKeyColumnImplementation;
63
import org.netbeans.modules.db.metadata.model.spi.ForeignKeyColumnImplementation;
63
import org.netbeans.modules.db.metadata.model.spi.ForeignKeyImplementation;
64
import org.netbeans.modules.db.metadata.model.spi.ForeignKeyImplementation;
65
import org.netbeans.modules.db.metadata.model.spi.FunctionImplementation;
64
import org.netbeans.modules.db.metadata.model.spi.IndexColumnImplementation;
66
import org.netbeans.modules.db.metadata.model.spi.IndexColumnImplementation;
65
import org.netbeans.modules.db.metadata.model.spi.IndexImplementation;
67
import org.netbeans.modules.db.metadata.model.spi.IndexImplementation;
66
import org.netbeans.modules.db.metadata.model.spi.MetadataImplementation;
68
import org.netbeans.modules.db.metadata.model.spi.MetadataImplementation;
Lines 120-125 Link Here
120
122
121
    public abstract Procedure createProcedure(ProcedureImplementation impl);
123
    public abstract Procedure createProcedure(ProcedureImplementation impl);
122
124
125
    public abstract Function createFunction(FunctionImplementation impl);
126
123
    public abstract Schema createSchema(SchemaImplementation impl);
127
    public abstract Schema createSchema(SchemaImplementation impl);
124
128
125
    public abstract Table createTable(TableImplementation impl);
129
    public abstract Table createTable(TableImplementation impl);
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/MetadataUtilities.java (+17 lines)
Lines 188-191 Link Here
188
            throw new SQLException(t);
188
            throw new SQLException(t);
189
        }
189
        }
190
    }
190
    }
191
    
192
    /**
193
     * Call {@link DatabaseMetaData#geFunctions(String, String, String)},
194
     * wrapping any internal runtime exception into an {@link SQLException}.
195
     */
196
    public static ResultSet getFunctions(DatabaseMetaData dmd,
197
            String catalog, String schemaPattern, String functionNamePattern)
198
            throws SQLException {
199
        try {
200
            return dmd.getFunctions(catalog, schemaPattern,
201
                    functionNamePattern);
202
        } catch (SQLException e) {
203
            throw e;
204
        } catch (Throwable t) {
205
            throw new SQLException(t);
191
}
206
}
207
    }
208
}
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Function.java (-11 / +11 lines)
Lines 43-64 Link Here
43
package org.netbeans.modules.db.metadata.model.api;
43
package org.netbeans.modules.db.metadata.model.api;
44
44
45
import java.util.Collection;
45
import java.util.Collection;
46
import org.netbeans.modules.db.metadata.model.spi.ProcedureImplementation;
46
import org.netbeans.modules.db.metadata.model.spi.FunctionImplementation;
47
47
48
/**
48
/**
49
 *
49
 *
50
 * @author Andrei Badea
50
 * @author Andrei Badea
51
 */
51
 */
52
public class Procedure extends Tuple {
52
public class Function extends Tuple {
53
53
54
    final ProcedureImplementation impl;
54
    final FunctionImplementation impl;
55
55
56
    Procedure(ProcedureImplementation impl) {
56
    Function(FunctionImplementation impl) {
57
        this.impl = impl;
57
        this.impl = impl;
58
    }
58
    }
59
59
60
    /**
60
    /**
61
     * Returns the schema containing this table.
61
     * Returns the schema containing this function.
62
     *
62
     *
63
     * @return the parent schema.
63
     * @return the parent schema.
64
     */
64
     */
Lines 76-91 Link Here
76
    }
76
    }
77
77
78
    /**
78
    /**
79
     * Returns the return value of this procedure
79
     * Returns the return value of this function
80
     * 
80
     * 
81
     * @return the return value for this procedure
81
     * @return the return value for this function
82
     */
82
     */
83
    public Value getReturnValue() {
83
    public Value getReturnValue() {
84
        return impl.getReturnValue();
84
        return impl.getReturnValue();
85
    }
85
    }
86
86
87
    /**
87
    /**
88
     * Returns the columns in the result set for this procedure.
88
     * Returns the columns in the result set for this function.
89
     *
89
     *
90
     * @return the columns.
90
     * @return the columns.
91
     * @throws MetadataException if an error occurs while retrieving the metadata.
91
     * @throws MetadataException if an error occurs while retrieving the metadata.
Lines 106-114 Link Here
106
    }
106
    }
107
107
108
    /**
108
    /**
109
     * Returns the list of parameters for this procedure
109
     * Returns the list of parameters for this function
110
     *
110
     *
111
     * @return the list of parameters for this procedure
111
     * @return the list of parameters for this function
112
     * @throws MetadataException if an error occurs while retrieving the metadata
112
     * @throws MetadataException if an error occurs while retrieving the metadata
113
     */
113
     */
114
    public Collection<Parameter> getParameters() {
114
    public Collection<Parameter> getParameters() {
Lines 132-137 Link Here
132
132
133
    @Override
133
    @Override
134
    public String toString() {
134
    public String toString() {
135
        return "View[name='" + getName() + "']"; // NOI18N
135
        return "Function[name='" + getName() + "']"; // NOI18N
136
    }
136
    }
137
}
137
}
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Metadata.java (+6 lines)
Lines 50-55 Link Here
50
import org.netbeans.modules.db.metadata.model.spi.ColumnImplementation;
50
import org.netbeans.modules.db.metadata.model.spi.ColumnImplementation;
51
import org.netbeans.modules.db.metadata.model.spi.ForeignKeyColumnImplementation;
51
import org.netbeans.modules.db.metadata.model.spi.ForeignKeyColumnImplementation;
52
import org.netbeans.modules.db.metadata.model.spi.ForeignKeyImplementation;
52
import org.netbeans.modules.db.metadata.model.spi.ForeignKeyImplementation;
53
import org.netbeans.modules.db.metadata.model.spi.FunctionImplementation;
53
import org.netbeans.modules.db.metadata.model.spi.IndexColumnImplementation;
54
import org.netbeans.modules.db.metadata.model.spi.IndexColumnImplementation;
54
import org.netbeans.modules.db.metadata.model.spi.IndexImplementation;
55
import org.netbeans.modules.db.metadata.model.spi.IndexImplementation;
55
import org.netbeans.modules.db.metadata.model.spi.MetadataImplementation;
56
import org.netbeans.modules.db.metadata.model.spi.MetadataImplementation;
Lines 170-175 Link Here
170
        }
171
        }
171
172
172
        @Override
173
        @Override
174
        public Function createFunction(FunctionImplementation impl) {
175
            return new Function(impl);
176
        }
177
178
        @Override
173
        public Parameter createParameter(ParameterImplementation impl) {
179
        public Parameter createParameter(ParameterImplementation impl) {
174
            return new Parameter(impl);
180
            return new Parameter(impl);
175
        }
181
        }
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/MetadataElementHandle.java (-2 / +34 lines)
Lines 75-80 Link Here
75
    private static final int FOREIGN_KEY = 3;
75
    private static final int FOREIGN_KEY = 3;
76
    private static final int FOREIGN_KEY_COLUMN = 4;
76
    private static final int FOREIGN_KEY_COLUMN = 4;
77
    private static final int INDEX_COLUMN = 4;
77
    private static final int INDEX_COLUMN = 4;
78
    private static final int RETURN_VALUE = 3;
79
    private static final int FUNCTION = 2;
78
80
79
    // The hierarchy of names for this element (e.g. ["mycatalog","myschema","mytable","mycolumn"])
81
    // The hierarchy of names for this element (e.g. ["mycatalog","myschema","mytable","mycolumn"])
80
    //
82
    //
Lines 196-201 Link Here
196
                return (T) resolveForeignKeyColumn(metadata);
198
                return (T) resolveForeignKeyColumn(metadata);
197
            case INDEX_COLUMN:
199
            case INDEX_COLUMN:
198
                return (T) resolveIndexColumn(metadata);
200
                return (T) resolveIndexColumn(metadata);
201
            case RETURN_VALUE:
202
                return (T) resolveReturnValue(metadata);
203
            case FUNCTION:
204
                return (T) resolveFunction(metadata);
199
            default:
205
            default:
200
                throw new IllegalStateException("Unhandled kind " + kinds[kinds.length -1]);
206
                throw new IllegalStateException("Unhandled kind " + kinds[kinds.length -1]);
201
        }
207
        }
Lines 236-247 Link Here
236
242
237
    private Procedure resolveProcedure(Metadata metadata) {
243
    private Procedure resolveProcedure(Metadata metadata) {
238
        Schema schema = resolveSchema(metadata);
244
        Schema schema = resolveSchema(metadata);
239
        if (schema != null) {
245
        if (schema != null && kinds[PROCEDURE] == Kind.PROCEDURE) {
240
            return schema.getProcedure(names[PROCEDURE]);
246
            return schema.getProcedure(names[PROCEDURE]);
241
        }
247
        }
242
        return null;
248
        return null;
243
    }
249
    }
244
250
251
    private Function resolveFunction(Metadata metadata) {
252
        Schema schema = resolveSchema(metadata);
253
        if (schema != null && kinds[FUNCTION] == Kind.FUNCTION) {
254
            return schema.getFunction(names[FUNCTION]);
255
        }
256
        return null;
257
    }
258
    
259
    private Value resolveReturnValue(Metadata metadata) {
260
        Function proc = resolveFunction(metadata);
261
        if (proc != null) {
262
            return proc.getReturnValue();
263
        }
264
        Procedure proc2 = resolveProcedure(metadata);
265
        if(proc2 != null) { 
266
            return proc.getReturnValue();
267
        }
268
        return null;
269
    }
270
    
245
    private PrimaryKey resolvePrimaryKey(Metadata metadata) {
271
    private PrimaryKey resolvePrimaryKey(Metadata metadata) {
246
        Table table = resolveTable(metadata);
272
        Table table = resolveTable(metadata);
247
        if (table != null) {
273
        if (table != null) {
Lines 283-288 Link Here
283
        if (proc != null) {
309
        if (proc != null) {
284
            return proc.getParameter(names[PARAMETER]);
310
            return proc.getParameter(names[PARAMETER]);
285
        }
311
        }
312
        Function proc2 = resolveFunction(metadata);
313
        if(proc2 != null) { 
314
            return proc2.getParameter(names[PARAMETER]);
315
        }
286
        return null;
316
        return null;
287
    }
317
    }
288
318
Lines 335-341 Link Here
335
        FOREIGN_KEY(ForeignKey.class),
365
        FOREIGN_KEY(ForeignKey.class),
336
        INDEX(Index.class),
366
        INDEX(Index.class),
337
        FOREIGN_KEY_COLUMN(ForeignKeyColumn.class),
367
        FOREIGN_KEY_COLUMN(ForeignKeyColumn.class),
338
        INDEX_COLUMN(IndexColumn.class);
368
        INDEX_COLUMN(IndexColumn.class),
369
        RETURN_VALUE(Value.class),
370
        FUNCTION(Function.class);
339
371
340
        public static Kind of(MetadataElement element) {
372
        public static Kind of(MetadataElement element) {
341
            return of(element.getClass());
373
            return of(element.getClass());
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Parameter.java (-5 lines)
Lines 62-72 Link Here
62
        this.impl = impl;
62
        this.impl = impl;
63
    }
63
    }
64
64
65
    @Override
66
    public Procedure getParent() {
67
        return impl.getParent();
68
    }
69
70
    public Direction getDirection() {
65
    public Direction getDirection() {
71
        return impl.getDirection();
66
        return impl.getDirection();
72
    }
67
    }
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Procedure.java (-2 / +2 lines)
Lines 58-64 Link Here
58
    }
58
    }
59
59
60
    /**
60
    /**
61
     * Returns the schema containing this table.
61
     * Returns the schema containing this procedure.
62
     *
62
     *
63
     * @return the parent schema.
63
     * @return the parent schema.
64
     */
64
     */
Lines 132-137 Link Here
132
132
133
    @Override
133
    @Override
134
    public String toString() {
134
    public String toString() {
135
        return "View[name='" + getName() + "']"; // NOI18N
135
        return "Procedure[name='" + getName() + "']"; // NOI18N
136
    }
136
    }
137
}
137
}
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Schema.java (-1 / +22 lines)
Lines 137-143 Link Here
137
    }
137
    }
138
138
139
    /**
139
    /**
140
     * Get the list of procedures for thi shema
140
     * Get the list of procedures for this schema
141
     *
141
     *
142
     * @return the procedures
142
     * @return the procedures
143
     * @throws MetadataException if an error occurs while retrieving the metadata
143
     * @throws MetadataException if an error occurs while retrieving the metadata
Lines 158-163 Link Here
158
    }
158
    }
159
159
160
    /**
160
    /**
161
     * Get the list of functions for this schema
162
     *
163
     * @return the functions
164
     * @throws MetadataException if an error occurs while retrieving the metadata
165
     */
166
    public Collection<Function> getFunctions() {
167
        return impl.getFunctions();
168
    }
169
170
    /**
171
     * Return a function with the given name
172
     *
173
     * @param name a function name
174
     * @return a function named {@code name} or {@code null} if there is no such function.
175
     * @throws MetadataException if an error occurs while retrieving the metadata
176
     */
177
    public Function getFunction(String name) {
178
        return impl.getFunction(name);
179
    }
180
    
181
    /**
161
     * Refresh the metadata for this schema
182
     * Refresh the metadata for this schema
162
     */
183
     */
163
    public void refresh() {
184
    public void refresh() {
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCFunction.java (-17 / +16 lines)
Lines 55-72 Link Here
55
import org.netbeans.modules.db.metadata.model.api.Column;
55
import org.netbeans.modules.db.metadata.model.api.Column;
56
import org.netbeans.modules.db.metadata.model.api.MetadataException;
56
import org.netbeans.modules.db.metadata.model.api.MetadataException;
57
import org.netbeans.modules.db.metadata.model.api.Parameter;
57
import org.netbeans.modules.db.metadata.model.api.Parameter;
58
import org.netbeans.modules.db.metadata.model.api.Parameter.Direction;
59
import org.netbeans.modules.db.metadata.model.api.Schema;
58
import org.netbeans.modules.db.metadata.model.api.Schema;
60
import org.netbeans.modules.db.metadata.model.api.Value;
59
import org.netbeans.modules.db.metadata.model.api.Value;
61
import org.netbeans.modules.db.metadata.model.spi.ProcedureImplementation;
60
import org.netbeans.modules.db.metadata.model.spi.FunctionImplementation;
62
61
63
/**
62
/**
64
 *
63
 *
65
 * @author David Van Couvering
64
 * @author David Van Couvering
66
 */
65
 */
67
public class JDBCProcedure extends ProcedureImplementation {
66
public class JDBCFunction extends FunctionImplementation {
68
67
69
    private static final Logger LOGGER = Logger.getLogger(JDBCProcedure.class.getName());
68
    private static final Logger LOGGER = Logger.getLogger(JDBCFunction.class.getName());
70
69
71
    private final JDBCSchema jdbcSchema;
70
    private final JDBCSchema jdbcSchema;
72
    private final String name;
71
    private final String name;
Lines 75-81 Link Here
75
    private Map<String, Parameter> parameters;
74
    private Map<String, Parameter> parameters;
76
    private Value returnValue;
75
    private Value returnValue;
77
76
78
    public JDBCProcedure(JDBCSchema jdbcSchema, String name) {
77
    public JDBCFunction(JDBCSchema jdbcSchema, String name) {
79
        this.jdbcSchema = jdbcSchema;
78
        this.jdbcSchema = jdbcSchema;
80
        this.name = name;
79
        this.name = name;
81
    }
80
    }
Lines 123-142 Link Here
123
122
124
    @Override
123
    @Override
125
    public String toString() {
124
    public String toString() {
126
        return "JDBCProcedure[name='" + name + "']"; // NOI18N
125
        return "JDBCFunction[name='" + name + "']"; // NOI18N
127
    }
126
    }
128
127
129
    protected JDBCColumn createJDBCColumn(int position, ResultSet rs) throws SQLException {
128
    protected JDBCColumn createJDBCColumn(int position, ResultSet rs) throws SQLException {
130
        return new JDBCColumn(this.getProcedure(), position, JDBCValue.createProcedureValue(rs));
129
        return new JDBCColumn(this.getFunction(), position, JDBCValue.createFunctionValue(rs, this.getFunction()));
131
    }
130
    }
132
131
133
    protected JDBCParameter createJDBCParameter(int position, ResultSet rs) throws SQLException {
132
    protected JDBCParameter createJDBCParameter(int position, ResultSet rs) throws SQLException {
134
        Direction direction = JDBCUtils.getDirection(rs.getShort("COLUMN_TYPE"));
133
        Parameter.Direction direction = JDBCUtils.getFunctionDirection(rs.getShort("COLUMN_TYPE"));
135
        return new JDBCParameter(this, JDBCValue.createProcedureValue(rs), direction, position);
134
        return new JDBCParameter(this.getFunction(), JDBCValue.createFunctionValue(rs, this.getFunction()), direction, position);
136
    }
135
    }
137
136
138
    protected JDBCValue createJDBCValue(ResultSet rs) throws SQLException {
137
    protected JDBCValue createJDBCValue(ResultSet rs) throws SQLException {
139
        return JDBCValue.createProcedureValue(rs);
138
        return JDBCValue.createFunctionValue(rs, this.getFunction());
140
    }
139
    }
141
140
142
    protected void createProcedureInfo() {
141
    protected void createProcedureInfo() {
Lines 148-168 Link Here
148
        int paramCount = 0;
147
        int paramCount = 0;
149
148
150
        try {
149
        try {
151
            ResultSet rs = jdbcSchema.getJDBCCatalog().getJDBCMetadata().getDmd().getProcedureColumns(jdbcSchema.getJDBCCatalog().getName(), jdbcSchema.getName(), name, "%"); // NOI18N
150
            ResultSet rs = jdbcSchema.getJDBCCatalog().getJDBCMetadata().getDmd().getFunctionColumns(jdbcSchema.getJDBCCatalog().getName(), jdbcSchema.getName(), name, "%"); // NOI18N
152
            try {
151
            try {
153
                while (rs.next()) {
152
                while (rs.next()) {
154
                    short columnType = rs.getShort("COLUMN_TYPE");
153
                    short columnType = rs.getShort("COLUMN_TYPE");
155
                    switch (columnType) {
154
                    switch (columnType) {
156
                        case DatabaseMetaData.procedureColumnResult:
155
                        case DatabaseMetaData.functionColumnResult:
157
                            addColumn(++resultCount, rs, newColumns);
156
                            addColumn(++resultCount, rs, newColumns);
158
                            break;
157
                            break;
159
                        case DatabaseMetaData.procedureColumnIn:
158
                        case DatabaseMetaData.functionColumnIn:
160
                        case DatabaseMetaData.procedureColumnInOut:
159
                        case DatabaseMetaData.functionColumnInOut:
161
                        case DatabaseMetaData.procedureColumnOut:
160
                        case DatabaseMetaData.functionColumnOut:
162
                        case DatabaseMetaData.procedureColumnUnknown:
161
                        case DatabaseMetaData.functionColumnUnknown:
163
                            addParameter(++paramCount, rs, newParams);
162
                            addParameter(++paramCount, rs, newParams);
164
                            break;
163
                            break;
165
                        case DatabaseMetaData.procedureColumnReturn:
164
                        case DatabaseMetaData.functionReturn:
166
                            setReturnValue(rs);
165
                            setReturnValue(rs);
167
                            break;
166
                            break;
168
                        default:
167
                        default:
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCParameter.java (-6 / +6 lines)
Lines 45-51 Link Here
45
import java.util.logging.Logger;
45
import java.util.logging.Logger;
46
import org.netbeans.modules.db.metadata.model.api.Nullable;
46
import org.netbeans.modules.db.metadata.model.api.Nullable;
47
import org.netbeans.modules.db.metadata.model.api.Parameter.Direction;
47
import org.netbeans.modules.db.metadata.model.api.Parameter.Direction;
48
import org.netbeans.modules.db.metadata.model.api.Procedure;
48
import org.netbeans.modules.db.metadata.model.api.MetadataElement;
49
import org.netbeans.modules.db.metadata.model.api.SQLType;
49
import org.netbeans.modules.db.metadata.model.api.SQLType;
50
import org.netbeans.modules.db.metadata.model.spi.ParameterImplementation;
50
import org.netbeans.modules.db.metadata.model.spi.ParameterImplementation;
51
51
Lines 56-68 Link Here
56
public class JDBCParameter extends ParameterImplementation {
56
public class JDBCParameter extends ParameterImplementation {
57
57
58
    private static final Logger LOGGER = Logger.getLogger(JDBCParameter.class.getName());
58
    private static final Logger LOGGER = Logger.getLogger(JDBCParameter.class.getName());
59
    private final JDBCProcedure jdbcProcedure;
59
    private final MetadataElement parent;
60
    private final Direction direction;
60
    private final Direction direction;
61
    private final int ordinalPosition;
61
    private final int ordinalPosition;
62
    private final JDBCValue value;
62
    private final JDBCValue value;
63
63
64
    public JDBCParameter(JDBCProcedure jdbcProcedure, JDBCValue value, Direction direction, int ordinalPosition) {
64
    public JDBCParameter(MetadataElement parent, JDBCValue value, Direction direction, int ordinalPosition) {
65
        this.jdbcProcedure = jdbcProcedure;
65
        this.parent = parent;
66
        this.direction = direction;
66
        this.direction = direction;
67
        this.value = value;
67
        this.value = value;
68
        this.ordinalPosition = ordinalPosition;
68
        this.ordinalPosition = ordinalPosition;
Lines 74-81 Link Here
74
    }
74
    }
75
75
76
    @Override
76
    @Override
77
    public Procedure getParent() {
77
    public MetadataElement getParent() {
78
        return jdbcProcedure.getProcedure();
78
        return parent;
79
    }
79
    }
80
80
81
    @Override
81
    @Override
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCProcedure.java (-4 / +4 lines)
Lines 127-142 Link Here
127
    }
127
    }
128
128
129
    protected JDBCColumn createJDBCColumn(int position, ResultSet rs) throws SQLException {
129
    protected JDBCColumn createJDBCColumn(int position, ResultSet rs) throws SQLException {
130
        return new JDBCColumn(this.getProcedure(), position, JDBCValue.createProcedureValue(rs));
130
        return new JDBCColumn(this.getProcedure(), position, JDBCValue.createProcedureValue(rs, this.getProcedure()));
131
    }
131
    }
132
132
133
    protected JDBCParameter createJDBCParameter(int position, ResultSet rs) throws SQLException {
133
    protected JDBCParameter createJDBCParameter(int position, ResultSet rs) throws SQLException {
134
        Direction direction = JDBCUtils.getDirection(rs.getShort("COLUMN_TYPE"));
134
        Direction direction = JDBCUtils.getProcedureDirection(rs.getShort("COLUMN_TYPE"));
135
        return new JDBCParameter(this, JDBCValue.createProcedureValue(rs), direction, position);
135
        return new JDBCParameter(this.getProcedure(), JDBCValue.createProcedureValue(rs, this.getProcedure()), direction, position);
136
    }
136
    }
137
137
138
    protected JDBCValue createJDBCValue(ResultSet rs) throws SQLException {
138
    protected JDBCValue createJDBCValue(ResultSet rs) throws SQLException {
139
        return JDBCValue.createProcedureValue(rs);
139
        return JDBCValue.createProcedureValue(rs, this.getProcedure());
140
    }
140
    }
141
141
142
    protected void createProcedureInfo() {
142
    protected void createProcedureInfo() {
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCSchema.java (+48 lines)
Lines 70-75 Link Here
70
    protected Map<String, Table> tables;
70
    protected Map<String, Table> tables;
71
    protected Map<String, View> views;
71
    protected Map<String, View> views;
72
    protected Map<String, Procedure> procedures;
72
    protected Map<String, Procedure> procedures;
73
    protected Map<String, Function> functions;
73
74
74
    public JDBCSchema(JDBCCatalog jdbcCatalog, String name, boolean _default, boolean synthetic) {
75
    public JDBCSchema(JDBCCatalog jdbcCatalog, String name, boolean _default, boolean synthetic) {
75
        this.jdbcCatalog = jdbcCatalog;
76
        this.jdbcCatalog = jdbcCatalog;
Lines 129-134 Link Here
129
    }
130
    }
130
131
131
    @Override
132
    @Override
133
    public Function getFunction(String name) {
134
        return initFunctions().get(name);
135
    }
136
137
    @Override
138
    public Collection<Function> getFunctions() {
139
        return initFunctions().values();
140
    }
141
    
142
    @Override
132
    public void refresh() {
143
    public void refresh() {
133
        tables = null;
144
        tables = null;
134
        views = null;
145
        views = null;
Lines 148-153 Link Here
148
        return new JDBCProcedure(this, procedureName);
159
        return new JDBCProcedure(this, procedureName);
149
    }
160
    }
150
161
162
    protected JDBCFunction createJDBCFunction(String functionName) {
163
        return new JDBCFunction(this, functionName);
164
    }
165
151
    protected JDBCView createJDBCView(String viewName) {
166
    protected JDBCView createJDBCView(String viewName) {
152
        return new JDBCView(this, viewName);
167
        return new JDBCView(this, viewName);
153
    }
168
    }
Lines 224-229 Link Here
224
        procedures = Collections.unmodifiableMap(newProcedures);
239
        procedures = Collections.unmodifiableMap(newProcedures);
225
    }
240
    }
226
241
242
    protected void createFunctions() {    
243
        LOGGER.log(Level.FINE, "Initializing functions in {0}", this);
244
        Map<String, Function> newProcedures = new LinkedHashMap<String, Function>();
245
        try {
246
            ResultSet rs = MetadataUtilities.getFunctions(jdbcCatalog.getJDBCMetadata().getDmd(),
247
                    jdbcCatalog.getName(), name, "%"); // NOI18N
248
            try {
249
                while (rs.next()) {
250
                    String functionName = MetadataUtilities.trimmed(rs.getString("FUNCTION_NAME")); // NOI18N
251
                    Function function = createJDBCFunction(functionName).getFunction();
252
                    newProcedures.put(functionName, function);
253
                    LOGGER.log(Level.FINE, "Created function {0}", function);
254
                }
255
            } finally {
256
                if (rs != null) {
257
                    rs.close();
258
                }
259
            }
260
        } catch (SQLException e) {
261
            throw new MetadataException(e);
262
        }
263
        functions = Collections.unmodifiableMap(newProcedures);
264
    }
265
227
    private Map<String, Table> initTables() {
266
    private Map<String, Table> initTables() {
228
        if (tables != null) {
267
        if (tables != null) {
229
            return tables;
268
            return tables;
Lines 252-255 Link Here
252
        createProcedures();
291
        createProcedures();
253
        return procedures;
292
        return procedures;
254
    }
293
    }
294
    
295
    private Map<String, Function> initFunctions() {
296
        if (functions != null) {
297
            return functions;
255
}
298
}
299
300
        createFunctions();
301
        return functions;
302
    }
303
}
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCTable.java (-2 / +2 lines)
Lines 142-151 Link Here
142
        int position = 0;
142
        int position = 0;
143
        JDBCValue jdbcValue;
143
        JDBCValue jdbcValue;
144
        if (isOdbc(rs)) {
144
        if (isOdbc(rs)) {
145
            jdbcValue = JDBCValue.createTableColumnValueODBC(rs);
145
            jdbcValue = JDBCValue.createTableColumnValueODBC(rs, this.getTable());
146
        } else {
146
        } else {
147
            position = rs.getInt("ORDINAL_POSITION");
147
            position = rs.getInt("ORDINAL_POSITION");
148
            jdbcValue = JDBCValue.createTableColumnValue(rs);
148
            jdbcValue = JDBCValue.createTableColumnValue(rs, this.getTable());
149
        }
149
        }
150
        return new JDBCColumn(this.getTable(), position, jdbcValue);
150
        return new JDBCColumn(this.getTable(), position, jdbcValue);
151
    }
151
    }
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCUtils.java (-2 / +16 lines)
Lines 152-158 Link Here
152
        }
152
        }
153
    }
153
    }
154
    
154
    
155
    public static Direction getDirection(short sqlDirection) {
155
    public static Direction getProcedureDirection(short sqlDirection) {
156
        switch (sqlDirection) {
156
        switch (sqlDirection) {
157
            case DatabaseMetaData.procedureColumnOut:
157
            case DatabaseMetaData.procedureColumnOut:
158
                return Direction.OUT;
158
                return Direction.OUT;
Lines 161-171 Link Here
161
            case DatabaseMetaData.procedureColumnIn:
161
            case DatabaseMetaData.procedureColumnIn:
162
                return Direction.IN;
162
                return Direction.IN;
163
            default:
163
            default:
164
                LOGGER.log(Level.INFO, "Unknown direction value from DatabaseMetadat.getProcedureColumns(): " + sqlDirection);
164
                LOGGER.log(Level.INFO, "Unknown direction value from DatabaseMetadata.getProcedureColumns(): " + sqlDirection);
165
                return Direction.IN;
165
                return Direction.IN;
166
        }
166
        }
167
    }
167
    }
168
168
169
    public static Direction getFunctionDirection(short sqlDirection) {
170
        switch (sqlDirection) {
171
            case DatabaseMetaData.functionColumnOut:
172
                return Direction.OUT;
173
            case DatabaseMetaData.functionColumnInOut:
174
                return Direction.INOUT;
175
            case DatabaseMetaData.functionColumnIn:
176
                return Direction.IN;
177
            default:
178
                LOGGER.log(Level.INFO, "Unknown direction value from DatabaseMetadata.getFunctionColumns(): " + sqlDirection);
179
                return Direction.IN;
180
        }
181
    }
182
    
169
    public static Ordering getOrdering(String ascOrDesc) {
183
    public static Ordering getOrdering(String ascOrDesc) {
170
        if (ascOrDesc == null || ascOrDesc.length() == 0) {
184
        if (ascOrDesc == null || ascOrDesc.length() == 0) {
171
            return Ordering.NOT_SUPPORTED;
185
            return Ordering.NOT_SUPPORTED;
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCValue.java (-8 / +22 lines)
Lines 60-65 Link Here
60
60
61
    private static final Logger LOGGER = Logger.getLogger(JDBCValue.class.getName());
61
    private static final Logger LOGGER = Logger.getLogger(JDBCValue.class.getName());
62
62
63
    private final MetadataElement parent;
63
    private final String name;
64
    private final String name;
64
    private final SQLType type;
65
    private final SQLType type;
65
    private final int length;
66
    private final int length;
Lines 75-81 Link Here
75
     * @return a newly created JDBCValue instance
76
     * @return a newly created JDBCValue instance
76
     * @throws java.sql.SQLException
77
     * @throws java.sql.SQLException
77
     */
78
     */
78
    public static JDBCValue createProcedureValue(ResultSet rs) throws SQLException {
79
    public static JDBCValue createProcedureValue(ResultSet rs, MetadataElement parent) throws SQLException {
79
        String name = MetadataUtilities.trimmed(rs.getString("COLUMN_NAME"));
80
        String name = MetadataUtilities.trimmed(rs.getString("COLUMN_NAME"));
80
        SQLType type = JDBCUtils.getSQLType(rs.getInt("DATA_TYPE"));
81
        SQLType type = JDBCUtils.getSQLType(rs.getInt("DATA_TYPE"));
81
        int length = rs.getInt("LENGTH");
82
        int length = rs.getInt("LENGTH");
Lines 84-100 Link Here
84
        short radix = rs.getShort("RADIX");
85
        short radix = rs.getShort("RADIX");
85
        Nullable nullable = JDBCUtils.getProcedureNullable(rs.getShort("NULLABLE"));
86
        Nullable nullable = JDBCUtils.getProcedureNullable(rs.getShort("NULLABLE"));
86
87
87
        return new JDBCValue(name, type, length, precision, radix, scale, nullable);
88
        return new JDBCValue(parent, name, type, length, precision, radix, scale, nullable);
88
    }
89
    }
89
90
90
    /**
91
    /**
92
     * Create a value from a row in getFunctionColumns()
93
     *
94
     * @param rs the result set from getFunctionColumns, assumed to be at a valid row
95
     * @return a newly created JDBCValue instance
96
     * @throws java.sql.SQLException
97
     */
98
    public static JDBCValue createFunctionValue(ResultSet rs, MetadataElement parent) throws SQLException {
99
        // Delegate to the procedure Version - currently the same columns are used
100
        return createProcedureValue(rs, parent);
101
    }
102
    
103
    /**
91
     * Create a value from a row in DBMD.getColumns()
104
     * Create a value from a row in DBMD.getColumns()
92
     *
105
     *
93
     * @param rs the result set from getProcedureColumns, assumed to be at a valid row
106
     * @param rs the result set from getProcedureColumns, assumed to be at a valid row
94
     * @return a newly created JDBCValue instance
107
     * @return a newly created JDBCValue instance
95
     * @throws java.sql.SQLException
108
     * @throws java.sql.SQLException
96
     */
109
     */
97
    public static JDBCValue createTableColumnValue(ResultSet rs) throws SQLException {
110
    public static JDBCValue createTableColumnValue(ResultSet rs, MetadataElement parent) throws SQLException {
98
        String name = MetadataUtilities.trimmed(rs.getString("COLUMN_NAME"));
111
        String name = MetadataUtilities.trimmed(rs.getString("COLUMN_NAME"));
99
        SQLType type = JDBCUtils.getSQLType(rs.getInt("DATA_TYPE"));
112
        SQLType type = JDBCUtils.getSQLType(rs.getInt("DATA_TYPE"));
100
113
Lines 112-118 Link Here
112
        short radix = rs.getShort("NUM_PREC_RADIX");
125
        short radix = rs.getShort("NUM_PREC_RADIX");
113
        Nullable nullable = JDBCUtils.getColumnNullable(rs.getShort("NULLABLE"));
126
        Nullable nullable = JDBCUtils.getColumnNullable(rs.getShort("NULLABLE"));
114
127
115
        return new JDBCValue(name, type, length, precision, radix, scale, nullable);
128
        return new JDBCValue(parent, name, type, length, precision, radix, scale, nullable);
116
    }
129
    }
117
130
118
    /**
131
    /**
Lines 123-129 Link Here
123
     * @return a newly created JDBCValue instance
136
     * @return a newly created JDBCValue instance
124
     * @throws java.sql.SQLException
137
     * @throws java.sql.SQLException
125
     */
138
     */
126
    public static JDBCValue createTableColumnValueODBC(ResultSet rs) throws SQLException {
139
    public static JDBCValue createTableColumnValueODBC(ResultSet rs, MetadataElement parent) throws SQLException {
127
        String name = MetadataUtilities.trimmed(rs.getString("COLUMN_NAME"));
140
        String name = MetadataUtilities.trimmed(rs.getString("COLUMN_NAME"));
128
        SQLType type = JDBCUtils.getSQLType(rs.getInt("DATA_TYPE"));
141
        SQLType type = JDBCUtils.getSQLType(rs.getInt("DATA_TYPE"));
129
        int length = 0;
142
        int length = 0;
Lines 137-146 Link Here
137
        short radix = rs.getShort("RADIX");
150
        short radix = rs.getShort("RADIX");
138
        Nullable nullable = JDBCUtils.getColumnNullable(rs.getShort("NULLABLE"));
151
        Nullable nullable = JDBCUtils.getColumnNullable(rs.getShort("NULLABLE"));
139
152
140
        return new JDBCValue(name, type, length, precision, radix, scale, nullable);
153
        return new JDBCValue(parent, name, type, length, precision, radix, scale, nullable);
141
    }
154
    }
142
155
143
    public JDBCValue(String name, SQLType type, int length, int precision, short radix, short scale, Nullable nullable) {
156
    public JDBCValue(MetadataElement parent, String name, SQLType type, int length, int precision, short radix, short scale, Nullable nullable) {
157
        this.parent = parent;
144
        this.name = name;
158
        this.name = name;
145
        this.type = type;
159
        this.type = type;
146
        this.length = length;
160
        this.length = length;
Lines 193-199 Link Here
193
207
194
    @Override
208
    @Override
195
    public MetadataElement getParent() {
209
    public MetadataElement getParent() {
196
        throw new UnsupportedOperationException("Not supported yet.");
210
        return this.parent;
197
    }
211
    }
198
212
199
}
213
}
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCView.java (-1 / +1 lines)
Lines 99-105 Link Here
99
99
100
    protected JDBCColumn createJDBCColumn(ResultSet rs) throws SQLException {
100
    protected JDBCColumn createJDBCColumn(ResultSet rs) throws SQLException {
101
        int ordinalPosition = rs.getInt("ORDINAL_POSITION");
101
        int ordinalPosition = rs.getInt("ORDINAL_POSITION");
102
        return new JDBCColumn(this.getView(), ordinalPosition, JDBCValue.createTableColumnValue(rs));
102
        return new JDBCColumn(this.getView(), ordinalPosition, JDBCValue.createTableColumnValue(rs, this.getView()));
103
    }
103
    }
104
104
105
    protected void createColumns() {
105
    protected void createColumns() {
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/mysql/MySQLProcedure.java (-5 / +6 lines)
Lines 44-49 Link Here
44
44
45
import java.sql.ResultSet;
45
import java.sql.ResultSet;
46
import java.sql.SQLException;
46
import java.sql.SQLException;
47
import org.netbeans.modules.db.metadata.model.api.MetadataElement;
47
import org.netbeans.modules.db.metadata.model.api.Nullable;
48
import org.netbeans.modules.db.metadata.model.api.Nullable;
48
import org.netbeans.modules.db.metadata.model.api.Parameter.Direction;
49
import org.netbeans.modules.db.metadata.model.api.Parameter.Direction;
49
import org.netbeans.modules.db.metadata.model.api.SQLType;
50
import org.netbeans.modules.db.metadata.model.api.SQLType;
Lines 64-76 Link Here
64
65
65
    @Override
66
    @Override
66
    protected JDBCParameter createJDBCParameter(int position, ResultSet rs) throws SQLException {
67
    protected JDBCParameter createJDBCParameter(int position, ResultSet rs) throws SQLException {
67
        Direction direction = JDBCUtils.getDirection(rs.getShort("COLUMN_TYPE"));
68
        Direction direction = JDBCUtils.getProcedureDirection(rs.getShort("COLUMN_TYPE"));
68
        return new JDBCParameter(this, createValue(rs), direction, position);
69
        return new JDBCParameter(this.getProcedure(), createValue(rs, this.getProcedure()), direction, position);
69
    }
70
    }
70
71
71
    @Override
72
    @Override
72
    protected JDBCValue createJDBCValue(ResultSet rs) throws SQLException {
73
    protected JDBCValue createJDBCValue(ResultSet rs) throws SQLException {
73
        return createValue(rs);
74
        return createValue(rs, this.getProcedure());
74
    }
75
    }
75
76
76
    @Override
77
    @Override
Lines 85-91 Link Here
85
     * Logged as a MySQL bug - http://bugs.mysql.com/bug.php?id=41269
86
     * Logged as a MySQL bug - http://bugs.mysql.com/bug.php?id=41269
86
     * When this is fixed this workaround will need to be backed out.
87
     * When this is fixed this workaround will need to be backed out.
87
     */
88
     */
88
    private static JDBCValue createValue(ResultSet rs) throws SQLException {
89
    private static JDBCValue createValue(ResultSet rs, MetadataElement parent) throws SQLException {
89
        String name = rs.getString("COLUMN_NAME");
90
        String name = rs.getString("COLUMN_NAME");
90
91
91
        int length = 0;
92
        int length = 0;
Lines 101-107 Link Here
101
        short radix = rs.getShort("RADIX");
102
        short radix = rs.getShort("RADIX");
102
        Nullable nullable = JDBCUtils.getProcedureNullable(rs.getShort("NULLABLE"));
103
        Nullable nullable = JDBCUtils.getProcedureNullable(rs.getShort("NULLABLE"));
103
104
104
        return new JDBCValue(name, type, length, precision, radix, scale, nullable);
105
        return new JDBCValue(parent, name, type, length, precision, radix, scale, nullable);
105
    }
106
    }
106
107
107
108
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/spi/FunctionImplementation.java (-5 / +5 lines)
Lines 45-52 Link Here
45
import java.util.Collection;
45
import java.util.Collection;
46
import org.netbeans.modules.db.metadata.model.MetadataAccessor;
46
import org.netbeans.modules.db.metadata.model.MetadataAccessor;
47
import org.netbeans.modules.db.metadata.model.api.Column;
47
import org.netbeans.modules.db.metadata.model.api.Column;
48
import org.netbeans.modules.db.metadata.model.api.Function;
48
import org.netbeans.modules.db.metadata.model.api.Parameter;
49
import org.netbeans.modules.db.metadata.model.api.Parameter;
49
import org.netbeans.modules.db.metadata.model.api.Procedure;
50
import org.netbeans.modules.db.metadata.model.api.Schema;
50
import org.netbeans.modules.db.metadata.model.api.Schema;
51
import org.netbeans.modules.db.metadata.model.api.Value;
51
import org.netbeans.modules.db.metadata.model.api.Value;
52
52
Lines 54-66 Link Here
54
 *
54
 *
55
 * @author Andrei Badea
55
 * @author Andrei Badea
56
 */
56
 */
57
public abstract class ProcedureImplementation {
57
public abstract class FunctionImplementation {
58
58
59
    private Procedure table;
59
    private Function table;
60
60
61
    public final Procedure getProcedure() {
61
    public final Function getFunction() {
62
        if (table == null) {
62
        if (table == null) {
63
            table = MetadataAccessor.getDefault().createProcedure(this);
63
            table = MetadataAccessor.getDefault().createFunction(this);
64
        }
64
        }
65
        return table;
65
        return table;
66
    }
66
    }
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/spi/ParameterImplementation.java (-2 / +2 lines)
Lines 45-51 Link Here
45
import org.netbeans.modules.db.metadata.model.MetadataAccessor;
45
import org.netbeans.modules.db.metadata.model.MetadataAccessor;
46
import org.netbeans.modules.db.metadata.model.api.Parameter;
46
import org.netbeans.modules.db.metadata.model.api.Parameter;
47
import org.netbeans.modules.db.metadata.model.api.Parameter.Direction;
47
import org.netbeans.modules.db.metadata.model.api.Parameter.Direction;
48
import org.netbeans.modules.db.metadata.model.api.Procedure;
48
import org.netbeans.modules.db.metadata.model.api.MetadataElement;
49
49
50
/**
50
/**
51
 *
51
 *
Lines 64-70 Link Here
64
64
65
    public abstract Direction getDirection();
65
    public abstract Direction getDirection();
66
66
67
    public abstract Procedure getParent();
67
    public abstract MetadataElement getParent();
68
68
69
    public abstract int getOrdinalPosition();
69
    public abstract int getOrdinalPosition();
70
70
(-)db.metadata.model/src/org/netbeans/modules/db/metadata/model/spi/SchemaImplementation.java (+10 lines)
Lines 43-50 Link Here
43
package org.netbeans.modules.db.metadata.model.spi;
43
package org.netbeans.modules.db.metadata.model.spi;
44
44
45
import java.util.Collection;
45
import java.util.Collection;
46
import java.util.Collections;
46
import org.netbeans.modules.db.metadata.model.MetadataAccessor;
47
import org.netbeans.modules.db.metadata.model.MetadataAccessor;
47
import org.netbeans.modules.db.metadata.model.api.Catalog;
48
import org.netbeans.modules.db.metadata.model.api.Catalog;
49
import org.netbeans.modules.db.metadata.model.api.Function;
48
import org.netbeans.modules.db.metadata.model.api.Procedure;
50
import org.netbeans.modules.db.metadata.model.api.Procedure;
49
import org.netbeans.modules.db.metadata.model.api.Schema;
51
import org.netbeans.modules.db.metadata.model.api.Schema;
50
import org.netbeans.modules.db.metadata.model.api.Table;
52
import org.netbeans.modules.db.metadata.model.api.Table;
Lines 77-82 Link Here
77
79
78
    public abstract Collection<Procedure> getProcedures();
80
    public abstract Collection<Procedure> getProcedures();
79
81
82
    public Function getFunction(String name) {
83
        return null;
84
    }
85
86
    public Collection<Function> getFunctions() {
87
        return Collections.EMPTY_LIST;
88
    }
89
    
80
    public abstract boolean isDefault();
90
    public abstract boolean isDefault();
81
91
82
    public abstract boolean isSynthetic();
92
    public abstract boolean isSynthetic();
(-)db.metadata.model/test/unit/src/org/netbeans/modules/db/metadata/model/api/MetadataElementHandleTest.java (-1 / +70 lines)
Lines 44-49 Link Here
44
44
45
import java.sql.Connection;
45
import java.sql.Connection;
46
import java.sql.DriverManager;
46
import java.sql.DriverManager;
47
import java.sql.SQLException;
47
import java.sql.Statement;
48
import java.sql.Statement;
48
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle.Kind;
49
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle.Kind;
49
import org.netbeans.modules.db.metadata.model.jdbc.JDBCMetadata;
50
import org.netbeans.modules.db.metadata.model.jdbc.JDBCMetadata;
Lines 74-84 Link Here
74
        stmt.executeUpdate("CREATE TABLE BAR (ID INT NOT NULL PRIMARY KEY, FOO_ID INT NOT NULL, FOREIGN KEY (FOO_ID) REFERENCES FOO)");
75
        stmt.executeUpdate("CREATE TABLE BAR (ID INT NOT NULL PRIMARY KEY, FOO_ID INT NOT NULL, FOREIGN KEY (FOO_ID) REFERENCES FOO)");
75
        stmt.executeUpdate("CREATE INDEX FOO_INDEX ON FOO(FOO)");
76
        stmt.executeUpdate("CREATE INDEX FOO_INDEX ON FOO(FOO)");
76
        stmt.executeUpdate("CREATE VIEW FOOVIEW AS SELECT * FROM FOO");
77
        stmt.executeUpdate("CREATE VIEW FOOVIEW AS SELECT * FROM FOO");
78
        stmt.executeUpdate("CREATE PROCEDURE XY (IN S_MONTH INTEGER, IN S_DAYS VARCHAR(255)) "
79
                + " DYNAMIC RESULT SETS 1 "
80
                + " PARAMETER STYLE JAVA READS SQL  DATA LANGUAGE JAVA "
81
                + " EXTERNAL NAME 'org.netbeans.modules.db.metadata.model.api.MetadataElementHandleTest.demoProcedure'");
82
        stmt.executeUpdate("CREATE FUNCTION TO_DEGREES(RADIANS DOUBLE) RETURNS DOUBLE "
83
                + "PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA "
84
                + "EXTERNAL NAME 'java.lang.Math.toDegrees'");
77
        stmt.close();
85
        stmt.close();
78
        metadata = new JDBCMetadata(conn, "APP").getMetadata();
86
        metadata = new JDBCMetadata(conn, "APP").getMetadata();
79
    }
87
    }
80
88
81
    public void testResolve() {
89
    public void testResolve() throws SQLException {
82
        Catalog catalog = metadata.getDefaultCatalog();
90
        Catalog catalog = metadata.getDefaultCatalog();
83
        MetadataElementHandle<Catalog> catalogHandle = MetadataElementHandle.create(catalog);
91
        MetadataElementHandle<Catalog> catalogHandle = MetadataElementHandle.create(catalog);
84
            Catalog resolvedCatalog = catalogHandle.resolve(metadata);
92
            Catalog resolvedCatalog = catalogHandle.resolve(metadata);
Lines 120-125 Link Here
120
        View resolvedView = viewHandle.resolve(metadata);
128
        View resolvedView = viewHandle.resolve(metadata);
121
        assertSame(view, resolvedView);
129
        assertSame(view, resolvedView);
122
130
131
        Function function = schema.getFunction("TO_DEGREES");
132
        MetadataElementHandle<Function> procedureHandle = MetadataElementHandle.create(function);
133
        Function resolvedFunction = procedureHandle.resolve(metadata);
134
        assertSame(function, resolvedFunction);
135
        
136
        assertTrue(function.getParameters().size() > 0);
137
        
138
        for(Parameter param: function.getParameters()) {
139
            MetadataElementHandle<Parameter> paramHandle = MetadataElementHandle.create(param);
140
            Parameter resolvedParam = paramHandle.resolve(metadata);
141
            assertSame(param, resolvedParam);
142
        }
143
        
144
        Value value = function.getReturnValue();
145
        assertNotNull(value);
146
        MetadataElementHandle<Value> valueHandle = MetadataElementHandle.create(value);
147
        Value resolvedValue = valueHandle.resolve(metadata);
148
        assertSame(value, resolvedValue);
149
        
150
        Procedure procedure = schema.getProcedure("XY");
151
        MetadataElementHandle<Procedure> functionHandle = MetadataElementHandle.create(procedure);
152
        Procedure resolvedProcedure = functionHandle.resolve(metadata);
153
        assertSame(procedure, resolvedProcedure);
154
        
155
        assertTrue(procedure.getParameters().size() > 0);
156
        
157
        for(Parameter param: procedure.getParameters()) {
158
            MetadataElementHandle<Parameter> paramHandle = MetadataElementHandle.create(param);
159
            Parameter resolvedParam = paramHandle.resolve(metadata);
160
            assertSame(param, resolvedParam);
161
        }
162
        
163
        value = procedure.getReturnValue();
164
        assertNull(value);
165
        
166
        // Ensure conflicting names of functions and procudures don't spill over
167
        // a MetadataElementHandle<Parameter> from a procedure must not be
168
        // resolvable against a function with the same "path" (Function name = 
169
        // procedure name and same parameter name)
170
        procedure = schema.getProcedure("XY");
171
        MetadataElementHandle<Parameter> paramHandle = MetadataElementHandle.create(procedure.getParameters().iterator().next());
172
        assertNotNull(paramHandle.resolve(metadata));
173
        
174
        Statement stmt = conn.createStatement();
175
        stmt.executeUpdate("DROP PROCEDURE XY");
176
        stmt.executeUpdate("CREATE FUNCTION XY (S_MONTH INTEGER, S_DAYS VARCHAR(255)) RETURNS DOUBLE "
177
                + " PARAMETER STYLE JAVA READS SQL  DATA LANGUAGE JAVA "
178
                + " EXTERNAL NAME 'org.netbeans.modules.db.metadata.model.api.MetadataElementHandleTest.demoProcedure'");
179
        stmt.close();
180
        
181
        metadata.refresh();
182
        
183
        schema = metadata.getDefaultSchema();
184
        
185
        assertNotNull(schema.getFunction("XY"));
186
        
187
        assertNull(schema.getProcedure("XY"));
188
        
189
        assertNull(paramHandle.resolve(metadata));
190
        
191
123
        // Negative test - what happens if you create a handle for null
192
        // Negative test - what happens if you create a handle for null
124
        try {
193
        try {
125
            MetadataElementHandle<Catalog> bogusHandle = MetadataElementHandle.create((Catalog)null);
194
            MetadataElementHandle<Catalog> bogusHandle = MetadataElementHandle.create((Catalog)null);

Return to bug 156304