13
Wed, Nov
5 New Articles

Internet Power Programming with VisualAge for Java

Java
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

For most AS/400 programmers, Java is an unfamiliar language: first, its syntax is unlike RPG or COBOL; second, it is object-oriented. But, with IBM's VisualAge for Java, it may not be as difficult to learn, because you can learn how to use it incrementally. You can start with the Rapid Application Development (RAD) environment to get applications up quickly without writing one line of code. Later, as you get more comfortable with Java's syntax and object-oriented programming, you can dig deeper and start writing and modifying Java code. This article will give you an overview about how you might use VisualAge for Java to create an Internet- or intranet-ready application. To illustrate how easy it is, a hypothetical order-entry applet/application is presented.

VisualAge for Java is available in three editions: Entry (which can be downloaded free from http://www.software.ibm.com/ad/vajava), Professional, and Enterprise. (In the first quarter of 1998, VisualAge for Java, AS/400 Feature will be available for the Enterprise edition. It will include special AS/400 features such as the AS/400 Toolbox for Java and a server-side debugger. A beta version of the AS/400 Toolbox for Java is available today at http://iws.as400.ibm.com/toolbox/javabeta.htm.)

To develop this application, we selected the Enterprise edition of VisualAge for Java, because the VisualAge for Java Enterprise edition includes the following components not included in the Professional edition:

o Database Access allows access to any relational database that supports an ODBC or a JDBC driver.

o CICS Access allows CICS transactions to be wrappered (externalized) and used within a Java application.

o C ++ Server Access allows access to C++ services by generating Java beans and C++ code to allow interoperability between Java and C++.

o RMI Access allows a Java program in one virtual machine to send messages to another Java object running in a different virtual machine. These objects can even be on different machines.

Enterprise Access Builder for Data (also referred to as Data Access Builder or DAX) is part of the VisualAge for Java Enterprise edition. You can use it to generate data access classes based on your existing relational database tables, such as DB2/400.

You use DAX to generate the Java classes to access data. These generated Java classes, which are JavaBeans, can be used directly in your Java programs or within VisualAge for Java composition editor. (JavaBeans are a standard Java class architecture, so these generated classes can be used in any JavaBeans-compliant IDE or utility.) Some of the other key features of DAX include the following:

o JDBC access to data. DAX generates classes that use JDBC to access your database. You can use the JDBC driver, which is part of the AS/400 Toolbox for Java.

o Rapid development, but still object-oriented. In minutes, DAX can generate Java source code that allows you to add, update, delete, and retrieve rows in your database. DAX generates the code in a consistent, extendable, object-oriented fashion, enabling the benefits of object-oriented programming.

o Stored procedures. You can use DAX to generate code that calls stored procedures resident on DB2/400 files. You will often get better performance with stored procedures than with JDBC data access.

o Commitment control and connection. Services are provided for connecting to your databases. In addition, commit and rollback methods are generated for transactions.

This section describes how to create a sample application/applet using the VisualAge for Java DAX. The application you will build is for the ABC Parts Supply Company, a fictitious parts wholesaler. The application simply allows ABC customers to place orders by selecting the customer and the part being ordered, and then entering the quantity of the part being ordered. Today, this function of order taking is being performed by five ABC employee service personnel via the telephone. With some user interface design changes, this application could allow ABC customers to submit orders 24 hours a day, from anywhere, via the Internet while reducing ABC's customer service staff requirements.

The application operates over three DB2/400 files described in Figure 1.

The application being created should look like that illustrated in Figure 2. This window allows you to view a list of parts and customers and to create orders. When the Display Records push button is clicked, all the customer records are read from the database and placed in the customer multicolumn list box. Then, the parts records are read from the database and placed in the parts multicolumn list box. The user can then select a customer and part from the lists.

When the Place Order push button is clicked, the Parts file record is updated (based on the user- specified order quantity), the quantity available is reduced, and the quantity sold field is incremented. Then, a new order record (which includes the customer ID, part ID, and quantity ordered) is written to the ORDERS database.

A key feature of Java is its support of object-oriented programming (OOP). The concept of OOP is too large to cover in detail here, but I will use and discuss elementary elements of OOP. The diagram in Figure 3 illustrates the use of Unified Modeling Language (UML) to describe our object model. UML is a diagramming language to describe object data properties, actions, and relationships with other objects. (Refer to Rational Software Corporation's Web site at http://www.rational.com for more information on UML.) An object model is produced with UML through object-oriented analysis (OOA) and object-oriented design (OOD).

OOP's goal is to increase programmer productivity and quality of software development. Toward this goal, OOP software should be designed to do two things:

1. Model the real world. OOP allows us to create objects and classes that are like their real-world counterparts, making software simpler and more understandable.

2. Reuse software. Objects can be created in an abstract way and then subclassed or extended using inheritance. This allows object properties and operations to be reused.

The UML object model in Figure 3 illustrates the software design we will use for constructing our sample application.

UML uses a rectangle with three compartments to describe a class. The top compartment contains the class name. The middle compartment contains the attributes or properties of the class. The bottom compartment contains the operations or methods that this class will be able to do.

The table in Figure 4 describes all the classes illustrated in Figure 3. Note that only the most significant attributes and operations are listed.

Without the VisualAge for Java Enterprise DAX, we would have to create all the classes manually as well as code all the logic to select, update, and insert records into our database. With the DAX, much of the code is generated for us. First, we create a VisualAge project and package to hold the classes we will create. Next, we start the DAX and select Map Schema, which starts the database-to-Java object mapping process. Selecting the ODBC Data Source that represents your target system identifies the location of your data source. From this point, clicking the Get Tables button will retrieve the available tables and views on the target system. Selecting a particular file, such as the PARTS file, results in a screen like that shown in Figure 5.

The DAX has at this point targeted the database that you specified and retrieved all the fields present in the PARTS database file you selected. DAX will create a Java class named Parts and add variables for each field in the file as well as the Java methods to retrieve and set the variables value. For example, the database contains a field named partno, so DAX will generate an instance variable called partno and a method called getPartno to get the value. DAX will also generate a method called setPartno to set the value of the Java instance variable. We can also change the names of the instance variables to something more descriptive, such as partNumber instead of partno.

Along with the Parts class, several other classes are generated, including a PartsManager. The PartsManager class is capable of retrieving and instantiating (materializing) a collection of Part objects.

Upon completion of the generation process, the classes shown in Figure 6 should be generated by DAX in your Java package. The table contained in Figure 7 describes each generated class. These generated classes are the reusable elements that we will use to build our application.

We then follow the same process to generate Order file and Customer file classes, such as Order, OrderManager, OrderResultForm, Customer, CustomerManager, CustomerResultForm, and so forth (the same as what was generated for the Parts file).

The Company class contains a PartsManager object, an OrderManager object, and a CustomerManager object. This class handles processing for a new order. It integrates our other xxxManager classes to give us the ability to create orders. DAX generated the xxxManager classes for us, but we must create the Company class because it is part of our object model, which DAX knows nothing about. To create the Company class, we simply create a class within one of our packages.

Figure 8 shows the Company class created within a package called SalesCompany. It shows partsManager, orderManager, and customerManager instance variables created as private variables. Along with these variables are methods to get the values of these variables. For example, the customerManager variable has a getCustomerManager method, which returns the value of the variable. The returned value will be an instance of a CustomerManager object. These variables do not have associated set methods, because there is no need in this application to set the variables.

The import statements allow you to use classes and objects that exist in a different package. The defaultDatastore variable is used to hold our connection object. This connection object, which is generated by DAX, contains the URL, connection status, and methods to connect and disconnect from the database. The defaultDatastore variable has a "getter" method to return the datastore object.

Figure 9 shows the "newOrder(Parts aPart, Customer aCustomer, String aQuantity)" method, which becomes our most important method. It is called when the user clicks the Place Order button after selecting a customer and a part and specifying a quantity. This method accepts those three objects in the parameter list. The method then creates a new order object and sets the appropriate data in it, updates the part object by reducing the inventory and incrementing the number sold, and adds the order record to the database.

Our last task is to create a user interface for our ABC Parts Ordering System. We will just assemble and connect the classes that DAX created for us, along with our custom Company class.

We create a new class called OrderMainFrame, which extends from the java.awt.Frame that we will use to compose our GUI windows. Leveraging the power of VisualAge's visual building technology, we quickly and easily connect the components, resulting in a working application as illustrated in Figure 10.

The technical benefits of using VisualAge for Java's DAX instead of coding custom data access classes offer significant timesavings. DAX can generate in minutes what it would take several days to generate by custom coding. In addition, programmers can extend and customize DAX- generated classes. Many advanced capabilities-such as asynchronous processing via threads-are

also generated for your use.

The business benefits of increased customer service and lower employee labor costs are an obvious goal of many organizations that want to leverage the enormous capabilities of the Internet. Collectively, these technologies will allow organizations to wake up and smell the coffee!

Paul Holm is an advisory software engineer within IBM's AS/400 Division. His background includes five years as a DB2/400 developer. More recently, he spent five years as an object- oriented development specialist focusing on Smalltalk and Java. He can be reached by email at This email address is being protected from spambots. You need JavaScript enabled to view it..

Figure 1: The AS/400 files used by the sample Java application





Internet_Power_Programming_with_VisualAge_for_Java05-00.png 437x183

Figure 2: The "Parts Order Management" window




Figure 3: The "Parts Order Management" UML design



Internet_Power_Programming_with_VisualAge_for_Java06-00.png 825x645





Internet_Power_Programming_with_VisualAge_for_Java07-00.png 431x560

Figure 4: Sample application class descriptions





Internet_Power_Programming_with_VisualAge_for_Java07-01.png 437x541

Figure 5: The DAX generation window




Figure 6: Classes generated by DAX



Internet_Power_Programming_with_VisualAge_for_Java08-00.png 825x647




Figure 7: DAX-generated class descriptions



Internet_Power_Programming_with_VisualAge_for_Java09-00.png 825x1020





Internet_Power_Programming_with_VisualAge_for_Java10-00.png 422x881

Figure 8: The DAX generation window




Figure 9: The newOrder method



Internet_Power_Programming_with_VisualAge_for_Java11-00.png 825x791

public void newOrder(Parts aPart , Customer aCustomer, String aQuantity) {

/* convert the input string aQuantity to a short value. It comes in a string because it comes from the
user interface */

short quantitySold = (new Short(aQuantity)).shortValue();
/* Create a new order and populate the order data */

Orders newOrder = new Orders();
newOrder.setQuantity(quantitySold);
newOrder.setCustomerId(aCustomer.getCustomerId());
newOrder.setPartId(aPart.getPartId());
newOrder.setOrdertmsp(new java.sql.Timestamp(System.currentTimeMillis())); // sets the timestamp to
the current clock timestamp

/* Update the part inventory quantity and amount sold. */

short newQuantity = (short)(aPart.getQuantity().shortValue() - quantitySold);
aPart.setQuantity(new Short(newQuantity));
short newNumSold = (short)(aPart.getNumSold().shortValue() + quantitySold);
aPart.setNumSold(new Short(newNumSold));

/** There is a bug in the EAB that prevents the update() methods from running. Instead of using
update() methods we will delete the part record and re-add it with the updated inventory quantity */

Parts aNewPart = (Parts) aPart.clone(); //Create a copy of the part record.

/* Delete and re-add the part */

try {
aPart.delete();
aNewPart.add(); }
catch(Exception e) {

System.out.println("Error updating part "+e); }

/** Add the new order to the database */

try {
newOrder.add(); }
catch(Exception problem) {

System.out.println("error adding order " + problem); }

}

Figure 10: The working application





Internet_Power_Programming_with_VisualAge_for_Java12-00.png 825x645
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: