Friday 8 December 2017

Oracle ADF Essentials/ Oracle ADF with MYSQL

Using Oracle ADF along with MYSQL can be a tricky since it was originally designed to work with Oracle Database. Like we understand that there are some trivial differences to certain operators across both engines.

Consider that you are using a view criteria that uses 'Contains' or 'Begins With' conditions for the bind variables.  MySQL doesn't support the pipe operator for concatenation out of the box.

The issue and solution is articulated here. One solution is to SET sql_mode='PIPES_AS_CONCAT';. This will fix the engine itself.
If you have additional constraints or dependent queries due to which you can't change the engine, here's another solution.

Let's take a User ViewObject with a user search view criteria, looks like the screenshot below



Create a Custom Implentation that extends the ViewObjectImpl class and overrides buildQuery method.

Let's dive into the code real quick

public class CustomVOImpl extends ViewObjectImpl {
    public CustomVOImpl(String string, ViewDefImpl viewDefImpl) {
        super(string, viewDefImpl);
    }

    public CustomVOImpl() {
        super();
    }
   
    @Override
     protected String buildQuery(int noUserParams, boolean forRowCount)
     {
       String query = super.buildQuery(noUserParams, forRowCount);
       if (query!=null) {
         query = query.replace( "( ? || '%')", " (CONCAT( ?, '%' ) )");
         query = query.replace( "('%' || ? || '%')", " (CONCAT('%', ?, '%' ) )");
       }
       //System.out.println("Updated query"+query);
       return query;
     }

     @Override
     protected String buildQuery(int noUserParams, boolean forRowCount, String selClause, String fromClause, String whereClause, int subQueryLevel)
     {
       String query = super.buildQuery(noUserParams, forRowCount, selClause, fromClause, whereClause, subQueryLevel);
       if (query!=null) {
           query = query.replace( "( ? || '%')", " (CONCAT( ?, '%' ) )");
           query = query.replace( "('%' || ? || '%')", " (CONCAT('%', ?, '%' ) )");
       }
        // System.out.println("Updated query"+query);
       return query;
     }
}
To explain in detail, query.replace( "( ? || '%')", " (CONCAT( ?, '%' ) )"). The '?' is where our bind parameter plugs itself in. Now replacing pipe operator with MySQL concat looks like (CONCAT( ?, '%' ) ). This concatenates bind parameter with a trailing '%' wildcard character.
Likewise to '%' || ? || '%' translates to (CONCAT('%', ?, '%' ) ).

Finally don't forget to incorporate this change in your ViewObject.!


 I did not find anything else that got funny with ADF Essentials + MySQL with Integrated WLS. Had to do some additional configs on Glassfish which I will explain it in a different blog post.



Tuesday 7 March 2017

Getting selected Rows in Oracle APEX Interactive Grid

I tried doing lot of things!! A lot, indeed. Very little help  out there on Stack Overflow. So I'm writing this to help developers who are starting with Oracle APEX.

Use Case : Get selected row(s) from a region such as Interactive Grid/Interactive Report. APEX does not provide a declarative way to perform this operation in Javascript. I tried apex.item(), $v() etc. Nothing seemed to work out.

These are the steps I followed to get the selected selected row from the interactive grid in Oracle APEX.

1. Have a ROW Selector column in the Interactive Grid





2. Create a Dynamic Action in the Grid, with the Event being 'Selection Change [Interactive Grid]'. Now this event is fired each time a selection is changed in the grid. I've disabled multi-select in my grid, but this approach works for multiple selections too.



3. In true action, select 'Execute Javascript Code' and type in the following code


if(this.data != null){
    if(this.data.selectedRecords[0]!= null){
        selectedRecord = this.data.selectedRecords[0][0];
        console.log(selectedRecord);
    }

}




 How did I figure this out? Let's just simple do a console.log(this) on the 'Selection Change' Event.

Here's the screenshot of what is logged on the console.



this.data has selectedRecords, there you go!!! Had some trouble figuring that out! Phew!

Tags : Oracle APEX 5, Oracle APEX5  Interactive Grid selected row javascript, Oracle APEX5 Interactive Grid javascript listener, Oracle APEX5 Region Row Selection, APEX5 region javascript, Oracle APEX5 blog, Oracle APEX5 javascript Interactive grid
 

Creating a headless slave node in Hudson

Generally the Hudson builds are tied up to a slave node. The Slave node can be launched in two ways

        1. As a JNLP client in windows
        2. Via SSH on a Linux machine

Since, the Hudson is generally on Linux Machines, this article focuses on creating a new slave node for Hudson.

1. Navigate to  Hudson home page in your web browser.
2. Click on 'Manage Hudson'.
3. Select 'Managed Nodes'
4. Select 'Create New Node'
5. Provide an appropriate name, click Ok

6. Enter the number of Executors. This is required for the number of concurrent executions to be done
7. Enter the directory where the Hudson Job artifacts should go in
7. In the Launch drop down,
              a. Select Launch Via  Windows slave agent with JNLP
              b. Select Launch Slave via SSH. Click on 'Advanced' to type in additional fields from where the Slave node has to be launched. Type in IP Address, username, password and other fields. Click 'Save'.

Now, the slave node is ready and we can tie up Hudson jobs to this node ;-)