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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With