LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-09-2007, 06:01 PM   #1
hgb
Member
 
Registered: Jun 2004
Distribution: Mandrake 10, SUSE 10.x, DEbian
Posts: 125

Rep: Reputation: 15
Question what is the best way for "react" to Database actualization.


Suppose you have 2 apps, one for monitoring the DB and another that is using actually the database, what is the preferred, best way to watch for this change???

I mean, I can be reading (pooling) to see if the data is changed from one snapshot to the next, but I think about "events" and those events fire the actualization of the front-end GUI (perhaps a list of events/human checks pending).



Another way to see it is, if I have a "snapshot" (result of a select) of the DB that Im making manipulations (or more like showing part of it) but not directly over the DB, what is the "best" way to update the snapshot without being checking each X time if there is a change in the DB.

[added in edit] Another way to see it is, suppose you are reading this thread and I delete it, you will not be able to see the change until you refresh, but before that, I already have confirmed the deletion of this thread and you wherent notified with a message "this thread has been deleted, you whant to save it?" but see that there shouldnt be pooling of the data, but an event send to your browser launching that little funciton..., what is the best way if I not use pooling of change??? or there is no other way??


The question come because I have choosed to take a snapshoot of certain views and not retrieve them each time there is an "action" over the view (because not always will be changed, or I can take a subset to show or to "keep in the eye" without ask again to the DBMS what subset should I "keep in the eye") and work programatically on them, that is instead of --select name from viewx where name="xname"-- or --select name, id from viewx where name="xname" do something like --take snapshot of viewx and provide functions (interface) for ask names and other funny things, and not update the snapshot until the view in the DB is changed--.


Yes, I can take the "snapshot" each time there is an interaction of an event in the GUI, but what happend if there is no event in the GUI (the user is watching the GUI) and there are 2 or 3 changes of the view in the DB.




Being with a timer in a thread is the only way... or aka pooling for changes?, Im missing some?.

I know there are triggers that can be launched when certain conditions happend... but they are internal to the DB (they dosent send events/signals to apps)... how those events/triggers will launch an update of my snapshot??.

Last edited by hgb; 03-09-2007 at 06:14 PM.
 
Old 03-09-2007, 06:35 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
You could (in postgres, at least, if you used a non-trusted
language for the trigger-function) use a trigger to activate
on OS-level, but it's not very portable. Unless your result-
sets that you "cache" on the client-side is very large (re-
running the query takes over a few seconds) and the time was
prohibitive the polling of the database on client-side events
is one sensible way to go about it. Another option would be
to lock the rows you're looking at (select for update [which
may upset colleagues wanting to change or retrieve it]).

It all depends on the actual needs.


Cheers,
Tink
 
Old 03-09-2007, 10:05 PM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Sounds like the observer pattern to me. How you implement it would depend upon the application.
 
Old 03-12-2007, 02:25 PM   #4
hgb
Member
 
Registered: Jun 2004
Distribution: Mandrake 10, SUSE 10.x, DEbian
Posts: 125

Original Poster
Rep: Reputation: 15
I see that you say about the observer pattern, I guess it can be a solution, but the subject to observe then should be the "interface" that is used to update, insert, delete data in the DBMS and not really the data in the DBMS, then I should take care of this in the design of the other components that "update, insert and delete" because they are outside of the app (observer component) and instead of provide "direct" access to the DB provide an interface that they can use and that is perhaps like "static/unique in instance".




Or perhaps have a table where I can put the latest changes in the things of interest that are writed automatically be the trigger and do pooling in that table...
 
Old 03-12-2007, 10:35 PM   #5
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
One way to achieve this would be to build an intermediate layer between the GUI and the database then the GUI will tell this layer which pieces of data it wants and if it wishes to be notified of any alterations to that data. The GUI will send any data alterations to this intermediate layer, which will be responsible for updating the database and seeeing if any other GUI instance wants to be notified of changes to this piece of data.
 
Old 03-13-2007, 12:03 PM   #6
hgb
Member
 
Registered: Jun 2004
Distribution: Mandrake 10, SUSE 10.x, DEbian
Posts: 125

Original Poster
Rep: Reputation: 15
Yea, but actually the code that people have here, dosent follow a pattern...

In fact people here have 1 app that is the "GUI" for watch and set some manual options in the data in DBMS (with some pooling), and there is other app that do some automatic updates time to time... the question is... I think I can add the layer that watches for sqlcommands like "update", "insert", "delete" (even a simple tokenizer for see if there is a reference to x table not a complete SQL parser...), the problem come in the way that this 2 different apps dosent have a common layer for communicate with the DB and that being 2 different instances, how they will share the same instance for communicate with the DB.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"ORA-12547: TNS:lost contact" when creating database in Oracle 10g Dtsazza Linux - Software 4 04-25-2009 09:54 AM
run adapt but "package system database is locked" ctdarksilver Ubuntu 4 08-24-2006 04:27 AM
Snort database: Closing connection to database "" Homer Glemkin Linux - Security 2 07-14-2005 06:58 PM
How to find back "history" database after "history -c" ? san_lss Linux - Newbie 1 01-07-2004 11:53 AM
Can't find init file for database "SID_NAME" cyrilbritto Linux - General 0 08-20-2003 07:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration