[#1626] Explicitly implement hashCode() and equals() in some
additional QueryParts
This commit is contained in:
parent
4ecb5b6614
commit
1b0d7c08b9
@ -42,6 +42,7 @@ import org.jooq.BindContext;
|
||||
import org.jooq.Catalog;
|
||||
import org.jooq.RenderContext;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* A common base class for database catalogs
|
||||
@ -97,4 +98,25 @@ public class CatalogImpl extends AbstractQueryPart implements Catalog {
|
||||
public List<Schema> getSchemas() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// XXX: Object API
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getName() != null ? getName().hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
|
||||
// [#1626] CatalogImpl equality can be decided without executing the
|
||||
// rather expensive implementation of AbstractQueryPart.equals()
|
||||
if (that instanceof CatalogImpl) {
|
||||
return StringUtils.equals(getName(), (((CatalogImpl) that).getName()));
|
||||
}
|
||||
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +35,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.jooq.BindContext;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.RenderContext;
|
||||
@ -74,4 +76,25 @@ class NameImpl extends AbstractQueryPart implements Name {
|
||||
public final String[] getName() {
|
||||
return qualifiedName;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// XXX: Object API
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
|
||||
// [#1626] NameImpl equality can be decided without executing the
|
||||
// rather expensive implementation of AbstractQueryPart.equals()
|
||||
if (that instanceof NameImpl) {
|
||||
return Arrays.equals(getName(), (((NameImpl) that).getName()));
|
||||
}
|
||||
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,6 +40,7 @@ import org.jooq.Package;
|
||||
import org.jooq.RenderContext;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* A default implementation for packages (containers of stored procedures and
|
||||
@ -93,6 +94,20 @@ public class PackageImpl extends AbstractQueryPart implements Package {
|
||||
|
||||
// [#1938] This is a much more efficient hashCode() implementation
|
||||
// compared to that of standard QueryParts
|
||||
return name.hashCode();
|
||||
return name != null ? name.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
|
||||
// [#1626] PackageImpl equality can be decided without executing the
|
||||
// rather expensive implementation of AbstractQueryPart.equals()
|
||||
if (that instanceof PackageImpl) {
|
||||
return
|
||||
StringUtils.equals(schema, ((PackageImpl) that).getSchema()) &&
|
||||
StringUtils.equals(name, ((PackageImpl) that).name);
|
||||
}
|
||||
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,6 +41,7 @@ import org.jooq.Configuration;
|
||||
import org.jooq.DataType;
|
||||
import org.jooq.Parameter;
|
||||
import org.jooq.RenderContext;
|
||||
import org.jooq.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* A common base class for stored procedure parameters
|
||||
@ -103,6 +104,18 @@ class ParameterImpl<T> extends AbstractQueryPart implements Parameter<T> {
|
||||
|
||||
// [#1938] This is a much more efficient hashCode() implementation
|
||||
// compared to that of standard QueryParts
|
||||
return name.hashCode();
|
||||
return name != null ? name.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
|
||||
// [#1626] ParameterImpl equality can be decided without executing the
|
||||
// rather expensive implementation of AbstractQueryPart.equals()
|
||||
if (that instanceof ParameterImpl) {
|
||||
return StringUtils.equals(name, ((ParameterImpl<?>) that).name);
|
||||
}
|
||||
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,6 +145,14 @@ public class SchemaImpl extends AbstractQueryPart implements Schema {
|
||||
// XXX: Object API
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
// [#1938] This is a much more efficient hashCode() implementation
|
||||
// compared to that of standard QueryParts
|
||||
return getName() != null ? getName().hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user