Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add support for using where() on bulk Update statements #120

Closed
rbygrave opened this issue Apr 30, 2014 · 8 comments
Closed

ENH: Add support for using where() on bulk Update statements #120

rbygrave opened this issue Apr 30, 2014 · 8 comments
Assignees
Milestone

Comments

@rbygrave
Copy link
Member

Hi,

I was looking at the option to do createUpdate() on Ebean and noticed
that you have to write the where clause yourself. Is it an option to
use the expression lists from queries for this as well.

So we would get something like:

// can be Update as well of course
Delete delete = Ebean.createDelete(Order.class); 
delete.where().eq("myproperty", "somevalue");

int rows = delete.execute();

etc.

This way we can use the same code for select queries and delete
queries.

Would be nice if this would include some option to update as well, but
maybe that's to much to ask for:

Update update = Ebean.createUpdate(Order.class);
update.where().eq("myproperty", "somevalue");
update.setProperty("myproperty", "somenewvalue");
int rows = update.execute();

Let me know what you think.

@rbygrave rbygrave changed the title Add support for using where() on Update and Delete multirow statements ENH: Add support for using where() on Update and Delete multirow statements Apr 30, 2014
@rbygrave rbygrave modified the milestones: 4.0.1, 6.0.1 Apr 30, 2014
@icode
Copy link
Contributor

icode commented Jan 18, 2015

+1

@rbygrave
Copy link
Member Author

Note that for Delete you can now do this via: #398

@wenzhihong2003
Copy link

+1, this is discuss in #459

@zhangshifeng
Copy link
Contributor

👍

@rbygrave
Copy link
Member Author

This only relates to updates now so changing title.

@rbygrave rbygrave changed the title ENH: Add support for using where() on Update and Delete multirow statements ENH: Add support for using where() on bulk Update statements Apr 18, 2016
@wenzhihong2003
Copy link

@rbygrave , has plan to support this future?

@rbygrave
Copy link
Member Author

rbygrave commented Apr 21, 2016

Q: Would I like to support this feature?
A: Yes.

Q: When might I get to look at implementing it?
A: Not sure. This is not a sponsored feature etc. I'll need to review all the priorities on all the open issues around 1st May.

@rbygrave rbygrave self-assigned this May 23, 2016
@rbygrave rbygrave modified the milestones: 8.0, 7.12.1 May 23, 2016
@rbygrave
Copy link
Member Author

So this has been supported by the addition of UpdateQuery which has some set() methods and uses an underlying Query.

Example 1:

    int rows = server.update(Customer.class);
        .set("status", Customer.Status.ACTIVE)
        .set("updtime", new Timestamp(System.currentTimeMillis()))
        .where()
          .eq("status", Customer.Status.NEW)
          .eq("billingAddress.country", nz)
          .gt("id", 1000)
        .update();

Example 2:

    int rows = server
      .update(Customer.class)
        .set("status", Customer.Status.ACTIVE)
        .set("updtime", new Timestamp(System.currentTimeMillis()))
        .where()
          .eq("status", Customer.Status.NEW)
          .gt("id", 1000)
        .update();

Note that there is a setNull() and setRaw() options in addition to the set property in the above 2 examples.

.setRaw("status = coalesce(status, ?)", Customer.Status.ACTIVE)
.setRaw("status = coalesce(status, 'A')")
.setNull("notes")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants