Skip to main content

PHP and .Net Web development for U2 using Web DE / RedBack objects

Access UniVerse and UniData using RedBack Objects with PHP and .Net

Ray Else, IBM U2 Software Developer, IBM
Ray Else
Ray Else works for IBM U2, with several years experience helping clients develop Web/U2 Applications and assisting IBM U2 engineering with testing of new products and features. He has an M.S. in technical instruction/technical writing/film history from the University of North Texas.

Summary:  IBM® U2 Web DE, U2 Web Development Environment (previously called RedBack®), is a Web framework for accessing UniVerse® and UniData® databases. In this article, examine the history and essential framework of Web DE, and learn how PHP and .NET can reference Web DE RedBack Objects (RBOs) to access U2 data stores in a similar way that ASP and Java™ technology can use them.

Date:  16 Oct 2008
Level:  Intermediate
Activity:  2038 views

History

This article does not cover Web DE RPC protocol or the use of the new simple Web form painter. For those topics, please refer to the official product documentation.

The first incarnation of Web DE, called RedBack, hit the streets in 1998. Today we estimate 1,500 companies use Web DE/RedBack to help run their business — everyone from family-operated businesses to large enterprises and government agencies.


Architecture

U2 is no longer an IBM brand

In October 2009, the U2 products became products of Rocket Software.

The architecture consists of virtual RedBack Objects (RBOs) callable from Windows®, UNIX®, or Linux® through a middleware framework that relies on a pool of responders on the U2 database side to handle requests to read or write data. Until 2005, most RedBack development was done using Microsoft's ASP technology on Windows, or using Java technology on Unix and Linux servers.


Figure 1. Web DE / RedBack architecture
Web DE / RedBack architecture


RedBack Objects (RBOs)

You have your choice of RBOs to inherit from, and you use the Web Designer tool to maintain these. The following are the most commonly used RBOs:

  • SLRBO class – "StateLess" RBO object; fastest database access object; for "create your own" objects where you create your own properties and write your own Methods (Database Reads and Writes) in Basic; intended for one "request/response" hit to database
  • RBO/uObject class – (stateful) intended to bring back a single record from a specific file; can do auto-reads and auto-writes (by setting a value in a key property you define, and then calling ReadData and/or WriteData methods); you can also add your own Methods to this object
  • RBO/uQuery class – (stateful) intended to bring back a recordset of multiple records from a specific file using a U2 (pick flavor) select statement; this object is particularly interesting for reports since you can "page" the data to your Web page if you wish (in other words, you can show them page one of data selected, allowing the user to request page two, and so on)
  • RBO/SB class – (stateful) object for System Builder (SB+) sites that want to call certain SB+ processes from the Web

RedBack = Web DE

In 2006, IBM rechristened RedBack to U2 Web Development Environment (Web DE). ASP.NET development has replaced ASP, so we investigated how to use RedBack Objects with ASP.NET. We also added a new simple ASP.NET form painter with data-binding to assist Web novices get their U2 data on the Web. And, as you are probably aware, PHP has become popular on non-Windows Web servers, so we investigated (and are still researching) how best to use RBOs with PHP. The following sections cover both PHP and ASP.NET use of RBOs.


PHP use of RBOs

PHP can be configured to support COM or JAVA object creation, which is handy since Web DE / RedBack supports COM (through its RedPages.dll) or JAVA (through its RedBeans.jar). Whether configuring PHP for COM access or JAVA access, test your setup, calling a simple "Hello World" COM or Java program first, following examples found on the Web. Then you can have confidence moving forward, creating RedObjects (RBOs) using the RedPages.dll or the RedBeans.jar.

If you install the Windows Version of PHP for IIS, you get COM Object access automatically; the JAVA access requires installing a JVM and more, so it can be tricky (again, search the Web for help on getting PHP to work with JAVA).

Of course, you have to install the appropriate Web DE / RedBack gateway on the Web server and configure it to be able to access your U2 data server (this is covered in the standard U2 product documentation).

Once you have PHP COM set up and Web DE configured, the PHP COM object syntax is straightforward:
$rbObj = new COM("RedBack.RedObject");


Listing 1. Sample code showing PHP COM RBO object use

<?php
// Web DE / RedBack 4.2.6+ stateless object example
$lastname = "";
// create new ADO/COM RedBack object
$rbObj = new COM("RedBack.RedObject");
// for stateful object we would use open2 instead of open3
$rbObj->open3("rbexamples","EXMOD:EmpReader");
// set property
$rbObj->Property("EmpId")->Value = "1011";
// call method / subroutine
$rbObj->callMethod("DoRead");
$lastname = $rbObj->Property("LastName")->Value;
$rbObj = NULL;
?>

