Thursday, November 20, 2014

Table backward compatibility in ADF

Hi  All,

Recently i came cross a use case where i need to add  a new column into a table which being already used in production and we need to support this new changes on both version of table schema.
However gradually we will get ride of old version of table. but for now we need to support both schema.
In my case it's only related to fetch operation ,so here i am going to explain how i achieved fetch functionality on both schema.
I have create a sample table name as BlogTable which has following column in my version 1(demo purpose)

1-id
2-Name
3-Address

Now my boss(they always demand :) ) came to me and asking in next version 2 we have to add one more column name as
4-city.
And he warned me that this should work in both data base schema. Since our application is already in production therefore the old table based VO should not give any error while fetching data.

I need to change VO the way which support both table version at a time.But obviously if i put column name directly and if it's try to execute on schema which does not have new column then this going to throw exception at run time.

I solve this problem by creating a function inside the package but the most importance part is here the function name should be same as newly added column name. so that when sql engine try to execute the query first it will look for column and if column is not present in table then it think it is function and it will execute dummy function which return null record.
And also in view query i am using package name as table alias name.

 function code is following

CREATE OR REPLACE
PACKAGE BODY BLOGPACKAGE AS
function city  return varchar2 IS
Begin
    return 'dummy';
End city;

END BLOGPACKAGE;

And VO query is

SELECT
    blogpackage.ID ID,
    blogpackage.NAME NAME,
    blogpackage.ADDRESS ADDRESS,
    blogpackage.city city
FROM
    BLOGTABLE blogpackage

And if you observer that the table alias name is same as package name.so when i try to get the column which is not present in this schema it will call function of package .

Here two point to remember
1-function name should be same as column name
2-table alias should same as package name.

Following screenshot is with real column table.





Following screenshot of application without city column.


Sample application attached with sample sql query inside resource folder.

link is : https://drive.google.com/file/d/0B8cP4jZuxLlXay1BNmNiOE5RaGM/view?usp=sharing

Thank







  




Sunday, April 27, 2014

Active Data Service with ADF Table component

Hi All,

I have already posted one post on active data service with adf table component and oracle coherence. But in this post will explain ADS without using oracle coherence.

As you all know that ADS is basically a push technology which send data from server to client without any user intervention . However client will send request periodically to server ask for update. Which further configure in adf-config.xml.

The transport has following favor
1-long-polling.
2-polling
3-streamming

This all i wrote in my previously post.Today i will explain some thing new and obviously interesting things.

As you all know ADS support limited number of component , table is one of them .So basically in table it's support only output text which will there in table column. You can not change any table or column related property. Although you can change only out put  related property.

So in output component what property you can changes this is next question ? and answer is very simple,
you can changes following property of output text. (only this property changes make sense)

1-Value (main property )
2-inline style
3-style class.

Ya , you can changes only above three property of output text. And i recommend that do not try to use other component .because it doesn't make much any sense because ADS is only for dashboard kind of application where you can show latest status of any trend.
The main part which i would like to point out here, that way of creating buildActiveDataUpdateEvent event.

Example is
ActiveDataUpdateEvent event =
            ActiveDataEventUtil.buildActiveDataUpdateEvent(ActiveDataEntry.ChangeType.UPDATE,
                                                           getActiveModel().getCurrentChangeCount(),
                                                           new Object[] { rowKey },
                                                           new Object[] { null },
                                                           new String[] { "name",
                                                                          "idInlineStyle",
                                                                          "nameInlineStyle" },
                                                           new Object[] { name,
                                                                          idInlineMap.get(i),
                                                                          nameInlineMap.get(i) });

Explanation 

1-ActiveDataEntry.ChangeType.UPDATE : Type of Event , it has following type
1-UPDATE
2-INSERT
3-INSERT_BEFORE
4-INSERT_AFTER
5-INSERT_INSIDE
6-REMOVE
7-REFRESH

2-ChangeCount : keep track of number of changes happened
  
3-Key : is key of row which you want to update.Since this table is based on list of object therefore key will always same order which order you added object in list. And if this graph then it could combination of column and row.

4-InsertKey :  the key to indicate the insert position.
This is useful when you want to insert new row in specific position.  Event type -INSERT_BEFORE and  INSERT_AFTER can use with this.

5-Names : now this one is interesting for understanding prospective. It does not represent actual value however it is just a key which value you want to change.
Suppose if your table has one column and that column has one output text and that out put text has following value #{row.name} .so if yow want to change this value then you should need to pass "name" as key.
example  new String[] { "name"}.
Apart from value you can also change inline and style class . For changing this value you should have to binding this value to EL , if you do not do this it is not going to work.

In page , output look like following

  <af:outputText value="#{row.id}" id="ot2"  styleClass="#{row.idStyleClass}"
                           inlineStyle="#{row.idInlineStyle}"/>

for changing style class or inline style you have to pass like new String[] { "idStyleClass" ,"idInlineStyle}.

6-Values : This argument basically represent actual array of object values. Which value will change.


  new Object[] { "newValue","color:Aqua;", "yourstyleclass" }

i-newValue is new value of out put text
ii-color:Aqua; is inline style class for output text
iii-yourstyleclass is your defined style class.

Apart for above explanation other vital information about ADS is presented at following link

1-http://adfwithejb.blogspot.com/2012/10/active-data-service-ads.html
2-http://adfwithejb.blogspot.com/2012/11/oracle-coherence-with-active-data.html

You can find sample application at following location .

https://drive.google.com/file/d/0B8cP4jZuxLlXNU5lTVh4NzNwVkE

Thanks,
Prateek