Chapter 3 DynaScript Predefined Objects


java methods

The java object has these methods:

CreateComponent method

Syntax

java.CreateComponent( componentName [, managerUrl, id, password, narrowingComponent] )

Description

Creates an instance of a Jaguar component, using CORBA naming services, through Java. The parameters are:

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" );

Note  

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.

Return

A Jaguar component object or null if the component could not be created. This is a DynaScript Java object.

Example

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.

Note  

site.GetErrorInfo( )
The site.GetErrorInfo( ) method may be used for retrieving error information.

See also

"Calling Jaguar Component Methods from PowerDynamo" in the PowerDynamo User's Guide.

CreateObject method

Syntax

java.CreateObject( className [, list of constructor parameters ] )

Description

Instantiates a Java class object. The parameters are:

Note  

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.

Return

A DynaScript object representing the Java class. Returns Null if the Java class cannot be created.

Example

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 );
}
-->

See also

"PowerDynamo and Java" in the PowerDynamo User's Guide.

CallStaticMethod method

Syntax

java.CallStaticMethod( className, staticMethod [, list of method parameters] )

Description

Calls a static Java method. You need not create a Java object (java.CreateObject) to call static methods of that object. The parameters are:

Return

The return type is dependent on the type of return value of the static method.

Example

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 );

-->

See also

"PowerDynamo and Java" in PowerDynamo User's Guide

GetHomeInterface method

Syntax

java.GetHomeInterface(component_name [, provider_url, user_id, password] )

Description

Allows access to the EJBHome interface for a Jaguar component. The parameters are:

Note   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.

Example

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(...)

See also

"PowerDynamo and Java" in the PowerDynamo User's Guide.

GetUserTransaction method

Syntax

java.GetUserTransaction(  [ <provider_url>, <user_id>, <password>] )

Description

Allows access to the EJB UserTransaction object. The parameters are:

Note   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.

Comments

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:

  1. Use the same name server to create the UserTransaction object that was used when creating the component instances. That is, supply the same provider_url to GetUserTransaction() and GetHomeInterface() , CreateComponent() . The initial-context values of the URLs can differ.
  2. Get the UserTransaction object and begin the transaction before creating any component instances.
  3. In addition, follow the same restrictions as other Java clients when using the UserTransaction object. Refer to the Jaguar CTS Programmer's Guide and Jaguar CTS Reference Manual for details.

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 */ }
...

Example

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
}

See also

"PowerDynamo and Java" in the PowerDynamo User's Guide.

 


Copyright © 1999 Sybase, Inc. All rights reserved.