Database transactions with Mapper

View: New views
6 Messages — Rating Filter:   Alert me  

Database transactions with Mapper

by GA-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello guys,

Is it possible to manage database transactions in Mapper? or does it  
manage them automatically?

For instance, I have a Restful service that performs some database  
actions. If the last action fails for some reason in some point and I  
respond to the caller with an error, is it possible to rollback the  
previous database changes?

Thanks in advance,

GA


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to liftweb@...
To unsubscribe from this group, send email to liftweb+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Database transactions with Mapper

by bearfeeder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If you have the following line in your Boot.scala file:

    S.addAround(DB.buildLoanWrapper)

Then all RDBMS statements executed during a given HTTP request are part of a single transaction.  S.addAround runs the HTTP request inside a given function.  The DB.buildLoanWrapper function begins transactions before the request processing begins and commits/rolls back after the processing has ended (well, this is no long technically true... it marks each DB Connection as potentially being part of a transaction, but once the connection is actually used, it is committed/rolled back at the end).

So, if you want to roll back the transaction:

DB.rollback(DefaultConnectionIdentifier)

Is this what you're looking for?

On Fri, Nov 6, 2009 at 7:49 AM, GA <my_lists@...> wrote:

Hello guys,

Is it possible to manage database transactions in Mapper? or does it
manage them automatically?

For instance, I have a Restful service that performs some database
actions. If the last action fails for some reason in some point and I
respond to the caller with an error, is it possible to rollback the
previous database changes?

Thanks in advance,

GA






--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to liftweb@...
To unsubscribe from this group, send email to liftweb+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Database transactions with Mapper

by GA-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That's exactly what I am looking for. Thanks David.


On Nov 6, 2009, at 5:19 PM, David Pollak wrote:

If you have the following line in your Boot.scala file:

    S.addAround(DB.buildLoanWrapper)

Then all RDBMS statements executed during a given HTTP request are part of a single transaction.  S.addAround runs the HTTP request inside a given function.  The DB.buildLoanWrapper function begins transactions before the request processing begins and commits/rolls back after the processing has ended (well, this is no long technically true... it marks each DB Connection as potentially being part of a transaction, but once the connection is actually used, it is committed/rolled back at the end).

So, if you want to roll back the transaction:

DB.rollback(DefaultConnectionIdentifier)

Is this what you're looking for?

On Fri, Nov 6, 2009 at 7:49 AM, GA <my_lists@...> wrote:

Hello guys,

Is it possible to manage database transactions in Mapper? or does it
manage them automatically?

For instance, I have a Restful service that performs some database
actions. If the last action fails for some reason in some point and I
respond to the caller with an error, is it possible to rollback the
previous database changes?

Thanks in advance,

GA






--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to liftweb@...
To unsubscribe from this group, send email to liftweb+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Database transactions with Mapper

by oshyshko :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Looks like "S.addAround(DB.buildLoanWrapper)" has no effect.


2 Query     SET autocommit=0
2 Query     SET autocommit=0
2 Query     SELECT accounts.id, accounts.name, accounts.user_c FROM
accounts WHERE id = 205
2 Query     commit
2 Query     SET autocommit=0
2 Query     SET autocommit=0
2 Query     SELECT accounts.id, accounts.name, accounts.user_c FROM
accounts WHERE id = 206
2 Query     commit
2 Query     SET autocommit=0
2 Query     SET autocommit=0
2 Query     SELECT accounts.id, accounts.name, accounts.user_c FROM
accounts WHERE id = 207


Any ideas what can be wrong?


class Boot extends Bootable {
  def boot {
    DB.defineConnectionManager(DefaultConnectionIdentifier, DBVendor)
    S.addAround(DB.buildLoanWrapper)
    ...
   }
}

- scala 2.7.6
- liftweb 1.1-M6
- MySQL 5.1


On Nov 6, 6:19 pm, David Pollak <feeder.of.the.be...@...> wrote:
> If you have the following line in your Boot.scala file:
>
>     S.addAround(DB.buildLoanWrapper)
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to liftweb@...
To unsubscribe from this group, send email to liftweb+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Database transactions with Mapper

by bearfeeder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Fri, Nov 6, 2009 at 10:14 PM, oshyshko <oshyshko@...> wrote:

Looks like "S.addAround(DB.buildLoanWrapper)" has no effect.


What code are you using to make the query?

Please create a fully running example (making a GitHub project is the best way to do this) so that I can see exactly what is happening.
 


2 Query     SET autocommit=0
2 Query     SET autocommit=0
2 Query     SELECT accounts.id, accounts.name, accounts.user_c FROM
accounts WHERE id = 205
2 Query     commit
2 Query     SET autocommit=0
2 Query     SET autocommit=0
2 Query     SELECT accounts.id, accounts.name, accounts.user_c FROM
accounts WHERE id = 206
2 Query     commit
2 Query     SET autocommit=0
2 Query     SET autocommit=0
2 Query     SELECT accounts.id, accounts.name, accounts.user_c FROM
accounts WHERE id = 207


Any ideas what can be wrong?


class Boot extends Bootable {
 def boot {
   DB.defineConnectionManager(DefaultConnectionIdentifier, DBVendor)
   S.addAround(DB.buildLoanWrapper)
   ...
  }
}

- scala 2.7.6
- liftweb 1.1-M6
- MySQL 5.1


On Nov 6, 6:19 pm, David Pollak <feeder.of.the.be...@...> wrote:
> If you have the following line in your Boot.scala file:
>
>     S.addAround(DB.buildLoanWrapper)
>





--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to liftweb@...
To unsubscribe from this group, send email to liftweb+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Database transactions with Mapper

by oshyshko :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I have found the problem.

This is what I have in web.xml:
    <filter-mapping>
        <filter-name>LiftFilter</filter-name>
        <url-pattern>*.html</url-pattern>
    </filter-mapping>

By default it should be like this:

    <filter-mapping>
        <filter-name>LiftFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

"S.addAround(DB.buildLoanWrapper)" does work, if the request path is
covered by LiftFilter.
And it does not work, if not covered (my case) -- in this case it will
create separate transactions.

So its okay.


Now I see thatreal problem is because I use BlazeDS servet which
should not be covered by LiftFilter. I wrote about it:
http://groups.google.com/group/liftweb/browse_thread/thread/33a4d1d111f54ef0/ea4c08393ce76c1d
Looks like the old problem has reappeared in a new place.


On Nov 7, 5:10 pm, David Pollak <feeder.of.the.be...@...> wrote:
> On Fri, Nov 6, 2009 at 10:14 PM, oshyshko <oshys...@...> wrote:
>
> > Looks like "S.addAround(DB.buildLoanWrapper)" has no effect.
>
> What code are you using to make the query?
>
> Please create a fully running example (making a GitHub project is the best
> way to do this) so that I can see exactly what is happening.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to liftweb@...
To unsubscribe from this group, send email to liftweb+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---