orm is a perfect anti-pattern

10
/20 @yegor256 1 what do you think?

Upload: yegor-bugayenko

Post on 16-Jan-2017

1.017 views

Category:

Software


1 download

TRANSCRIPT

Page 1: ORM is a perfect anti-pattern

/20@yegor256 1

what do you think?

Page 2: ORM is a perfect anti-pattern

/20@yegor256 2

ORM is a perfect anti-pattern

Yegor Bugayenko

Page 3: ORM is a perfect anti-pattern

/20@yegor256 3

book.setTitle(“Object Thinking”); session.update(book);

Book

Session

MySQL

JDBC

UPDATE bookSET title = “Object Thinking” WHERE id = 555

book.getTitle(); statement.executeUpdate();

this.title

Page 4: ORM is a perfect anti-pattern

/20@yegor256 4Map attrs = new HashMap(); attrs.put(“title”, “Object Thinking”); book.updateAttributes(attrs);

Book Base

MySQL

JDBC

UPDATE bookSET title = “Object Thinking” WHERE id = 555

statement.executeUpdate();

Page 5: ORM is a perfect anti-pattern

/20@yegor256 5

it’s offensive

Page 6: ORM is a perfect anti-pattern

/20@yegor256 6

SQL-speaking objects

Page 7: ORM is a perfect anti-pattern

/20@yegor256 7

book.rename(“Object Thinking”);

Book

MySQL

JDBC

UPDATE book SET title = “Object Thinking” WHERE id = 555

statement.executeUpdate();

Page 8: ORM is a perfect anti-pattern

/20@yegor256 8

JDBC, jOOQ, jcabi-jdbc

Page 9: ORM is a perfect anti-pattern

/20@yegor256 9

public class Book { private final DataSource source; private final int id; Book(DataSource db, int id) { this.source = db; this.id = id; } public void rename(String title) { new JdbcSession(this.source) .sql(“UPDATE book SET title=? WHERE id=?”) .set(title) .set(this.id) .update(); } }

Page 10: ORM is a perfect anti-pattern

/20@yegor256 10

www.yegor256.com