001package io.ebean.bean; 002 003import java.io.Serializable; 004 005/** 006 * Represents a "origin" of an ORM object graph. This combines the call stack 007 * and query plan hash. 008 * <p> 009 * The call stack is included so that the query can have different tuned fetches 010 * for each unique call stack. For example, a query to fetch a customer could be 011 * called by three different methods and each can be treated as a separate 012 * origin point (and autoTune can tune each one separately). 013 * </p> 014 */ 015public final class ObjectGraphOrigin implements Serializable { 016 017 private static final long serialVersionUID = 410937765287968708L; 018 019 private final CallOrigin callOrigin; 020 021 private final String beanType; 022 023 private final int queryHash; 024 025 private final String key; 026 027 public ObjectGraphOrigin(int queryHash, CallOrigin callOrigin, String beanType) { 028 this.callOrigin = callOrigin; 029 this.beanType = beanType; 030 this.queryHash = queryHash; 031 this.key = callOrigin.getOriginKey(queryHash); 032 } 033 034 /** 035 * The key includes the queryPlan hash and the callStack hash. This becomes 036 * the unique identifier for a query point. 037 */ 038 public String getKey() { 039 return key; 040 } 041 042 /** 043 * The type of bean the query is fetching. 044 */ 045 public String getBeanType() { 046 return beanType; 047 } 048 049 /** 050 * The call stack involved. 051 */ 052 public CallOrigin getCallOrigin() { 053 return callOrigin; 054 } 055 056 public String getTopElement() { 057 return callOrigin.getTopElement(); 058 } 059 060 @Override 061 public String toString() { 062 return "key[" + key + "] type[" + beanType + "] " + callOrigin.getTopElement(); 063 } 064 065 @Override 066 public int hashCode() { 067 int hc = 92821 * callOrigin.hashCode(); 068 hc = 92821 * hc + beanType.hashCode(); 069 hc = 92821 * hc + queryHash; 070 return hc; 071 } 072 073 @Override 074 public boolean equals(Object obj) { 075 if (obj == this) { 076 return true; 077 } 078 if (!(obj instanceof ObjectGraphOrigin)) { 079 return false; 080 } 081 082 ObjectGraphOrigin e = (ObjectGraphOrigin) obj; 083 return e.queryHash == queryHash 084 && e.beanType.equals(beanType) 085 && e.callOrigin.equals(callOrigin); 086 } 087}