From b66fb3db6951b2b6d3ace72ca3e197c7c2048e86 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Thu, 18 Dec 2008 20:58:00 +0000 Subject: Fixes for excessive class generation and memory usage when opening multiple repositories. --- .../repo/indexed/IndexEntryGenerator.java | 23 +++++++++++++--------- .../carbonado/repo/sleepycat/BDBStorage.java | 11 ++++++++--- 2 files changed, 22 insertions(+), 12 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo') diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryGenerator.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryGenerator.java index a126224..7fb80dc 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryGenerator.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryGenerator.java @@ -28,6 +28,7 @@ import com.amazon.carbonado.Storable; import com.amazon.carbonado.SupportException; import com.amazon.carbonado.info.StorableIndex; import com.amazon.carbonado.info.StorableProperty; +import com.amazon.carbonado.synthetic.SyntheticStorableReferenceAccess; import com.amazon.carbonado.synthetic.SyntheticStorableReferenceBuilder; /** @@ -100,7 +101,7 @@ class IndexEntryGenerator { } } - private SyntheticStorableReferenceBuilder mBuilder; + private SyntheticStorableReferenceAccess mIndexAccess; /** * Convenience class for gluing new "builder" style synthetics to the traditional @@ -112,13 +113,17 @@ class IndexEntryGenerator { // but we have nothing better available to us Class type = index.getProperty(0).getEnclosingType(); - mBuilder = new SyntheticStorableReferenceBuilder(type, index.isUnique()); + SyntheticStorableReferenceBuilder builder = + new SyntheticStorableReferenceBuilder(type, index.isUnique()); for (int i=0; i { * @return class of index entry, which is a custom Storable */ public Class getIndexEntryClass() { - return mBuilder.getStorableClass(); + return mIndexAccess.getReferenceClass(); } /** @@ -138,7 +143,7 @@ class IndexEntryGenerator { * @param master master whose primary key properties will be set */ public void copyToMasterPrimaryKey(Storable indexEntry, S master) { - mBuilder.copyToMasterPrimaryKey(indexEntry, master); + mIndexAccess.copyToMasterPrimaryKey(indexEntry, master); } /** @@ -149,7 +154,7 @@ class IndexEntryGenerator { * @param master source of property values */ public void copyFromMaster(Storable indexEntry, S master) { - mBuilder.copyFromMaster(indexEntry, master); + mIndexAccess.copyFromMaster(indexEntry, master); } /** @@ -161,13 +166,13 @@ class IndexEntryGenerator { * @param master source of property values */ public boolean isConsistent(Storable indexEntry, S master) { - return mBuilder.isConsistent(indexEntry, master); + return mIndexAccess.isConsistent(indexEntry, master); } /** * Returns a comparator for ordering index entries. */ public Comparator getComparator() { - return mBuilder.getComparator(); + return mIndexAccess.getComparator(); } } diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java index f4a010b..1733167 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java @@ -24,6 +24,7 @@ import java.util.Map; import org.cojen.classfile.TypeDesc; +import com.amazon.carbonado.CorruptEncodingException; import com.amazon.carbonado.Cursor; import com.amazon.carbonado.FetchDeadlockException; import com.amazon.carbonado.FetchException; @@ -104,7 +105,7 @@ abstract class BDBStorage implements Storage, Storag private final Class mType; /** Does most of the work in generating storables, used for preparing and querying */ - private StorableCodec mStorableCodec; + StorableCodec mStorableCodec; /** * Reference to an instance of Proxy, defined in this class, which binds @@ -135,7 +136,7 @@ abstract class BDBStorage implements Storage, Storag { mRepository = repository; mType = type; - mRawSupport = new Support(repository, this); + mRawSupport = new Support(repository, this); mTriggerManager = new TriggerManager(); try { // Ask if any lobs via static method first, to prevent stack @@ -1009,7 +1010,7 @@ abstract class BDBStorage implements Storage, Storag // Note: BDBStorage could just implement the RawSupport interface, but // then these hidden methods would be public. A simple cast of Storage to // RawSupport would expose them. - private static class Support implements RawSupport { + private class Support implements RawSupport { private final BDBRepository mRepository; private final BDBStorage mStorage; private Map> mProperties; @@ -1128,6 +1129,10 @@ abstract class BDBStorage implements Storage, Storag return mStorage.getLocator(clob); } + public void decode(S dest, int generation, byte[] data) throws CorruptEncodingException { + mStorableCodec.decode(dest, generation, data); + } + public SequenceValueProducer getSequenceValueProducer(String name) throws PersistException { -- cgit v1.2.3