Object Datasource

A object datasource is a datasource that allows data to be extracted at runtime from Java objects and Enterprise Java Beans.

To use the DataSource Wizard, right-click on the folder where the object datasource is to be created. The list of available actions will appear. Select the “Add” option, then the “Datasource” from the sub-options that appear.

The DataSource Wizard will appear. For object datasource, there are four steps:

  • Select datasource type
  • Define parameters
  • Define Javascript
  • Define security option

Select Datasource Type

In the first DataSource Wizard page, select “Object” from the list of available options, then click on the “Next” button.

Define Parameters

In this second page, the two parameters of the object datasource need to be defined.

  • Details
  • Schema

Define Details

This part requires you to define a name and a brief description (optional) for the object datasource.

Field Description Mandatory
Name Name of object datasource. Yes
Description Brief description of object datasource. No

The mandatory field must be filled, else an error message will appear in the page with a red dot and the “Next” button will not be enabled.

Fill in the fields as required and click on the “Next” button.

Define Schema

This part requires you to define the schema for the object datasource.

To add a field, click on the “Add” button at the left of the page. The “Add Column” dialog box will appear.

Key in the name of the field in the “Name” field and select the data type from the drop-down list in the “Data Type” field. Click on the “Ok” button to add the column.

Repeat the same process until all desired fields as added.

The order of the fields are according to the sequence they are added. To re-order the fields, select the desired property, then click on the “Move Up” or “Move Down” buttons to move the field to the desired position.

You can also edit the field by selecting the desired field, then clicking on the “Edit” button. The “Edit Column” dialog box will appear.

Edit the information as required and click on the “Ok” button to save the change.

If a field is added by mistake, you can remove the field by selecting it, then click on the “Delete” button.

After all required properties are added, click on the “Next” button to continue. Alternatively, if you wish to use the default Javascript and security options, click on the “Finish” button to complete the process.

Define Object Javascript

In this page, you can view and edit the default Javascript for the object datasource.

The JavaScript entered here must conform to the pattern in the default JavaScript.

Edit as required and click on the “Next” button to go to the Security page or click on the “Finish” button to use the default security options.

Security Option

The last page in the wizard for the object datasource allows you to set the security options for the datasource.

There are three options.

Type Description
Read Only When selected and saved, the next time a user opens this datasource, the user will not be able to edit any details of the datasource (such as name, description and column names).
Hide Details When selected and saved, the next time when this datasource is opened, the user will only be able to see the name and description of the datasource.
Encrypted This is to be used with either Read Only or Hide Details options or both.
Checking the checkbox will prompt the user to enter a password, then re-enter to confirm the password (both password must be the same). After this is done, if another user would like to edit any selections, he will need to enter the password.

By default, none of the options are selected. Select the options are desired. More than one option can be selected. If “Encrypted” is selected, provide a password in the pop-up dialog box. Click on the “Finish” button to complete the process.

The new datasource will appear in the repository on the left.

You can change the security option of the datasource through the DataSource Wizard by clicking on the “Properties” icon at the Top Row in the Workspace after the datasource is selected. The second page in the DataSource Wizard allows you to change the security options.

Object DataSource API

The pushTo method is the engine that drives all datasource record generation. It takes two parameters, cxt a PushContent object, and dl A DataListener object.

PushContent

The PushContent provides useful method for other datasources, but is unlikely to be useful within JAvaScript as the functions it provides can be done directly.

String getParameter(String name)

This function gets the value of a parameter. You should use ${substitution} in JAvaScript instead of callig this method, as substitutions are detected and will be included in prompts, whereas calls to getPArameter will not be detected.

String substitute(String s)

This function performs ${substitution} replacement on an input string. Again, this is not useful within JAvaScript, as you can use ${subsitution} strings directly in the code.

DataListener

A DataListener receives data from a DataSource for subsequent processing. For Java use, DataListener (an iterface) and all the classes referenced by it are in the com.elixirtech.data2 package. The methods listed are all public.

void startData(IDataSource src)

This method must be invoked before sending any records or groups, to allow the listener to prepare for receipt. The src should be this (the ObjectDataSource itself).

void startGroup(DataGroup group)

This method is called to indicate that the subsequent records are part of a group. This method should not be called if the data is not already sorted and grouped. Where data is grouped, groups may be nested, within other groups, but all records must be within the innermost groups. You are not allowed to have a group that contains both records and child groups. Similarly, if the top level is grouped, it can contain no records outside of those groups.

boolean processRecord(DataRecord record)

Each record that the data source supplies is passed to the listener through this method call. Usually the method will return true. If the method returns false, then it indicates that the listener does not want to receive any more records. In this case, you can choose to stop sending records (additional ones will just be discarded anyway), but must send the necessary endGroup and endData calls to gracefully terminate the operation. The same applies if exceptions are caught - you should still send the necessary symmetrical endXXX calls to balance the startXXX calls you have already made.

void endGroup(DataGroup group)

This method is called to indicate the end of a group. Each call to startGroup should be matched with a corresponding call to the endGroup after the necessary records have been processed.

void endData(DataSource src)

This method must be invoked after sending all records and groups to indicate that no more information is available. The src should be this.

DataGroup

DataGroup delimits a set of sorted records into groups.

DataGroup(int level, String name)

Construct a DataGroup at a particular level (starting at one). If groups are nested, then child groups would be at level two, etc. The name may be any String - the use depends on the DataListener. For example, an XLSX DataStore will use the group name as the name of the Sheet.

int gelevel()

Retrieve the group level.

int geName()

Retrieve the group name.

DataRecord

A DataRecord supplies an array of objects conforming to the DataSource schema to the DataListener. The ObjectDataSource supplies a method newRecordInstance() to instantiate a record with the appropriate structure. Note that records cannot be reused - once a record has been passed to the DataListener, you cannot modify it and pass it again.

Object[] getData()

Get the array backing this DataRecord so that you can set values before passing it to the DataListener. You should set the values in the array according to their order in the schema (zero-based).