-
-
Notifications
You must be signed in to change notification settings - Fork 336
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
Document SqlObject mixins and how to use them #620
Comments
Hi @Shujito, A mixin is an interface that you can implement/extend in your SQL Object types, to add extra methods to your SQL object. There are two mixins,
interface ContactDao extends GetHandle {
default List<Contact> getFullContacts() {
return getHandle().createQuery(
"select * from contact c left join phones p on c.id = p.contactId")
.fold(new LinkedHashMap<Integer,Contact>(), (map, rs, ctx) -> {
// etc
})
.values()
.stream()
.collect(toList());
}
interface ContactDao extends Transactional {
default void createFullContact(Contact contact) {
begin();
try {
int contactId = createContact(contact.getName());
createPhones(contact.getPhones());
commit();
}
catch (Exception e) {
rollback();
}
}
@SqlUpdate("insert into contact(id, name) values (nextval('contact_seq'), :name)")
@GetGeneratedKeys
int createContact(@BindBean Contact contact);
@SqlBatch("insert into phone(id, contact_id, phone_type, phone_number) " +
"values (nextval('phone_seq'), :contactId, :phoneType, :phoneNumber)")
void createPhones(@BindBean List<Phone> phones);
} |
So, with these then I can query for more complex objects. |
That's the idea, yes. It all depends on how you formulate your query though. |
That makes it all clear now, I'll abuse this feature as soon as I see the need of it. |
Tracked in #802 |
The lack of documentation on that makes me wonder
The text was updated successfully, but these errors were encountered: