Save or update in Groovy
Asked Answered
T

1

6

Usually in Java I execute a SELECT statement and check the size of ResultSet. If it is zero I issue a INSERT and otherwise an UPDATE.

Since Groovy provides syntactic sugar on top of JDBC, I'm wondering if it provides a way to ease this process? Is there an easier way to save or update a record?

Note: I know that Hibernate offers this, but I'd rather stick only with Groovy API.

Talie answered 13/8, 2013 at 9:14 Comment(0)
S
5

There's a lightweight ORM called GStorm here which I've had on my list of things to investigate which has basically no dependencies, but doesn't handle related domain objects

And a library to leverage Grails GORM here (which obviously pulls GORM out of Grails so has quite a few dependencies including Hibernate)

Other than that (and probably some other examples I've missed), there's nothing I know of to do what you're trying to do. I guess you'd have to write your own (you could switch between the INSERT or UPDATE depending on whether you pass a Primary Key -- assuming primary keys are auto-generated by the DB)

Schreibe answered 13/8, 2013 at 10:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.