Project

General

Profile

Actions

Feature #6131

closed

Why Transaction is not movable?

Added by Oleg Artenii over 6 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Urgent
Assignee:
-
Target version:
-
Start date:
11/13/2017
Due date:
% Done:

0%

Estimated time:

Description

https://github.com/emweb/wt/blob/3175635b60f3389bb1f9d01e4107436f29054229/src/Wt/Dbo/Transaction.h#L92-L94

In my project I have Entities. Each entity has a Model. Each Model is linked to a database (at the moment only one), encapsulates a Wt::Dbo::Session and the logic to do the queries. To the outside world the Model offers functions like Load/Store(Entity).

To be able to make custom/grouped queries and need a common transaction for them. Instead of doing Wt::Dbo::Session& Model::GetSession() (thus everybody will have direct access to session) I want to make:

Wt::Dbo::Transaction Model::CreateTransaction() {
    return Wt::Dbo::Transaction{*mEncapsulatedSession.get()};
}

Then I will be able to do:

{
    Wt::Dbo::Transaction transaction = model.CreateTransaction();
    model.Store(entity1, transaction); // an overloaded Store() that accepts Wt::Dbo::Transaction& as second parameter and doesn't create a new transaction
    model.Store(entity2, transaction);
}

Can you make Transaction movable? I don't see a reason why it's not movable.

Actions #1

Updated by Roel Standaert over 6 years ago

It was explicitly made not movable because there was no proper implementation for it, and there is also not a proper moved-from state.

You could of course return a std::unique_ptr to a transaction, though, or put it into some other object that wraps it.

Actions #2

Updated by Roel Standaert over 6 years ago

I could maybe consider making Transaction objects copyable, though.

Copying a transaction like so:

Wt::Dbo::Transaction t{session};
Wt::Dbo::Transaction t2 = t;

Would then have the same effect as:

Wt::Dbo::Transaction t{session};
Wt::Dbo::Transaction t2{session};

Note that in any case, Transaction has a session() method, so you can always access the underlying Session object.

I've also noticed though that Transaction has a virtual destructor, so it's probably still best not to make Transaction copyable.

Actions #3

Updated by Oleg Artenii over 6 years ago

Note that in any case, Transaction has a session() method, so you can always access the underlying Session object.

Thanks. Then close this issue please.

There is a much more important one https://redmine.emweb.be/issues/6130

Actions #4

Updated by Roel Standaert over 6 years ago

  • Status changed from New to Closed
Actions

Also available in: Atom PDF