[top]
[prev]
[next]

Road Map
Glossary
Table of Contents
Index
Documentation Top
Global Index
|
Static Method Aliases
If you call some static method names often, you may get tired of specifying the full class name or even the class alias:
VALUES (CLASS java.lang.Math).sqrt(25.0);
Cloudscape allows you to create aliases or shorthand names for static methods. These aliases are database-specific. If you want to use them in more than one database, you must define them in each database.
Create a Method Alias
To create a method alias, you use the CREATE METHOD ALIAS command.
- Execute the following statement in ij:
CREATE METHOD ALIAS sqrt FOR java.lang.Math.sqrt;
Once you create the alias, you can execute this static function without having to type the full package and class name, and without having to use the CLASS keyword.
- Execute the following statement:
VALUES (sqrt(25.0));
- Execute this statement:
CREATE METHOD ALIAS abs FOR java.lang.Math.abs;
- Execute the following statement:
VALUES (abs(-3));
toursDB has some method aliases already defined for you.
One alias that returns a value is called findcity, and it's an alias for JBMSTours.serializabletypes.City.findCity.
- Before executing it, let's expand the maximum display width of columns in ij:
maximumDisplayWidth 100;
Execute Method Aliases for Database-Side Methods
When static methods are database-side JDBC methods, they resemble traditional stored procedures. Creating method aliases for these methods makes them easier to use.
- To execute a static method that returns a value or a method alias for such a method, you use the VALUES expression. Execute these:
VALUES (findcity(GETCURRENTCONNECTION(), 1).toString());
VALUES (findcity(GETCURRENTCONNECTION(), 'Amsterdam', 'Netherlands').toString());
VALUES (findcity(GETCURRENTCONNECTION(), 'AMS').toString());
Note that the alias finds all signatures of the method.
- To execute a static method that does not return a value or a method alias for such a method, you use the CALL statement. The method alias cleanOutFlightAvailability is an alias for the static method JBMSTours.FlightBuilder.cleanOutFlightAvailability. That method deletes all entries in the FlightAvailability table that are earlier than the current date; customers do not need to know the availability of flights that have already occurred. Try executing it:
CALL cleanOutFlightAvailability(GETCURRENTCONNECTION());
The product installation includes scripts for creating method aliases for the static methods of java.lang.Math. See the Cloudscape Developer's Guide for information.
- In ij, disconnect from toursDB:
disconnect; - Shut down the system and exit using the exit command:
exit;
|