psaw.mora
psaw.mora

Reputation: 958

How To:Transaction Rollback in squeryl

Can anybody please tell me how to handle a transaction rollback in squeryl explicitly?

And also how can we add or remove columns in squeryl dynamically?

Thanx...

Upvotes: 2

Views: 757

Answers (2)

Dave Whittaker
Dave Whittaker

Reputation: 3102

Just to elaborate a bit on the response from @didierd. There is one Session/Connection bound to each transaction. You can access the current Session, and thereby the Connection with code like:

Session.currentSession.connection

Or, if you're not sure if you're within a transaction

Session.currentSessionOption map {_.connection}

If you do roll back the transaction this way it will be your responsibility to start a new one or make sure there is no further use of the connection, so use with care.

Upvotes: 5

Didier Dupont
Didier Dupont

Reputation: 29538

You have an access to the JDBC's java.sql.Connection (connection in Session), so if you really cannot use transaction / inTransaction, you can call rollback there.

With access to the connection, you can also execute arbitrary SQL requests and so change the database schema, but be mindful that your squeryl-using code has a static, compile time known schema.

Upvotes: 1

Related Questions