Util Examples

Contents Hide

  

Example 1. Creating/Accessing a Base64 Object

// Creating a Base64 Object

blob = new Blob(record.get(i));

str = util.encodeBase64(blob);

 

// Accessing the object

bytes = util.decodeBase64(str);

Note:

Example 2.  Decompressing Client Binary Data

The sample code below has a similar effect to having a mapping with 'Need to Decompress Data' set to true.

byteValue = record.get(5);

if (byteValue != null)

{

    blobValue = new Blob(byteValue);

    blobValue.decompress();

    psInsertRecord.setBytes(6, blobValue.getBytes());

}

else

{

    psInsertRecord.setNull(6, java.sql.Types.BLOB);

}

Note:

Example 3.  Create a Grouping

Similar to a join statement in SQL.

vectData = new Vector() ;

vectData.add(parentResultSet);

vectData.add(childResultSet1);

vectData.add(childResultSet2);

 

vectRelationships = getRelationships() ;

 

result = Util.groupData(vectData, vectRelationships);

Note:

Example 4.  Read a Grouping

The following will read the result given in Example 3 and will return the sizes of each subset to BrightServer's info log via the ScriptSession object.

for (i = 0; i < result.size(); i++)

{

    tuple = result.get(i);

 

    orderedParent = tuple.get(0);

    ScriptSession.logInfo(orderedParent.size());

 

    orderedChild1 = tuple.get(1);

    ScriptSession.logInfo(orderedChild.size());

 

    orderedChild2 = tuple.get(2);

    SriptSession.logInfo(orderedChild.size());

}

Note:

Example 5.  Create a Relationship for Grouping

The following creates a relationship with the relationship similar to the following SQL statement:

SELECT * FROM ORDER, ORDER_ITEM

WHERE ID = ORDER_ID

A similar relationship may be used in conjunction with the example shown in Example 3.

function getRelationships()

{

    vectRelationship = new Vector();

 

    vectRelationship.add("ORDER");

    vectRelationship.add("ORDER_ITEM");

 

    srcKeys = new Vector();

    srcKeys.add("ID");

    vectRelationship.add(srcKeys);

 

    dstKeys = new Vector();

    dstKeys.add("ORDER_ID");

    vectRelationship.add(dstKeys);

 

    vect = new Vector();

    vect.add(vectRelationship);

    return vect;

}

Note: