Documentation Archive Developer
Search
PATH  WebObjects 4.0 Documentation > EOF Tools and Techniques

Table of Contents Previous Section

Adding Stored Procedures

If your stored procedure is defined in the database at the time you create your model, you don't have to do anything to define it in your model. When you create a new model with EOModeler, the application reads stored procedure definitions from the database's data dictionary and stores them in the model's .eomodeld file. You can also add a stored procedure definition to an existing model.

To add a stored procedure:

  1. Select the Stored Procedures icon in the tree view.

  2. Choose Property Add Stored Procedure.

  3. Specify a name and external name for the stored procedure.

    Figure 38. Adding a Stored Procedure

You must also define an argument for a stored procedure's return value and for each of its parameters. Add arguments to a stored procedure the same way you add attributes to an entity. In fact, the arguments of a stored procedure are represented with EOAttribute objects.

Note: The Advanced Attribute Inspector isn't applicable to stored procedure arguments. As a result, you can't access it while editing a stored procedure argument.

To define and display the attributes of a stored procedure:

  1. Select the stored procedure in the tree view.

    Alternatively, you can double-click the icon to the left of a stored procedure in the Model Editor's stored procedure table.

  2. Choose Property Add Argument.

  3. Specify the argument's characteristics in the Model Editor's table.

    Minimally, you must provide values for the Name, Column, Direction, External Type, and Value Class characteristics.

Each table column corresponds to a single characteristic of a stored procedure argument. By default, the columns included in the table only represent a subset of the possible characteristics you can set for a given entity. To add columns for additional characteristics, use the Add Column menu in the lower left corner of the table.

The following table describes the characteristics you can set for a stored procedure argument.
Characteristic What it is
Allows Null Indicates whether the argument's value can be NULL.
Column The name of a parameter as it is defined in the database (doesn't apply to a "returnValue" argument).
Direction In, InOut, Out, or Void. Don't choose Void; it's reserved for future use.
External Type The data type of the argument as it's defined in the database.
Name The name your application uses for the argument.
Precision The number of significant digits (applies to number data only).
Scale The number of digits to the right of the decimal point (applies to number data only).
Value Class (Java) The Java type to which the argument value will be coerced in your application.
Value Class (Obj-C) The Objective-C type to which the argument value will be coerced in your application.
Value Type The format type for NSNumber classes such as "i" or "d".
Width The maximum width (applies to string, raw, and binary data).

For example, to add arguments for the Sybase stored procedure defined as:

create proc movie_by_date (@begin datetime, @end 
datetime) as
begin
	select
		CATEGORY, DATE_RELEASED, LANGUAGE, MOVIE_ID, RATING,
		REVENUE, STUDIO_ID, TITLE
	from MOVIES
	where DATE_RELEASED > @begin and DATE_RELEASED < @end
end
you would add an argument for @begin and @end with column names "begin" and "end", respectively.

Tip: If you're using Oracle, you can define a stored procedure to represent a function. Add an argument named "returnValue" and use the EOAdaptorChannel method returnValuesForLastStoredProcedureInvocation to get the function's result.

If the Framework invokes your stored procedure automatically, the argument names of a stored procedure must match the name of a corresponding EOAttribute object. For example, if you want to invoke a stored procedure whenever the Framework fetches a Movie object by its primary key, the stored procedure's argument names must correspond to the primary key attributes of the Movie entity. The following section discusses this requirement more thoroughly.

Table of Contents Next Section