diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractName.java b/jOOQ/src/main/java/org/jooq/impl/AbstractName.java index 28eb567a48..30b9895778 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractName.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractName.java @@ -375,10 +375,16 @@ abstract class AbstractName extends AbstractQueryPart implements Name { if (this == that) return true; - // [#1626] NameImpl equality can be decided without executing the + // [#1626] [#11126] NameImpl equality can be decided without executing the // rather expensive implementation of AbstractQueryPart.equals() - if (that instanceof AbstractName) - return Arrays.equals(getName(), (((AbstractName) that).getName())); + if (that instanceof AbstractName) { + + // [#11126] No need to access name arrays if not both names are equally qualified + if (qualified() != ((AbstractName) that).qualified()) + return false; + else + return Arrays.equals(getName(), (((AbstractName) that).getName())); + } return super.equals(that); } diff --git a/jOOQ/src/main/java/org/jooq/impl/Function.java b/jOOQ/src/main/java/org/jooq/impl/Function.java index 95ae7ff6c1..d203434e54 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Function.java +++ b/jOOQ/src/main/java/org/jooq/impl/Function.java @@ -70,4 +70,17 @@ final class Function extends AbstractField { public final void accept(Context ctx) { ctx.visit(getQualifiedName()).sql('(').visit(arguments).sql(')'); } + + // ------------------------------------------------------------------------- + // The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof Function) + return getQualifiedName().equals(((Function) that).getQualifiedName()) + && arguments.equals(((Function) that).arguments); + else + return super.equals(that); + } } diff --git a/jOOQ/src/main/java/org/jooq/impl/QueryPartCollectionView.java b/jOOQ/src/main/java/org/jooq/impl/QueryPartCollectionView.java index eac868e81e..b5ac061973 100644 --- a/jOOQ/src/main/java/org/jooq/impl/QueryPartCollectionView.java +++ b/jOOQ/src/main/java/org/jooq/impl/QueryPartCollectionView.java @@ -297,4 +297,23 @@ class QueryPartCollectionView extends AbstractQueryPart imp public final void clear() { wrapped.clear(); } + + // ------------------------------------------------------------------------- + // The Object API + // ------------------------------------------------------------------------- + + @Override + public int hashCode() { + return wrapped.hashCode(); + } + + @Override + public boolean equals(Object that) { + + // [#11126] Speed up comparisons of two QueryPartCollectionViews of the same type + if (that instanceof QueryPartCollectionView && getClass() == that.getClass()) + return wrapped.equals(((QueryPartCollectionView) that).wrapped); + else + return super.equals(that); + } } diff --git a/jOOQ/src/main/java/org/jooq/impl/SequenceImpl.java b/jOOQ/src/main/java/org/jooq/impl/SequenceImpl.java index fb62eaf925..c3903fb5b5 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SequenceImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/SequenceImpl.java @@ -85,17 +85,19 @@ public class SequenceImpl extends AbstractTypedNamed implem /** * Generated UID */ - private static final long serialVersionUID = 6224349401603636427L; - private static final Clause[] CLAUSES = { SEQUENCE, SEQUENCE_REFERENCE }; + private static final long serialVersionUID = 6224349401603636427L; + private static final Clause[] CLAUSES = { SEQUENCE, SEQUENCE_REFERENCE }; - private final boolean nameIsPlainSQL; - private final Schema schema; - private final Field startWith; - private final Field incrementBy; - private final Field minvalue; - private final Field maxvalue; - private final boolean cycle; - private final Field cache; + private final boolean nameIsPlainSQL; + private final Schema schema; + private final Field startWith; + private final Field incrementBy; + private final Field minvalue; + private final Field maxvalue; + private final boolean cycle; + private final Field cache; + private final SequenceFunction currval; + private final SequenceFunction nextval; @Deprecated public SequenceImpl(String name, Schema schema, DataType type) { @@ -133,6 +135,8 @@ public class SequenceImpl extends AbstractTypedNamed implem this.maxvalue = maxvalue; this.cycle = cycle; this.cache = cache; + this.currval = new SequenceFunction<>(SequenceMethod.CURRVAL, this); + this.nextval = new SequenceFunction<>(SequenceMethod.NEXTVAL, this); } @Override @@ -177,12 +181,12 @@ public class SequenceImpl extends AbstractTypedNamed implem @Override public final Field currval() { - return new SequenceFunction(SequenceMethod.CURRVAL); + return currval; } @Override public final Field nextval() { - return new SequenceFunction(SequenceMethod.NEXTVAL); + return nextval; } @Override @@ -203,18 +207,20 @@ public class SequenceImpl extends AbstractTypedNamed implem } } - private class SequenceFunction extends AbstractField { + private static class SequenceFunction extends AbstractField { /** * Generated UID */ - private static final long serialVersionUID = 2292275568395094887L; - private final SequenceMethod method; + private static final long serialVersionUID = 2292275568395094887L; + private final SequenceMethod method; + private final SequenceImpl sequence; - SequenceFunction(SequenceMethod method) { - super(method.name, SequenceImpl.this.getDataType()); + SequenceFunction(SequenceMethod method, SequenceImpl sequence) { + super(method.name, sequence.getDataType()); this.method = method; + this.sequence = sequence; } @Override @@ -237,7 +243,7 @@ public class SequenceImpl extends AbstractTypedNamed implem case POSTGRES: { ctx.visit(method.keyword).sql('('); - ctx.sql('\'').stringLiteral(true).visit(SequenceImpl.this).stringLiteral(false).sql('\''); + ctx.sql('\'').stringLiteral(true).visit(sequence).stringLiteral(false).sql('\''); ctx.sql(')'); break; } @@ -251,15 +257,15 @@ public class SequenceImpl extends AbstractTypedNamed implem case HSQLDB: case MARIADB: { if (method == SequenceMethod.NEXTVAL) - ctx.visit(K_NEXT_VALUE_FOR).sql(' ').visit(SequenceImpl.this); + ctx.visit(K_NEXT_VALUE_FOR).sql(' ').visit(sequence); else if (family == H2) - ctx.visit(SequenceImpl.this).sql('.').visit(method.keyword); + ctx.visit(sequence).sql('.').visit(method.keyword); else if (family == HSQLDB) - ctx.visit(K_CURRENT_VALUE_FOR).sql(' ').visit(SequenceImpl.this); + ctx.visit(K_CURRENT_VALUE_FOR).sql(' ').visit(sequence); else if (family == MARIADB) - ctx.visit(K_PREVIOUS_VALUE_FOR).sql(' ').visit(SequenceImpl.this); + ctx.visit(K_PREVIOUS_VALUE_FOR).sql(' ').visit(sequence); else if (family == FIREBIRD) - ctx.visit(N_GEN_ID).sql('(').visit(SequenceImpl.this).sql(", 0)"); + ctx.visit(N_GEN_ID).sql('(').visit(sequence).sql(", 0)"); @@ -281,7 +287,7 @@ public class SequenceImpl extends AbstractTypedNamed implem } case CUBRID: { - ctx.visit(SequenceImpl.this).sql('.'); + ctx.visit(sequence).sql('.'); if (method == SequenceMethod.NEXTVAL) ctx.visit(DSL.keyword("next_value")); @@ -293,11 +299,24 @@ public class SequenceImpl extends AbstractTypedNamed implem // Default is needed for hashCode() and toString() default: { - ctx.visit(SequenceImpl.this).sql('.').visit(method.keyword); + ctx.visit(sequence).sql('.').visit(method.keyword); break; } } } + + // ------------------------------------------------------------------------- + // The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof SequenceFunction) + return method == ((SequenceFunction) that).method + && sequence.equals(((SequenceFunction) that).sequence); + else + return super.equals(that); + } } // ------------------------------------------------------------------------ @@ -322,4 +341,16 @@ public class SequenceImpl extends AbstractTypedNamed implem public final Clause[] clauses(Context ctx) { return CLAUSES; } + + // ------------------------------------------------------------------------- + // The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof SequenceImpl) + return getQualifiedName().equals(((SequenceImpl) that).getQualifiedName()); + else + return super.equals(that); + } } diff --git a/jOOQ/src/main/java/org/jooq/impl/TableAlias.java b/jOOQ/src/main/java/org/jooq/impl/TableAlias.java index d742d7ad0f..865c173bef 100644 --- a/jOOQ/src/main/java/org/jooq/impl/TableAlias.java +++ b/jOOQ/src/main/java/org/jooq/impl/TableAlias.java @@ -171,4 +171,16 @@ final class TableAlias extends AbstractTable { public Class getRecordType() { return alias.wrapped().getRecordType(); } + + // ------------------------------------------------------------------------ + // XXX: Object API + // ------------------------------------------------------------------------ + + @Override + public boolean equals(Object that) { + if (that instanceof TableAlias) + return getUnqualifiedName().equals(((TableAlias) that).getUnqualifiedName()); + else + return super.equals(that); + } }