The PHP JAVA object syntax is similar:
$rbObj = new Java("com.ibm.redback.redbeans.RedObject");


Listing 2. Sample code showing PHP JAVA RBO object use
	
<?php
// Web DE / RedBack 4.2.6+ stateless object example
$lastname = "";
// RedBeans.jar needs to be in php classpath in php.ini
$rbObj = new Java("com.ibm.redback.redbeans.RedObject");
$rbObj->setRBOAccount("rbexamples");
$rbObj->setRBOClass("EXMOD:EmpReader");
// if using stateful object, would need to open it so:
//     $rbObj->open();
$rbObj->setProperty("EmpId", "1011");
$rbObj->callMethod("DoRead");
$lastname=$rbObj->getProperty("LastName");
$rbObj = NULL;
?>

Again, the PHP COM interface accesses through the RedPages.dll, whereas the JAVA interface accesses through the RedBeans.jar. Both the RedPages.dll and the RedBeans.jar look up how to access the U2 database server/account ("rbexamples" in the sample code) by looking in the Web DE gateway config file called rgw.ini. You can skip the need for the config file by using ip address, colon, port number, for example "127.0.0.1:8453", instead of the account name in your PHP code.


ASP.NET use of RBOs

Web DE gateway comes with a COM component (RedPages.dll), and since .NET supports COM, you can easily use your Web DE RBOs from ASP.NET. The trick is to create a COM reference in your project (see Figure 2). Note that if you want to use a uQuery (report) RBO through a Microsoft COM recordset, then you must make a reference to recordset as well.


Figure 2. Adding reference to Redpages.dll in Visual Studio 2005 or 2008
Add reference to Redpages.dll in Visual Studio

Once you have your reference, you can open RedBack Objects using open2 (stateful) or open3 (stateless).


Listing 3. Sample code showing ASP.NET (VB) RBO object use

Dim Id As String
Dim ro As New REDPAGESLib.RedObject
Dim prop As New REDPAGESLib.RedProperty
' hardcode the Id for now
Id = "1016"
' do RedBack Database Access using pre-defined RedBack Object
Try
'Make Connection to rbexamples database and Get Employee object definition
' from Module EXMOD, passing no User, Password, or previously stored object handle
' note Open2 can be used for stateful or stateless object
' but Open3 (available in RB 4.2.6) is best for stateless object use
' note Open3 has only the first 2 parameters
ro.Open2("rbexamples", "EXMOD:EmpReader", "", "", "")
'Set Id into Object Property
prop = ro.Property("EmpId")
prop.Value = Id
'Call Method to Read
ro.CallMethod("DoRead")
'If RBO or SLRBO we would check some status property to see if Read Okay,
'if uObject we can check new_item = 1 to see if record did not exist
'Get Values from Properties and put in Text of Labels
prop = ro.Property("FirstName")
FirstName.Text = prop.Value
prop = ro.Property("LastName")
LastName.Text = prop.Value
Catch ex As Exception
'Set Message label with error message
Mess.Text = "Exception occurred: " & ex.Message
Finally
If IsReference(ro) Then
'Close Object
ro.Close()
End If
End Try


