Identify Inconsistent Data (Changed Data)??

Hi Folks

I need to alert users to the fact that certain data changes have made the databases ‘inconsistent’ and specific process’ must be run to bring it back into normal status. Data (such as dimensions of an item) which will affect the pre-calculated budget for example, may have been changed during daily user activity.

Currently - where this data is changed on a form I can call a global function (in onDataChange) that updates a ‘modified_calcs’ table with the relevant column being set to true. A second function is then called to update a status indicator, on the solution header, about the resulting data inconsistency and offers to under-take the relevant calculation to remedy the situation.

However - there are a number of functions in the system that will be affected by SQL updates (some rawSQL and some Servoy) and that’s kind-a thrown me a bit! I know I can use table events to flag when a specific action has taken place on the table - but I need to work at the column level here. Additionally I’m trying to understand if its possible for this user client to have a function called when data is updated through data-broadcast, so when another user client makes the database inconsistent - all users are notified.

Q. Is there an event on a ‘column’ which will indicate it has been changed (by SQL or otherwise) - or will this have to be crafted into every SQL call?

Q. How can I be notified of data changes of other users. They will be updating a shared table of course (modified_calcs) so perhaps a table event there might suffice?

Q. If a column is changed by user (a) and there is a form based on that table, would a data change event be fired on that form for user (b)? (if the form is currently shown or not)?

Hope that makes sense??? I’m certain others will have had these same requirements in the past so any feedback on best practice for this will be gratefully received!

in Servoy 5 there is a new solution property onDataBroadCast

that will give you the servername, tablename etc… and what is changed.
so if you check that event,
after that, you can fire your own method, to bring everything in sync

Hope this helps

Harjo:
in Servoy 5 there is a new solution property onDataBroadCast

that will give you the servername, tablename etc… and what is changed.
so if you check that event,
after that, you can fire your own method, to bring everything in sync

Hope this helps

Thanks Harjo - are you suggesting that’s going to be useful for data changes performed in a SQL query - or just associated to my question on the Broadcast situation.

If so, perhaps you have some indicator how this method might be used - there is very little in the wiki about it? I guess the method runs on each broadcast (single table update) or does it return an array of data sources updated??? Is the broadcast two way - so data coming in (changed on other clients) and data going out (changed on this client) is reported?

I’ve realised that the table event on the modified_calcs table works really well, so changes from all users are notified to each client and my function is called correctly. Not sure about these SQL changed data though?

Kahuna:
are you suggesting that’s going to be useful for data changes performed in a SQL query - or just associated to my question on the Broadcast situation.

The function you can hook up to the onDataBroadcast event will only be triggered when changes are made where Servoy is aware of.
In other words: if you manipulate data from outside the application server, this event will not be triggered.

mboegem:

Kahuna:
are you suggesting that’s going to be useful for data changes performed in a SQL query - or just associated to my question on the Broadcast situation.

The function you can hook up to the onDataBroadcast event will only be triggered when changes are made where Servoy is aware of.
In other words: if you manipulate data from outside the application server, this event will not be triggered.

Thanks Marc- so if I do rawSQL() the do a flushAllClientCache - will that result in a databroadcast (forgive the dumb questions Marc)?

The only thing that will trigger a databroadcast are updates/insert/deletes performed of which Servoy is aware.

If you perform those actions outside the scope of Servoy, you can use the notifyDataChange function of the rawSQL plugin to generate the databroadcast yourself, but you need to know which actions have been performed on which records (server, table & PK).

If you don’t know that, you can flush the cache, which just means that the clients will reload all the data from the database (hence it’s a heavy operation!!!)

The onDataBroadCast event is fired in a client when the Application Server sends the client a notification that some of the data that the Client has cached has been altered by another Client. Note that only those Clients that have the altered data cached get notified by Application Server and it needs to be data cached in the client by Servoy’s internal mechanisms. For example, if the set of data is retrieved by calling databaseManager.getDataSetByQuery(…), the Application Server will not know about this data being used in teh Client and thus it will not notify the Client if the data is altered by another client.

Paul

pbakker:
The only thing that will trigger a databroadcast are updates/insert/deletes performed of which Servoy is aware.

Paul

Thanks for that feedback Paul - as usual, very succinct!

It seems like the table event would be the ‘kind of’ thing I need to notify the system of inconsistencies in the data. However its overkill to set data as inconsistent if, say just a description on a record has been changed - that shouldn’t call for a re-calc on that table in my set-up. So something similar to the ‘table event’ at the column level would be most appropriate.

So I guess I’m looking for some logic I could use in a global, called on a table event, that would recognise which columns had been updated and therefore I can decide if that will have made the data in that table inconsistent or not!

In my global can I determine which columns have been updated in an on/afterRecordUpdate? - How could that be determined?

Kahuna:
In my global can I determine which columns have been updated in an on/afterRecordUpdate? - How could that be determined?

Hi Ian,

this should help you:

function onRecordUpdate(record)
{
	if (!databaseManager.hasRecordChanges(record)) return;

	//Get a dataset with outstanding changes on a record
	var $dataset = databaseManager.getChangedRecordData(record);
	
	var $columns = $dataset.getColumnAsArray(1);
}

You will have to extend the method with the things you want after that.
We have created a table where we hold all the dataproviders per table on which this update should run, otherwise the method will always run to the end which won’t be needed in a lot of cases!

Hope this helps!

mboegem:

Kahuna:
In my global can I determine which columns have been updated in an on/afterRecordUpdate? - How could that be determined?

Hi Ian,

this should help you:

function onRecordUpdate(record)

{
if (!databaseManager.hasRecordChanges(record)) return;

//Get a dataset with outstanding changes on a record
var $dataset = databaseManager.getChangedRecordData(record);

var $columns = $dataset.getColumnAsArray(1);

}




You will have to extend the method with the things you want after that.
We have created a table where we hold all the dataproviders per table on which this update should run, otherwise the method will always run to the end which won't be needed in a lot of cases!

Hope this helps!

Thanks Marc - I’ll try and digest that tonight - appreciate your help again!