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