Re: Enable/Disable a database trigger when running a dbunit test



On 14 aug, 21:50, "John B. Matthews" <nos...@xxxxxxxxxxxxxx> wrote:
In article
<1c7f546f-680e-49ee-a302-4b2780ea9...@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
 Peter Fourneau <Peter.Fourn...@xxxxxxxxx> wrote:



I've created a testcase extending the
AbstractTransactionalDataSourceSpringContextTests.  This testclass is
infact a dbunit test.  I prepopulate the database with my own data,
perform a test and afterwords everything is rollbacked by the
TransactionalSpringTest (so original data in the db is preserved, my
own testdata should only exist in the test).
The dabase id's in this database are generated by a trigger.  This
trigger calls the sequencer to create the next value.  I don't want
this behaviour for my data I put in the table when running the test.
I want to define my own id's (so I can catchup the records after
calling te classToTest to check the changed values of this record) To
overcome this I ran an sql statement to disable the trigger. after
that I insert my own data and then I enable the trigger again.  Than
I call the method I want to test on the classToTest.  I've noticed
that the transaction is commited after enabling the trigger: the
original data in the database is lost, the testdata is now in place.

Is there a way to overcome this?  (It's not an option to let our
sofware call the sequencer before inserting data so we don't need a
trigger anymore)

Normal flow dbunit test:
1) open transaction
2) insert testdata
3) perform test
4) verify test results
5) rollback transaction

--> gives normal behaviour

In my case:
1) open transaction
2) disable trigger
3) insert testdata
4) enable trigger
5) perform test
6) verify test
7) rollback transaction

--> original data is lost, testdata is commited to database.

Instead of disabling the trigger, would it make sense to replace the
trigger with one that records the identifiers needed for analysis?

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Issue solved by starting up a seperate thread for enabling/disabling
the trigger. In this case the orginal transaction started up by the
dbunit test will not be affected.

Regards,

Peter F
.



Relevant Pages

  • Re: huge log file when inserting data
    ... Nothing else is running on the database. ... No trigger. ... The insert is in a transaction and it is committed. ... >space requirements. ...
    (microsoft.public.sqlserver.server)
  • Re: SQL 7 vs. 2000 issue -trigger and nulls
    ... >We're having trouble with a trigger updating some tables. ... course be locked by the current transaction, ... locking data and updating rows when the COMMIT inside the trigger is ... I seriously hope that SQL Server 7.0 simply disregarded these two ...
    (microsoft.public.sqlserver.mseq)
  • Enable/Disable a database trigger when running a dbunit test
    ... The dabase id's in this database are generated by a trigger. ... the transaction is commited after enabling the trigger: ... data in the database is lost, the testdata is now in place. ...
    (comp.lang.java.help)
  • Re: Question on Transactions for Allen Browne
    ... Did you BeginTrans on the WorkSpace? ... Or did you BeginTrans on the Database? ... I was trying to troubleshoot an issue I was having with a Transaction, ... The problem I was having was an error 3034 when trying to Rollback a failed ...
    (microsoft.public.access.formscoding)
  • Re: Scope of transaction processing wrapper
    ... Just pass the Database variable, and it will all rollback. ... This article illustrates transactions: ... My question is on the scope of what transaction ...
    (comp.databases.ms-access)