001    package com.mockrunner.mock.jdbc;
002    
003    import java.sql.RowId;
004    import java.util.Arrays;
005    
006    import com.mockrunner.base.NestedApplicationException;
007    
008    /**
009     * Mock implementation of <code>RowId</code>.
010     */
011    public class MockRowId implements RowId, Cloneable
012    {
013        private byte[] rowIdData;
014        
015        public MockRowId(byte[] data)
016        {
017            rowIdData = (byte[])data.clone();
018        }
019        
020        public byte[] getBytes()
021        {
022            return rowIdData;
023        }
024    
025        public boolean equals(Object otherObject)
026        {
027            if(null == otherObject) return false;
028            if(!otherObject.getClass().equals(this.getClass())) return false;
029            MockRowId otherRowId = (MockRowId)otherObject;
030            return Arrays.equals(rowIdData, otherRowId.getBytes());
031        }
032    
033        public int hashCode()
034        {
035            int value = 17;
036            for(int ii = 0; ii < rowIdData.length; ii++)
037            {
038                value = (31 * value) + rowIdData[ii];
039            }
040            return value;
041        }
042    
043        public String toString()
044        {
045            StringBuffer buffer = new StringBuffer();
046            buffer.append(this.getClass().getName() + ": [");
047            for(int ii = 0; ii < rowIdData.length; ii++)
048            {
049                buffer.append(rowIdData[ii]);
050                if(ii < rowIdData.length - 1)
051                {
052                    buffer.append(", ");
053                }
054            }
055            buffer.append("]");
056            return buffer.toString();
057        }
058    
059        public Object clone()
060        {
061            try
062            {
063                MockRowId copy = (MockRowId)super.clone();
064                copy.rowIdData = (byte[])rowIdData.clone();
065                return copy;
066            } 
067            catch(CloneNotSupportedException exc)
068            {
069                throw new NestedApplicationException(exc);
070            }
071        }
072    }