From 8dd098fb187c2c98bc1dae650072bb5b2313e4eb Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Sun, 21 Apr 2013 12:26:13 +0200 Subject: [PATCH] Added a type safety section to the home page --- jOOQ-website/index.php | 56 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/jOOQ-website/index.php b/jOOQ-website/index.php index b7adaee58d..2b037ab18b 100644 --- a/jOOQ-website/index.php +++ b/jOOQ-website/index.php @@ -16,7 +16,7 @@ function printContent() { of heavy mappers, hiding the beauty and simplicity of relational data. SQL was never meant to be object-oriented. SQL was never meant to be anything other than... SQL!

-

# What does jOOQ code look like?

+

# What does jOOQ code look like?

It's simple. With the jOOQ DSL, SQL looks almost as if it were natively supported by Java. For instance, get all books published in 2011, ordered by title

@@ -70,6 +70,56 @@ create.select(AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME, count()) +

# What does type safety mean to jOOQ?

+

SQL is a very type safe language. So is jOOQ. jOOQ uniquely respects SQL's row value expression typesafety. jOOQ will use your Java compiler to type-check the following:

+ +
+select().from(t).where(t.a.eq(select(t2.x).from(t2));
+// Type-check here: ---------------> ^^^^
+select().from(t).where(t.a.eq(any(select(t2.x).from(t2)));
+// Type-check here: -------------------> ^^^^
+select().from(t).where(t.a.in(select(t2.x).from(t2));
+// Type-check here: ---------------> ^^^^
+
+ +

And also set operations:

+ +
+select(t1.a, t1.b).from(t1).union(select(t2.a, t2.b).from(t2));
+// Type-check here: -------------------> ^^^^^^^^^^
+
+ +

And even row value expressions:

+ + + + + + +
+SELECT * FROM t WHERE (t.a, t.b) = (1, 2)
+
+SELECT * FROM t WHERE (t.a, t.b) OVERLAPS (date1, date2)
+
+SELECT * FROM t WHERE (t.a, t.b) IN (SELECT x, y FROM t2)
+
+UPDATE t SET (a, b) = (SELECT x, y FROM t2 WHERE ...)
+
+INSERT INTO t (a, b) VALUES (1, 2)
+ 
+
+select().from(t).where(row(t.a, t.b).eq(1, 2));
+// Type-check here: ----------------->  ^^^^
+select().from(t).where(row(t.a, t.b).overlaps(date1, date2));
+// Type-check here: ------------------------> ^^^^^^^^^^^^
+select().from(t).where(row(t.a, t.b).in(select(t2.x, t2.y).from(t2)));
+// Type-check here: -------------------------> ^^^^^^^^^^
+update(t).set(row(t.a, t.b), select(t2.x, t2.y).where(...));
+// Type-check here: --------------> ^^^^^^^^^^
+insertInto(t, t.a, t.b).values(1, 2);
+// Type-check here: ---------> ^^^^
+
+

# What is jOOQ?

jOOQ stands for Java Object Oriented Querying. It combines these essential features:

@@ -102,10 +152,10 @@ create.select(AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME, count())

# When not to use jOOQ