agora inbox for pljava-dev@postgresql.org  
help / color / mirror / Atom feed
[Pljava-dev] Triggerdata questions
2+ messages / 0 participants
[nested] [flat]

* [Pljava-dev] Triggerdata questions
@ 2005-07-05 18:03 
  2005-07-05 19:41 ` [Pljava-dev] Triggerdata questions 
  0 siblings, 1 reply; 2+ messages in thread

From:  @ 2005-07-05 18:03 UTC (permalink / raw)

  Hi everyone,

  I have a number of tables in a db, let's call it Main, which are a
replication of tables that are in other databases (more than one). All
the tables in db Main are empty, they are just used for front end
access and defining the relations that may exist between the tables
from the different databases.

  When an insert (for ex.) is issued to db Main a trigger is fired
that calls a java function that supposedly would re-issue the insert
to the real db. But i don't know how this can be done. Using the
triggerdata passed to my function i tried the following:

  (being td the Triggerdata received by the function)     

  Statement stat = (td.getNew()).getStatement();

  The function always throws a nullPointerException. From what i've
read, the resultSet returned by .getNew() is always null on inserts
and deletes, so this must be where the exception comes from, but even
on an update the resultSet seems to be returning a null value.

  And what i want to ask you is if you think this can be done this
way? If so, what am i doing wrong? If not, do you see another
solution?

  Thanks in advance.




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* [Pljava-dev] Triggerdata questions
  2005-07-05 18:03 [Pljava-dev] Triggerdata questions 
@ 2005-07-05 19:41 ` 
  0 siblings, 0 replies; 2+ messages in thread

From:  @ 2005-07-05 19:41 UTC (permalink / raw)

Joao,
There's a couple of misconseptions:

First, the ResultSet returned by getNew() and getOld() on a TriggerData 
are special purpose single row ResultSet used as an access mechanism to 
the NEW and OLD tuples of the trigger. There will never be a statement 
associated with those sets. The getStatement() method will always return 
null.

Second, the td.getNew() is never null on an BEFORE/AFTER INSERT ON EACH 
ROW trigger. An ON EACH ROW trigger will only return null on getNew() if 
the trigger is a BEFORE/AFTER DELETE. All STATEMENT triggers will return 
null on both getNew() and getOld() since there's no tuple associated 
with the statement as a whole.

Third, triggers are not an ideal way of achiving replication. What do 
you do when a transaction is rolled back? You would probably be better 
off looking at stuff like http://gborg.postgresql.org/project/slony1 or 
perhaps the recent ON COMMIT triggers found here 
http://gorda.di.uminho.pt/community.

Regards,
Thomas Hallgren

Joao Afonso wrote:

>  Hi everyone,
>
>  I have a number of tables in a db, let's call it Main, which are a
>replication of tables that are in other databases (more than one). All
>the tables in db Main are empty, they are just used for front end
>access and defining the relations that may exist between the tables
>from the different databases.
>
>  When an insert (for ex.) is issued to db Main a trigger is fired
>that calls a java function that supposedly would re-issue the insert
>to the real db. But i don't know how this can be done. Using the
>triggerdata passed to my function i tried the following:
>
>  (being td the Triggerdata received by the function)     
>
>  Statement stat = (td.getNew()).getStatement();
>
>  The function always throws a nullPointerException. From what i've
>read, the resultSet returned by .getNew() is always null on inserts
>and deletes, so this must be where the exception comes from, but even
>on an update the resultSet seems to be returning a null value.
>
>  And what i want to ask you is if you think this can be done this
>way? If so, what am i doing wrong? If not, do you see another
>solution?
>
>  Thanks in advance.
>_______________________________________________
>Pljava-dev mailing list
>Pljava-dev at gborg.postgresql.org
>http://gborg.postgresql.org/mailman/listinfo/pljava-dev
>  
>






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-07-05 19:41 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-07-05 18:03 [Pljava-dev] Triggerdata questions 
2005-07-05 19:41 ` 

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox