From: Bryan T. <tho...@us...> - 2007-02-17 21:34:26
|
Update of /cvsroot/cweb/bigdata/src/java/com/bigdata/objndx In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv12401/src/java/com/bigdata/objndx Modified Files: BTreeMetadata.java BTree.java FusedView.java Added Files: ReadOnlyIndex.java Log Message: Working through transactional isolation. Index: BTree.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/objndx/BTree.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** BTree.java 15 Feb 2007 14:23:49 -0000 1.33 --- BTree.java 17 Feb 2007 21:34:21 -0000 1.34 *************** *** 438,442 **** * The hard reference queue for {@link Leaf}s. * ! * @see BTreeMetadata#read(IRawStore, long) */ public BTree(IRawStore store, BTreeMetadata metadata, --- 438,447 ---- * The hard reference queue for {@link Leaf}s. * ! * @see BTreeMetadata#load(IRawStore, long), which will re-load a ! * {@link BTree} or derived class from its {@link BTreeMetadata} ! * record. ! * ! * @see #newMetadata(), which must be overriden if you subclass ! * {@link BTreeMetadata} */ public BTree(IRawStore store, BTreeMetadata metadata, Index: BTreeMetadata.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/objndx/BTreeMetadata.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** BTreeMetadata.java 13 Feb 2007 23:01:02 -0000 1.9 --- BTreeMetadata.java 17 Feb 2007 21:34:18 -0000 1.10 *************** *** 3,6 **** --- 3,7 ---- import java.io.Externalizable; import java.io.Serializable; + import java.lang.reflect.Constructor; import java.nio.ByteBuffer; *************** *** 47,50 **** --- 48,56 ---- public final IValueSerializer valueSer; + /** + * The name of the class that will be used to re-load the index. + */ + public final String className; + public final RecordCompressor recordCompressor; *************** *** 95,105 **** this.nentries = btree.nentries; ! this.valueSer = btree.nodeSer.valueSerializer; this.recordCompressor = btree.nodeSer.recordCompressor; this.useChecksum = btree.nodeSer.useChecksum; ! /* * Note: This can not be invoked here since a derived class will not --- 101,113 ---- this.nentries = btree.nentries; ! this.valueSer = btree.nodeSer.valueSerializer; + this.className = btree.getClass().getName(); + this.recordCompressor = btree.nodeSer.recordCompressor; this.useChecksum = btree.nodeSer.useChecksum; ! /* * Note: This can not be invoked here since a derived class will not *************** *** 130,135 **** * @param addr * the address of the metadata record. ! * * @return the metadata record. */ public static BTreeMetadata read(IRawStore store, long addr) { --- 138,149 ---- * @param addr * the address of the metadata record. ! * * @return the metadata record. + * + * @see #load(IRawStore, long), which will load the btree not just the + * {@link BTreeMetadata}. + * + * @todo review remaining uses of this method vs + * {@link #load(IRawStore, long)}. */ public static BTreeMetadata read(IRawStore store, long addr) { *************** *** 139,142 **** --- 153,201 ---- } + + /** + * Re-load the {@link BTree} or derived class from the store. The + * {@link BTree} or derived class MUST provide a public construct with the + * following signature: <code> + * + * <i>className</i>(IRawStore store, BTreeMetadata metadata) + * + * </code> + * + * @param store + * The store. + * @param addr + * The address of the {@link BTreeMetadata} record for that + * class. + * + * @return The {@link BTree} or derived class loaded from that + * {@link BTreeMetadata} record. + * + * @see BTree#newMetadata(), which MUST be overloaded if you subclass extend + * {@link BTreeMetadata}. + */ + public static BTree load(IRawStore store, long addr) { + + BTreeMetadata metadata = read(store, addr); + + try { + + Class cl = Class.forName(metadata.className); + + Constructor ctor = cl.getConstructor(new Class[] { + IRawStore.class, BTreeMetadata.class }); + + BTree btree = (BTree) ctor.newInstance(new Object[] { store, + metadata }); + + return btree; + + } catch(Exception ex) { + + throw new RuntimeException(ex); + + } + + } // /** Index: FusedView.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/objndx/FusedView.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FusedView.java 13 Feb 2007 23:01:02 -0000 1.4 --- FusedView.java 17 Feb 2007 21:34:21 -0000 1.5 *************** *** 51,56 **** import java.util.NoSuchElementException; - import com.bigdata.isolation.Value; - /** * <p> --- 51,54 ---- *************** *** 64,70 **** * @todo support N sources for a {@link FusedView} by chaining together multiple * {@link FusedView} instances if not in a more efficient manner. - * - * @todo Do a variant that uses {@link Value}s and supports a merged view - * showing only the most recent data version under any given key.gb */ public class FusedView implements IIndex { --- 62,65 ---- *************** *** 251,254 **** --- 246,255 ---- } + /** + * Helper class merges entries from the sources in the view. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ protected static class FusedEntryIterator implements IEntryIterator { --- NEW FILE: ReadOnlyIndex.java --- /** The Notice below must appear in each file of the Source Code of any copy you distribute of the Licensed Product. Contributors to any Modifications may add their own copyright notices to identify their own contributions. License: The contents of this file are subject to the CognitiveWeb Open Source License Version 1.1 (the License). You may not copy or use this file, in either source code or executable form, except in compliance with the License. You may obtain a copy of the License from http://www.CognitiveWeb.org/legal/license/ Software distributed under the License is distributed on an AS IS basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Copyrights: Portions created by or assigned to CognitiveWeb are Copyright (c) 2003-2003 CognitiveWeb. All Rights Reserved. Contact information for CognitiveWeb is available at http://www.CognitiveWeb.org Portions Copyright (c) 2002-2003 Bryan Thompson. Acknowledgements: Special thanks to the developers of the Jabber Open Source License 1.0 (JOSL), from which this License was derived. This License contains terms that differ from JOSL. Special thanks to the CognitiveWeb Open Source Contributors for their suggestions and support of the Cognitive Web. Modifications: */ /* * Created on Feb 16, 2007 */ package com.bigdata.objndx; /** * A fly-weight wrapper that does not permit write operations and reads * through onto an underlying {@link IIndex}. * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ */ public class ReadOnlyIndex implements IIndex, IRangeQuery { private final IIndex src; public ReadOnlyIndex(IIndex src) { if(src==null) throw new IllegalArgumentException(); this.src = src; } public boolean contains(byte[] key) { return src.contains(key); } public Object insert(Object key, Object value) { throw new UnsupportedOperationException(); } public Object lookup(Object key) { return src.lookup(key); } public Object remove(Object key) { throw new UnsupportedOperationException(); } public int rangeCount(byte[] fromKey, byte[] toKey) { return src.rangeCount(fromKey, toKey); } public IEntryIterator rangeIterator(byte[] fromKey, byte[] toKey) { return src.rangeIterator(fromKey, toKey); } public void contains(BatchContains op) { src.contains(op); } public void insert(BatchInsert op) { throw new UnsupportedOperationException(); } public void lookup(BatchLookup op) { src.lookup(op); } public void remove(BatchRemove op) { throw new UnsupportedOperationException(); } } |