Greetings from the Edge: Using javaobj in DATA Step - PowerPoint PPT Presentation

About This Presentation
Title:

Greetings from the Edge: Using javaobj in DATA Step

Description:

Greetings from the Edge: Using javaobj in DATA Step Richard A. DeVenezia – PowerPoint PPT presentation

Number of Views:75
Avg rating:3.0/5.0
Slides: 32
Provided by: Richa516
Category:

less

Transcript and Presenter's Notes

Title: Greetings from the Edge: Using javaobj in DATA Step


1
Greetings from the EdgeUsing javaobj in DATA
Step
Richard A. DeVenezia
2
Java is ...
  • java.sun.comThe Java 2 Platform provides robust
    end-to-end solutions for networked applications
    as well as a trusted standard for embedded
    applications
  • Widespread
  • Networked
  • Applications
  • Analysis and management

3
javaobj is ...
  • DATA Step
  • Experimental
  • Part of broader initiative
  • Component Interface
  • Object Dot Syntax

4
Component Interface is ...
  • support.sas.com/rnd/... DATA Step Component
    Interface provides a mechanism for accessing
    predefined component objects from within a DATA
    Step program.
  • Instantiate
  • Create an object
  • declare Type var, var _new_
  • Access
  • var.method()

5
Java development
  • Free kit
  • java.sun.com/j2se
  • compiler, packager and loader javac, jar, java
  • Runtime Environment
  • Online training
  • Tutorials
  • numerous web sites and publications

6
SAS session
  • CLASSPATH
  • Location of Java classes
  • Configuration options
  • Host preset environment variable
  • Command line-set CLASSPATH myPathCLASSPATH
  • configuration file (sasv9.cfg)-set CLASSPATH
    myPathCLASSPATH

7
Java coding pattern
  • public class Class
  • private double variable
  • public double getVariable()
  • return this.variable
  • public void setVariable(double variable)
  • this.variable variable

8
Declare statement
  • declare javaobj var
  • var _NEW_ javaobj
  • ('Class' ,arg-1,,arg-N)
  • - or -
  • declare javaobj
  • var ('Class' ,arg-1,,arg-N)

9
Signature
  • public void setX (double X) this.X X
  • public void setX (String X)
  • try
  • this.X Double.parseDouble(X)
  • catch (Exception e)
  • this.X Double.Nan
  • Pattern of argument types
  • Correspondence
  • DATA Step ERROR ?

10
Accessing methods and fields
  • public Type Method (args)
  • obj.callTypeMethod ( Method, args, return )
  • fields
  • obj.getsetTypeField ( field, value )

11
HelloSAS.java
  • public class HelloSAS
  • public HelloSAS ()
  • public String getMessage ()
  • return "Hello SAS"

