Skip to content. | Skip to navigation

Sections
Personal tools
You are here: Home Accelerate Articles PHP and .Net Web development for U2 using Web DE / RedBack objects

PHP and .Net Web Development for U2 Using Web DE / RedBack Objects

Rocket U2 Web DE, Rocket 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.

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

Level: Intermediate

Ray Else ( relse@rs.com), Software Developer, Rocket Software

16 Oct 2008


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

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.


 

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, RedBack was renamed 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");

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

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

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

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

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

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


About the author

AUTHOR NAME photo

Ray Else works for Rocket U2, with several years experience helping clients develop Web/U2 Applications and assisting 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.

 

 

Document Actions