Oracle and change data notification to keep BigMemory cache in-sync

Provide DB user the ability to execute DBMS AQ package

-- Execute the following using sysdba to use the DBMS_AQ package
--GRANT EXECUTE ON dbms_aq TO scott;
--GRANT aq_administrator_role TO scott;

EXECUTE dbms_aqadm.grant_system_privilege('ENQUEUE_ANY', 'scott', TRUE);
EXECUTE dbms_aqadm.grant_system_privilege('DEQUEUE_ANY', 'scott', TRUE);

Now define a queue that can capture near real time updates to our table of interest

EXECUTE dbms_aqadm.stop_queue(queue_name => 'accounts_queue');
EXECUTE dbms_aqadm.drop_queue(queue_name => 'accounts_queue');
EXECUTE DBMS_AQADM.DROP_QUEUE_TABLE(queue_table => 'accounts_queue_table');
EXECUTE dbms_aqadm.create_queue_table(queue_table => 'accounts_queue_table',queue_payload_type => 'sys.aq$_jms_text_message',multiple_consumers => false);
EXECUTE dbms_aqadm.create_queue(queue_name => 'accounts_queue', queue_table =>'accounts_queue_table', queue_type => DBMS_AQADM.NORMAL_QUEUE, retention_time => 0, max_retries => 5, retry_delay => 60);
EXECUTE dbms_aqadm.start_queue(queue_name => 'accounts_queue');

-- helper procedure
SET SERVEROUTPUT ON
CREATE OR REPLACE
PROCEDURE enqueueAccount(accountID VARCHAR2)
AS
  msg SYS.AQ$_JMS_TEXT_MESSAGE;
  queue_options DBMS_AQ.ENQUEUE_OPTIONS_T;
  msg_props DBMS_AQ.MESSAGE_PROPERTIES_T;
  msg_id RAW(16);
BEGIN
  msg := SYS.AQ$_JMS_TEXT_MESSAGE(NULL,NULL,NULL,NULL); 
  msg.text_vc  := accountID;
  msg.text_len := LENGTH(msg.text_vc);
  DBMS_AQ.ENQUEUE(queue_name => 'accounts_queue' , enqueue_options => queue_options , message_properties => msg_props, payload => msg , msgid => msg_id);
END;
/
-- trigger that enqueues messages
CREATE OR REPLACE TRIGGER AccountsTableTrigger 
AFTER INSERT OR UPDATE ON ACCOUNTS
FOR EACH row 
BEGIN
    enqueueAccount(:new.ACCOUNTNUMBER);
END;
/

-- lets now insert a record into our table
insert into ACCOUNTS values('a1','jim',100);
commit;


Now we can simply use Oracle AQ java libraries to dequeue messages infact using JMS APIs.

Note that you will need install the following Oracle jars within your local maven repo manually

<dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc</artifactId>
            <version>11g</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>aqapi</artifactId>
            <version>11g</version>
            <type>jar</type>
        </dependency>

AgileApps and Objects: “If everything could hang from an object, the world would be more object oriented”

We often strive to find THE  programming paradigm and orient the engineering team  towards viewing all problems with that single lens. We have had such “oriented” techniques  driving engineering discipline for quite a while now, and the list includes techniques such as  object-orientation, service-orientation, & aspect-orientation to name a few. Having said that, enterprises that have made use of the right paradigm(s) to solve the right problem(s) have often had to resort to using more  than one of these tools & platforms to be effective.

One way of doing it is through what I call it,  “loosely hanging constructs” across such seemingly unrelated disciplines. We can for example start with the “Object Oriented” or objects at the helm to model the key participants of the solution but  then we need to find intuitive techniques to associate these objects with their related constructs from other unrelated paradigms.

That is where AgileApps from SoftwareAG comes in. So lets dig deeper to understand how AgileApps achieves this goal.

Among the core  principles of “Object Orientation”  the most commonly used technique leads one to create objects that model the key participants within the problem domain. Objects are very powerful constructs, and they encapsulate data and methods that act on that data. Those methods end up being the externally visible contracts that act or react to changes made within the environment it is hosted in – environment within which objects interact with one another. In today’s world, the domain use cases that need to blend together to create a business solution are many and varied.  Attempting to resort to pure OO constructs to model all such interactions is non-intuitive, and inclined to fail. Some of the common such domain use cases, their associated paradigms, and constructs are:-

Domain use case Paradigm Constructs
To manage user interactions Model-View-Controller HTML(5),…
To integrate applications message integration patterns Services,Bus,…
To sprinkle human actions Worflow engine Task,Inbox,..
To provide end-2-end visibility Process models EPC,IDEF,..
To analyze and visualize data Reporting tool Cube,Dimensions,..
To let the business user manager their business decision Rules engine RETE,Decision tables,Decision Tree,…

multiple_paradigms

Figure A: Multiple paradigms in a single platform has its own challenges

In a nutshell we have to mix many of these seemingly unrelated  paradigms  to meet our need. Often many of these disparate paradigms have their own development and runtime environments. Gluing them together is a project of its own that requires decent amount of investment.

AgileApps from SoftwareAG provides an effective technique to manage such varied paradigms required to build out an application stack. AgileApps provides the proven reference implementation  that  stitches many of these disparate paradigms & their associated constructs into one. It lets you to define objects, the data they store and the relationship between them. It then goes beyond, and blends in the disparate paradigms discussed above & hangs them right  alongside the object within context.

hang_paradigms_from_objects

Figure B: Multiple paradigms hang off objects defined  within AgileApps

Therefore unlike other reference implementations where one has to invest time & money in establishing the patterns to use/reuse artifacts across the platform, AgileApps is a  full stack application development platform that comes embedded with both  design time guidance as well as runtime execution artifacts to glue multiple concerns onto a single application stack. Under the banner of the object , it allows one to hang many if not all of the constructs we highlighted earlier, making it easy to manage artifacts effectively when it comes to designing the overall solution. See the screenshot of the AgileApps platform that shows how processes, rules and other artifacts/constructs related to  “Inventory “object” are organized :-

AgileAppsScreenShot

Figure C: Screenshot of an Object named “Inventory” and its associated constructs spanning multiple paradigms 

Traditionally we have made developers and users hop across various tools & their unique nuances to leverage domain specific constructs and develop artifacts. All of that complexity is now avoided and very intuitively unified under AgileApps platform, providing both developers and users alike with a nice, intuitive and efficient way for managing various inter-dependent artifacts.

Check out more features of AgilesApps at http://www.softwareag.com/corporate/products/webmethods_process/agileapps/overview/default.asp