3 Lab Cache Studio
3 Lab Cache Studio
Version 2010.1
17 February 2010
This book was assembled and formatted in Adobe Page Description Format (PDF) using tools and information from the following sources:
Sun Microsystems, RenderX, Inc., Adobe Systems, and the World Wide Web Consortium at www.w3c.org.The primary document development
tools were special-purpose XML-processing applications built by InterSystems using Caché and Java.
and
Caché WEBLINK, Distributed Cache Protocol, M/SQL, M/NET, and M/PACT are registered trademarks of InterSystems Corporation.
, , and
InterSystems Jalapeño Technology, Enterprise Cache Protocol, ECP, and InterSystems Zen are trademarks of InterSystems Corporation.
All other brand or product names used herein are trademarks or registered trademarks of their respective companies or organizations.
This document contains trade secret and confidential information which is the property of InterSystems Corporation, One Memorial Drive,
Cambridge, MA 02142, or its affiliates, and is furnished for the sole purpose of the operation and maintenance of the products of InterSystems
Corporation. No part of this publication is to be used for any other purpose, and this publication is not to be reproduced, copied, disclosed,
transmitted, stored in a retrieval system or translated into any human or computer language, in any form, by any means, in whole or in part,
without the express prior written consent of InterSystems Corporation.
The copying, use and disposition of this document and the software programs described herein is prohibited except to the limited extent
set forth in the standard software license agreement(s) of InterSystems Corporation covering such programs and related documentation.
InterSystems Corporation makes no representations and warranties concerning such software programs other than those set forth in such
standard software license agreement(s). In addition, the liability of InterSystems Corporation for any losses or damages relating to or arising
out of the use of such software programs is limited in the manner set forth in such standard software license agreement(s).
THE FOREGOING IS A GENERAL SUMMARY OF THE RESTRICTIONS AND LIMITATIONS IMPOSED BY INTERSYSTEMS
CORPORATION ON THE USE OF, AND LIABILITY ARISING FROM, ITS COMPUTER SOFTWARE. FOR COMPLETE INFORMATION
REFERENCE SHOULD BE MADE TO THE STANDARD SOFTWARE LICENSE AGREEMENT(S) OF INTERSYSTEMS CORPORATION,
COPIES OF WHICH WILL BE MADE AVAILABLE UPON REQUEST.
InterSystems Corporation disclaims responsibility for errors which may appear in this document, and it reserves the right, in its sole discretion
and without notice, to make substitutions and modifications in the products and practices described in this document.
• Integrated syntax coloring and syntax checking for Caché ObjectScript, Basic, Java, SQL, JavaScript, HTML, and
XML.
• Support for teams of developers working with a common repository of application source code.
• A graphical, source code debugger.
• The ability to organize application source code into projects.
Caché Studio is a client application, built using Caché objects, that runs on Windows-based operating systems. It can connect
to any Caché server (compatible with the current version of Caché Studio) regardless of what platform and operating system
that server is using.
Note: A Studio client must be running either the same version of Caché or a higher version than the Caché server that
it is connecting to. Example: Caché 2008.2 Studio can connect to a Caché 2008.2 (or earlier version) server. Caché
2008.1 Studio cannot connect to a Caché 2008.2 (or later) server. This applies also to maintenance releases.
Example: Caché 2008.2.1 Studio can connect to a Caché 2008.2.1 (or earlier maintenance release or version)
server. Caché 2008.2.0 Studio cannot connect to a Caché 2008.2.1 (or later maintenance release or version) server.
1. Editors: Class Editorfor editing class definitions, Routine Editor for editing routines, and CSP Editor for editing CSP
definition text.
2. Workspace window: three tabs let you display: the contents of the current project, all open windows, or the content of
the current namespace.
3. Class Inspector window: for viewing and modifying keywords in a class definition.
4. Output window: displays output from the Caché server (such as messages generated during class compilation).
In addition to the windows displayed above, Caché Studio contains wizards and templates for assisting with common tasks.
These include:
• New Class wizard: defines a new class.
• Class member wizards that add members to class definitions for: properties, indexes, relationships, methods, parameters,
SQL triggers, queries, projections, storage, foreign keys, and XData blocks.
• Wizards that create classes from other technologies; from: Java classes and jar files, SML schema, SOAP client classes,
that provide access to COM objects, and DLL assembly files from .NET.
• HTML templates that add: colors, tables, tags, and scripts.
• CSP Form wizard: creates an HTML form bound to a Caché object in a CSP page.
• Zen templates that add: charts, tables, methods, and styles.
Parameter Description
? Help info
/Servername=ServerName Connect to the server named ServerName.
/Server=cn_iptcp:127.0.0.1[1972]:: Connect to the server at ip address[[port, here
127.0.0.1[1972] server.
/Namespace=User Connect to the User namespacer. Server should
be defined.
/Project=MyProject Open project MyProject. Server and Namespace
should be defined
cn_iptcp://127.0.0.1:1972/User/test.int Load routine test.int. cn_iptcp is a case sensitive
protocol identifier.
/files="tag+1^myroutine.int",User.Class1.cls Open listed documents and set cursor in specified
position. Server and namespace should be defined
/pid=123 Attach to process. Server and Namespace should
be defined
/fastconnect=127.0.0.1[1972]:USER:_SYSTEM:SYS Connect without connection definition in registry
using ip address[[port]:USER:username:password
1.2 Projects
Caché Studio uses projects to organize application source code.
A project is a set of class definitions, CSP files, and routines. For example, you might create a Caché Studio project to
group all classes and CSP files for a single application.
You are always in a project, either one that you created or the default project that is created when you first open Studio
called Default_yourusername (a prefix of Default_ followed by your user name).
All files in a single project must be in the same namespace (and Caché server). Each class, CSP file, or routine can be
associated with any number of projects. Each namespace can contain any number of projects.
The project stores information such as the class hierarchy in a given Caché namespace, used when you edit classes or CSP
files. The project also stores debugging information (such as how to start the application you want to debug).
A class definition can be projected for use by other technologies. In the case of SQL and ActiveX, this projection is automatic.
In the case of Java (or C++) there is an additional compilation step in which a Java class is generated that corresponds to
the Caché class definition. For details, see the chapter “Adding Class Projections.”
Within Caché Studio, class definitions can be displayed and edited in a Class Editor window. Class definitions can also be
viewed in the Class Inspector window as keywords and their corresponding values in tables.
This example defines a class called MyApp.Student (with no properties, methods, or other members) that extends (is derived
from) the class MyApp.Person (since Student and Person are in the same package, we can omit MyApp from the Extends
statement). The { } (braces) enclose the definition of the class members (of which there are none in this example).
You can specify additional characteristics for this class by defining values for class keywords. This is done by placing a
list of keywords (possibly with values) in [ ] (brackets) immediately following the class declaration (after the class name
and superclass name (if any)).
For example, you can specify that the class as Final and the name of its corresponding SQL table as StudentTable.
Class MyApp.Student Extends Person [Final, SqlTableName=StudentTable]
{
You can also provide a description for this class by placing a description comment (identified by ///, three slashes) imme-
diately before the declaration of the class. This description is used when you view the class documentation via the Caché
online class reference. It may contain HTML markup. Example:
/// This is a simple Student class
/// It is derived from the Person class
Class MyApp.Student Extends Person
{
}
You can use the C-style //, two slashes, and /* */, begin with slash asterisk and end with asterisk slash, comments anywhere
in a class definition to comment out a section of the class definition.
1.3.1.2 Properties
You can define a property in a class definition using the Property keyword:
Class MyApp.Student Extends Person
{
Property GPA As %Float;
}
This example defines a property named GPA with type %Float (specified using As). The end of the property definition is
marked with a final semicolon (;).
As with the class declaration, you can add a description for this property using a preceding /// comment and we can specify
additional property keywords in [ ] brackets:
Class MyApp.Student Extends Person
{
/// Grade Point Average for the Student
Property GPA As %Float [ Required ];
}
If you want to specify parameter values for the property data type (parameters give you a way to customize the behavior
of a property), placed them in ( ), parentheses, as part of the type name. Note that the values for data type parameters are
treated as literal values; enclose strings in quotation marks.
Class MyApp.Student Extends Person
{
/// Grade Point Average for the Student
Property GPA As %Float(MINVAL=0.0, MAXVAL=5.0) [ Required ];
}
1.3.1.3 Methods
You can define a method in a class definition using the Method keyword:
Class MyApp.Student Extends Person
{
/// This method wastes count seconds.
Method WasteTime(count As %Integer=1) As %Boolean [Final]
{
// loop and sleep
For i = 1:1:count {
Write "."
Hang 1
}
Quit 1
}
}
The return type of the method is specified using As followed by a class name. The formal argument list follows the method
name and is enclosed in ( ) (parentheses). The implementation of the method is contained in { } (braces) following the
method declaration.
As with a property, you can use /// (three slashes) comments to specify a description (with HTML markup, if desired) and
additional keyword values are placed in [ ] (brackets).
You can specify the programming language for a method using the Language keyword. For example, the code below defines
a method in Basic:
/// Find the sum of numbers from 1 to <var>count</var>.
Method SumUp(count As %Integer) As %Integer [Language = basic]
{
total = 0
For i = 1 To count
total = total + i
Next
Return i
}
A single class can contain methods that use different languages. Or you can specify the default programming language for
an entire class using the class-level Language keyword.
1.8 Debugging
Caché Studio includes a source-level, GUI debugger. The debugger attaches (or starts up and attaches to) a target process
running on the same Caché server that Studio is connected to. The debugger controls this target process remotely and allows
you to watch variables, step through code, and set breakpoints.
You typically must have a project open in order to use the debugger; the project contains the information needed to start
the debug target (name of a routine, method, CSP page, Zen page, or client application). In addition, the project stores a
list of breakpoints set in a prior debugging session for subsequent reuse.
You may attach and break into a running process without having a project open. In this case Studio does not remember
breakpoint settings from previous sessions. See more about debugging in the chapter “ Using the Studio Debugger.”
Also, you can only connect to a namespace if you have Read or Write permission for its default database.
The way in which a user is granted these various privileges depends on the instance’s security level:
• For an instance with minimal security, all users, including UnknownUser, have all privileges and access to all names-
paces. When presented with the Studio login screen, either leave the Username and Password fields blank or enter
“ _SYSTEM” and “SYS ” as the username-password pair.
• For an instance with normal security, you must be explicitly granted the specified privileges. This is established by
being assigned to a role or roles that holds these privileges.
• For an instance with locked-down security, the service that governs access to Studio (%Service_Bindings) is disabled
by default. By default, no user has access to Studio.
Note: Studio access may also be affected by any changes to default settings that have occurred since installation.
Refer to the %Studio.SourceControl.Base class and the “Using Studio Source Control Hooks ” appendix for more details.
By default, Studio displays the Workspace window and creates a new project called Default_system. The Studio
Workspace window indicates the name of the current project as well as the server connection and namespace name.
The Workspace window should be displayed by default; if you don't see it, display it using the View > Workspace or
with the Alt-3 keyboard accelerator.
3. To save the new project, use the File > Save Project As and enter Phone Book.
You can save this project to the Caché server at any time using the File > Save Project.
You see a Class Editor window containing the definition of your new class:
Class PhoneBook.Person Extends %Persistent
{
}
Add a PhoneNumber property to the class definition in the same way as you did the Name property by running the New
Property wizard again. You could have also added this new property by copying, pasting, and modifying the Name property
directly into the Class Editor window. Items are indented to structure the code to improve readability. A plus/minus
expansion box is provided to the left of each item so that you can collapse sections of the code that you are not currently
looking at.
Class PhoneBook.Person Extends %Persistent [ ClassType=Persistent ]
{
Property Name As %String;
Property PhoneNumber As %String;
}
2. A CSP Editor window is displayed containing source for the new CSP page entitled Unititled.csp. Click File > Save. In
the Save As dialog, double-click /csp/user to open this directory, enter Person.csp, and click Save As.
3. In the editor window, position the cursor in the <BODY> section of the CSP source file. Delete the words “ My page
body.” Select Tools > Templates > Web Form Wizard.
4. Select the PhoneBook.Person class and click Next.
5. Click the Name and PhoneNumber properties from the list of available properties. They should appear in the Selected
Properties list.
6. Click Finish.
Studio displays the HTML source for a bound form in the CSP Editor window:
<html>
<head>
</head>
<body>
<!-- Put your page code here -->
<head>
<title>Cache Server Page - PhoneBook.Person (USER)</title>
</head>
<h1 align='center'>PhoneBook.Person</h1>
<!-- This function is needed by the search button on the form -->
<script language='javascript'>
<!--
function update(id)
{
#server(..formLoad(id))#;
return true;
}
// -->
</script>
<!-- use CSP:OBJECT tag to create a reference to an instance of the class -->
<csp:object name='objForm' classname='PhoneBook.Person' OBJID='#(%request.Get("OBJID"))#'>
<!-- use csp:search tag to create a javascript function to invoke a search page -->
<csp:search name='form_search' classname='PhoneBook.Person' where='%Id()' options='popup,nopredicates'
onselect='update'>
To learn more about using CSP to create Web pages, see the book Using Caché Server Pages (CSP).
3. Find the Super keyword and click on it to highlight it. The field currently holds the class name %Persistent. An ellipsis
button (...) appears at the right of this field. Click on it. This opens a dialog in which you can choose superclasses in
addition to %Persistent.
4. In the left-hand column of the dialog, navigate to the %ZEN.DataModel.Adaptor class and select it. At the center of the
dialog, click the > button. The %ZEN.DataModel.Adaptor class name now appears in the right-hand column underneath
%Persistent.
5. Click OK.
6. Save and compile the PhoneBook.Person class.
5. The wizard prompts you to select an initial page layout. Click Title Page. Then click Finish.
6. The Zen Page Wizard creates and displays a skeletal Zen page with pre-defined class parameters and the XML blocks
XData Style and XData Contents. You do not need to study this code in detail, but be aware of the location of XData
Contents in the class. You will be editing this XML block to add items to your new Zen page:
XData Contents [XMLNamespace="http://www.intersystems.com/zen"]
{
<page xmlns="http://www.intersystems.com/zen" title="">
<html id="title">Title</html>
<vgroup width="100%">
<!-- put page contents here -->
</vgroup>
</page>
}
7.
Save and compile the class by choosing Build > Compile or Ctrl-F7 or the Compile icon .
8.
View the Web page by choosing View > Web Page or the View Web Page icon . At this point, the only item visible
in the browser is the text displayed by the <html> element:
If you examine the XData Contents block above, you will see that the <html> element provides an id="title"
attribute. id="title" refers to the style definition #title that appears in the XData Style block in the same Zen
page class. #title determines the background color, layout, and font choices that you see when you view the page.
The default XData Style block for the Title Page layout looks like this:
XData Style
{
<style type="text/css">
/* style for title bar */
#title {
background: #C5D6D6;
color: black;
font-family: Verdana;
font-size: 1.5em;
font-weight: bold;
padding: 5px;
border-bottom: 1px solid black;
text-align: center;
}
</style>
}
9. Edit the text contents of the <html> element to provide a more meaningful title:
<html id="title">My Telephone Book</html>
10. Save and compile the class, then view the Web page. It should look like this:
All you need to do is position the cursor between <vgroup> and </vgroup> and begin typing.
After you type the character < the Studio Assist feature prompts you to choose from a list of all elements. Typing <d
brings you to the part of the list that includes <dataController> and <dynaForm>. Double-click on one of the choices
to select it. Then type a space character and Studio Assist prompts you to choose from a list of attributes appropriate
for that element. You can continue in this manner until you have entered the entire line.
Alternatively, if you are viewing this document online, you may cut and paste the <dataController> and <dynaForm>
lines from the example above.
3. Provide two <button> elements in XData Contents, exactly as shown below:
You can type the new elements, or if you are viewing this document online, for convenience you may cut and paste
the <button> lines from this example.
4. Save and compile the class, then view the Web page. It should look like this:
5. If you are curious about clicking the buttons New and Save, try it. An error message displays. Click OK to dismiss it.
To understand why you saw an error message when you clicked the buttons, look carefully at the values of the onclick
attribute for each <button> element in XData Contents. Each onclick value is a JavaScript expression that executes
automatically whenever the button is clicked.
In these examples, the onclick expression invokes a method that runs in JavaScript on the client. The special variable
zenPage indicates that the method is defined in the current Zen page class. The methods themselves are called
newRecord and saveRecord.
In order to make these onclick values work, you must create client-side JavaScript methods in the Zen page class. This
is quite simple to do using the Zen Method Wizard in Studio.
4. Change the code within curly brackets so the method now looks like this:
/// Create a new instance of the controller object.
Method newRecord() [Language = JavaScript]
{
var controller = zenPage.getComponentById('source');
controller.createNewObject();
}
5. Repeat the above steps to add the saveRecord method. When using the Zen Method Wizard, enter values in the dialog
as follows:
• Enter the Method Name saveRecord
• Choose is an instance method
• Choose runs on the client
• Provide a Description.
• Clear the Try/Catch check box.
• Click Finish. Your new method appears in the page class.
6. Save and compile the class, then view the Web page.
7. Click the New button on the page. The Name and PhoneNumber fields become empty so that you can enter new
information for the next entry. After you have typed in each field, click the Save button. The new entry is saved in the
database.
8. Use New and Save repeatedly to add more entries.
The <tablePane> sql attribute provides an SQL statement. SELECT lists the two properties from your PhoneBook.Person
class, and FROM provides the full package and class name. This SQL query provides the data for the <tablePane>.
3. Save and compile the class, then view the Web page.
4. Use New and Save to add more entries to the database.
5. Click the browser refresh button to view the updated table. The new entries are visible.
6. Remove the need for the user to refresh after each new entry, by refreshing the table automatically after each save. To
accomplish this, add two lines to the saveRecord method, so that it looks like this:
/// Save the current instance of the controller object.
Method saveRecord() [Language = JavaScript]
{
var form = zenPage.getComponentById('MyForm');
form.save();
var table = zenPage.getComponentById('people');
table.executeQuery();
}
7. Save and compile the class, then view the Web page. It should look like this:
8. Use New and Save to add more entries to the database. Each time you click Save, the saveRecord method updates the
table so that the newest entry becomes visible.
You can use all of these techniques interchangeably; Studio automatically ensures that all of these representations are
synchronized.
This chapter discusses general aspects of creating class definitions. Most of the following chapters in this book describe
how to create class members, such as properties, methods, parameters, and so forth.
Note: You must have an open project before you can work with class definitions in the Caché Studio. When working
with class definitions, Studio performs numerous interactions with the Caché server (such as for providing lists
of classes, class compiling, etc.). Internally, Studio uses projects to manage the details of this server interaction.
Package Name
Package to which the new class belongs. You can select an existing package name or enter a new name. If you
enter a new name, the new package is automatically created when you save your class definition.
For more information on packages see the chapter “Packages ” in Using Caché Objects.
Class Name
Name of your new class. This must be a valid class name and must not conflict with the name of a previously
defined class. Note that you cannot change this class name later.
For specifics of class naming conventions in Caché, see the section “Naming Conventions” in Using Caché
Objects.
Description
(optional) Description of the new class. This description is used when the class' documentation is displayed in the
online class library documentation.
A description may include HTML formatting tags. For more details see the section “Using HTML in Descriptions”
in the “ Class Definition Syntax ” appendix in this book.
Persistent
Create a definition for a persistent class. Persistent objects can be stored in the database.
Serial
Create a definition for a serial class. Serial objects can be embedded in persistent objects to create complex data
types such as addresses.
Registered
Create a definition for a registered class. Registered objects are not stored in the database.
Abstract
Create a definition for an abstract class with no superclass.
Datatype
Create a definition for a data type class. A data type class is used to create user-defined data types.
Extends
Extend an existing class: check Extends and enter (or choose from a list) the name of an existing superclass.
SQL Category
The SQL Category used by the Caché SQL Engine when it performs logical operations on this data type.
Owner
(optional) For a persistent class, enter the SQL user name to be the owner of the new class. This user name controls
privileges when this class is used via SQL. If this field is left blank, then the default owner, _system, is used.
XML Enabled
(optional) If selected, the class is XML-enabled; that is, it has the ability to project itself as an XML document. It
can also be used in Web Service methods. This is equivalent to adding the %XML.Adaptor class to the class'
superclass list.
For more information see Using XML with Caché as well as Using SOAP and Web Services with Caché.
Data Population
(optional) If you select this option, your new class supports automatic data population. This is equivalent to adding
the %Library.Populate class to the class' superclass list.
Automatic data population allows you to easily create random data with which you can test the operation of your
class. To populate a class, compile it and then execute the class' Populate method (inherited from the
%Library.Populate class). For example, using the Caché terminal:
Do ##class(MyApp.Person).Populate(100)
For more information see the chapter “Caché Data Population Utility ” in Using Caché Objects.
MultiValue Enabled
The created class inherits from %MV.Adaptor, such that the class uses MV storage and the data appears as a “file”
to MultiValue programs and queries.
Content Type
Specifies what the content type served by this CSP class is. The available options are HTML or XML. This option
is used to set the value of the CONTENTTYPE parameter of the new class to text/html or text/xml respectively.
You can later change this to whatever value you want.
You can save this class definition in the Caché database, add class members such as properties or methods, or edit the class
definition using the Class Inspector.
Note: By default, the New Class wizard creates classes that use Caché ObjectScript for method code. You can change
this default value to Basic with Tools > Options dialog, Environment, General tab.
If the class definition you want to open is currently being edited by someone else, you are asked if you want to open the
class definition for read-only access.
For a list of class keywords and their meanings, see Caché Classes. For details on class definitions see the Class Definition
Language reference.
To delete a class definition, in the Workspace window, select a class and select Edit > Delete. The class and all of its generated
files are deleted.
Note: You can control how classes are compiled using options on Tools > Options dialog, Compiler tab).
When a full (non-incremental) compilation is performed, all of the extra routines containing incrementally compiled
methods are removed. Perform a full compilation on all classes before deploying an application to avoid having extra routines.
1. Member Selector: Controls which set of keywords are displayed. You can choose to view either the Class-wide keywords
or the keywords for a specific class member (such as properties or methods).
2. Item Selector: Controls which specific class member is displayed (such as a particular property). The contents of the
list depend on the value of the Member Selector. Selecting (Summary) displays a list of all the members of the type
specified by the Member Selector.
3. Keywords: Lists the keywords for the current class or class member selected by the Member and Item Selectors.
Highlighting a keyword displays its description and allows editing (click Edit at the right of the value or directly edit
the value). Keywords whose value was set explicitly (not inherited or set by default) are shown in bold.
4. Values: Lists the values of keywords displayed in the keyword list. Values modified since the last time the class defi-
nition has been saved are displayed in blue.
When the Class Inspector is activated its background turns white and its contents are updated to reflect the current class
definition. If you modify any keyword values using the inspector, the corresponding Class Editor window becomes inactive
(turn gray). When you are finished with the inspector, click the original Class Editor window. It becomes active and display
the result of the modifications you made using the Class Inspector.
If you right-click in the Class Inspector, it displays a popup menu allowing you to perform operations such as adding new
class members.
For more information on class packages see the chapter “Packages” in Using Caché Objects.
To add a property using the Class Editor, position the cursor on a blank line in the Class Editor and enter a property decla-
ration:
Class MyApp.Person Extends %Persistent [ClassType = persistent]
{
Property Name As %String;
Property Title As %String;
}
Alternatively, copy an existing property declaration, paste it into a new location, and edit it.
For details on property definitions see the “Class Definition Syntax ” appendix.
Property Name
(required) Name of the new property. This name must be a valid property name and must not conflict with the
name of a previously defined property.
For a general discussion on names see the chapter “Caché Classes ” in Using Caché Objects.
Description
(optional) Description of the new property. This description is used when the class' documentation is displayed
in the online class library documentation.
A description may include HTML formatting tags. For more details see “Using HTML in Descriptions ” in the
“ Class Definition Syntax” appendix.
Single Valued
A single-valued property is just that; it contains a single value. A single-valued property has a type associated
with it. This type is the name of a Caché class. If the class used as a type is a data type class, then the property is
a simple literal property; if it is a persistent class, then the property is a reference to an instance of that class; if it
is a serial class, then the property represents an embedded object.
You can enter a class name directly or choose from a list of available classes, including streams, using the Browse
button.
For a description of the basic data type classes provided with Caché, see the chapter “Data Types ” in Using Caché
Objects.
Collection
A collection property contains multiple values. There are two collection types, List (a simple, ordered list) and
Array (a simple dictionary with elements associated with key values). As with a single-valued property, a collection
property also has a data type. In this case, the data type specifies the type of the elements contained in the collection.
Relationship
A relationship property defines an association between two objects. For more details on relationships, see the
chapter “Adding Relationships to a Class ” in this book.
Required
(optional) This is only relevant for persistent or serial classes. Specifies that this property is required (NOT NULL
in SQL terminology). For persistent or serial objects a required property must be given a value or any attempt to
save the object fails.
Indexed
(optional) This is only relevant for persistent classes. Specifies that an index should be created based on this
property. This is equivalent to creating an index based on this field.
Unique
(optional) This is only relevant for persistent classes. Specifies that the value of this property must be unique in
the extent (set of all) objects of this class. This is equivalent to creating a unique index based on this field.
Calculated
(optional) A calculated property has no in-memory storage allocated for it when an object instance is created.
Instead, you must provide accessor (Get or Set) methods for the property. If you choose this option, the New
Property wizard can generate an empty Get accessor method for you.
If you want to make further modifications to this property you can do this using either the Class Editor or the Class
Inspector.
To add a method using the Class Editor, position the cursor on a blank line in the Class Editor and enter a method declaration:
Class MyApp.Person Extends %Persistent [ClassType = persistent]
{
Method NewMethod() As %String
{
Quit ""
}
}
Alternatively, you can do this by copying and pasting an existing method declaration and then editing it.
For details on method definitions see the Class Definition Syntax appendix.
Method Name
(required) Name of the new method. This name must be a valid method name and must not conflict with the name
of a previously defined method.
For a general discussion on names see the chapter “Caché Classes ” in Using Caché Objects.
Description
(optional) Description of the new method. This description is used when the class' documentation is displayed in
the online class library documentation.
A description may include HTML formatting tags. For more details see the section “Using HTML in Descriptions”
in the appendix “Class Definition Syntax ” in this book.
Return Type
(optional) Indicates the type of the value returned by this method. This type is the name of a Caché class. You can
type this name in directly or choose from a list of available classes using the Browse button.
For example, a method that returns a true (1) or false (0) value would have a return type of %Boolean. Leave this
field empty if your new method has no return value.
For a description of the basic data type classes provided with Caché see the chapter “Data Types” in Using Caché
Objects.
Arguments
(optional) Indicates the names, types, default values, and how data is passed (by reference or by value) for any
formal arguments. The arguments are displayed in order in a table. You can add a new item to the argument list
using Add located on the side of the table. This displays a popup dialog allowing you to specify the name of the
argument, its type, its optional default value, and whether it is passed by value or by reference. Using the other
buttons, you can remove and rearrange the order of items in the list.
Private
(optional) Indicates whether this method is public or private. Private methods may only be invoked from other
methods of the same class.
Final
(optional) Indicates whether this method is final. Final methods cannot be overridden by subclasses.
Class Method
(optional) Indicates that the new method is a class method (as opposed to an instance method). Class methods may
be invoked without having an object instance.
Language
Indicates the language used to create the method.
At this point, you can use the Class Editor to add code to the body of the method.
To add a method using the Class Editor, position the cursor on a blank line in the Class Editor and enter a class parameter:
Parameter P1 = "x";
Name
(required) Name of the class parameter. This name must be a valid parameter name and must not conflict with the
name of a previously defined parameter.
For a general discussion on names see the chapter “Caché Classes ” in Using Caché Objects.
Description
(optional) Description of the new class parameter. This description is used when the class' documentation is displayed
in the online class library documentation.
A description may include HTML formatting tags. For more details see the section “Using HTML in Descriptions”
in the “ Class Definition Syntax ” appendix.
Default
Default value for the class parameter. This will be the default value for this parameter for all instances of this
class.
To add a relationship using the Class Editor, position the cursor on a blank line in the Class Editor and enter a relationship
declaration:
Class MyApp.Company Extends %Persistent [ClassType = persistent]
{
Relationship TheEmployees As Employee [cardinality=many, inverse=TheCompany];
}
A relationship definition must specify values for both the cardinality and inverse keywords.
As this relationship has two sides, also enter the inverse relationship in the class definition of Employee:
Class MyApp.Employee Extends %Persistent [ClassType = persistent]
{
Relationship TheCompany As Company [cardinality=one, inverse=TheEmployees];
}
If the two sides of the relationship do not correctly correspond to each other, there are errors when you try to compile.
The New Property wizard prompts you for information. The procedure is identical to creating a new, non-relationship
property except that you specify Relationship on the property type.
Property Name
(required) Name of the relationship. This name must be a valid relationship (property) name and must not conflict
with the name of a previously defined relationship or property.
For a general discussion on names see the chapter “Caché Classes ” in Using Caché Objects.
Description
(optional) Description of the new relationship. This description is used when the class' documentation is displayed
in the online class library documentation.
A description may include HTML formatting tags. For more details see Using HTML in Descriptions in the Class
Definition Language reference.
7.1.5 Results of Creating a New Relationship with the New Property Wizard
After creating a new relationship with the New Property wizard, the Class Editor window is updated to include the new
relationship definition. For example:
/// This is an Employee class
class MyApp.Employee extends %Persistent [ClassType = persistent]
{
If you want to make further modifications to this relationship, you can do this using either the Class Editor or the Class
Inspector.
Additionally you can use the Modify Relationship wizard, which has the advantage of automatically determining the changes
required to the inverse of a relationship.
You can invoke the Modify Relationship wizard by following these steps:
1. Display the list of properties in the Class Inspector
2. Right-click the desired relationship in the list of properties and click Add/Modify Relationship command from the pop-
up menu.
The %SQLQuery class automatically provides an implementation of the query interface. The %Query class does not; the
query definition merely provides a query interface; you must write methods to implement the actual query functionality.
You can add a new query to a class definition in two ways:
• Edit the class definition using the Class Editor.
• Using the New Query wizard
To add a query using the Class Editor, position the cursor on a blank line in the Class Editor and enter a query declaration:
Class MyApp.Person Extends %Persistent [ClassType = persistent]
{
Property Name As %String;
Alternatively, you can copy and paste an existing query declaration and then edit it.
For a general introduction to queries, see the chapter “Queries ” of Using Caché Objects. For details on query definitions,
see the Class Definition Language reference.
, in the toolbar.
Click Finish at any time; default values are provided for any information you have not specified.
Query Name
(required) Name of the new query. This name must be a valid query name and must not conflict with the name of
a previously defined query.
For a discussion of names, see the chapter “Caché Classes ” in Using Caché Objects.
Implementation
(required) You must specify if this query is based on an SQL statement (which the wizard generates for you) or
on user-written code (in which case you have to provide the code for the query implementation).
Description
(optional) Description of the new query. This description is used when the class documentation is displayed in the
online class library documentation.
A description may include HTML formatting tags. For more details see Using HTML in Descriptions in the Class
Definition Language reference.
You can build a set of conditions by selecting values from the set of combo boxes. The expression box can contain an
expression (such as a literal value) or a query argument (as an SQL host variable with a prepended : colon character).
If you want to make further modifications to this query you can do this using either the Class Editor or the Class Inspector.
If you specified a user-written query, the Class Editor contains both the new query definition as well as skeletons of the
query methods you are expected to implement:
Class MyApp.Person Extends %Persistent [ClassType = persistent]
{
// ...
ClassMethod MyQueryClose(
ByRef qHandle As %Binary
) As %Status [ PlaceAfter = MyQueryExecute ]
{
Quit $$$OK
}
ClassMethod MyQueryExecute(
ByRef qHandle As %Binary,
ByVal aaa As %Library.String
) As %Status
{
Quit $$$OK
}
ClassMethod MyQueryFetch(
ByRef qHandle As %Binary,
ByRef Row As %List,
ByRef AtEnd As %Integer = 0
) As %Status [ PlaceAfter = MyQueryExecute ]
{
Quit $$$OK
}
Query MyQuery(
ByVal aaa As %Library.String
) As %Query(ROWSPEC = "C1,C2")
{
To add an index using the Class Editor, position the cursor on a blank line in the Class Editor and enter an index declaration:
Index NameIndex On Name;
Alternatively, copy and paste an existing index declaration and then edit it.
For details on index definitions see the Class Definition Language reference.
Index Name
(required) Name of the new index. This name must be a valid index name and must not conflict with the name of
a previously defined index.
For a discussion of valid names, see the chapter “ Caché Classes” in Using Caché Objects.
Description
(optional) Description of the new index. This description is used when the class' documentation is displayed in
the online class library documentation.
A description can include HTML formatting tags. For details, see the section “Using HTML in Descriptions” in
the “Class Definition Syntax” appendix of this manual.
Normal Index
A normal index is used for indexing on property values. You can further qualify a normal index by selecting one
of the following:
Unique Index The set of properties associated with this index must have a combined value
that is unique in the extent of objects of this class.
IDKEY The set of properties associated with this index are used to create the Object
ID value used to store instances of this class in the database.You cannot modify
the values of properties that are part of an IDKEY definition once an object has
been saved. IDKEY implies that the property or properties are unique (as with
a Unique Index).
SQL Primary The set of properties associated is reported as the SQL Primary Key for the
Key SQL table projected for this class. This implies that the property or properties
are unique (as with a Unique Index).
Extent Index
An extent index is used to keep track of which objects belong to a specific class in a multiclass extent of objects.
It differs from a so-called normal index in that you cannot specify additional characteristics for it.
You can also select how the index is physically implemented in the database:
Standard Index
This index is a traditional cross-index on the specified property or properties.
Bitmap Index
A bitmap index uses a compressed representation of a set of object ID values that correspond to a given indexed
value. See Bitmap Indices in Using Caché SQL for more information.
Bitslice Index
A bitslice index is a specialized form of index that enables very fast evaluation of certain expressions, such as
sums and range conditions. Bitslice indices are currently automatically used in certain Cache SQL queries. Future
versions of Cache SQL will make further use of bitslice indices to optimize additional queries.
You can edit the index definition with either the Class Editor or the Class Inspector.
Class Description
%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.
%Projection.EJBFlexible Generates the appropriate external files required by a generic EJB Server for the Caché
EJB Binding for the associated class.
%Projection.EJBJBoss Generates a set of Enterprise Java Bean client classes to enable access to the class from
an JBoss EJB server. In addition, any other files, such as deployment descriptors are
created.
%Projection.EJBPramati Generates a set of Enterprise Java Bean client classes to enable access to the class from
an Pramati EJB server. In addition, any other files, such as deployment descriptors are
created.
%Projection.EJBWebLogic Generates a set of Enterprise Java Bean client classes to enable access to the class from
an WebLogic EJB server. In addition, any other files, such as deployment descriptors are
created.
%Projection.Java Generates a Java client class to enable access to the class from Java.
%Projection.Monitor Registers this class as a routine that works with Cache Monitor. Metadata is written to
Monitor.Application, Monitor.Alert, Monitor.Item and Monitor.ItemGroup. A new persistent class is
created called Monitor.Sample.
Class Description
%Projection.MV Generates an MV class that enables access to the class from MV.
%Projection.StudioDocument Registers this class as a routine that works with Studio.
%Projection.XML Generates an XML class that enables access to the class from XML.
%Studio.Extension.Projection Projects the XData 'menu' block to the menu table.
%ZEN.Object.Projection Projection class used by %ZEN.Component.object classes. This is used to manage
post-compilation actions for Zen components.
%ZEN.PageProjection Projection class used by %ZEN.Component.page. Currently this does nothing.
%ZEN.Tempa
l te.Tempa
l teProe
j co
tin Projection class used by %ZEN.Templage.studioTemplate class.
You can also create your own projection classes and use them from Studio as you would any built-in projection class.
You can add a new projection to a class definition in two ways:
• Editing the class definition using the Class Editor.
• Using the New Projection wizard
To add a projection using the Class Editor, position the cursor at a blank line and enter a projection declaration:
Projection MyProjection As %Projection.XML;
Alternatively, you can copy and paste an existing projection declaration and then edit it.
For details on projection definitions, see the Class Definition Language reference.
Projection Name
(required) 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) Description of the new projection.
Projection Type
Name of a projection class whose methods are executed 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.
To edit this projection definition, use either the Class Editor or the Class Inspector.
To add an XData block using the Class Editor, position the cursor at a blank line and enter an XData declaration:
XData ProductionDefinition
{
<Production>
<ActorPoolSize2/ActorPoolSize>
</Production>
}
Alternatively, you can copy and paste an existing XData block and then edit it.
XData Name
(required) Name of the new XData. This name must be a valid name and must not conflict with the name of a
previously defined XData.
Description
(optional) Description of the new XData.
To specify an SQL table name for a class, view the Class information in the Class Inspector and edit the value for the
SqlTableName keyword.
To specify an SQL name for a class member, select the desired property in the Class Inspector and edit the value for its
appropriate SQL name keyword (such as SqlFieldName for properties and SqlName for indices).
You can invoke this stored procedure from an ODBC or JDBC client using a CALL statement:
CALL Employee_ListEmployees()
Following this call, the ODBC or JDBC application can fetch the contents of the result set returned by the class query.
Note that you can use this same technique with query definitions that are based on custom-written code; you are not limited
to defining stored procedures solely based on SQL statements.
ClassMethod Authenticate(
ctx As %SQLProcContext,
name As %String,
ByRef approval As %Integer
) [SqlProc]
{
// ...
Quit
}
Note that the first argument of a method used as an SQL stored procedure is an instance of a %SQLProcContext object. For
more information, see the chapter “Defining and Using Stored Procedures ” in Using Caché SQL.
You can invoke this stored procedure from an ODBC client using a CALL statement:
CALL Employee_Authenticate('Elvis')
To invoke this stored procedure from a JDBC client, you can use the following code:
prepareCall("{? = call Employee_Authenticate(?)}")
To add an SQL trigger using the Class Editor, position the cursor on a blank line in the Class Editor and enter a trigger
declaration:
Class MyApp.Company Extends %Persistent [ClassType = persistent]
{
/// This trigger updates the Log table for every insert
Trigger LogEvent [ Event = INSERT ]
{
// ...
}
The New SQL Trigger wizard prompts you for information. Click Finish at any time (default values are provided for any
information you have not specified).
Trigger Name
(required) Name of the trigger. This name must be a valid trigger name and must not conflict with the name of a
previously defined trigger.
Description
(optional) Description of the new trigger. This description is used when the class' documentation is displayed in
the online class library documentation.
Event Type
This specifies which SQL event fires the trigger. The choices are Insert (when a new row is inserted), Update
(when a row is updated), or Delete (when a row is deleted).
Event Time
This specifies when the trigger is fired. The choices are Before or After the event occurs.
To add an SQL foreign key using the Class Editor, position the cursor on a blank line in the Class Editor and enter a foreign
key declaration:
Class MyApp.Company Extends %Persistent [ClassType = persistent]
{
Description
(optional) Description of the new foreign key. This description is used when the class' documentation is displayed
in the online class library documentation.
A description can include HTML formatting tags. For more details see Using HTML in Descriptions in the Class
Definition Language reference.
Note: Storage definitions are a fairly advanced feature of Caché objects. In most cases, you do not need to work with
storage definitions; the Caché class compiler automatically creates and manages storage definitions for persistent
objects.
If you use storage definitions, you typically work with them in the following cases:
• You need detailed control over the storage used by a persistent object, perhaps for performance tuning.
• You are mapping an object definition on top of a preexisting data structure.
A class can have any number of storage definitions, though only one can be used at one time. A new class does not have
a storage definition until either you first a) save and compile the class, or, b) you explicitly add one. You can add a new
storage definition to a class using Class > Add > New Storage.
Note: Compiling a class automatically generates its storage definition. Only persistent and serial classes have storage
definitions.
Within Studio, you can view and edit the storage definition(s) for a class in two different ways:
• Visually, using the Storage Inspector in the Class Inspector window: select Storage in the Class Inspector and click
the desired storage definition.
• Textually, using the Class Editor window: use View > View Storage to display the storage definition in the body of the
class definition.
Storage Name
(required) Name of the new storage definition. This name must be a valid class member name and must not conflict
with the name of a previously defined storage definition.
Storage Type
(required) Type of storage used by this storage definition. The type specifies which storage class is responsible
for implementing the storage interface for this class. The choices are:
• Caché Storage—this storage definition is based on the %CacheStorage class. This is the default storage type
used for new persistent classes.
• Caché SQL Storage—this storage definition is based on the %CacheSQLStorage class. This storage type uses
SQL statements to perform storage operations. This storage type is used for mapping objects to existing data
structures or to talk to remote RDBMS via the Caché SQL Gateway.
• Custom Storage—this storage definition is based on a user-defined storage class.
Description
(optional) Description of the new storage definition.
A description can include HTML formatting tags. For more details see Using HTML in Descriptions in the Class
Definition Language reference.
DataLocation
Name of the global as well as any leading subscripts used to store instances of the persistent class. For example,
to specify that data should be stored in the global ^data, enter ^data in this field. To specify that data should be
stored in the global subnode ^data("main"), enter ^data("main").
IndexLocation
Name of the global as well as any leading subscripts used to store index entries for the persistent class. By default,
indices are stored in the Index Reference global with an additional subscript based on the Index name. You can
override this on an index-by-index basis.
IdLocation
Name of the global as well as any leading subscripts used to contain the default object ID counter. The object ID
counter is used to maintain the ID number of the next object instance of this type.
At this point, the Class Inspector displays storage keywords along with their values.
Data Nodes
Represents the set of data mappings used by the %CacheStorage storage class. The Data Nodes editor, which you
can invoke by double-clicking on the Data Nodes keyword, allows you to view and edit the set of data node
specifications for the storage definition: that is, you can directly specify how your class' properties are stored in
global nodes.
A storage definition is displayed as an in-line XML island in the body of the class definition using the same XML elements
that are used in the external, XML-representation of a class definition.
For example, suppose you have a simple persistent MyApp.Person class:
/// A simple persistent class
Class MyApp.Person Extends %Persistent [ ClassType = persistent ]
{
Property Name As %String;
Property City As %String;
}
After compiling this class (to ensure that the class compiler has created a storage definition for it), you can display its
storage definition using the View > View Storage. This results in following display in the Class Editor window:
/// A simple persistent class
Class MyApp.Person Extends %Persistent [ ClassType = persistent ]
{
<Storage name="Default">
<Data name="PersonDefaultData">
<Value name="1">
<Value>City</Value>
</Value>
<Value name="2">
<Value>Name</Value>
</Value>
</Data>
<DataLocation>^MyApp.PersonD</DataLocation>
<DefaultData>PersonDefaultData</DefaultData>
<IdLocation>^MyApp.PersonD</IdLocation>
<IndexLocation>^MyApp.PersonI</IndexLocation>
<Type>%Library.CacheStorage</Type>
</Storage>
}
The XML storage definition includes all the defined storage keywords and their corresponding values represented as XML
elements.
You can directly edit this definition in the Class Editor as you would any other part of the class definition. If you enter
invalid XML syntax the editor colors it as an error.
The storage definition can be useful in cases where you need to do simple or repetitive modifications.
For example, suppose you want to change the name of a property City to HomeCity, while preserving the physical storage
layout (that is, you want the new property name to access the values stored with the old name). You can do this using the
Class Editor as follows:
1. Load the class definition into a Studio Class Editor window and display its storage.
2. Use the Editor's Replace command to replace all occurrences of the property City with HomeCity. You must be careful
to only change those occurrences of City that represent the property name (such as in the property definition, method
code, descriptions, and in the body of the storage definition); do not replace the values of any class definition keywords.
3. Save and recompile the class definition.
4. Save the page with File > Save. The Save As dialog appears. Within the dialog, double-click the CSP application
/csp/samples (this is the directory in which we are going to save this CSP page) and then enter Sample.csp in the Filename
box. Click Save As.
5. Compile the page with Build > Compile .
6. View the resulting Web page from a browser with View > Web Page.
At this point, you should see a very simple Web page containing the words My Sample CSP Page in your browser.
To make this example more interesting, we can add an SQL query to the page that executes when the page is requested:
1. Position the cursor in the CSP Editor window at the start of the blank line after My Sample CSP Page.
2. Select Insert > SQL Query. In the dialog that appears enter the following SQL query:
Now your CSP page displays a list of names and social security numbers in an HTML table.
The templates are in theCSP/samples directory in the installation directory . To view a sample, open a file in Studio, such
as zipcode.csp and then select View > Web Page. The Web Form Wizard is available in the Tools > Templates > Templates
menu.
You can open a URL Viewer window using the File > Open URL and entering a URL in the resulting dialog.
To try this with a CSP sample page, do the following:
1. Select File > Open URL.
2. If you have a Web server on your local system, enter http://localhost/csp/samples/custom.csp
If you do not have a Web Server on your local system, use the test HTTP server on the 8972 port (or the port number
your system is configured for): http://localhost:8972/csp/samples/custom.csp
At this point, you sees the HTML returned by the custom.csp page displayed in a syntax-coloring window.
Note: You can use the URL viewer to view syntax-colored source for any Web page on the internet.
By default, when you create a new Caché ObjectScript routine, it is saved as a .mac routine. Select File > Save As to save
this as a different type of routine (changing the extension from .mac to .inc for example).
Select View > View Other to display .int code corresponding to a given .mac file and vice versa.
You can connect the debugger to a target process in one of the following ways:
• Define a debug target (name of program, routine, or Zen or CSP page to debug) for the current project using Project
> Settings > Debugging > Debug Target (or Debug > Debug Target). Then select Debug > Go to start the target program
and connect to its server process.
• Select Debug > Attach and choose a running process on a Caché server.
Sometimes using command-line debugging with the zbreak command can give you better control. For more information
on zbreak, see the chapter “Command-Line Routine Debugging ” in Using Caché ObjectScript.
Main() PUBLIC {
Set a = 10
For i = 1:1:10 {
Set b = i
Write b," "
}
}
4. Save and compile the new routine as MyTest.MAC using File > Save As.
5. Define a debug target for the project by selecting the Debug > Debug Target tab, selecting Class Method or Caché
Routine, and entering the name of the entry point in your new routine, Main^MyTest.
6. Set a breakpoint in the routine: Position the cursor anywhere on the line Set a = 10 and press F9, the Toggle
Breakpoint key. A breakpoint indicator appears in the left margin, .
7. Select Debug > Go to begin debugging. When the debugger stops at your breakpoint, the next command to be executed
is outlined with a yellow box. The INT file opens in a new window (if you enabled the Keep Generated Source
Code option, on the Tools > Options dialog, Compiler, General Flags tab).
8. Enter b and a (as Watch points) into the Watch window (View > Watch) so that you can watch the values.
9. Step through execution of the program by repeatedly selecting Debug > Step Into (F11) and notice the b value change.
You can stop debugging by stepping to the end of the program or by selecting Debug > Stop.
16.2.2 Breakpoints
A project maintains a list of breakpoints that you set with F9. When you start debugging a project's debug target (with
Debug > Go), the breakpoints defined by the project are set in the target process.
To view breakpoints, select Debug > Breakpoints > View Breakpoints. To add and remove breakpoints, place the cursor at
the breakpoint location and select Debug > Breakpoints > Toggle Breakpoint or F9. You can also add or remove breakpoints
using Project > Settings > Debugging > Breakpoints.
Note: 20 is the maximum number of breakpoints that can exist in a routine. If more than 20 breakpoints are set, the
Debugger displays <ROUTINELOAD>^%Debugger.System.1 and halts debugging.
Restart Halts execution of the target process, restarts it, and resumes
debugging (as if the Go command was used).
Break Pauses execution of the target process (that is, if the debugger
is attached to a target process that is currently running, not
stopped).
Step Into Executes the current command in the target process and stops
on the next command, stepping into any function calls or
loop bodies.
Step Over Execute the current command in the target process and stops
on the next command. The debugger steps over any function
calls or code blocks (such as loops) it encounters; it stops on
the command following the function call or code block.
You can also change the value of a variable in the target process by entering a new value in the Value column of the Watch
Window.
Studio comes with a set of Caché-supplied standard Studio templates. In addition, you can create your own custom templates
using CSP.
Note: To ensure that Studio templates open quickly, disable the automatic detection of proxy settings in Internet Explorer.
1. Open Internet Explorer and click Tools > Internet Options and the Connections tab.
2. Click LAN Settings and uncheck any checked boxes. Make sure nothing on this page is checked and then
click OK twice to close the Internet Options dialog.
Any text that is highlighted when you open a template is replaced by the template. Many templates use the currently high-
lighted text as input to the template program.
Note: By default, Studio templates use a session timeout of 90 seconds. If you are entering data into a Studio template,
the session ends after 90 seconds of no user input. For more information, see the section “Default Timeout ”
below.
17.2.1 Templates
This section contains three tables defining the templates available in Studio for use with CSP or Zen:
Table 17–1: CSP Templates
Template Description
HTML Color Select to insert an HTML color value string (such as #F0F0F0) at the cursor point.
HTML Input Select to insert an HTML input control at the cursor point.
HTML Script Select to insert a <SCRIPT> tag at the cursor point, with the specified language and
content.
HTML Table Select to insert an HTML table at the cursor point with the specified characteristics.
Select Preview to display a preview window.
HTML Tag Select to insert an HTML tag at the cursor point, selected from a list with specified
attributes. Or if you highlight an existing HTML tag and then invoke the template, you
can edit the displayed attribute values.
Template Description
SQL Statement Select to insert code for a specified SQL Statement at the cursor point. Select Preview
to see test results of the table (using data in the database) in a popup preview window.
You can specify whether the template returns only the SQL text, an embedded SQL
cursor based on the SQL text, or a %ResultSet object based on the SQL text.
Web Form Wizard Select to open a Wizard with which you can create a CSP form, specifying class
members and a table style for the form to use. (See Building a Simple Application
with Studio for an example.
Template Description
Zen Chart Template Select to insert a Zen chart definition within an Xdata block of a Zen page class,
selecting type, style, and attributes. For more information see the chapter “Zen
Charts” of Using Zen Components.
Zen Element Select to insert a Zen element within an Xdata block of a Zen page class. You can
Template insert and edit built-in, custom, or composite Zen components or create a new Zen
component. For more information, see the chapter “Zen Layout ” in Using Zen.
Zen Method Select to insert a method. The wizard lets you select a scope, either instance or class,
Template a location where the method will execute, a name, and whether to add a try/catch
error processing template. You can further edit it in the Studio editor.
Zen Style Template Select to insert a CSS style declaration within an Xdata Style block of a Zen class.
A table displays the CSS style declarations defined by Zen components. You can
select one and override it within your page by editing details. For more information,
see the chapter “Zen Style” in Using Zen.
Zen TablePane Select to insert a new Zen tablePane definition within an Xdata block of a Zen page
Template class. Select the source of the query or table for this tablePane and then adjust
properties as desired. For more information, see the chapter “Zen Style” in Using
Zen.
Note: You should have some familiarity with CSP development before attempting to create Studio templates.
To make it easier to develop templates, Caché includes a set of custom CSP tags that perform all the basic operations of
templates. These tags are described in the following sections.
The power of templates comes from the fact that they are running on a Caché server and have the entire power of Caché
at their disposal. Therefore, for example, templates can perform sophisticated database operations.
When invoking a template, Studio passes parameters to the server, where they are accessible, in the %request object. These
parameters (which are case-sensitive) include:
• Project Name—the name of the current Studio project.
• Namespace—the name of the namespace Studio is connected to.
• User Name—the name of the current Studio user.
• Document Name—the name of the current Studio document, if any.
• SelectedText—the current selected text in the current document, if any.
Give each template a unique name (unless you are replacing an existing template with a new one).
3. Save and compile this CSP document with Build > Compile. It does not matter what file name you use for the CSP
document or which namespace or CSP application you store it in.
To make a Studio template accessible to all namespaces, save it in the %SYS namespace in /isc/studio/usertemplates.
You have now defined a template called MyTemplate (its name is specified by the name attribute of the <csp:StudioSim-
pleTemplate> tag). When you are in an open CSP page in the Studio Editor, select Tools > Templates > MyTemplate, and
the text SOME TEXT! is inserted into the page.
The Template dialog lists templates whose type matches the document type from which you invoked the Template dialog.
In our example, the MyTemplate template has a type of CSP. When you are in a CSP page in the Studio Editor, it appears
on the Tools > Templates list.
You can also edit the type attribute, a comma-separated list of document types, to specify the document types the template
can be called from. The list of types includes:
Table 17–5: Studio Template Types
The body of the simple template is inserted at the cursor location. For example:
<html>
<body>
SOME TEXT!
</body>
</html>
For example, we could create a simple template that returns the current date and time (using the $ZDT function) in an
HTML <B> (boldface) tag:
<csp:StudioSimpleTemplate name="Now" type="CSP">
<B>#($ZDT($H,3))#</B>
The response is contained in a <template> element. The body of the response is delimited using the
##www.intersystems.com:template_delimiter## delimiter.
1. A <csp:StudioInteractiveTemplate> tag specifying that this is an interactive template as well as the template's name
and type.
2. An HTML form whose ACTION attribute links it to the final page of the template, MyScript2.csp (see below).
3. A SELECT control for specifying a script language.
4. A TEXTAREA control for entering the contents of the script.
5. A SUBMIT button that submits the contents of the form to the MyScript2.csp page.
The final template page, MyScript2.csp, uses the values submitted from the form to create a response that is sent back to
Studio:
<csp:StudioGenerateTemplate>
<SCRIPT LANGUAGE="CACHE" RUNAT="SERVER">
Write "<SCRIPT"
Write " LANGUAGE=""",$G(%request.Data("language",1)),""""
If ($G(%request.Data("language",1))="CACHE") {
Write " RUNAT=""SERVER"""
}
Write ">",!
Write $G(%request.Data("script",1)),!
Write "<","/SCRIPT>",!
</SCRIPT>
This page starts with a <csp:StudioGenerateTemplate> tag and then includes Caché ObjectScript code that sends back a
SCRIPT tag (with appropriate attributes) to Studio. To test this, create a new CSP page and select Tools > Templates >
MyScript. Enter some Caché ObjectScript in the script box and click Ok. Script tags with your script are entered automatically
into your new CSP page.
After saving this CSP file (you can save it under any CSP application) and compiling it, it appears in the Studio New dialog
as MyCSPPage When selected, a new, untitled CSP document is created with the following contents:
<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR="FFDDFF">
<H1>New CSP Page</H1>
</BODY>
</HTML>
You can create more sophisticated New Document Templates by adding logic or by using an interactive template, as
described above for Text Templates.
Note that when adding an item to a project in this way, you must append the type of item (.CLS, .CSP, .MAC, and so on)
to the item name. Also note that the item must exist before you add it to a project; adding a class to a project does not
automatically create such a class (but, perhaps, your Add-in Template does this using the %Dictionary class provided in
the class library).
Open URL Displays HTML source in an editor. This is useful when you
are developing a Web-based application to view progress.
Close Closes the current editor.
Save As Saves the contents of the current editor with a name that you
specify.
New Project Creates a new project in the current Caché server and
namespace.
Open Project Opens an existing project in the current Caché server and
namespace.
To open a project from a different server or namespace, use
File > Change Namespace to change to a different namespace or
switch to a different server. Use File > New Studio to open a
project in a second Studio window.
Save Project Saves setting for the current project. It does not save any
modified documents belonging to the project.
Save Project As Saves the current project with a name you specify.
Close Project Closes the current project.
Clone Ensemble only. Creates a clone of the current BPL or DTL
document and requests a document name.
Cut Deletes the current text selection and copies it to the clipboard.
Paste Inserts the contents of the clipboard at the current cursor location.
Delete Deletes the current text selection without copying it to the clipboard. If
you highlight an item in the Workspace window, the item and any of its
generated files are deleted.
Select All Selects all the contents of the current document.
Find Searches for text in the current document.You can use wildcard matching
with the * (asterisk to match any number of any character) and ?
(question mark to match a single character).
Find In Files Searches for text in multiple files on the Caché server. Enter a string to
search for, select the type of file to search (such as .cls for class defini-
tions), and click Find.
Studio searches the selected files in the current Caché namespace and
returns a list of all (up to the first 500) files that contain the search string.
Double-click an item in the search results to open the file and display
the item, marked by the cursor.
Note that Find in Files searches stored data; it does not search modified
open documents. If you search only in the current project and the current
project is either a new project or a modified project, you are prompted
to save the project. If you refuse, Find in Files is canceled.
The Filter field can contain the elements in the list below. You can use
SQL AND and OR logical operators to enter more than one filter. For
example, Type=5 AND Modified>01/01/08. The contents of the Filter
field forms part of an SQL WHERE clause. The fields come from the
%Studio.OpenDialogItems class.
Replace Replaces one text string with another in the current document.
18.2.3 Bookmarks
You can use bookmarks to keep track of locations in your application source. Bookmarks are stored on the local machine
in which Studio is running; they are not shared among multiple users. The bookmark options are:
Toggle Bookmark Adds or removes a bookmark at the current line in the current
document.
Clear Bookmarks Removes all bookmarks defined for the current document.
Next Bookmark Moves the cursor to the next bookmark in the current document.
Previous Bookmark Moves the cursor to the previous bookmark in the current document.
Expand Commands Replaces all abbreviated Caché ObjectScript commands contained in the currently
selected text with their full names. For example, the following code:
S x = 10
Is replaced with:
Set x = 10
Compress Replaces all Caché ObjectScript commands contained in the currently selected text
Commands with their abbreviated versions. For example:
Set x = 10
Output Shows or hides the Output window. The Output window displays
output from the server (such as error messages resulting from
compilation). You can enter COS commands into this window; they
are executed on the server.
Watch Shows or hides the Watch window. The Watch window displays
watch points when debugging.
Toolbars Lets you select Studio toolbars to show or hide.
Text Size Lets you Increase, return to Normal, or Decrease text size of text
in Studio.
Toggle Special Characters Toggles the display of spaces, tabs, and end-of-line characters in
the Studio Editor window.
View Other Code Displays any source code generated by the compiler, such as .INT
and .MAC files, related to the position of the cursor. This option
works only if the current window has one or more source files
currently generated for it.
View Other Documents Displays other documents related to the current document. In some
situations,View Other Code results in the same behavior as View Other
Documents.
View Storage Available only for persistent and serial class definitions.
Toggles the display of a persistent (or serial) class storage definition
in the current editor window. A class storage definition is displayed
as an XML island in the body of the class definition and can be
edited in the same way as any other text.
Expand Code Available only in some files. Displays complete code in text editor
window.
Contract Code Available only in some files. Contracts some code sections in text
editor window. Click the plus icon to expand a section.
Show Class Documentation Available only in class definition files or when a class is selected.
Displays online documentation for the current class derived from
the (saved) descriptions of class members.
Language Mode Available only when you are in a source code file, such as .INT or
.MAC.
Select from a list of Caché language versions as appropriate for
your site.
18.3.1 Toolbars
The Toolbars menu lets you toggle the display of toolbars and lets you customize toolbars.
Toolbars, displaying text labels are shown below. To display text labels in Studio, choose View > Toolbars > Customize,
the Toolbars tab. Select a toolbar and select Show text tabels. (If a toolbar is already selected, uncheck the toolbar, recheck
the toolbar, and check Show text labels.)
Figure 18–1: Standard Toolbar
Commands Lists menus and all commands on Studio menus. Drag a command and drop it
into an open toolbar. To remove a command from a toolbar, drag it off the toolbar.
Toolbars Select check boxes to display toolbars. Toolbars can include text labels if you
select Show text labels. The Menu Bar cannot be unchecked. Click New to create a
new toolbar.
Tools Adds menu items to the Studio Tools menu. Specify an item name, it's command,
any arguments, and it's initial directory.
Options Select check boxes to turn on the display of screen tips, screen tips including
shortcut keys, and large icons.
Add Item Adds the item in the current editor window to the current project.
Remove Item Removes the item in the current editor window from the current project.
Settings Select to edit settings for the current project:
• General: HTTP Address used by Studio to set Web pages for this project: Set URL
location for Web pages for this project. Defines: Define a macro that is applied when
you compile the project. You can define a debug macro which can be tested by other
macros and turns on additional checking in the code. For example, debug=1 defines
the macro $$$debug to be 1.
• Debugging: Set Debug target and Breakpoints. See the chapter “ Using the Studio
Debugger” for details.
Add Select one of: New Property, New Method, New Class Parameter, New Query, New Index, New
SQL Trigger, New Foreign Key, New Storage, New Projection, or New XData Opens a wizard for
the item and inserts an item definition into the current class definition. See separate
chapters in this book for details on options for each of these class members.
Override Opens a window that lists items that the current class inherits, from which you select.
Then it inserts an override definition into the current class definition. Items listed include
Properties, Methods, Parameters, Queries, SQL Triggers, and XData routines.
Superclasses Lists superclasses of the current class alphabetically. You can pick from these to Add to
Project, Show Documentation, or Open.
Derived Classes Lists classes derived from the current class (subclasses). You can pick from these to Add
to Project, Show Documentation, or Open.
Create Subclass Displays the New Class Wizard. A class created using this option becomes a derived
class of the class in the current window and inherits its members, including properties,
methods, class parameters, applicable class keywords, and the parameters and keywords
of the inherited properties and inherited methods.
A projection automatically creates related files for other languages when you compile a class. For example, adding a Pro-
jection of type %Projection.Java generates a new Java class when it compiles so that you can use your class from a Java
application.
Compile Compiles the contents of the current window. Uses settings of the
Compiler tab from Tools > Options. Any messages from the compiler
are displayed in the Output Window.
If Skip Related Up-to-date Classes is enabled then:
• The current class definition is only compiled if it has been modi-
fied.
• If possible, Studio performs an incremental compile; if the only
change to a class definition is in the implementation of one or
more methods then only these methods are compiled.
Compile with Options Use to select options for this session only or to change the default
compile options. Default options can also be set with the Tools >
Options, Compiler tab
Rebuild All Compiles all the components in the current project whether or not
they have been modified from the last compile.
Class Browser Opens the Studio Class Browser. The Class Browser displays a list of all classes
in the current namespace as well as their members (defined and inherited).
Show Plan for SQL Opens dialog for an SQL statement. An SQL statement selected in the active
Statement document is displayed and editable in the dialog. Clicking Show Plan displays the
query execution plan in a web page.
Source Control Lets you choose from a list of available Source Control classes. A source control
class defines a set of server-side methods that are called by Studio when it per-
forms certain actions, such as loading and saving documents to the database.
For more information see the section on “Source Control Hooks”.
Templates Displays a list of Studio Templates. A template injects a stream of text at the current
cursor location. Studio provides templates. In addition, you can create your own.
For more information see the chapter on “ Studio Templates” .
Add-Ins Contains a list of wizards that help you add items to an open Studio file or connect
to existing files using standard formats. The wizards are the .NET Gateway Wizard,
the Activate Wizard, the Java Gateway Wizard, the SOAP Client Wizard, the XML
Schema Wizard, and the XSL Transform Wizard. For more on these wizards, see
the section “Add-In Templates”.
Export Exports one or more items (class definitions, projects, routines) to either a local
file or a file on the server system.
Export Special Export RO, the format created with the %RO utility.
Import Remote Lets you import an item from a remote file (that is; a file that is on the same machine
as the server that Studio is connected to). All imported items are placed into new
document windows.
You can use this option to import a project, class definition, or routines from either
XML, or .RTN (%RO Routine format files).
The Import Remote option displays a dialog that lists all the items contained in the
file from which you can select. You can also specify whether the imported items
should be added to the current project and if they should be compiled.
Import Local Lets you import an item from a local file (that is a file on the same machine as
Studio). All imported items are placed into new document windows.
You can use this option to import a project, class definition, or routines from either
XML, or .RTN (%RO Routine format files).
The Import Local option displays a dialog that lists all the items contained in the
file. You can select which items you want to import. You can also specify whether
the imported items should be added to the current project and if they should be
compiled.
Compare Compares an open file to one that you select with Browse.You must have specified
an external compare tool with the Compare setting in Options > Environment > General.
Copy Class Creates a copy of an existing class with a new name.
Generate C++ Projection Creates C++-related files when this class is compiled so you can use this class
from a C++ application. For more information, see the chapter Using the C++
Binding in the book Using C++ with Caché.
Options Lets you set Studio options. For details on options see the chapter “Studio
Options.”
Help The Help option displays context-sensitive help for selected syntactical elements. To
use, right-click text and select Help.
For example, if you right-click the word Do in Caché ObjectScript code and select Help
, the reference page for the Do command is displayed in your browser.
Set Syntax Color Displays a dialog in which you can choose the color used to display a specific syntactical
element.
To use, right-click text and select Set Syntax Color.
Goto <TAG> Available when editing an ObjectScript routine. Lets you jump to the code that defines
the ObjectScript tag.
To use, in an ObjectScript routine, right-click a tag and select Goto <TAG> . If the right-
clicked tag is defined in another routine, Studio automatically opens this routine.
Set current item as Sets the current item as the debug target.
debug target
block of text
In the following table a block of text means a number of whole lines. To select a block of text, put the caret at the
start of the first line, press Shift, and click the down arrow till all of the relevant lines are highlighted. The caret
will be at the start of the line beneath the last whole line.
Accelerator Action
General
F1 Context Help
F4 Change Namespace or Connection
F8 Toggles Full Screen Display of Studio
Ctrl+N New Document
Ctrl+O Open Document
Ctrl+Shift+O Open Project
Ctrl+P Print
Opens the Print dialog. If text is selected, Selection is checked.
Ctrl+S Save
Ctrl+Shift+I Export
Ctrl+I Import Local
Display
Ctrl++ Expand All
Expands all sections that can be expanded.
Accelerator Action
Ctrl+Shift+N Toggles Line Numbers Display.
Ctrl+Tab Next Window
Ctrl+Shift+Tab Previous Window
Navigation
Home Go To Beginning of Line
Subsequent presses hops the caret between the beginning of the line and the
beginning of text on the line.
Editing
Insert Toggle Insert/Overwrite Mode
Toggles between Insert mode (new characters are inserted when typing) and
Overwrite mode (new characters replace existing characters when typing).
Accelerator Action
Ctrl+Backspace or Delete Previous Word or to Start of Word
Ctrl+Shift+Delete
If the caret is at the end of a word, deletes the word. If caret is in the middle of
a word, deletes from caret to start of word.
Accelerator Action
Tab Block Indent
With no selection, pressing Tab inserts a tab. With a block of text selected,
pressing Tab indents the block a tab's width. If tab expansion is turned on, these
add spaces instead of a tab. If selection is not whole lines, text is replaced by
a tab.
Accelerator Action
Ctrl+Alt+L Toggle Studio Debug Logging
Turns logging on or off. If on, information is sent to the file
/cacheinstall/bin/CD###.log for Studio debugging purposes. This file can become
very large. Use carefully. For details, see “Logging” in Using Caché Direct.
Wizards: Arguments for New Method wizard and Parameters for New Query wizard
Alt+A Add
Alt+R Remove
Alt+U Up
Alt+D Down
General
Preferred Language: Sets the default language version used to create new classes.
Items shown in recently used lists: Specifies the number of items displayed in the most recently used file list (under
the File menu).
Open File Added to Project: If enabled, adding a file to the current project automatically opens the file in Studio.
Tabbed Document Selector: If enabled, displays a tab for each open document. You can choose whether the row
displays on the top of bottom of the Studio window.
When connected show documents from last time: If selected, when you start Studio all documents that were open
the last time you were in the current namespace are reopened.
Hide Find and Replace window after operation complete: If selected, the Find and Replace dialog exits when it
completes it task.
Compare: Select a document to compare this document to using Tools > Compare.
Font
Specifies the typeface and size of the fonts used in the following windows and print. Each can use any Windows
font but it is limited to a single typeface and size: Editor Window, Output Window, Print, Workspace, Inspector.
Class
Expert Mode: Displays all class attribute values, including usually hidden ones, in both the Inspector and the Class
Definition windows.
Multiline Method Argument: If selected, method arguments are displayed in the class editor one per line. Note that
if Multiline Method Argument is enabled and you use Find in Files and then click a line in the Find in Files output
of a file that has multiline method arguments, the cursor may go to the wrong line number. Disable Multiline
Method Arguments if this is a problem.
Option explicit:
If selected, you see a syntax error if you refer to a variable that hasn't been declared. (Select this
and Studio Assist to display undeclared local variables when entering a #DIM statement in a method.)
Show internal class members in Studio Assist: If selected, Studio Assist lists class members marked as internal.
Track variables: If selected, a green wavy underline indicates any questionable use of a variable—specifically: A
variable is used that has no value, was never created, or has already been killed. Or a variable is given a value,
but never used or killed before being used.
Open class in contracted view:If selected, by default a class opens with all collapsible sections contracted (as
though Ctrl+- had been pressed). If not selected, a class opens with collapsible sections open (as though Ctrl++
had been pressed).
Show storage by default: If enabled, storage is shown by default in open class definitions.
Advanced
Auto Save prevents you from losing changes to Studio documents on a software or system failure. By default,
Auto Save is enabled and saves every 5 minutes. It saves any document that is open and has been modified since
the last save into a file that is a text representation of the document, C:\Documents and Settings\<username>\Local
Settings\Temp\CST*.tmp. If you subsequently save (or close) the document, this .tmp file is deleted. If Studio
crashes, the next time that Studio is opened, you get a message telling you that the temporary file exists. If you
open this temporary document, you can paste the relevant portions into a Studio document.
Server status check timerdetermines how often Studio checks to see if open documents and/or the open project
changed on the Server outside of this Studio process. If Studio is the active application, it uses the first setting,
Studio is active application (2–60 sec). If Studio is running in the background, it uses the second setting: Studio is
background application (30–600 sec).
Automatically reload document when it is modified on the server and it has not been edited in Studio:If selected
and you have a document open in an editor, but have not yet edited it, and someone else saves a new version to
the server, the file in your window is automatically updated. This setting can be enabled on a namespace basis
using a global: Set ^SYS("Studio","Reload")=1 (or 0 to turn off).
Clear undo stack on document reload: If selected, the list of previous actions used when you select Undo or Redo
is emptied. If not selected, the list is maintained and your last action of “reload ” is added to the list.
Show generated documents in Namespace tree: If selected, the namespace window in workspace shows generated
files. If not selected, generated files are not displayed.
Use INT as default for COS: If selected, when you select File > New > Caché Objectscript Routine, an INT file is
opened. If not selected, a MAC file is opened.
Pass credentials to View Web Page: If selected, Studio checks your permissions when you select View Web
Page.
Export flags:Enter flags that you want to use when exporting files. See the article InterSystems Product Miscellanyfor
more information.
Colors
The Studio syntax checker uses a different coloring scheme for each language it supports. This option lets you
specify the colors used to highlight syntactic elements when Studio syntax coloring is enabled.
To change the color used by the Studio Editor for a specific syntax element do the following in the Options dialog
Appearance tab:
1. Select a language (such as Caché ObjectScript) from the available options
2. Select a syntax element (such as comments)
3. Select the desired foreground (and background color if you must!) color
4. Click Apply to use the new color scheme.
Note: You can also change the color for a particular syntax element by right-clicking it in the editor window
and selecting Set Syntax Color.
Indentation
Defines characteristics of automatic indentation.
• Basic: If enabled, if a line begins with a tab, a space, or any combination of spaces and tabs, when you press
Enter, the next line is started automatically with the same combination of spaces and tabs.
• User-defined ('/t' for tab)
: If enabled, you can specify any characters that you would like to be automatically entered at the start of each
subsequent line. For example, if you enter the set of characters \t.#/; (tab, dot, pound, slash, semi-colon)
and if a line begins with any of these characters or any combination of these characters, when you press Enter,
the next line is started automatically with the same combination of characters.
• None: No automatic indentation is provided.
View
Controls the display of some items.
• Show Special Characters: If enabled, the editor displays newline and tab characters using special symbols.
• Show Line Numbers: If enabled, the editor displays line numbers.
• Tab Size: Specifies the size of a tab by number of spaces.
• Convert tabs to spaces: If enabled, the editor converts tabs to spaces.
• Cloudy background color for generated files:If enabled, the editor displays generated files with a greyed
background color to differentiate them from user-created files.
Compile Flags
Keep Generated Source Code: If enabled, specifies that the compiler should not delete any intermediate source
code (routines) that it creates as a consequence of compiling.
Compile Dependent Classes: If enabled, the compiler compiles all of a class' dependent subclasses.
Skip Related Up-to-date Classes: If enabled, this sets the
“Do not compile up-to-date classes” flag and the compiler
does not compile related classes that have not been modified since their last compilation. The class that is current
in the editor is always, however, recompiled.
Compile In-use Classes: If enabled, the compiler compiles a class even if there currently are instances of the class
in active use.
Flags: Enter any flags that you want to use.
Optimization Level
• No optimization:Recommended during development. It does not recompile dependent classes and it keeps a
strong correspondence between source and object code so it is easier to read and debug. Default.
• Optimize properties: Optimizes any reference to ..property to the instance variable reference (for simple
properties described by datatypes where the get/set method is not overridden).
• Optimize within class and calls to library classes: Optimizes classes, as well as calls to system (% ) classes (as
code may be extracted and moved during the process). Note that incremental compile no longer works for
optimized classes.
Behavior
Compile INT on Save: If enabled, an INT routine is compiled when it is saved. If not enabled, only the source code
is saved. Note that if the source code does not match the compiled object code, errors generated when running the
object code may reference source lines that do not correspond to the error.
Compile MAC on Save: If enabled, a MAC routine is compiled when it is saved. If not enabled, only the source
code is saved. Note that if the source code does not match the compiled object code, errors generated when running
the object code may reference source lines that do not correspond to the error.
Before Compile: You can choose a default behavior of Studio when you select Compile. Before compiling, Studio
will automatically save all modified documents, prompt to save modified documents, or do not save modified doc-
uments.
Default Collation: Specifies the default index collation used when defining a mapping to legacy data structures.
Private Row ID: Specifies whether new classes should have their SqlRowIdPrivate flag set by default.
Automatically Generate Row ID: Automatically creates a row id field when mapping data to existing storage
structures.
A.1 Overview
To place a Caché development project under souce control, you do the following:
• Represent units of code as XML files and write them to a document system. Caché considers a class definition, a routine,
or a CSP file as a single unit called a document.
• Place the XML files under source control.
• Ensure that the XML files are kept synchronized with the Caché documents (and vice versa), and make sure that both
are kept in the appropriate read-write state.
• Ensure that you can perform source control activities from within Studio.
• Ensure that Studio always has the same information that the source control system has as to whether a document has
been checked out, and, if checked out, by whom.
You will need to set up a bidirectional mapping between the internal names and the external names. In practice, deciding
how to do this may be one of the most challenging parts of creating a source control interface. This mapping is customer-
specific and should be considered carefully.
Generally you would like the source control tool to group similar items. For example, the sample uses the following
directory structure:
• Class files are in the cls subdirectory, which contains subdirectories corresponding to the package hierarchy of the
classes.
• .INT routines are in the int subdirectory.
• .MAC routines are in the mac subdirectory.
• CSP files are in the csp subdirectory, which contains subdirectories corresponding to the package hierarchy of the CSP
files.
This approach might be problematic if you had large numbers of routines. In such a case, you might prefer to group routines
into subdirectories in some manner, perhaps by function.
• An XDATA block named Menu that defines an additional menu for Studio: Source Control. By default, this menu
contains the menu items Check In, Check Out, Undo Check Out, Get Latest, and Add To Source Control. This XDATA
block also defines additional menu items for the context menu in Studio.
All these menu items call methods also defined in this class.
• Methods named CheckIn, CheckOut, UndoCheckOut, GetLatest, and AddToSourceControl, which do nothing by default.
To extend Studio, you define a new class that extends one of these classes. As you see in a “ Activating a Source Control
Class” , the System Management Portal provides a way to indicate which extension class is currently active in a given
namespace. If an extension class is active in a given namespace, and if that class defines an XDATA menu block, those
menu items are added to Studio.
The details depend upon the source control system. The sample demonstrates some useful techniques.
4. Implement the GetStatus method of your source control class. This is required. You might also need to implement
the IsInSourceControl method, if the default implementation is not suitable.
1. Use the System Management Portal to specify which extension class, if any, Studio should use for a given namespace.
To specify the class to use:
a. Navigate to the [Home] > [Configuration] > [Studio Source Control Settings] page of the System Management Portal.
b. On the left, click the namespace to which this setting should apply.
c. Click the name of the extension class to use (or click NONE) and click OK.
This list includes all compiled subclasses of %Studio.Extension.Base.
2. If Studio is currently open, close it and reopen it, or switch to another namespace and then switch back.
A.4.1 Example 1
For the following fragment, we have used the Caché Activate Wizard to generate wrapper methods for the API for VSS.
Then we can include code like the following within your source control methods:
do ..VSSFile.CheckIn(..VSSFile.LocalSpec,Description)
The details depend on the source control software, its API, and your needs.
A.4.2 Example 2
The following fragment uses a Windows command-line interface to check out a file. In this example, the source control
system is Perforce:
/// Check this routine/class/csp file out of source control.
Method CheckOut(IntName As %String, Description As %String) As %Status
{
Set file=..ExternalName(IntName)
If file="" Quit $$$OK
//...
Set cmd="p4 edit """_file_""""
//...
Quit sc
}
In this example, RunCmd is another method, which executes the given command and does some generic error checking.
Also, this CheckOut method calls the OnBeforeLoad method, which ensures that the Caché document and the external
XML file are synchronized.
Note: The class in your SAMPLES namespace could be slightly different from the examples shown here. In particular,
some of the line breaks have been adjusted for readability in this document.
A.5.1 Introduction
Studio.SourceControl.Example is a partial example that does not make any calls to a source control system. It simply
maintains external XML files that such a system would use. Despite this simplification, however, the sample demonstrates
all the following:
• Establishing and maintaining a relationship between each Caché document and a corresponding external file.
• Keeping Caché up-to-date with the status of each file.
• Appropriately controlling the read-write state of each Caché document.
• Defining methods to check files in and out.
Note that the sample does not modify the read-write state of the external files; the source control system would be respon-
sible for that. Also, the sample implements only the Check In and Check Out methods.
To try this example in the SAMPLES namespace, do the following:
1. Use the System Management Portal to enable this source control class (Studio.SourceControl.Example), as described
earlier in “ Activating a Source Control Class.”
2. In the Studio Workspace window, double-click a Caché document. Notice a message like the following in the Output
window:
File C:\sources\cls\User\LotteryUser.xml not found, skipping import
At this step, you have implicitly added the Caché document to the source control system.
5. Try to make another edit. The Studio displays a dialog box that asks if you want to check the file out. Click No. Notice
that the Caché document remains read-only.
6. Click Source Control —> Check Out and then click Yes. You can now edit the Caché document.
7. Click Source Control —> Check In and then click Yes. The Caché document is now read-only again.
Other menu items on the Source Control menu do nothing, because the sample implements only the Check In and Check
Out methods.
A.5.2 Global
The Studio.SourceControl.Example sample uses a global to record any needed persistent information. Methods in this class
maintain and use the ^MySourceControl global, which has the following structure:
Node Contents
^MySourceControl("base") The absolute path of the directory that will
store the XML files. The default is C:\sources\
^MySourceControl(0,IntName), where IntName is the The date and time when the corresponding
internal name of a Caché file external file was last modified
^MySourceControl(1,IntName) The date and time when this Caché
document was last modified
^MySourceControl(2,IntName) The name of the user who has this Caché
document checked out, if any
Within the sample, the ExternalName method determines the external file name for any Caché document. This method is
as follows:
The sample is suitable only for Windows, of course. The implementation of this method would need to be different on
UNIX® or VMS.
Note:
• The method checks to see whether the external file exists yet. If the external file exists, the method compares its time
stamp to the time stamp of the Caché document. If the external file is more recent than the Caché document, the method
loads it.
It is not strictly necessary to check the time stamps; this method could load the external document every time. The
check is performed because it offers a performance improvement.
• The method sets the relevant nodes of the ^MySourceControl global.
The OnAfterSave method is analogous, as you can see in the sample itself.
Note: Not only does Studio call these methods automatically as noted above, we will call these methods whenever we
need to ensure that the Caché document and the external document are synchronized.
Studio calls this method at various times when you work with a Caché document. It uses this method to determine if a
Caché document is read-only, for example. When you implement a source control class, you must implement this method
appropriately.
In the sample, this method is implemented as follows:
Method GetStatus(IntName As %String,
ByRef IsInSourceControl As %Boolean,
ByRef Editable As %Boolean,
ByRef IsCheckedOut As %Boolean,
ByRef UserCheckedOut As %String) As %Status
{
Set Editable=0,IsCheckedOut=0,UserCheckedOut=""
Set filename=..ExternalName(IntName)
Set IsInSourceControl=(filename'=""&&(##class(%document).Exists(filename)))
If 'IsInSourceControl Set Editable=1 Quit $$$OK
If $data(^MySourceControl(2,IntName))
{Set IsCheckedOut=1
Set UserCheckedOut=$listget(^MySourceControl(2,IntName))}
Notes:
• This method uses the ^MySourceControl global to see whether the current user can actually check this Caché
document in.
• If the user can check the document out, the method does the following:
– The method calls OnAfterSave to make sure that the Caché document and the external document are synchronized.
– The method kills the appropriate node of the ^MySourceControl global to indicate that the document is now
checked in.
With View > View Storage, you can also display the storage definition for a persistent class definition. (A storage definition
specifies the physical structure used to store a class in a database.) The storage definition is displayed as an XML island
(a block of XML) in the class definition.
B.2.1.2 Case
When a class definition is regenerated, the class definition language might change the case of certain class metadata to a
customary case (such as lowercase to uppercase). Certain keywords, the names of members, and any implementation code
which are sensitive to case are not changed by Studio.
B.2.2 Statements
A class definition statement defines the characteristics of a class or a member of a class. Each statement consists of the
following parts:
• Description (optional)
• Declaration (required)
• Keyword List (optional)
• Body (optional)
In this case, the description consists of “This method returns 1 if successful. ”; the declaration consists of Method Test();
the keyword list contains Private and the body contains Write 1.
B.2.2.1 Description
A description is a special type of comment that precedes a class or class member and specifies the value of the Description
keyword for the class or class member.
A description is indicated using three slashes, (///). Text between /// and the end of the line is included in the description.
For example, here is a property with a description:
/// This property represents a Name
Property Name As %String;
If a class definition is closed and reopened, descriptions separated by white space are concatenated, thus:
/// This is line one
becomes:
/// This is line one
/// This is line two
Method x()
{
}
and is placed immediately before the element to which they relate when the class definition is regenerated.
A description must be placed outside of any statement. A description at the very end of a document (with no member defi-
nition following it) is not associated with any member definition and is lost when the document is saved or regenerated.
METHOD
Use to tag method names. If the method exists, the contents are displayed as a hyperlink to the method's documentation.
For example:
/// This is identical to the <METHOD>Unique</METHOD> method.
Method x()
{
}
PROPERTY
Use to tag property names. If the property exists, the contents are displayed as a hyperlink to the property's documentation.
For example:
/// This uses the value of the <PROPERTY>State</PROPERTY> property.
Method x()
{
}
• Property
• Query
• Relationship
• Trigger
• XData
The class or class member type is followed by an identifier that specifies the name of the class or class member, such as
Class Manager. Depending on the statement type there can be additional specifications, such as the data type of a property
or the value of a parameter.
If a keyword has a boolean value (true or false), the presence of the keyword indicates a true value; you do not have to
specify a value using =. A false value is indicated by placing the word Not immediately before the keyword:
Property X As %Integer [ Final, Not Required ];
If a keyword value is an identifier (such as a property name), you can place the identifier directly after the = (white space
is ignored). If the value is not an identifier, you must enclose it in quotation marks:
Property Colors As %String [ SqlListDelimiter = "," ];
If a keyword value consists of a list of values, enclose the entire list in matching parentheses, ( ), and delimit list items with
commas (,).
Method Z() [ Final, PlaceAfter = (X, Y), Private ]
{
}
B.2.3 Comments
The class definition language supports both // and /* style comments. Any text between /* and */ is ignored. Any text
between // and the end of the line is ignored.
Note that commented-out sections of class definitions are stored in the database when a class definition is saved.
Here are some examples of comments in a class definition:
Click View > Show Class Documentation to see the documentation for this class. Example:
Comments that begin with /// that are within the body of a class member definition are not put into the Class Reference.
Note: The description line for a class declaration cannot begin with either a single or a double slash. If you do either of
these, the class declaration is marked as an error from the start of the description line to the last bracket of the
class declaration; in other words, the entire file is marked as in error, underlined with red wavy lines, with red
arrows in the left column.
The description line for a class member declaration cannot begin with a single slash. If you do this, the class
member declaration is marked as an error from the start of the description line to the last bracket of the class
declaration; in other words, the declaration is marked as in error, underlined with red wavy lines, with red arrows
in the left column.
B.3 Statements
The following sections describe class definition statements in more detail.
If a class has multiple superclasses, place their names in () (parentheses) and separate them with , (comma):
Class Platypus Extends (Mammal, Reptile)
{
}
The following table displays the keywords that can appear in the optional keyword list. Do not provide a value for keywords
marked as Boolean:
Table II–1: Class Keywords
The following table displays the keywords that can appear in the optional keyword list. You do not provide a value for
keywords marked as Boolean:
To define a collection property (which can be a list or an array) use the following syntax:
Property Aliases As List Of %String;
The following table displays the keywords that can appear in the optional keyword list. Do not provide a value for keywords
marked as Boolean:
Table II–3: Property Keywords
You can use any of property keywords in a Relationship keyword list. You can also specify property parameters as you
would with a Property statement.
The following table displays the required keywords. See the Property Keyword List for the other allowed keywords. :
Table II–4: Relationship Keywords
If an index is on multiple properties, place the properties in a list using ( ), parentheses. The order of the property names
in the list determines the order in which the properties are used (as subscripts) in the index.
Index NameIndex On (LastName,FirstName);
The following table displays the optional keywords. Do not provide a value for keywords marked as Boolean:
B.3.6.2 As Clause
A Method statement can include an As clause that specifies the method's return type; this is equivalent to setting the value
of the method's ReturnType keyword:
The return type is the name of another Caché class. If the As clause is omitted then the method is defined as returning no
value:
Method Hello()
{
Write "Hello"
}
The following table displays the keywords that can appear in the keyword list. Do not provide a value for keywords marked
as Boolean:
Table II–6: Method Keywords
Note that this Basic method does not work unless it is running on a version of Caché that supports Basic.
The declaration of a Query contains the name of the query and its argument list. The argument list is specified in the same
manner as the Method statement.
A Query contains an As clause that specifies the name of the class used to provided the query interface methods. The class
name in the As clause can contain parameter values in the same manner as the Property statement.
The body of a Query statement is assumed to be SQL text used to define the query. A user-defined query (of type %Query)
does not require a body, but it does require you to specify its ROWSPEC parameter:
Query Custom() As %Query(ROWSPEC = "Name,Title")
{
}
The following table displays the keywords that can appear in the keyword list. Do not provide a value for keywords marked
as Boolean:
Table II–7: SQL Query Keywords
The following table displays the keywords that can appear in the keyword list. Do not provide a value for keywords marked
as Boolean:
Table II–8: SQL Trigger Keywords
The declaration consists of the word ForeignKey followed by the name of the foreign key and a list of properties constrained
by the foreign key in matching ( ) characters.
The required References clause specifies the name of the class the foreign key references as well as the name of a key
(unique index) in the referenced class.
The ForeignKey statement has no body.
The following table displays the keywords that can appear in the keyword list. Do not provide a value for keywords marked
as Boolean:
Table II–9: SQL ForeignKey Keywords
Projects
What is a project?
A project is a collection of class definitions, routines, and/or CSP files that you can group together for the sake of convenience.
Using projects gives you an easy way to return to your work when you start a Studio session. For example, you can place
all the classes related to an application, or part of an application, in a project. When you start Studio, open this project and
the Project tab of the Workspace window displays all the classes in a convenient list.
You can also export and import entire projects to and from a single external file making it easy to save or pass around
application code.
No. A project can only contain items that are visible to the current Caché namespace.
Yes. A project is a specified set of items (class definitions, routines, and CSP files) that you choose to group together. The
items themselves have no link back to the projects they may belong to. There is no limit to how many projects an item can
belong to.
You are not required to use projects with Studio; you can completely ignore them if you like. To ignore projects, do not
add any items to the default project and ignore the prompt asking you if you want to save your project when you exit Studio.
Yes. Select Tools > Export > Export Project. Enter a file name and press OK. This exports the entire contents of the current
project (including the project definition) to a single XML file.
Select File > Open to list all your projects. Right-click a project and select Delete.
Note that you can use File > Open to delete any type of item on the server in this way.
Opening Files
How do I open a class definition?
To open an existing class definition (that is, one saved on the Caché server), do the following:
1. Make sure you are connected to the Caché namespace and server containing the class definition.
2. Select File > Open.
3. In the Open dialog, make sure that class definitions are listed by selecting Class Definitions (.CLS) or All in
the File Types combo box.
4. Package names are listed in the file list as folders. Click a package name to list all the classes (or sub-packages) within
the package. Double-click a class name to open it.
5. Alternatively, you can enter the name of the class you want directly into the filename edit box with a .cls extension
(such as Sample.Person.cls) and click Open.
To open an existing routine (that is, one saved in the Caché server), do the following:
1. Make sure you are connected to the Caché namespace and server containing the routine.
2. Select File > Open.
3. In the Open dialog, make sure that routines are listed by selecting either MAC routines (.MAC), INT routines
(.INT), or All in the File Types combo box. Double-click a routine name.
4. Alternatively, you can enter a routine name with extension directly into the filename edit box (such as MyRoutine.MAC)
and click Open.
You can open a CSP file in the same way that you open a class definition or a routine. The main difference is that the Open
dialog lists CSP Applications (for example, /csp/samples) as folders; click the name of an application to see the CSP pages
within it.
What does the Show System check box in the Open dialog do?
If the Show System check box is selected, then the File > Open dialog lists system items (items whose names start with the
% character and are stored in the %CACHELIB database) along with items in the current namespace.
Yes. You can use the “*” character as a wildcard to match any number of any character as you can in a standard File >
Open dialog. You can use file extensions to filter certain items; for example, “*.cls” lists all Class Definitions in the selected
package. You can use the “ ?” character to match any character. Note that these are Windows pattern matching conventions,
not Caché pattern matching.
The Studio File > Open dialog lists items from only the current namespace and server. To open a routine from a different
namespace or server:
1. Select File > Change Namespace.
2. Open the desired routine.
Yes. You can list % classes (classes whose package name starts with a % character and are stored within the %CACHELIB
database) from the File > Open dialog by selecting the Show System check box at the bottom.
Studio opens % classes as read-only if you open them while connected to a namespace other than %CACHELIB.
Studio maintains a connection to a specific Caché namespace and server. It uses this connection to provide a list of classes
(such as for specifying property types, super classes, etc.). It also uses this connection for debugging. File > Connect lets
you connect to a different server.
Debugging
How do I start the debugger?
You can connect the debugger to a target process in of the following ways:
• Define a “ debugging target” (name of program or routine to debug) for the current project with Project > Settings.
Then select Debug > Go to start the target program and connect to its server process.
• Select Debug > Attach to select from a list of running processes on a Caché server to connect to.
For more details refer to the chapter “Using the Studio Debugger ” in this book.
The Caché Studio debugger lets you step through the execution of programs running on a Caché server. These programs
can include INT files, MAC files, methods within CLS files, CSP classes responding to HTTP requests, server-side methods
invoked from Java or ActiveX clients, or server-hosted applications.
1. To view the INT file during debugging and to save the INT for further review later, set the Keep Generated Source
Code option before you compile your class, located on the Tools > Options > Compiler > General Flags page.
2. Set a breakpoint at the desired location in a class method (or any of the other files mentioned above) by pressing F9
(toggles breakpoint) on the desired source line.
3. Set a debug target to specify where you want the debugger to begin code execution using Debug > Debug Target. Enter
the name of the class and the method that you want to step through.
4. Start the debugger with F5 or Debug > Go.
Yes. While debugging, enter a variable name (or an expression) in the left-hand column of the Studio Watch Window.
Each time the debugger pauses, the variable or expression is reevaluated.
Editing
What do the different colors in the editor mean? Can I change the colors in the editor?
The Studio uses colors to differentiate the syntax elements of a given language.
You can change the colors used for the various syntax elements as follows:
1. Select Tools > Options > Editor > Colors.
2. Select a language.
3. Select an element (comment, variable, etc.)—the list of available elements depends on the selected language.
4. Select Foreground and Background colors and click OK.
The wavy, red line indicates that the underlined code (or possibly code before it) contains syntax errors.
Yes. Studio has complete support for Unicode and Kanji characters.
Yes. The Studio Editor supports Hebrew and Arabic characters, as well as bidirectional editing.
Importing Files
Can I import class definitions or routines from external files?
Studio is a client/server application; the Studio itself runs on a client system and talks to a server. The server can either be
on the same machine or on a remote machine. The Studio uses the terms “ Local” and “Remote ” to refer to operating
system files (such as when you are importing or exporting) that are stored on the client and server systems, respectively.
If both the client and server are on the same system then there is no difference between Local and Remote.
Printing
Can I print from Studio?
Templates
What is a Template?
Yes. You can use Studio to create new Templates. See the chapter “Using Studio Templates ” in this book.
Multiuser Support
Does Studio support development by multiple users?
• Use local Caché servers (on the developer's system) and store source code in a source control system as exported XML
files.
What happens if I try to open a class (or routine) that someone else is editing?
Studio displays a dialog stating that the class (or routine) is in use by someone else and asks you if you want to open it in
read-only mode.
What if someone wants to edit a super class of a class that I am working on?
Studio does not prevent another developer from modifying the super class of a class you are working on.
While Studio could take out locks on all subclasses whenever a class is opened for editing, in practice this would be
annoying and unwieldy. Instead, a development team needs to work out rules and procedures for defining and modifying
super classes. This is similar to how development teams in other languages (say Java) usually work with class definitions
in source control systems.
Classes
How do I create a new class?
Use the New command in the File menu and ask for a new Class Definition. This invokes the New Class Wizard.
For more details, see the chapter Class Definitions in this book.
Yes. You can see all the source code generated by the Class Compiler with View > View Other Code (available when the
current window contains a class definition).
Make sure that the Keep Generated Source Code option is set before you compile your class. This option is located on the
Tools > Options > Compiler > General Flags page.
When I try to compile my class, the Studio says it is up to date and does not need to be compiled. Can I force a
compile to happen?
Yes. Turn off the Skip related up-to-date classes option. This option is located on the Tools > Options > Compiler > General
Flags page.
Routines
How do I create an INT routine?
Create a new Caché ObjectScript routine using the New command in the File menu and then save the new routine using a
name with a .INT extension. You can create an include (.INC) file in the same fashion.
SQL
How do I define an SQL View?
Studio does not include a mechanism for defining SQL views. To do this, as well as other SQL tasks, use the Caché System
Management Portal.
Source Control
Does Studio integrate with external Source Control systems?
At this point, Studio has been configured to interact with the source-control system. When Studio attempts to open a document,
prior to opening it, the OnBeforeLoad method of your source-control class is invoked; typically, this method checks the
timestamp on a file representation of the document and, if it is newer in the file, the method calls a Caché function to import
this into the current namespace. This makes sure that the user is seeing the most up-to-date version of the file.
If you modify the file and save it, then Studio calls the OnAfterSave method of the source-control class, which typically
exports this document to the filesystem. (This keeps these files in sync with the routines, classes, etc. that are in Caché.)
When you attempt to modify a document, Studio attempts to get a lock on it, which also triggers a call to a source control
method GetStatus. If the file is locked in source control, Studio can then ask if you want to check it out. This triggers a
call to the CheckOut method which performs the actions required the item out.
%Studio.SourceControl.Base and %Studio.Extension.Base provide a set of methods that allow you to create interactions
between Studio and your source-control system that are as simple or complex as you choose.
Yes. You can define hooks—code that is executed whenever items are saved to or loaded from the server. For details see
the appendix “Using Studio Source Control Hooks”.
Compatibility
Can I connect a Studio client to any Caché server?
A Studio client must be either the same version or a higher version than the Caché server that it is connecting to. Example:
Caché 2008.2 Studio can connect to a Caché 2008.2 server or an earlier server. Caché 2008.1 Studio cannot connect to a
Caché 2008.2 (or later) server. To put it another way, Studio works with any server (including UNIX® or OpenVMS
servers) that has the same or lower version of Caché than Studio itself (as long as the server is running Caché v5.1 or
higher).
The Studio client only runs on Windows platforms. You can use a Windows-client to talk to any server. You can also use
a partition manager, such as VMWARE, to run both Windows and Linux partitions on your development system and run
Studio in the Windows partition with Caché running in the Linux partition. The only trick is to configure your networking
so that the Windows partition can talk to the Linux partition via TCP/IP. Studio can also run under Windows on an Intel-
based Macintosh.
Studio Implementation
Why doesn't Studio use the licensed components of Microsoft Visual Studio?
There are several reasons why we built Caché Studio from the “ground up” instead of licensing or extending Visual Studio:
• The Caché Studio editor uses advanced parsing technology not available within the Microsoft Studio framework.
• Microsoft cannot guarantee the compatibility of future versions of Visual Studio.
At this time, the only way to get acceptable performance for the Studio editor is to use direct calls to the Windows API.
While there are syntax-coloring editors developed using Java they do not offer the sophisticated multi-language parsing
used by Studio and they typically require very high performance computers for decent performance.