From d025e69cce3ff409c0d45a821245800a830609cf Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sun, 16 Mar 2008 23:48:13 +0000 Subject: Support updates to replicated LOBs. --- .../com/amazon/carbonado/lob/AbstractBlob.java | 27 ++++++++++++++++++++++ .../com/amazon/carbonado/lob/AbstractClob.java | 27 ++++++++++++++++++++++ .../java/com/amazon/carbonado/lob/BlobClob.java | 4 ++++ .../com/amazon/carbonado/lob/ByteArrayBlob.java | 7 ++++++ .../com/amazon/carbonado/lob/CharArrayClob.java | 7 ++++++ .../java/com/amazon/carbonado/lob/FileBlob.java | 7 ++++++ src/main/java/com/amazon/carbonado/lob/Lob.java | 8 +++++++ .../java/com/amazon/carbonado/lob/StringClob.java | 7 ++++++ 8 files changed, 94 insertions(+) (limited to 'src/main/java/com/amazon/carbonado/lob') diff --git a/src/main/java/com/amazon/carbonado/lob/AbstractBlob.java b/src/main/java/com/amazon/carbonado/lob/AbstractBlob.java index 6440978..1d331bc 100644 --- a/src/main/java/com/amazon/carbonado/lob/AbstractBlob.java +++ b/src/main/java/com/amazon/carbonado/lob/AbstractBlob.java @@ -196,4 +196,31 @@ public abstract class AbstractBlob implements Blob { } } } + + @Override + public int hashCode() { + Object locator = getLocator(); + return locator == null ? super.hashCode() : locator.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof AbstractBlob) { + Object locator = getLocator(); + if (locator != null) { + AbstractBlob other = (AbstractBlob) obj; + return locator == other.getLocator(); + } + } + return false; + } + + @Override + public String toString() { + Object locator = getLocator(); + return locator == null ? super.toString() : ("Blob@" + locator); + } } diff --git a/src/main/java/com/amazon/carbonado/lob/AbstractClob.java b/src/main/java/com/amazon/carbonado/lob/AbstractClob.java index 6e4e273..8531ba4 100644 --- a/src/main/java/com/amazon/carbonado/lob/AbstractClob.java +++ b/src/main/java/com/amazon/carbonado/lob/AbstractClob.java @@ -165,4 +165,31 @@ public abstract class AbstractClob implements Clob { } } } + + @Override + public int hashCode() { + Object locator = getLocator(); + return locator == null ? super.hashCode() : locator.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof AbstractClob) { + Object locator = getLocator(); + if (locator != null) { + AbstractClob other = (AbstractClob) obj; + return locator == other.getLocator(); + } + } + return false; + } + + @Override + public String toString() { + Object locator = getLocator(); + return locator == null ? super.toString() : ("Clob@" + locator); + } } diff --git a/src/main/java/com/amazon/carbonado/lob/BlobClob.java b/src/main/java/com/amazon/carbonado/lob/BlobClob.java index 9822171..107f422 100644 --- a/src/main/java/com/amazon/carbonado/lob/BlobClob.java +++ b/src/main/java/com/amazon/carbonado/lob/BlobClob.java @@ -96,6 +96,10 @@ public class BlobClob extends AbstractClob { mBlob.setLength(length << 1); } + public Object getLocator() { + return mBlob.getLocator(); + } + protected Blob getWrappedBlob() { return mBlob; } diff --git a/src/main/java/com/amazon/carbonado/lob/ByteArrayBlob.java b/src/main/java/com/amazon/carbonado/lob/ByteArrayBlob.java index eadd8e1..028f575 100644 --- a/src/main/java/com/amazon/carbonado/lob/ByteArrayBlob.java +++ b/src/main/java/com/amazon/carbonado/lob/ByteArrayBlob.java @@ -305,6 +305,13 @@ public class ByteArrayBlob extends AbstractBlob { } } + /** + * Always returns null. + */ + public Object getLocator() { + return null; + } + private static class Input extends InputStream { private final ByteArrayBlob mBlob; private long mPos; diff --git a/src/main/java/com/amazon/carbonado/lob/CharArrayClob.java b/src/main/java/com/amazon/carbonado/lob/CharArrayClob.java index ed6b5e9..1472da3 100644 --- a/src/main/java/com/amazon/carbonado/lob/CharArrayClob.java +++ b/src/main/java/com/amazon/carbonado/lob/CharArrayClob.java @@ -310,6 +310,13 @@ public class CharArrayClob extends AbstractClob { } } + /** + * Always returns null. + */ + public Object getLocator() { + return null; + } + private static class Input extends Reader { private final CharArrayClob mClob; private long mPos; diff --git a/src/main/java/com/amazon/carbonado/lob/FileBlob.java b/src/main/java/com/amazon/carbonado/lob/FileBlob.java index c351361..eeba914 100644 --- a/src/main/java/com/amazon/carbonado/lob/FileBlob.java +++ b/src/main/java/com/amazon/carbonado/lob/FileBlob.java @@ -109,4 +109,11 @@ public class FileBlob extends AbstractBlob { throw new PersistException(e); } } + + /** + * Always returns null. + */ + public Object getLocator() { + return null; + } } diff --git a/src/main/java/com/amazon/carbonado/lob/Lob.java b/src/main/java/com/amazon/carbonado/lob/Lob.java index a09bfe0..404500f 100644 --- a/src/main/java/com/amazon/carbonado/lob/Lob.java +++ b/src/main/java/com/amazon/carbonado/lob/Lob.java @@ -24,6 +24,14 @@ package com.amazon.carbonado.lob; * @author Brian S O'Neill */ public interface Lob { + /** + * Returns an object which identifies the Lob data, which may be null if + * not supported. + * + * @since 1.2 + */ + Object getLocator(); + /** * Two Lobs are considered equal if the object instances are the same or if * they point to the same content. Lob data is not compared, as that would diff --git a/src/main/java/com/amazon/carbonado/lob/StringClob.java b/src/main/java/com/amazon/carbonado/lob/StringClob.java index f19d63d..fe9b05d 100644 --- a/src/main/java/com/amazon/carbonado/lob/StringClob.java +++ b/src/main/java/com/amazon/carbonado/lob/StringClob.java @@ -87,6 +87,13 @@ public class StringClob extends AbstractClob { denied(); } + /** + * Always returns null. + */ + public Object getLocator() { + return null; + } + private PersistException denied() { return new PersistDeniedException("Read-only"); } -- cgit v1.2.3