12
HelloSAS.sas
  • data _null_
  • declare javaobj j (HelloSAS')
  • length message 200
  • j.callStringMethod ('getMessage', message)
  • put message
  • run
  • --- log --
  • messageHello SAS

13
Gotchas
  • Classes are cached per SAS session
  • Java class recompiled ?
  • Restart SAS
  • Signature Types
  • pass double, String, Object (new)
  • return double, String

14
Example 8 - Enumeration
  • import java.util.Enumeration
  • public class Example8
  • private Enumeration e
  • public Example8 ()
  • e System.getProperties().propertyNames()
  • public String getProperty ()
  • if (e.hasMoreElements())
  • String p (String) e.nextElement()
  • return p "" System.getProperty(p)
  • else
  • return null

15
Example 8 - DATA Step
  • data _null_
  • dcl javaobj j ('Example8')
  • length s 200
  • j.callStringMethod ('getProperty', s)
  • do while (s ne '')
  • put s
  • j.callStringMethod ('getProperty', s)
  • end
  • run
  • --- log ---
  • java.vm.version1.4.1_01-b01
  • java.vm.vendorSun Microsystems Inc.

16
Object Persistence
  • No
  • javaobj gone when DATA Step ends
  • obj.delete() recommended
  • Birdie
  • An instantiated javaobj creates a JNI reference
    which will not be garbage collected. The
    reference needs to be explicitly deleted.

17
A Case for Persistence
  • Creating SAS Table from Query
  • Query -gt ResultSet
  • Requires Two SAS Passes
  • ResultSetMetaData
  • Read ResultsSet into Data Set
  • Same Query for each pass
  • not wanted

18
Databases
  • Commercial
  • Open source
  • Postgresql, mySQL
  • communities of devoted developers and users
  • JDBC
  • 109 drivers
  • trademark
  • not an acronym (just like ess-a-ess)

19
Persistence RMI
  • Objects can persist outside SAS
  • in RMI server process
  • Obtaining reference and access
  • requires Java wrapper class

20
Gateway - an RMI Scheme
  • Server
  • DATA Step is client of server
  • via a wrapper
  • Server allocates resources
  • Returns handles
  • Methods

21
Gateway Implementation
  • Three Classes
  • An Interface
  • GatewayInterface
  • An Implementation
  • GatewayManager
  • A Server
  • GatewayServer

22
GatewayInterface
  • Declares methods
  • public int getConnectionHandle ( String
    driverClass, String databaseURL, String
    username, String password )throws
    RemoteException
  • public int getStatementHandle (int cHandle)
    throws RemoteException
  • public int executeQuery (int handle, String sql)
    throws RemoteException

23
GatewayManager
  • Implements the Interface
  • public int getConnectionHandle ( String
    driverClass, String databaseURL, String
    username, String password)throws
    RemoteException try System.out.println
    ("loading "driverClass) Class.forName(driverCl
    ass) System.out.println ("connecting to
    "databaseURL) con DriverManager.getConnectio
    n (databaseURL, username,
    password) System.out.println
    ("connected")

24
GatewayServer
  • Hosts a GatewayManager
  • protected static final String RMI_NAME
    "JDBC-GATEWAY-MANAGER" public static void
    main(String args)try LocateRegistry.crea
    teRegistry(1099) GatewayManager manager new
    GatewayManager (5) Naming.rebind (RMI_NAME,
    manager) System.out.println (
    manager.getClass().getName() " ready to
    manage " 5 " connections.")

25
GatewayServer
  • getReferenceToPersistentManager()
  • Convience method
  • Client starts immediately after server
  • for (i0ilt4i) try remote
    Naming.lookup(RMI_NAME) catch
    (java.rmi.NotBoundException e)
    Thread.currentThread().sleep(250/ms/)

26
DataStepGatewayAdapter
  • Reimplements GatewayInterface
  • delegates everything to
  • performs typecasting where needed
  • public class DataStepGatewayAdapter private
    GatewayInterface dbi public DataStepGatewayAdap
    ter() throws Exception dbi
    GatewayServer.getReferenceToPersistentManager
    () public int getStatementHandle (double
    cHandle) throws Exception return
    dbi.getStatementHandle ( (int) cHandle)

27
SAS Macros
  • Facilitate use of Gateway
  • startServer
  • getConnectionHandle
  • getStatementHandle
  • jdbcLoadTable
  • jdbcQuery

28
Using the macros
  • let jdbc_server_policy gateway.policy
  • let jdbc_driver org.postgresql.Driver
  • let db_url jdbcpostgresql//www.devenezia.com
    5434/sesug03demo
  • let username sesug03demo
  • let password D3m0oeoe
  • let cHandle
  • getConnectionHandle ( driver jdbc_driver ,
    url db_url , user username , pass
    password , cHandle_mv cHandle )

29
Using the macros
  • jdbcLoadTable (
  • cHandlecHandle,
  • datasashelp.zipcode,
  • obs20)
  • jdbcQuery (
  • cHandlecHandle,
  • sqlSELECT FROM ZIPCODE, outWORK.ZIPCODE)

30
JDBC connection pattern
  • Class.forName(jdbcDriver)
  • Connection con DriverManager.getConnection
  • ( URL, username, password )
  • jdbcDriver org.postgresql.Driver
  • URL jdbcpostgresql//www.devenezia.com5434/se
    sug03demo
  • username sesug03demo
  • password D3m0oeoe

31
Conclusion
  • Javaobj opens new horizons
  • Hybrid solutions
  • Combine best features of different technologies
  • Web
  • www.devenezia.com/papers/sesug-2003
Write a Comment
User Comments (0)
About PowerShow.com