DZone
Database Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Database Zone > Traversing Relationships, Conditional Navigation, Query, and Update With JavaScript and Oracle ABCS

Traversing Relationships, Conditional Navigation, Query, and Update With JavaScript and Oracle ABCS

Storing conditional data and utilizing conditional queries can be complex, but using Oracle ABCS with a bit of JavaScript can help solve your problems.

Shay Shmeltzer user avatar by
Shay Shmeltzer
·
Dec. 21, 16 · Database Zone · Tutorial
Like (2)
Save
Tweet
3.96K Views

Join the DZone community and get the full member experience.

Join For Free

 Oracle Application Builder Cloud Service (ABCS) lets you do a lot of things in a declarative way, however for more complex validation and conditional logic you might need to resort to some basic coding in JavaScript.

I ran into such a case with an application I was developing and figured out that the code sample from that system will be a good way to illustrate some coding techniques in ABCS.

The application I was working on allows people to register to various events. Each event has a certain capacity, so if there are too many people registered to an event, we want the rest to be added to a wait list. For each record of a person registering, we keep a reference to the event they want to attend. So the logic flow is:

  1. Check how many open spaces are available for the event we are trying to register for.
  2. If there is space in the event, save the new person data, and show a success message.
  3. If there isn't space, update the person "Waitlisted" field to be true, save the data, and show a message saying that the person is on the wait list. 

In the demo video below, I'm showing how to:

  • Define declarative conditional flow of steps based on results from custom code.
  • Traverse relationships between custom object through code.
  • Execute a conditional query and run through the results from a custom object with code.
  • Set the value for a property of a custom object through code.

For reference, here is the complete code from the sample:

require([     
  'operation/js/api/Conditions',     
         'operation/js/api/Operator' ], 
        function (Conditions, Operator) {     
          var lab = Abcs.Entities().findById('Lab');     
          var id = lab.getProperty('id');    
          //condition is to find a lab with the id that is in the page's 
          //drop down box     
          var condition = Conditions.SIMPLE(
            id, Operator.EQUALS, $Person.getValue('ref2Combo_Box'));     
          var operation = Abcs.Operations().read({         
            entity: lab,         
              condition: condition     });     
          //if query returned value we loop over the 
          //rows and check the capacity and registration columns     
          operation.perform().then(function (operationResult) {         
            if (operationResult.isSuccess()) {             
              operationResult.getData().forEach(function (oneRecord) { 

                if ((oneRecord.Capacity - oneRecord.Registered) < 1) { 
                  $Person.setValue('Waitlisted', true);                     
                  reject("error");                 
                } else                 
                {                     
                  resolve("ok");                 
                }             
              });        
            }     
          }).catch(function (operationResult) {         
            if (operationResult.isFailure()) {             
              // Insert code you want to perform if fetching of records failed
              alert('didnt worked');            
              reject("error");        
            }   
          });
        });


More information on the JavaScript APIs used here are in the Oracle ABCS Documentation.

Database ABC (stream cipher) JavaScript

Published at DZone with permission of Shay Shmeltzer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Flask vs. Django: Which Python Framework to Choose?
  • How To Check for JSON Insecure Deserialization (JID) Attacks With Java
  • Top 7 Features in Jakarta EE 10 Release
  • How Java Apps Litter Beyond the Heap

Comments

Database Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo