From 03d975fdb7f0902cd959766811e5e12d116df91b Mon Sep 17 00:00:00 2001 From: Hardy Ferentschik Date: Thu, 5 May 2011 15:40:56 +0200 Subject: [PATCH] HHH-6174 Implementing toString, equals and hashCode --- .../metamodel/relational/Schema.java | 132 +++++++++++++----- 1 file changed, 100 insertions(+), 32 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/relational/Schema.java b/hibernate-core/src/main/java/org/hibernate/metamodel/relational/Schema.java index 383c247326..5960917e23 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/relational/Schema.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/relational/Schema.java @@ -32,6 +32,74 @@ import java.util.Map; * @author Steve Ebersole */ public class Schema { + private final Name name; + private Map inLineViews = new HashMap(); + private Map tables = new HashMap(); + + public Schema(Name name) { + this.name = name; + } + + public Schema(Identifier schema, Identifier catalog) { + this( new Name( schema, catalog ) ); + } + + public Name getName() { + return name; + } + + public Table getTable(Identifier name) { + return tables.get( name ); + } + + public Table createTable(Identifier name) { + Table table = new Table( this, name ); + tables.put( name, table ); + return table; + } + + public InLineView getInLineView(String logicalName) { + return inLineViews.get( logicalName ); + } + + public InLineView createInLineView(String logicalName, String subSelect) { + InLineView inLineView = new InLineView( this, logicalName, subSelect ); + inLineViews.put( logicalName, inLineView ); + return inLineView; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append( "Schema" ); + sb.append( "{name=" ).append( name ); + sb.append( '}' ); + return sb.toString(); + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + Schema schema = (Schema) o; + + if ( name != null ? !name.equals( schema.name ) : schema.name != null ) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + return name != null ? name.hashCode() : 0; + } + public static class Name { private final Identifier schema; private final Identifier catalog; @@ -52,43 +120,43 @@ public class Schema { public Identifier getCatalog() { return catalog; } - } - private final Name name; + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append( "Name" ); + sb.append( "{schema=" ).append( schema ); + sb.append( ", catalog=" ).append( catalog ); + sb.append( '}' ); + return sb.toString(); + } - public Schema(Name name) { - this.name = name; - } + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - public Schema(Identifier schema, Identifier catalog) { - this( new Name( schema, catalog ) ); - } + Name name = (Name) o; - public Name getName() { - return name; - } + if ( catalog != null ? !catalog.equals( name.catalog ) : name.catalog != null ) { + return false; + } + if ( schema != null ? !schema.equals( name.schema ) : name.schema != null ) { + return false; + } - private Map tables = new HashMap(); + return true; + } - public Table getTable(Identifier name) { - return tables.get( name ); - } - - public Table createTable(Identifier name) { - Table table = new Table( this, name ); - tables.put( name, table ); - return table; - } - - private Map inLineViews = new HashMap(); - - public InLineView getInLineView(String logicalName) { - return inLineViews.get( logicalName ); - } - - public InLineView createInLineView(String logicalName, String subSelect) { - InLineView inLineView = new InLineView( this, logicalName, subSelect ); - inLineViews.put( logicalName, inLineView ); - return inLineView; + @Override + public int hashCode() { + int result = schema != null ? schema.hashCode() : 0; + result = 31 * result + ( catalog != null ? catalog.hashCode() : 0 ); + return result; + } } }