From 7c0c40265f156b3669361887d60e067719cff450 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sat, 16 Feb 2008 00:52:09 +0000 Subject: Remove obsolete StorableSerializer class. --- .../amazon/carbonado/cursor/MergeSortBuffer.java | 38 ++++++++-------------- 1 file changed, 13 insertions(+), 25 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/cursor') diff --git a/src/main/java/com/amazon/carbonado/cursor/MergeSortBuffer.java b/src/main/java/com/amazon/carbonado/cursor/MergeSortBuffer.java index 6380605..1057d01 100644 --- a/src/main/java/com/amazon/carbonado/cursor/MergeSortBuffer.java +++ b/src/main/java/com/amazon/carbonado/cursor/MergeSortBuffer.java @@ -43,8 +43,6 @@ import com.amazon.carbonado.Storable; import com.amazon.carbonado.Storage; import com.amazon.carbonado.SupportException; -import com.amazon.carbonado.gen.StorableSerializer; - import com.amazon.carbonado.spi.RAFInputStream; import com.amazon.carbonado.spi.RAFOutputStream; @@ -130,7 +128,6 @@ public class MergeSortBuffer extends AbstractCollection private int mSize; private int mTotalSize; - private StorableSerializer mSerializer; private WorkFilePool mWorkFilePool; private List mFilesInUse; @@ -201,12 +198,7 @@ public class MergeSortBuffer extends AbstractCollection // Make sure everything is set up to use temp files. { - if (mSerializer == null) { - try { - mSerializer = StorableSerializer.forType(mStorage.getStorableType()); - } catch (SupportException e) { - throw new UndeclaredThrowableException(e); - } + if (mWorkFilePool == null) { mWorkFilePool = WorkFilePool.getInstance(mTempDir); mFilesInUse = new ArrayList(); } @@ -220,15 +212,13 @@ public class MergeSortBuffer extends AbstractCollection OutputStream out = new BufferedOutputStream(new RAFOutputStream(raf), OUTPUT_BUFFER_SIZE); - StorableSerializer serializer = mSerializer; - if (mFilesInUse.size() < (MAX_OPEN_FILE_COUNT - 1)) { mFilesInUse.add(raf); int count = 0; for (S element : mElements) { // Check every so often if interrupted. interruptCheck(++count); - serializer.write(element, out); + element.writeTo(out); } } else { // Merge files together. @@ -273,7 +263,7 @@ public class MergeSortBuffer extends AbstractCollection // Check every so often if interrupted. interruptCheck(++count); S element = it.next(); - serializer.write(element, out); + element.writeTo(out); } mWorkFilePool.releaseWorkFiles(filesToMerge); @@ -287,6 +277,8 @@ public class MergeSortBuffer extends AbstractCollection raf.setLength(raf.getFilePointer()); // Reset to start of file in preparation for reading later. raf.seek(0); + } catch (SupportException e) { + throw new UndeclaredThrowableException(e); } catch (IOException e) { throw new UndeclaredThrowableException(e); } @@ -310,7 +302,7 @@ public class MergeSortBuffer extends AbstractCollection private Iterator iterator(List filesToMerge) { Comparator comparator = comparator(); - if (mSerializer == null) { + if (mWorkFilePool == null) { return new ObjectArrayIterator(mElements, 0, mSize); } @@ -328,7 +320,7 @@ public class MergeSortBuffer extends AbstractCollection InputStream in = new BufferedInputStream(new RAFInputStream(raf)); - pq.add(new InputIter(comparator, mSerializer, mStorage, in)); + pq.add(new InputIter(comparator, mStorage, in)); } return new Merger(pq); @@ -451,17 +443,13 @@ public class MergeSortBuffer extends AbstractCollection * Iterator that reads from an input stream of serialized Storables. */ private static class InputIter extends Iter { - private StorableSerializer mSerializer; private Storage mStorage; private InputStream mIn; private S mNext; - InputIter(Comparator comparator, - StorableSerializer serializer, Storage storage, InputStream in) - { + InputIter(Comparator comparator, Storage storage, InputStream in) { super(comparator); - mSerializer = serializer; mStorage = storage; mIn = in; } @@ -472,13 +460,13 @@ public class MergeSortBuffer extends AbstractCollection } if (mIn != null) { try { - mNext = mSerializer.read(mStorage, mIn); - // TODO: Serializer is unable to determine state of - // properties, and so they are lost. Since these storables - // came directly from a cursor, we know they are clean. - mNext.markAllPropertiesClean(); + S next = mStorage.prepare(); + next.readFrom(mIn); + mNext = next; } catch (EOFException e) { mIn = null; + } catch (SupportException e) { + throw new UndeclaredThrowableException(e); } catch (IOException e) { throw new UndeclaredThrowableException(e); } -- cgit v1.2.3