Changeset 2033

Show
Ignore:
Timestamp:
05/04/10 13:29:00 (4 months ago)
Author:
x.pechoultres@…
Message:

fix Database transaction : best transaction support, with Database::autoStartTransaction? slot

Location:
trunk/modules
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/Db/source/database.cl

    r1988 r2033  
    312312// commit all queries in a definitive way whereas rollbackTransaction(self) would 
    313313// left the database unchanged in addition to end the transaction. 
    314 [beginTransaction(self:Database) : void -> dbBeginTransaction(self)] 
     314[beginTransaction(self:Database) : void ->  
     315        if (self.onTransaction?) commitTransaction(self), 
     316        self.onTransaction? := true, 
     317        dbBeginTransaction(self)] 
    315318 
    316319// @doc Transaction 
    317320// commitTransaction(self) commits all queries that have been executed since 
    318321// the call to beginTransaction(self) and ends the current transaction. 
    319 [commitTransaction(self:Database) : void -> dbCommitTransaction(self)] 
     322[commitTransaction(self:Database) : void ->  
     323        if self.onTransaction? 
     324                (self.onTransaction? := false, 
     325                dbCommitTransaction(self)) 
     326        else //[1] warning : call dbCommitTransaction(~S) without starting transaction // self 
     327] 
    320328 
    321329// @doc Transaction 
    322330// rollbackTransaction(self) cancel all queries that have been executed since 
    323331// the call to beginTransaction(self) and ends the current transaction. 
    324 [rollbackTransaction(self:Database) : void -> dbRollbackTransaction(self)] 
    325  
    326  
     332[rollbackTransaction(self:Database) : void ->  
     333        if self.onTransaction? 
     334                (self.onTransaction? := false, 
     335                dbRollbackTransaction(self)) 
     336        else //[1] warning : call dbCommitTransaction(~S) without starting transaction // self 
     337] 
     338                 
    327339 
    328340// @cat Disconnection 
     
    339351 -> //[2] disconnect(DataBase = ~S) // self, 
    340352        while self.queries free(self.queries[length(self.queries)]), 
     353        if self.onTransaction? commitTransaction(self), 
    341354        dbDisconnect(self)] 
    342355 
  • trunk/modules/Db/source/model.cl

    r1988 r2033  
    115115                                private/firstQuery:Query,       // chained queries start here 
    116116                                private/currentQuery:Query,     // the current working query 
    117                                 private/autoCommit?:boolean) 
     117                                private/autoCommit?:boolean, 
     118                                onTransaction?:boolean = false, 
     119                                autoStartTransaction?:boolean = false) 
    118120 
    119121(inverse(queries) := database) 
  • trunk/modules/Dbo/source/update.cl

    r993 r2033  
    44[dbUpdate(db:Db/Database, self:object, lp:list[dbProperty]) : boolean -> 
    55        //[DBOJECTS] dbUpdate(object = ~S, lp = (~A)) // self, lp, 
     6        if (db.Db/autoStartTransaction? & not(db.Db/onTransaction?)) Db/beginTransaction(db), 
    67        let idProp := getIdProperty(self), nParam := 1, Params := list<any>(), 
    78                prepare? := (db.shouldPrepare? & 
     
    4142 
    4243-> //[DBOJECTS] dbUpdate(self = ~S,values = (~A), wheres = (~A)) // cl,values,wheres, 
     44        if (db.Db/autoStartTransaction? & not(db.Db/onTransaction?)) Db/beginTransaction(db), 
    4345        let tmp:boolean := false, 
    4446                n := 0, nParam := 1, Params := list<any>(),