Listing 4. Sample code showing ASP.NET (C#) RBO object use

string firstname;
string lastname;
REDPAGESLib.RedObject myrbo = new REDPAGESLib.RedObject();
REDPAGESLib.RedProperty myprop;
//note Open2 can be used for stateful or stateless object
//but Open3 (available in RB 4.2.6) is best for stateless object use
//note Open3 has only the first 2 parameters
myrbo.Open2 ("rbexamples", "EXMOD:EmpReader","","","");
myprop = (REDPAGESLib.RedProperty)myrbo.Property("EmpId");
myprop.Value = EmpId.Text;
myrbo.CallMethod("DoRead");
myprop = (REDPAGESLib.RedProperty)myrbo.Property("FirstName");
firstname = myprop.Value ;
myprop = (REDPAGESLib.RedProperty)myrbo.Property("LastName");
lastname = myprop.Value ;
Label1.Text = firstname + " " + lastname;

Web DE / Redback RBOs can get the data to you easily from the backend into simple strings or a recordset. To populate a dataset from strings or a recordset, you would have to write your own routine (though the new Web DE form painter does provide a little of this functionality with its auto-generated wrapper routines). Listing 5 illustrates the use of a stateful uQuery object in a stateful way. It has isolated the open stateful versus stateless logic in a separate Sub whose code is included in the listing (with the understanding that this code is sample code only and not intended for commercial use):


Listing 5. Sample code using a stateful uQuery RBO to get U2 data into a recordset (VB.NET)

Dim DatabaseName As String
Dim Id As String
Dim ro As New REDPAGESLib.RedObject
Dim prop As New REDPAGESLib.RedProperty
Dim rs As ADOR.Recordset
Dim rsForGridView As ADOR.Recordset
. . .
DatabaseName = "rbexamples"
OpenRedbackObject(ro, DatabaseName, "XD", "MemberQuery", "", "", "N")
prop = ro.Property("items_per_page")
prop.Value = iPageSize
'Set Id into Object Property
prop = ro.Property("select_criteria")
prop.Value = "SELECT MEMBERS WITH STATE = """ & Id & """ BY LASTNAME"
'Call Method to Read
rs = ro.CallMethod("Select")
prop = ro.Property("MaxRows")
Icnt = CInt(prop.Value)
'ItemsPerPage = CInt(prop.Value)
prop = ro.Property("items_per_page")
ItemsPerPage = CInt(prop.Value)
. . .
Public Sub OpenRedbackObject(ByRef ro, ByVal DatabaseName, ByVal ROModule,
ByVal ROName, ByVal Username, ByVal Password, ByVal Stateless)
' Sample Code only - not for commercial use - no warranty implied
Dim RBHandle As String
Dim RB_SessionId As String
Dim prevRBHandle As String
Dim strVariable As String
Dim IsOpen As Boolean
Dim objCookie As HttpCookie
RB_SessionId = ""
RBHandle = ROModule & ":" & ROName
If Stateless <> "N" Then Stateless = "Y"
If Stateless = "N" Then
' Handle Stateful using sessionid and object handle in cookies
For Each strVariable In Request.Cookies()
If strVariable = "RB_SessionId" Then
RB_SessionId = Request.Cookies(strVariable).Value
End If
If strVariable = "RB_" & ROName Then
prevRBHandle = Request.Cookies(strVariable).Value
If prevRBHandle <> "" Then
RBHandle = prevRBHandle
End If
End If
Next
End If
If Not (Session(ROName) Is Nothing) Then
ro = Session(ROName)
Try
ro.Open2(DatabaseName, RBHandle, Username, Password, RB_SessionId)
IsOpen = True
If Stateless = "N" Then
'Handle Stateful
objCookie = New HttpCookie("RB_SessionId", ro.SessionId)
Response.Cookies.Add(objCookie)
objCookie = New HttpCookie("RB_" & ROName, ro.RBOHandle)
Response.Cookies.Add(objCookie)
End If
Catch ex As Exception
'Set Message label with error message
Throw ex
End Try
End If
If Not IsOpen Then
Try
ro = New REDPAGESLib.RedObject()
ro.Open2(DatabaseName, RBHandle, Username, Password, RB_SessionId)
IsOpen = True
Session(ROName) = ro
If Stateless = "N" Then
'Handle Stateful
objCookie = New HttpCookie("RB_SessionId", ro.SessionId)
Response.Cookies.Add(objCookie)
objCookie = New HttpCookie("RB_" & ROName, ro.RBOHandle)
Response.Cookies.Add(objCookie)
End If
Catch ex As Exception
'Set Message label with error message
Throw ex
End Try
End If
End Sub

With a little effort you can populate a dataset from a recordset, and then databind the dataset to a gridview, as shown in the below sample ASP.NET app (Figure 3):


Figure 3. Screenshot of an ASP.NET Web app with a GridView holding U2 data
GridView holding U2 Data

Conclusion

Although Web DE / RedBack was intended originally for ASP and Java technology use, it is designed so flexibly that you can use RBOs with related technologies like ASP.NET and PHP.


Resources

Learn

Get products and technologies

  • Build your next development project with IBM trial software, available for download directly from developerWorks.

Discuss

About the author

Ray Else

Ray Else works for IBM U2, with several years experience helping clients develop Web/U2 Applications and assisting IBM U2 engineering with testing of new products and features. He has an M.S. in technical instruction/technical writing/film history from the University of North Texas.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Information Management, Open source
ArticleID=345890
ArticleTitle=PHP and .Net Web development for U2 using Web DE / RedBack objects
publish-date=10162008
author1-email=raymonde@us.ibm.com
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers