Expand my Community achievements bar.

SOLVED

Is it possible to sync LCDS with changes made directly to the database?

Avatar

Level 1

Here is the scenario:

LCDS has been setup to connect to a MySQL database using FlashBuilder RDS and Fiber.  Changes made within the Flex client application are correctly synchronized between all clients.

There is an existing system in place that makes direct inserts and updates to the same MySQL database.  Those inserts and updates need to be propagated to all Flex client applications.  Is it possible to have LCDS "watch" the database for inserts / updates and send those changes to all Flex clients?

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

You should not call refreshFill() etc, rather you should call the relevant CRUD method for the object changed, please see the Javadoc I linked to. For example:

public void createItem(String destination, Object item)

You use this method to indicate to to the Data Management Service that a new item has been created.

So on calling this method and committing the transaction, LCDS will take care of pushing the new object to clients etc.

View solution in original post

9 Replies

Avatar

Former Community Member

On the server side, you can invoke the relevant APIs on DataServiceTransaction (http://help.adobe.com/en_US/LiveCycleDataServicesES/3.1/Javadoc/flex/data/DataServiceTransaction.html) to notify LCDS of changes made to the database. These will then be pushed across to the relevant clients.

Avatar

Former Community Member

There is no functionality built-in to LCDS to monitor changes to a database. However, if you can intercept requests to change the database, they can be propagated to all the clients through LCDS.

Avatar

Level 1

Do you have any sample code that shows how to do this?

Simply calling dataServiceTransaction.refreshFill(...) doesn't seem to send any data to the client.

Since I am using Fiber, I ultimately need to be able to generically notify the client of updates to the database.  Or at least trigger LCDS to check for updates against the database and send the appropriate updates to the client.

Here is the current code that doesn't seem to work:

public void triggerRefresh() {

        DataDestination dt = DataDestination.getDataDestination("Test");

        DataMessage fillMessage = InternalMessage.createMessage();

        fillMessage.setOperation(DataMessage.UPDATE_OPERATION);

        DataServiceTransaction tx = DataServiceTransaction.begin(false); 

        Map identity = new HashMap();

        identity.put("id", 184);     // ID of record that has changed in db.

        ArrayList props = new ArrayList();

        props.add("Item");     // Class name and table name of changed object.

        PropertySpecifier ps = PropertySpecifier.getPropertySpecifier(dt, props, true);

        Object retObj = dt.getItemFromAdapter(identity, ps);

        fillMessage.setBody((Object)retObj);

        Collection<Object> result = (Collection<Object>)dt.getAdapter().invoke(fillMessage);

        System.out.println(result); // MOS added

        tx.refreshFill("Test", null, null);

        tx.commit();

}

Any suggestions?

Thanks,

Collin

Avatar

Level 1

Wow, everyone says this is possible but no one seems to know how to get it to work...

Avatar

Employee

We have many customers doing this.  You need to check your RDBMS vendor's documentation for invoking Java code from triggers, for example, if you want to go to that level. 

Avatar

Correct answer by
Former Community Member

You should not call refreshFill() etc, rather you should call the relevant CRUD method for the object changed, please see the Javadoc I linked to. For example:

public void createItem(String destination, Object item)

You use this method to indicate to to the Data Management Service that a new item has been created.

So on calling this method and committing the transaction, LCDS will take care of pushing the new object to clients etc.

Avatar

Level 1

Damon,

Thanks for your response. Our issue is not how to get the info that the DB table has been updated with a trigger. We can do that and then call whatever java code we need. The problem is figuring out the code to get LCDS to push an update for the objects that we know changed via the trigger to the connected clients.

The part of the equation that we can't find any example for is what curb47 was trying in his code above.

We know the DB has changed and can call a Java function, we don't know how to tell LCDS to refresh the in memory objects and put the changes to the clients.

I've been looking for an example of this for months. What am I missing?

Thanks,

R. Sparrow

Avatar

Employee

@R. Sparrow: See Ashish's response above.  You need to tell LCDS via the DataServiceTransaction APIs about CRUD operations to data sets it is managing, and LCDS will take care of notifying all subscribed clients.  So when a record is created, call createItem().  When a record is deleted, call deleteItem(), on update, call updateItem().

http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/javadoc/flex/data/DataServiceTransactio...

HTH

Damon

Avatar

Level 1

Damon and Ashish,

Thanks for the quick responses. Let me look into that and give it a try. We'll get back with you and let you know how it worked.

Thanks,

R. Sparrow

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----