001 package com.mockrunner.mock.jdbc;
002
003 import java.sql.Ref;
004 import java.sql.SQLException;
005 import java.util.Map;
006
007 import com.mockrunner.base.NestedApplicationException;
008
009 /**
010 * Mock implementation of <code>Ref</code>.
011 */
012 public class MockRef implements Ref, Cloneable
013 {
014 private Object object;
015 private String baseTypeName;
016
017 public MockRef(Object object)
018 {
019 this.object = object;
020 baseTypeName = "";
021 }
022
023 public String getBaseTypeName() throws SQLException
024 {
025 return baseTypeName;
026 }
027
028 /**
029 * Sets the base type name.
030 * @param baseTypeName the base type name
031 */
032 public void setBaseTypeName(String baseTypeName)
033 {
034 this.baseTypeName = baseTypeName;
035 }
036
037 public Object getObject(Map map) throws SQLException
038 {
039 return object;
040 }
041
042 public Object getObject() throws SQLException
043 {
044 return object;
045 }
046
047 public void setObject(Object object) throws SQLException
048 {
049 this.object = object;
050 }
051
052 public boolean equals(Object obj)
053 {
054 if(null == obj) return false;
055 if(!obj.getClass().equals(this.getClass())) return false;
056 MockRef other = (MockRef)obj;
057 if(null != baseTypeName && !baseTypeName.equals(other.baseTypeName)) return false;
058 if(null != other.baseTypeName && !other.baseTypeName.equals(baseTypeName)) return false;
059 if(null == object && null == other.object) return true;
060 if(null == object || null == other.object) return false;
061 return object.equals(other.object);
062 }
063
064 public int hashCode()
065 {
066 int hashCode = 0;
067 if(null != baseTypeName) hashCode = (31 * hashCode) + baseTypeName.hashCode();
068 if(null != object) hashCode = (31 * hashCode) + object.hashCode();
069 return hashCode;
070 }
071
072 public String toString()
073 {
074 return "Ref data: " + object.toString();
075 }
076
077 public Object clone()
078 {
079 try
080 {
081 return (MockRef)super.clone();
082 }
083 catch(CloneNotSupportedException exc)
084 {
085 throw new NestedApplicationException(exc);
086 }
087 }
088 }