From 7f31b11909cb0cdd858834dd00d1786992d01de1 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Sat, 10 Nov 2012 11:32:09 +0100 Subject: [PATCH] [#1966] Add a Row[N].equal(Record[N]) and similar convenience methods - Implemented this for degree = 1. Need a code generator! --- jOOQ/src/main/java/org/jooq/Row1.java | 48 ++++++++++++++ jOOQ/src/main/java/org/jooq/impl/RowImpl.java | 64 +++++++++++++------ 2 files changed, 92 insertions(+), 20 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/Row1.java b/jOOQ/src/main/java/org/jooq/Row1.java index 830464dc1f..4deaa8c8be 100644 --- a/jOOQ/src/main/java/org/jooq/Row1.java +++ b/jOOQ/src/main/java/org/jooq/Row1.java @@ -80,6 +80,14 @@ public interface Row1 extends Row { @Support Condition equal(Row1 row); + /** + * Compare this row value expression with a record for equality + * + * @see #equal(Row1) + */ + @Support + Condition equal(Record1 record); + /** * Compare this row value expression with another row value expression for * equality @@ -122,6 +130,14 @@ public interface Row1 extends Row { @Support Condition eq(Row1 row); + /** + * Compare this row value expression with a record for equality + * + * @see #eq(Row1) + */ + @Support + Condition eq(Record1 record); + /** * Compare this row value expression with another row value expression for * equality @@ -164,6 +180,14 @@ public interface Row1 extends Row { @Support Condition notEqual(Row1 row); + /** + * Compare this row value expression with a record for non-equality + * + * @see #notEqual(Row1) + */ + @Support + Condition notEqual(Record1 record); + /** * Compare this row value expression with another row value expression for * non-equality @@ -206,6 +230,14 @@ public interface Row1 extends Row { @Support Condition ne(Row1 row); + /** + * Compare this row value expression with a record for non-equality + * + * @see #ne(Row1) + */ + @Support + Condition ne(Record1 record); + /** * Compare this row value expression with another row value expression for * non-equality @@ -260,6 +292,14 @@ public interface Row1 extends Row { @Support Condition in(Row1... rows); + /** + * Compare this row value expression with a set of records for equality + * + * @see #in(Row1[]) + */ + @Support + Condition in(Record1... record); + /** * Compare this row value expression with a subselect for equality */ @@ -292,6 +332,14 @@ public interface Row1 extends Row { @Support Condition notIn(Row1... rows); + /** + * Compare this row value expression with a set of records for non-equality + * + * @see #notIn(Row1[]) + */ + @Support + Condition notIn(Record1... record); + /** * Compare this row value expression with a subselect for non-equality */ diff --git a/jOOQ/src/main/java/org/jooq/impl/RowImpl.java b/jOOQ/src/main/java/org/jooq/impl/RowImpl.java index f5c4832650..af0d79f871 100644 --- a/jOOQ/src/main/java/org/jooq/impl/RowImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/RowImpl.java @@ -68,6 +68,7 @@ import org.jooq.Field; import org.jooq.Operator; import org.jooq.QueryPart; import org.jooq.QueryPartInternal; +import org.jooq.Record1; import org.jooq.RenderContext; import org.jooq.Row1; import org.jooq.Row2; @@ -83,6 +84,7 @@ import org.jooq.Select; /** * @author Lukas Eder */ +@SuppressWarnings({ "rawtypes", "unchecked" }) class RowImpl extends AbstractQueryPart implements @@ -160,49 +162,41 @@ implements return result; } - @SuppressWarnings("unchecked") @Override public final Field field1() { return (Field) fields[0]; } - @SuppressWarnings("unchecked") @Override public final Field field2() { return (Field) fields[1]; } - @SuppressWarnings("unchecked") @Override public final Field field3() { return (Field) fields[2]; } - @SuppressWarnings("unchecked") @Override public final Field field4() { return (Field) fields[3]; } - @SuppressWarnings("unchecked") @Override public final Field field5() { return (Field) fields[4]; } - @SuppressWarnings("unchecked") @Override public final Field field6() { return (Field) fields[5]; } - @SuppressWarnings("unchecked") @Override public final Field field7() { return (Field) fields[6]; } - @SuppressWarnings("unchecked") @Override public final Field field8() { return (Field) fields[7]; @@ -257,6 +251,11 @@ implements return new Compare(row, Comparator.EQUALS); } + @Override + public final Condition equal(Record1 record) { + return new Compare(record.valuesRow(), Comparator.EQUALS); + } + @Override public final Condition equal(T1 t1) { return equal(row(t1)); @@ -392,6 +391,11 @@ implements return equal(row); } + @Override + public final Condition eq(Record1 record) { + return equal(record); + } + @Override public final Condition eq(T1 t1) { return equal(t1); @@ -527,6 +531,11 @@ implements return new Compare(row, Comparator.NOT_EQUALS); } + @Override + public final Condition notEqual(Record1 record) { + return new Compare(record.valuesRow(), Comparator.NOT_EQUALS); + } + @Override public final Condition notEqual(T1 t1) { return notEqual(row(t1)); @@ -662,6 +671,11 @@ implements return notEqual(row); } + @Override + public final Condition ne(Record1 record) { + return notEqual(record); + } + @Override public final Condition ne(T1 t1) { return notEqual(t1); @@ -797,6 +811,17 @@ implements return in(Arrays.asList(rows)); } + @Override + public final Condition in(Record1... records) { + Row1[] rows = new Row1[records.length]; + + for (int i = 0; i < records.length; i++) { + rows[i] = records[i].valuesRow(); + } + + return in(rows); + } + @Override public final Condition notIn(Row1... rows) { return notIn(Arrays.asList(rows)); @@ -842,51 +867,54 @@ implements return notIn(Arrays.asList(rows)); } - @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public final Condition notIn(Record1... records) { + Row1[] rows = new Row1[records.length]; + + for (int i = 0; i < records.length; i++) { + rows[i] = records[i].valuesRow(); + } + + return notIn(rows); + } + @Override public final Condition in(Collection rows) { QueryPartList> list = new QueryPartList>(rows); return new InRows(list, SubqueryOperator.IN); } - @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public final Condition notIn(Collection rows) { QueryPartList> list = new QueryPartList>(rows); return new InRows(list, SubqueryOperator.NOT_IN); } - @SuppressWarnings("rawtypes") @Override public final Condition equal(Select select) { return new Subquery(select, SubqueryOperator.EQUALS); } - @SuppressWarnings("rawtypes") @Override public final Condition eq(Select select) { return equal(select); } - @SuppressWarnings("rawtypes") @Override public final Condition notEqual(Select select) { return new Subquery(select, SubqueryOperator.NOT_EQUALS); } - @SuppressWarnings("rawtypes") @Override public final Condition ne(Select select) { return notEqual(select); } - @SuppressWarnings("rawtypes") @Override public final Condition in(Select select) { return new Subquery(select, SubqueryOperator.IN); } - @SuppressWarnings("rawtypes") @Override public final Condition notIn(Select select) { return new Subquery(select, SubqueryOperator.NOT_IN); @@ -924,7 +952,6 @@ implements private final RowImpl other; - @SuppressWarnings("unchecked") Overlaps(Row2 other) { this.other = (RowImpl) other; } @@ -939,7 +966,6 @@ implements delegate(context).bind(context); } - @SuppressWarnings({ "unchecked", "rawtypes" }) private final QueryPartInternal delegate(Configuration configuration) { DataType type0 = fields[0].getDataType(); DataType type1 = fields[1].getDataType(); @@ -1014,7 +1040,6 @@ implements private final RowImpl other; private final Comparator comparator; - @SuppressWarnings("unchecked") Compare(QueryPart other, Comparator comparator) { this.other = (RowImpl) other; this.comparator = comparator; @@ -1030,7 +1055,6 @@ implements delegate(context).bind(context); } - @SuppressWarnings({ "unchecked", "rawtypes" }) private final QueryPartInternal delegate(Configuration configuration) { if (asList(ASE, DERBY, FIREBIRD, INGRES, SQLSERVER, SQLITE, SYBASE).contains(configuration.getDialect())) { List conditions = new ArrayList();