![]()
![]() ![]() ![]() ![]() ![]() ![]() ![]() Documentation Top ![]() Global Index ![]() Reference Manual ![]() ![]() ![]() Developer's Guide ![]() ![]() Tuning Cloudscape ![]() ![]() |
SQL-J and Java Type CorrespondenceThis section covers the following topics:
Each built-in type in SQL-J has a Java class associated with it. For example, the corresponding type for an SQL-J INTEGER is java.lang.Integer. Consider the following SQL-J statement: It returns the value TRUE, since the SQL-J type INTEGER maps to the Java class java.lang.Integer.
|
Table 1-10, Conversion of SQL-J Types to Java Classes During Method Invocation, shows the correspondence between SQL-J types and Java classes. SQL-J expressions that become method receivers, as well as SQL-J expressions used as parameter values passed to the method, are mapped to Java types according to this table during method invocation.
The third column shows what primitive is used during second-chance conversion by Cloudscape if on the first pass it cannot find a method with the matching signature. This conversion is all-or-nothing; see Method Resolution and Type Correspondence.
In SQL-J statements, Cloudscape converts the return values of invoked Java methods and accessed fields of Java objects or classes to SQL-J values, except when the value is used as a receiver or parameter to another method. In that case, the value remains a Java value. This means, for example, that if a method returns a Java int type, that int can be passed directly to a Java method that takes an int; it is not first converted to a SQL-J INTEGER and then back to a Java java.lang.Integer.
Cloudscape converts return values to SQL-J built-in types according to Table 1-11, Conversion of Java Types to SQL-J Types.
No Java types map to FLOAT, CHAR, BIT, LONG VARBINARY, or LONG VARCHAR by default. The Java primitive types char and byte do not map to any SQL-J types.
General Method Invocation, the NEW command constructor method invocation, and the CALL statement method invocation all require method resolution.
The rules of Java determine which method is invoked based on the method signature. The signature of a method is its name, the class of the receiver, and the number and types of the parameters. Cloudscape searches the receiving class for a method with a matching signature. Cloudscape can find methods in superclasses of the receiving class. Cloudscape uses the method with the signature that has the best match according to the rules of Java. The return type of the method is determined by the best matching method.
If on the first attempt Cloudscape does not find a match, Cloudscape converts all SQL-J numeric types and BOOLEANs to their corresponding Java primitive types. (This conversion is all-or-nothing.) The conversion from SQL-J to Java primitive types is done according to Table 1-12, Second-Chance Conversion of SQL-J Types to Java Primitive Types,.
Thus:
finds the correct constructor. On the first attempt, Cloudscape looks for a method with a java.lang.Integer parameter (because that is the corresponding type of the SQL-J INTEGER type) and fails. On the second attempt, Cloudscape looks for a method with a primitive int parameter and succeeds.
Cloudscape uses Javas rules for parameter broadening to determine whether a method matches an invocation. For example, consider the following method invocation:
myColumn.myLongMethod((1).intValue())
The parameter is a java.lang.Integer (which is converted to an int on the second try) so the invocation can match a method that takes a long parameter.
When a primitive parameter is dynamic, you may need to CAST the parameter so that Cloudscape can determine its data type. For example:
ERROR 42X50: No method was found with the signature java.lang.Math.abs(UNTYPED).
Since you cannot work with primitive Java dynamic types within SQL-J, how do you do that? CAST it to the corresponding SQL-J data type. Suppose that in the above example, you want to use the signature of Math.abs that takes a primitive float value. That primitive data type corresponds to the SQL-J REAL data type, so this works;