This chapter discusses how to add and edit projection definitions within a class definition.
A projection definition instructs the Caché class compiler to perform certain operations when a class definition is compiled or removed. A projection defines the name of a projection class (derived from the %Projection.AbstractProjection class) that implements methods that are called when a) the compilation of a class is complete and b) when a class definition is removed (either because it is being deleted or because the class is about to be recompiled).
Caché includes a number of pre-defined projection classes that are used to automatically provide actions when a class is compiled. Typically these actions have to do with generating client code for that allows access to a class from other environments (such as Java or C++).
A class may contain any number of projection definitions. The actions for all of them will be invoked when the class is compiled (the order in which they are invoked is not defined).
Caché provides the following projection classes:
Projection Classes
Class Description
%Projection.Java Generates a Java client class to enable access to the class from Java.
%Projection.CPP Generates a C++ client class to enable access to the class from C++.
%Projection.EJB Generates a set of Enterprise Java Bean client classes to enable access to the class from an EJB server. In addition, any other files, such as deployment descriptors are created.
You can also create your own projection classes and use them from Studio as you would any built-in projection class.
Adding Projections to a Class Definition
You can add a new projection to a class definition in two ways:
  1. Directly editing the textual representation of the class definition using the Class Editor.
  2. Using the New Projection Wizard
To add a projection using the Class Editor, simply position the cursor to a blank line within the Class Editor and type in a projection declaration:
Projection MyProjection As %Projection.Java(LOCATION="\java");
Alternatively, you can do this by copying and pasting an existing projection declaration and then editing it.
For details on the textual representation of projection definitions refer to the Class Definition Language reference.
The New Projection Wizard
You can invoke the New Projection Wizard using the Add Member command within the Class menu and asking for a new Projection. Alternatively you can invoke the New Projection Wizard by right clicking on the Class Inspector and selecting Add Projection from the pop-up menu.
The New Projection Wizard will display a number of pages prompting you for information about the new projection. You can press the Finish button at any time (in this case, default values will be provided for any information you have not specified).
General Information
The New Projection Wizard will prompt you for the following information (you can later modify any of these values):
Projection Name
(required) This is the name of the new projection. This name must be a valid projection name and must not conflict with the name of a previously defined projection.
Description
(optional) This is a description of the new projection.
Projection Type
The type of a projection determines what actions will happen when your class definition is compiled or removed. You can select what kind of projection you would like to define:
Projection Type
The name of a projection class whose methods will be invoked when a class definition is compiled or removed.
Projection Parameters
A set of name/value pairs that control the behavior of the projection class. The list of available parameter names is determined by the selected projection class.
Results of Running the New Projection Wizard
After running the New Projection Wizard the text within the Class Editor window will be updated to include a textual representation of the new projection definition. For example:
/// This is a Person class
class MyApp.Person extends %Persistent [ClassType = persistent]
{
 
Property Name As %String;

Projection JavaClient As %Projection.Java;
}
If you wish to make further modifications to this projection definition you can do this using either the Class Editor or the Class Inspector.