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

Allow use of immutable POJOs instead of requiring POJOs with setters #188

Open
dalexander01 opened this issue Jun 15, 2015 · 5 comments
Open

Comments

@dalexander01
Copy link

Would be awesome if sql2o supported this like DBUtils and other jdbc utility api's.

@aartiPl
Copy link

aartiPl commented Jul 8, 2015

It's actually possible. Just implement RecordSetHandler interface and manually create immutable object from recordset. Then pass your RecordSetHandler implementation to e.g. executeAndFetch() method. In fact I prefer this way of using sql2o than automatic mapping. Less magic is better :-)

@arnaudroger
Copy link

I feel like hijacking the thread but SimpleFlatMapper as an integration point with sql2o and it supports Constructor injection. see
https://github.com/arnaudroger/SimpleFlatMapper/wiki/Sfm-integration-in-Jooq-And-Sql2o-for-performance#sql2o
https://github.com/arnaudroger/SimpleFlatMapper/blob/master/src/test/java/org/sfm/sql2o/Sql2oIntegrationTest.java

@Marco-Sulla
Copy link
Contributor

I don't think sql2o requires setters. In this SO answer, it's written that it uses sun.misc.Unsafe.

@plisker-m43
Copy link

plisker-m43 commented Jun 26, 2019

Has anyone successfully used sql2o with the Immutables library?

Edit: Solved. I annotated the abstract class with @Value.Modifiable, @Value.Immutable, and @Value.Style(of="new", create="new", allParameters = true), and then passed in ModifiableMyClass.class into the sql2o statement, and then called ModifiableMyClass#toImmutable on the result

@Marco-Sulla
Copy link
Contributor

Anyway I think it's useless to create a model without setters. On the contrary, it could be useful: you could use models also for doing queries.

For example, my little code creator for sql2o, EWA, creates a method in the Repository that find rows from a table searching for the not null parameters of a passed model. And it has a similar method for deleting rows. Furthermore, you can pass a model with only some parameter set and update only the not null parameters.

Limiting the model to a simple immutable data container is short-sighted.

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

6 participants