Chapter 3 DynaScript Predefined Objects
The java
object
has these methods:
java.CreateComponent( componentName [, managerUrl, id, password, narrowingComponent] )
Creates an instance of a Jaguar component, using CORBA naming services, through Java. The parameters are:
narrowing_component
parameter
of the CreateComponent method should be used. For example, if you
have stored your Java stubs for the SVU Jaguar package in com/sybase/jaguar/sample/svu/SVUMetaData then
you would use the following syntax to create an instance of a SVUMetaData
component that resides in the SVU Jaguar package:java.CreateComponent( "SVU/SVUMetaData", "iiop://localhost:9000", "Jagadmin", "", " com/sybase/jaguar/sample/svu/SVUMetaData" );
If however, you used the default value when generating stubs for the SVU package, your syntax would look like the following:
java.CreateComponent( "SVU/SVUMetaData" );
Setting the Java VM
The Java VM configuration option must
be set to the Sun VM for scripts with this method to execute. Change the
VM option using the Configuration\Default General
Settings\Java VM folder in Sybase Central.
A Jaguar component object or null if the component could not be created. This is a DynaScript Java object.
This example creates an instance of a component
called comp
. Once the object is
created, its method getMajors
is
called and the Record Set
is
displayed:
<HTML>
<H1>A CreateComponent example</H1>
<!--SCRIPT
document.writeln( "<H3>Testing SVUEnrollment getMajors</H3>" );
comp = java.CreateComponent( "SVU/SVUEnrollment" );
RecordSet = comp.getMajors();
query = java.CallStaticMethod( "com.sybase.CORBA.jdbc11.SQL", "getResultSet", RecordSet);
received = query.next();
i = 0;
while( received ) {
metadata = query.getMetaData();
document.writeln( "*****" );
columns = metadata.getColumnCount();
for( j = 1; j<= columns; j++ ) {
value = query.getString( j );
document.writeln( value );
}
received = query.next();
i++;
}
-->
</HTML>
For information on result sets and the getResultSet method, see the Jaguar CTS Programmer's Guide.
site.GetErrorInfo( )
The site.GetErrorInfo( ) method may
be used for retrieving error information.
"Calling Jaguar Component Methods from PowerDynamo" in the PowerDynamo User's Guide.
java.CreateObject( className [, list of constructor parameters ] )
Instantiates a Java class object. The parameters are:
Setting the Java VM
The Java VM configuration option
must be set to the Sun VM for scripts with this method to execute.
Change the VM option using the Configuration\Default
General Settings\Java VM folder in Sybase Central.
A DynaScript object representing the Java class. Returns Null if the Java class cannot be created.
This example creates an instance of Java class
that performs the fibonacchi mathematical procedure. It involves
the GenerateNext
method
and returns results.
<!--SCRIPT
fib = java.CreateObject( "Fibonacchi" );
// retrieve a property on the class
document.writeln( "The value of next is " + fib.next + " The value of prev is " + fib.prev );
// set a property on the class
fib.next = 5;
for( i = 0; i < 20; i++ ) {
// invoke a method on the class
fib.generateNext();
document.writeln( "The value of next is " + fib.next + " The value of prev is " + fib.prev );
}
-->
"PowerDynamo and Java" in the PowerDynamo User's Guide.
java.CallStaticMethod( className, staticMethod [, list of method parameters] )
Calls a static Java method. You need not create a Java object (java.CreateObject) to call static methods of that object. The parameters are:
The return type is dependent on the type of return value of the static method.
This example executes the static method doubleme
of
the class Fibonacchi
. Calling
a static method does not require that an object representing a Java
class instance be created.
<!--SCRIPT
result = java.CallStaticMethod("Fibonacchi", "doubleme", 2.5);
document.writeln( result );
-->
"PowerDynamo and Java" in PowerDynamo User's Guide
java.GetHomeInterface(component_name [, provider_url, user_id, password] )
Allows access to the EJBHome interface for a Jaguar component. The parameters are:
The Dynamo methods GetHomeInterface and GetUserTransaction enable access to EJB interfaces of Jaguar components.
To access EJB interfaces of Jaguar components, Dynamo requires a Jaguar client zip file, jagclient.zip, from a Jaguar CTS installation version 3.5 or above. Refer to PowerDynamo installation instructions for your platform and ensure that this file is included in your JAGUARCLASSES (Solaris) or CLASSPATH (NT) variable.Use java.GetHomeInterface
to
create an instance of the EJBHome interface for the component Test/Cart
.
Then use the Home interface to create an actual instance of Test/Cart
.
carthomeObj = java.GetHomeInterface("CartPackage/Cart") cartObj = carthomeObj.create("John", "7506"); cartObj.addItem(66) cartObj.addItem(22) cartObj.purchase() carthomeObj.remove(...)
"PowerDynamo and Java" in the PowerDynamo User's Guide.
java.GetUserTransaction( [ <provider_url>, <user_id>, <password>] )
Allows access to the EJB UserTransaction object. The parameters are:
The Dynamo methods GetHomeInterface and GetUserTransaction enable access to EJB interfaces of Jaguar components.
To access EJB interfaces of Jaguar components, Dynamo requires a Jaguar client zip file, jagclient.zip, from a Jaguar CTS installation version 3.5 or above. Refer to PowerDynamo installation instructions for your platform and ensure that this file is included in your JAGUARCLASSES (Solaris) or CLASSPATH (NT) variable.The components that participate in the transaction managed with the UserTransaction object must be in the same server as the UserTransaction object, which cannot be assumed if a Jaguar cluster is used to ensure that this requirement is met:
GetUserTransaction()
and GetHomeInterface()
, CreateComponent()
.
The initial-context values of the URLs can differ.
The UserTransaction interface defines exceptions that are
thrown when errors occur. For example, TransactionRolledbackException
is thrown when commit()
is
called after setRollbackOnly()
has
already been called for a transaction.
As many of the methods in the UserTransaction interface for
example, return void, begin()
, commit()
, rollback()
,
these exceptions are the only way to detect errors.
In DynaScript, exceptions are passed to the user through the site.GetErrorInfo()
method.
That is, the exception is converted to an error string. For example:
ut.begin()
...
ut.commit()
errMsg = site.GetErrorInfo();
if ((errMsg != null) && (errMsg != ""))
{
/* the transaction was not committed */
}
The UserTransaction.getStatus()
method
returns an integer value indicating the status of the current transaction.
Dynamo users can include the script ~/system/utils/usertran.ssc to
get the definitions of variables that map to the integer values
returned by getStatus()
.
import "~/system/utils/usertran.ssc"
...
ut = java.GetUserTransaction(...);
ut.begin()
status = ut.getStatus();
if (status != UserTran.STATUS_ACTIVE)
{ /* the transaction was not started */ }
...
Use java.GetUserTransaction
to
get the UserTransaction object, instantiate the components that
will participate in the transaction, begin the transaction, perform
the operations required in the transaction, and commit the transaction.
ut = java.GetUserTransaction("iiop://my-host:9000")
acctHome = java.GetHomeInterface("Bank/Account", "iiop://my-host:9000")
acct1 = acctHome.create("John", "Doe", "111-11-1111")
acct2 = acctHome.create("Jane", "Doe", "222-22-2222")
acct3 = = java.CreateComponent("Bank/Account", "iiop://my-host:9000")
ut.begin();
errMsg = site.GetErrorInfo();
if ((errMsg != null) && (errMsg != ""))
{
/* handle error, the transaction did not begin return
}
acct1.withdraw(100);
acct2.deposit(50);
acct3.deposit(50);
ut.commit();
errMsg = site.GetErrorInfo();
if ((errMsg != null) && (errMsg != ""))
{
/* handle error, the transaction did not commit return
}
"PowerDynamo and Java" in the PowerDynamo User's Guide.
Copyright © 1999 Sybase, Inc. All rights reserved. |