You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by zs...@apache.org on 2009/04/24 03:51:01 UTC
svn commit: r768120 [2/5] - in /hadoop/hive/trunk: ./
ql/src/java/org/apache/hadoop/hive/ql/util/
ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/
ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/
ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/h...
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IterationException.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IterationException.java?rev=768120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IterationException.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IterationException.java Fri Apr 24 01:50:59 2009
@@ -0,0 +1,115 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Cees de Groot. For written permission,
+ * please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ * nor may "JDBM" appear in their names without prior written
+ * permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ * (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2000 (C) Cees de Groot. All Rights Reserved.
+ * Contributions are Copyright (C) 2000 by their associated contributors.
+ *
+ * $Id: IterationException.java,v 1.2 2003/09/21 15:47:00 boisvert Exp $
+ */
+
+package org.apache.hadoop.hive.ql.util.jdbm.helper;
+
+
+/**
+ * Iteration exception.
+ *
+ * @author <a href="boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Revision: 1.2 $
+ */
+public class IterationException
+ extends WrappedRuntimeException
+{
+
+ /**
+ * Construct a new iteration exception wrapping an underlying exception
+ * and providing a message.
+ *
+ * @param message The exception message
+ * @param except The underlying exception
+ */
+ public IterationException( String message, Exception except )
+ {
+ super( message, except );
+ }
+
+
+ /**
+ * Construct a new iteration exception with a message.
+ *
+ * @param message The exception message
+ */
+ public IterationException( String message )
+ {
+ super( message, null );
+ }
+
+
+ /**
+ * Construct a new iteration exception wrapping an underlying exception.
+ *
+ * @param except The underlying exception
+ */
+ public IterationException( Exception except )
+ {
+ super( except );
+ }
+
+}
+
+
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongComparator.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongComparator.java?rev=768120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongComparator.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongComparator.java Fri Apr 24 01:50:59 2009
@@ -0,0 +1,116 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Cees de Groot. For written permission,
+ * please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ * nor may "JDBM" appear in their names without prior written
+ * permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ * (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package org.apache.hadoop.hive.ql.util.jdbm.helper;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+/**
+ * Comparator for java.lang.Long objects.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: LongComparator.java,v 1.4 2002/05/31 06:33:20 boisvert Exp $
+ */
+public final class LongComparator
+ implements Comparator, Serializable
+{
+
+ /**
+ * Version id for serialization.
+ */
+ final static long serialVersionUID = 1L;
+
+
+ /**
+ * Compare two objects.
+ *
+ * @param obj1 First object
+ * @param obj2 Second object
+ * @return a positive integer if obj1 > obj2, 0 if obj1 == obj2,
+ * and a negative integer if obj1 < obj2
+ */
+ public int compare( Object obj1, Object obj2 )
+ {
+ if ( obj1 == null ) {
+ throw new IllegalArgumentException( "Argument 'obj1' is null" );
+ }
+
+ if ( obj2 == null ) {
+ throw new IllegalArgumentException( "Argument 'obj2' is null" );
+ }
+
+ long l1 = ( (Long) obj1 ).longValue();
+ long l2 = ( (Long) obj2 ).longValue();
+
+ if ( l1 > l2 ) {
+ return 1;
+ } else if ( l1 == l2 ) {
+ return 0;
+ } else {
+ return -1;
+ }
+ }
+
+}
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongSerializer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongSerializer.java?rev=768120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongSerializer.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongSerializer.java Fri Apr 24 01:50:59 2009
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Cees de Groot. For written permission,
+ * please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ * nor may "JDBM" appear in their names without prior written
+ * permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ * (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package org.apache.hadoop.hive.ql.util.jdbm.helper;
+
+import java.io.IOException;
+
+/**
+ * Optimized serializer for long integers.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: LongSerializer.java,v 1.2 2003/09/21 15:47:00 boisvert Exp $
+ */
+public class LongSerializer
+ implements Serializer
+{
+
+
+ public static final LongSerializer INSTANCE = new LongSerializer();
+
+
+ /**
+ * Construct a LongSerializer.
+ */
+ public LongSerializer()
+ {
+ // no op
+ }
+
+
+ /**
+ * Serialize the content of an object into a byte array.
+ *
+ * @param obj Object to serialize
+ * @return a byte array representing the object's state
+ */
+ public byte[] serialize( Object obj )
+ throws IOException
+ {
+ Long number = (Long) obj;
+ return Conversion.convertToByteArray( number.longValue() );
+ }
+
+
+ /**
+ * Deserialize the content of an object from a byte array.
+ *
+ * @param serialized Byte array representation of the object
+ * @return deserialized object
+ */
+ public Object deserialize( byte[] serialized )
+ throws IOException
+ {
+ long number = Conversion.convertToLong( serialized );
+ return new Long( number );
+ }
+
+}
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/MRU.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/MRU.java?rev=768120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/MRU.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/MRU.java Fri Apr 24 01:50:59 2009
@@ -0,0 +1,352 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Cees de Groot. For written permission,
+ * please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ * nor may "JDBM" appear in their names without prior written
+ * permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ * (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2000 (C) Cees de Groot. All Rights Reserved.
+ * Contributions are Copyright (C) 2000 by their associated contributors.
+ *
+ * $Id: MRU.java,v 1.8 2005/06/25 23:12:31 doomdark Exp $
+ */
+
+package org.apache.hadoop.hive.ql.util.jdbm.helper;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+
+/**
+ * MRU - Most Recently Used cache policy.
+ *
+ * Methods are *not* synchronized, so no concurrent access is allowed.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: MRU.java,v 1.8 2005/06/25 23:12:31 doomdark Exp $
+ */
+public class MRU implements CachePolicy {
+
+ /** Cached object hashtable */
+ Hashtable _hash = new Hashtable();
+
+ /**
+ * Maximum number of objects in the cache.
+ */
+ int _max;
+
+ /**
+ * Beginning of linked-list of cache elements. First entry is element
+ * which has been used least recently.
+ */
+ CacheEntry _first;
+
+ /**
+ * End of linked-list of cache elements. Last entry is element
+ * which has been used most recently.
+ */
+ CacheEntry _last;
+
+
+ /**
+ * Cache eviction listeners
+ */
+ Vector listeners = new Vector();
+
+
+ /**
+ * Construct an MRU with a given maximum number of objects.
+ */
+ public MRU(int max) {
+ if (max <= 0) {
+ throw new IllegalArgumentException("MRU cache must contain at least one entry");
+ }
+ _max = max;
+ }
+
+
+ /**
+ * Place an object in the cache.
+ */
+ public void put(Object key, Object value) throws CacheEvictionException {
+ CacheEntry entry = (CacheEntry)_hash.get(key);
+ if (entry != null) {
+ entry.setValue(value);
+ touchEntry(entry);
+ } else {
+
+ if (_hash.size() == _max) {
+ // purge and recycle entry
+ entry = purgeEntry();
+ entry.setKey(key);
+ entry.setValue(value);
+ } else {
+ entry = new CacheEntry(key, value);
+ }
+ addEntry(entry);
+ _hash.put(entry.getKey(), entry);
+ }
+ }
+
+
+ /**
+ * Obtain an object in the cache
+ */
+ public Object get(Object key) {
+ CacheEntry entry = (CacheEntry)_hash.get(key);
+ if (entry != null) {
+ touchEntry(entry);
+ return entry.getValue();
+ } else {
+ return null;
+ }
+ }
+
+
+ /**
+ * Remove an object from the cache
+ */
+ public void remove(Object key) {
+ CacheEntry entry = (CacheEntry)_hash.get(key);
+ if (entry != null) {
+ removeEntry(entry);
+ _hash.remove(entry.getKey());
+ }
+ }
+
+
+ /**
+ * Remove all objects from the cache
+ */
+ public void removeAll() {
+ _hash = new Hashtable();
+ _first = null;
+ _last = null;
+ }
+
+
+ /**
+ * Enumerate elements' values in the cache
+ */
+ public Enumeration elements() {
+ return new MRUEnumeration(_hash.elements());
+ }
+
+ /**
+ * Add a listener to this cache policy
+ *
+ * @param listener Listener to add to this policy
+ */
+ public void addListener(CachePolicyListener listener) {
+ if (listener == null) {
+ throw new IllegalArgumentException("Cannot add null listener.");
+ }
+ if ( ! listeners.contains(listener)) {
+ listeners.addElement(listener);
+ }
+ }
+
+ /**
+ * Remove a listener from this cache policy
+ *
+ * @param listener Listener to remove from this policy
+ */
+ public void removeListener(CachePolicyListener listener) {
+ listeners.removeElement(listener);
+ }
+
+ /**
+ * Add a CacheEntry. Entry goes at the end of the list.
+ */
+ protected void addEntry(CacheEntry entry) {
+ if (_first == null) {
+ _first = entry;
+ _last = entry;
+ } else {
+ _last.setNext(entry);
+ entry.setPrevious(_last);
+ _last = entry;
+ }
+ }
+
+
+ /**
+ * Remove a CacheEntry from linked list
+ */
+ protected void removeEntry(CacheEntry entry) {
+ if (entry == _first) {
+ _first = entry.getNext();
+ }
+ if (_last == entry) {
+ _last = entry.getPrevious();
+ }
+ CacheEntry previous = entry.getPrevious();
+ CacheEntry next = entry.getNext();
+ if (previous != null) {
+ previous.setNext(next);
+ }
+ if (next != null) {
+ next.setPrevious(previous);
+ }
+ entry.setPrevious(null);
+ entry.setNext(null);
+ }
+
+ /**
+ * Place entry at the end of linked list -- Most Recently Used
+ */
+ protected void touchEntry(CacheEntry entry) {
+ if (_last == entry) {
+ return;
+ }
+ removeEntry(entry);
+ addEntry(entry);
+ }
+
+ /**
+ * Purge least recently used object from the cache
+ *
+ * @return recyclable CacheEntry
+ */
+ protected CacheEntry purgeEntry() throws CacheEvictionException {
+ CacheEntry entry = _first;
+
+ // Notify policy listeners first. if any of them throw an
+ // eviction exception, then the internal data structure
+ // remains untouched.
+ CachePolicyListener listener;
+ for (int i=0; i<listeners.size(); i++) {
+ listener = (CachePolicyListener)listeners.elementAt(i);
+ listener.cacheObjectEvicted(entry.getValue());
+ }
+
+ removeEntry(entry);
+ _hash.remove(entry.getKey());
+
+ entry.setValue(null);
+ return entry;
+ }
+
+}
+
+/**
+ * State information for cache entries.
+ */
+class CacheEntry {
+ private Object _key;
+ private Object _value;
+
+ private CacheEntry _previous;
+ private CacheEntry _next;
+
+ CacheEntry(Object key, Object value) {
+ _key = key;
+ _value = value;
+ }
+
+ Object getKey() {
+ return _key;
+ }
+
+ void setKey(Object obj) {
+ _key = obj;
+ }
+
+ Object getValue() {
+ return _value;
+ }
+
+ void setValue(Object obj) {
+ _value = obj;
+ }
+
+ CacheEntry getPrevious() {
+ return _previous;
+ }
+
+ void setPrevious(CacheEntry entry) {
+ _previous = entry;
+ }
+
+ CacheEntry getNext() {
+ return _next;
+ }
+
+ void setNext(CacheEntry entry) {
+ _next = entry;
+ }
+}
+
+/**
+ * Enumeration wrapper to return actual user objects instead of
+ * CacheEntries.
+ */
+class MRUEnumeration implements Enumeration {
+ Enumeration _enum;
+
+ MRUEnumeration(Enumeration enume) {
+ _enum = enume;
+ }
+
+ public boolean hasMoreElements() {
+ return _enum.hasMoreElements();
+ }
+
+ public Object nextElement() {
+ CacheEntry entry = (CacheEntry)_enum.nextElement();
+ return entry.getValue();
+ }
+}
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/ObjectBAComparator.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/ObjectBAComparator.java?rev=768120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/ObjectBAComparator.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/ObjectBAComparator.java Fri Apr 24 01:50:59 2009
@@ -0,0 +1,184 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Cees de Groot. For written permission,
+ * please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ * nor may "JDBM" appear in their names without prior written
+ * permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ * (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package org.apache.hadoop.hive.ql.util.jdbm.helper;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Comparator;
+
+/**
+ * Comparator for objects which have been serialized into byte arrays.
+ * In effect, it wraps another Comparator which compares object and provides
+ * transparent deserialization from byte array to object.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: ObjectBAComparator.java,v 1.1 2002/05/31 06:33:20 boisvert Exp $
+ */
+public final class ObjectBAComparator
+ implements Comparator, Serializable
+{
+
+ /**
+ * Version id for serialization.
+ */
+ final static long serialVersionUID = 1L;
+
+
+ /**
+ * Wrapped comparator.
+ */
+ private Comparator _comparator;
+
+
+ /**
+ * Construct an ObjectByteArrayComparator which wraps an Object Comparator.
+ *
+ * @param comparator Object comparator.
+ */
+ public ObjectBAComparator( Comparator comparator )
+ {
+ if ( comparator == null ) {
+ throw new IllegalArgumentException( "Argument 'comparator' is null" );
+ }
+
+ _comparator = comparator;
+ }
+
+
+ /**
+ * Compare two objects.
+ *
+ * @param obj1 First object
+ * @param obj2 Second object
+ * @return 1 if obj1 > obj2, 0 if obj1 == obj2, -1 if obj1 < obj2
+ */
+ public int compare( Object obj1, Object obj2 )
+ {
+ if ( obj1 == null ) {
+ throw new IllegalArgumentException( "Argument 'obj1' is null" );
+ }
+
+ if ( obj2 == null ) {
+ throw new IllegalArgumentException( "Argument 'obj2' is null" );
+ }
+
+ try {
+ obj1 = Serialization.deserialize( (byte[]) obj1 );
+ obj2 = Serialization.deserialize( (byte[]) obj2 );
+
+ return _comparator.compare( obj1, obj2 );
+ } catch ( IOException except ) {
+ throw new WrappedRuntimeException( except );
+ } catch ( ClassNotFoundException except ) {
+ throw new WrappedRuntimeException( except );
+ }
+ }
+
+
+ /**
+ * Compare two byte arrays.
+ */
+ public static int compareByteArray( byte[] thisKey, byte[] otherKey )
+ {
+ int len = Math.min( thisKey.length, otherKey.length );
+
+ // compare the byte arrays
+ for ( int i=0; i<len; i++ ) {
+ if ( thisKey[i] >= 0 ) {
+ if ( otherKey[i] >= 0 ) {
+ // both positive
+ if ( thisKey[i] < otherKey[i] ) {
+ return -1;
+ } else if ( thisKey[i] > otherKey[i] ) {
+ return 1;
+ }
+ } else {
+ // otherKey is negative => greater (because MSB is 1)
+ return -1;
+ }
+ } else {
+ if ( otherKey[i] >= 0 ) {
+ // thisKey is negative => greater (because MSB is 1)
+ return 1;
+ } else {
+ // both negative
+ if ( thisKey[i] < otherKey[i] ) {
+ return -1;
+ } else if ( thisKey[i] > otherKey[i] ) {
+ return 1;
+ }
+ }
+ }
+ }
+ if ( thisKey.length == otherKey.length) {
+ return 0;
+ }
+ if ( thisKey.length < otherKey.length ) {
+ return -1;
+ }
+ return 1;
+ }
+
+}
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serialization.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serialization.java?rev=768120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serialization.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serialization.java Fri Apr 24 01:50:59 2009
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Cees de Groot. For written permission,
+ * please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ * nor may "JDBM" appear in their names without prior written
+ * permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ * (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package org.apache.hadoop.hive.ql.util.jdbm.helper;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * Serialization-related utility methods.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: Serialization.java,v 1.1 2002/05/31 06:33:20 boisvert Exp $
+ */
+public final class Serialization
+{
+
+ /**
+ * Serialize the object into a byte array.
+ */
+ public static byte[] serialize( Object obj )
+ throws IOException
+ {
+ ByteArrayOutputStream baos;
+ ObjectOutputStream oos;
+
+ baos = new ByteArrayOutputStream();
+ oos = new ObjectOutputStream( baos );
+ oos.writeObject( obj );
+ oos.close();
+
+ return baos.toByteArray();
+ }
+
+
+ /**
+ * Deserialize an object from a byte array
+ */
+ public static Object deserialize( byte[] buf )
+ throws ClassNotFoundException, IOException
+ {
+ ByteArrayInputStream bais;
+ ObjectInputStream ois;
+
+ bais = new ByteArrayInputStream( buf );
+ ois = new ObjectInputStream( bais );
+ return ois.readObject();
+ }
+
+}
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serializer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serializer.java?rev=768120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serializer.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serializer.java Fri Apr 24 01:50:59 2009
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Cees de Groot. For written permission,
+ * please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ * nor may "JDBM" appear in their names without prior written
+ * permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ * (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package org.apache.hadoop.hive.ql.util.jdbm.helper;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+/**
+ * Interface used to provide a serialization mechanism other than a class' normal
+ * serialization.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: Serializer.java,v 1.1 2003/03/21 02:48:42 boisvert Exp $
+ */
+public interface Serializer
+ extends Serializable
+{
+
+ /**
+ * Serialize the content of an object into a byte array.
+ *
+ * @param obj Object to serialize
+ * @return a byte array representing the object's state
+ */
+ public byte[] serialize( Object obj )
+ throws IOException;
+
+
+ /**
+ * Deserialize the content of an object from a byte array.
+ *
+ * @param serialized Byte array representation of the object
+ * @return deserialized object
+ */
+ public Object deserialize( byte[] serialized )
+ throws IOException;
+
+}
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/SoftCache.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/SoftCache.java?rev=768120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/SoftCache.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/SoftCache.java Fri Apr 24 01:50:59 2009
@@ -0,0 +1,312 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Cees de Groot. For written permission,
+ * please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ * nor may "JDBM" appear in their names without prior written
+ * permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ * (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2000 (C) Cees de Groot. All Rights Reserved.
+ * Contributions are Copyright (C) 2000 by their associated contributors.
+ *
+ * $Id
+ */
+package org.apache.hadoop.hive.ql.util.jdbm.helper;
+
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+import java.lang.ref.Reference;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Wraps a deterministic cache policy with a <q>Level-2</q> cache based on
+ * J2SE's {@link SoftReference soft references}. Soft references allow
+ * this cache to keep references to objects until the memory they occupy
+ * is required elsewhere.
+ * <p>
+ * Since the {@link CachePolicy} interface requires an event be fired
+ * when an object is evicted, and the event contains the actual object,
+ * this class cannot be a stand-alone implementation of
+ * <code>CachePolicy</code>. This limitation arises because Java References
+ * does not support notification before references are cleared; nor do
+ * they support reaching soft referents. Therefore, this wrapper cache
+ * aggressively notifies evictions: events are fired when the objects are
+ * evicted from the internal cache. Consequently, the soft cache may return
+ * a non-null object when <code>get( )</code> is called, even if that
+ * object was said to have been evicted.
+ * <p>
+ * The current implementation uses a hash structure for its internal key
+ * to value mappings.
+ * <p>
+ * Note: this component's publicly exposed methods are not threadsafe;
+ * potentially concurrent code should synchronize on the cache instance.
+ *
+ * @author <a href="mailto:dranatunga@users.sourceforge.net">Dilum Ranatunga</a>
+ * @version $Id: SoftCache.java,v 1.1 2003/11/01 13:29:27 dranatunga Exp $
+ */
+public class SoftCache implements CachePolicy {
+ private static final int INITIAL_CAPACITY = 128;
+ private static final float DEFAULT_LOAD_FACTOR = 1.5f;
+
+ private final ReferenceQueue _clearQueue = new ReferenceQueue();
+ private final CachePolicy _internal;
+ private final Map _cacheMap;
+
+ /**
+ * Creates a soft-reference based L2 cache with a {@link MRU} cache as
+ * the internal (L1) cache. The soft reference cache uses the
+ * default load capacity of 1.5f, which is intended to sacrifice some
+ * performance for space. This compromise is reasonable, since all
+ * {@link #get(Object) get( )s} first try the L1 cache anyway. The
+ * internal MRU is given a capacity of 128 elements.
+ */
+ public SoftCache() {
+ this(new MRU(INITIAL_CAPACITY));
+ }
+
+ /**
+ * Creates a soft-reference based L2 cache wrapping the specified
+ * L1 cache.
+ *
+ * @param internal non null internal cache.
+ * @throws NullPointerException if the internal cache is null.
+ */
+ public SoftCache(CachePolicy internal) throws NullPointerException {
+ this(DEFAULT_LOAD_FACTOR, internal);
+ }
+
+ /**
+ * Creates a soft-reference based L2 cache wrapping the specified
+ * L1 cache. This constructor is somewhat implementation-specific,
+ * so users are encouraged to use {@link #SoftCache(CachePolicy)}
+ * instead.
+ *
+ * @param loadFactor load factor that the soft cache's hash structure
+ * should use.
+ * @param internal non null internal cache.
+ * @throws IllegalArgumentException if the load factor is nonpositive.
+ * @throws NullPointerException if the internal cache is null.
+ */
+ public SoftCache(float loadFactor, CachePolicy internal) throws IllegalArgumentException, NullPointerException {
+ if (internal == null) {
+ throw new NullPointerException("Internal cache cannot be null.");
+ }
+ _internal = internal;
+ _cacheMap = new HashMap(INITIAL_CAPACITY, loadFactor);
+ }
+
+ /**
+ * Adds the specified value to the cache under the specified key. Note
+ * that the object is added to both this and the internal cache.
+ * @param key the (non-null) key to store the object under
+ * @param value the (non-null) object to place in the cache
+ * @throws CacheEvictionException exception that the internal cache
+ * would have experienced while evicting an object it currently
+ * cached.
+ */
+ public void put(Object key, Object value) throws CacheEvictionException {
+ if (key == null) {
+ throw new IllegalArgumentException("key cannot be null.");
+ } else if (value == null) {
+ throw new IllegalArgumentException("value cannot be null.");
+ }
+ _internal.put(key, value);
+ removeClearedEntries();
+ _cacheMap.put(key, new Entry(key, value, _clearQueue));
+ }
+
+ /**
+ * Gets the object cached under the specified key.
+ * <p>
+ * The cache is looked up in the following manner:
+ * <ol>
+ * <li>The internal (L1) cache is checked. If the object is found, it is
+ * returned.</li>
+ * <li>This (L2) cache is checked. If the object is not found, then
+ * the caller is informed that the object is inaccessible.</li>
+ * <li>Since the object exists in L2, but not in L1, the object is
+ * readded to L1 using {@link CachePolicy#put(Object, Object)}.</li>
+ * <li>If the readding succeeds, the value is returned to caller.</li>
+ * <li>If a cache eviction exception is encountered instead, we
+ * remove the object from L2 and behave as if the object was
+ * inaccessible.</li>
+ * </ol>
+ * @param key the key that the object was stored under.
+ * @return the object stored under the key specified; null if the
+ * object is not (nolonger) accessible via this cache.
+ */
+ public Object get(Object key) {
+ // first try the internal cache.
+ Object value = _internal.get(key);
+ if (value != null) {
+ return value;
+ }
+ // poll and remove cleared references.
+ removeClearedEntries();
+ Entry entry = (Entry)_cacheMap.get(key);
+ if (entry == null) { // object is not in cache.
+ return null;
+ }
+ value = entry.getValue();
+ if (value == null) { // object was in cache, but it was cleared.
+ return null;
+ }
+ // we have the object. so we try to re-insert it into internal cache
+ try {
+ _internal.put(key, value);
+ } catch (CacheEvictionException e) {
+ // if the internal cache causes a fuss, we kick the object out.
+ _cacheMap.remove(key);
+ return null;
+ }
+ return value;
+ }
+
+ /**
+ * Removes any object stored under the key specified. Note that the
+ * object is removed from both this (L2) and the internal (L1)
+ * cache.
+ * @param key the key whose object should be removed
+ */
+ public void remove(Object key) {
+ _cacheMap.remove(key);
+ _internal.remove(key);
+ }
+
+ /**
+ * Removes all objects in this (L2) and its internal (L1) cache.
+ */
+ public void removeAll() {
+ _cacheMap.clear();
+ _internal.removeAll();
+ }
+
+ /**
+ * Gets all the objects stored by the internal (L1) cache.
+ * @return an enumeration of objects in internal cache.
+ */
+ public Enumeration elements() {
+ return _internal.elements();
+ }
+
+ /**
+ * Adds the specified listener to this cache. Note that the events
+ * fired by this correspond to the <em>internal</em> cache's events.
+ * @param listener the (non-null) listener to add to this policy
+ * @throws IllegalArgumentException if listener is null.
+ */
+ public void addListener(CachePolicyListener listener)
+ throws IllegalArgumentException {
+ _internal.addListener(listener);
+ }
+
+ /**
+ * Removes a listener that was added earlier.
+ * @param listener the listener to remove.
+ */
+ public void removeListener(CachePolicyListener listener) {
+ _internal.removeListener(listener);
+ }
+
+ /**
+ * Cleans the mapping structure of any obsolete entries. This is usually
+ * called before insertions and lookups on the mapping structure. The
+ * runtime of this is usually very small, but it can be as expensive as
+ * n * log(n) if a large number of soft references were recently cleared.
+ */
+ private final void removeClearedEntries() {
+ for (Reference r = _clearQueue.poll(); r != null; r = _clearQueue.poll()) {
+ Object key = ((Entry)r).getKey();
+ _cacheMap.remove(key);
+ }
+ }
+
+ /**
+ * Value objects we keep in the internal map. This contains the key in
+ * addition to the value, because polling for cleared references
+ * returns these instances, and having access to their corresponding
+ * keys drastically improves the performance of removing the pair
+ * from the map (see {@link SoftCache#removeClearedEntries()}.)
+ */
+ private static class Entry extends SoftReference {
+ private final Object _key;
+
+ /**
+ * Constructor that uses <code>value</code> as the soft
+ * reference's referent.
+ */
+ public Entry(Object key, Object value, ReferenceQueue queue) {
+ super(value, queue);
+ _key = key;
+ }
+
+ /**
+ * Gets the key
+ * @return the key associated with this value.
+ */
+ final Object getKey() {
+ return _key;
+ }
+
+ /**
+ * Gets the value
+ * @return the value; null if it is no longer accessible
+ */
+ final Object getValue() {
+ return this.get();
+ }
+ }
+}
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/StringComparator.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/StringComparator.java?rev=768120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/StringComparator.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/StringComparator.java Fri Apr 24 01:50:59 2009
@@ -0,0 +1,107 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Cees de Groot. For written permission,
+ * please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ * nor may "JDBM" appear in their names without prior written
+ * permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ * (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package org.apache.hadoop.hive.ql.util.jdbm.helper;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+/**
+ * Comparator for String objects. Delegates to String.compareTo().
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: StringComparator.java,v 1.5 2005/06/25 23:12:31 doomdark Exp $
+ */
+public final class StringComparator
+ implements Comparator, Serializable
+{
+
+ /**
+ * Version id for serialization.
+ */
+ final static long serialVersionUID = 1L;
+
+
+ /**
+ * Compare two objects.
+ *
+ * @param obj1 First object
+ * @param obj2 Second object
+ * @return a positive integer if obj1 > obj2, 0 if obj1 == obj2,
+ * and a negative integer if obj1 < obj2
+ */
+ public int compare( Object obj1, Object obj2 )
+ {
+ if ( obj1 == null ) {
+ throw new IllegalArgumentException( "Argument 'obj1' is null" );
+ }
+
+ if ( obj2 == null ) {
+ throw new IllegalArgumentException( "Argument 'obj2' is null" );
+ }
+
+ return ( (String) obj1 ).compareTo((String) obj2 );
+ }
+
+}
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Tuple.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Tuple.java?rev=768120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Tuple.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Tuple.java Fri Apr 24 01:50:59 2009
@@ -0,0 +1,139 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Cees de Groot. For written permission,
+ * please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ * nor may "JDBM" appear in their names without prior written
+ * permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ * (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package org.apache.hadoop.hive.ql.util.jdbm.helper;
+
+
+/**
+ * Tuple consisting of a key-value pair.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: Tuple.java,v 1.2 2001/05/19 14:02:00 boisvert Exp $
+ */
+public final class Tuple {
+
+ /**
+ * Key
+ */
+ private Object _key;
+
+
+ /**
+ * Value
+ */
+ private Object _value;
+
+
+ /**
+ * Construct an empty Tuple.
+ */
+ public Tuple() {
+ // empty
+ }
+
+
+ /**
+ * Construct a Tuple.
+ *
+ * @param key The key.
+ * @param value The value.
+ */
+ public Tuple( Object key, Object value ) {
+ _key = key;
+ _value = value;
+ }
+
+
+ /**
+ * Get the key.
+ */
+ public Object getKey() {
+ return _key;
+ }
+
+
+ /**
+ * Set the key.
+ */
+ public void setKey( Object key ) {
+ _key = key;
+ }
+
+
+ /**
+ * Get the value.
+ */
+ public Object getValue() {
+ return _value;
+ }
+
+
+ /**
+ * Set the value.
+ */
+ public void setValue( Object value ) {
+ _value = value;
+ }
+
+}
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/TupleBrowser.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/TupleBrowser.java?rev=768120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/TupleBrowser.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/TupleBrowser.java Fri Apr 24 01:50:59 2009
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Cees de Groot. For written permission,
+ * please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ * nor may "JDBM" appear in their names without prior written
+ * permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ * (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package org.apache.hadoop.hive.ql.util.jdbm.helper;
+
+import java.io.IOException;
+
+/**
+ * Browser to traverse a collection of tuples. The browser allows for
+ * forward and reverse order traversal.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: TupleBrowser.java,v 1.2 2001/05/19 14:02:00 boisvert Exp $
+ */
+public abstract class TupleBrowser {
+
+ /**
+ * Get the next tuple.
+ *
+ * @param tuple Tuple into which values are copied.
+ * @return True if values have been copied in tuple, or false if there is
+ * no next tuple.
+ */
+ public abstract boolean getNext( Tuple tuple )
+ throws IOException;
+
+
+ /**
+ * Get the previous tuple.
+ *
+ * @param tuple Tuple into which values are copied.
+ * @return True if values have been copied in tuple, or false if there is
+ * no previous tuple.
+ */
+ public abstract boolean getPrevious( Tuple tuple )
+ throws IOException;
+
+}
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/WrappedRuntimeException.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/WrappedRuntimeException.java?rev=768120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/WrappedRuntimeException.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/WrappedRuntimeException.java Fri Apr 24 01:50:59 2009
@@ -0,0 +1,169 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Cees de Groot. For written permission,
+ * please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ * nor may "JDBM" appear in their names without prior written
+ * permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ * (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package org.apache.hadoop.hive.ql.util.jdbm.helper;
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
+/**
+ * A run-time exception that wraps another exception. The printed stack
+ * trace will be that of the wrapped exception.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: WrappedRuntimeException.java,v 1.1 2002/05/31 06:33:20 boisvert Exp $
+ */
+public class WrappedRuntimeException
+ extends RuntimeException
+{
+
+
+ /**
+ * The underlying exception.
+ */
+ private final Exception _except;
+
+
+ /**
+ * Constructs a new runtime exception based on a checked exception.
+ *
+ * @param message The error message
+ * @param except The checked exception
+ */
+ public WrappedRuntimeException( String message, Exception except )
+ {
+ super( message == null ? "No message available" : message );
+
+ if ( except instanceof WrappedRuntimeException &&
+ ( (WrappedRuntimeException) except )._except != null )
+ {
+ _except = ( (WrappedRuntimeException) except )._except;
+ } else {
+ _except = except;
+ }
+ }
+
+
+ /**
+ * Constructs a new runtime exception based on a checked exception.
+ *
+ * @param except The checked exception
+ */
+ public WrappedRuntimeException( Exception except )
+ {
+ super( except == null || except.getMessage() == null ? "No message available" : except.getMessage() );
+
+ if ( except instanceof WrappedRuntimeException &&
+ ( (WrappedRuntimeException) except )._except != null )
+ {
+ _except = ( (WrappedRuntimeException) except )._except;
+ } else {
+ _except = except;
+ }
+ }
+
+
+ /**
+ * Returns the exception wrapped by this runtime exception.
+ *
+ * @return The exception wrapped by this runtime exception
+ */
+ public Exception getException()
+ {
+ return _except;
+ }
+
+
+ public void printStackTrace()
+ {
+ if ( _except == null ) {
+ super.printStackTrace();
+ } else {
+ _except.printStackTrace();
+ }
+ }
+
+
+ public void printStackTrace( PrintStream stream )
+ {
+ if ( _except == null ) {
+ super.printStackTrace( stream );
+ } else {
+ _except.printStackTrace( stream );
+ }
+ }
+
+
+ public void printStackTrace( PrintWriter writer )
+ {
+ if ( _except == null ) {
+ super.printStackTrace( writer );
+ } else {
+ _except.printStackTrace( writer );
+ }
+ }
+
+}
+
+
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/htree/HTree.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/htree/HTree.java?rev=768120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/htree/HTree.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/htree/HTree.java Fri Apr 24 01:50:59 2009
@@ -0,0 +1,206 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Cees de Groot. For written permission,
+ * please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ * nor may "JDBM" appear in their names without prior written
+ * permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ * (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2000 (C) Cees de Groot. All Rights Reserved.
+ * Contributions are (C) Copyright 2000 by their associated contributors.
+ *
+ */
+
+package org.apache.hadoop.hive.ql.util.jdbm.htree;
+
+import org.apache.hadoop.hive.ql.util.jdbm.RecordManager;
+import org.apache.hadoop.hive.ql.util.jdbm.helper.FastIterator;
+import java.io.IOException;
+
+/**
+ * Persistent hashtable implementation for PageManager.
+ * Implemented as an H*Tree structure.
+ *
+ * WARNING! If this instance is used in a transactional context, it
+ * *must* be discarded after a rollback.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: HTree.java,v 1.3 2005/06/25 23:12:32 doomdark Exp $
+ */
+public class HTree
+{
+
+ /**
+ * Root hash directory.
+ */
+ private HashDirectory _root;
+
+
+ /**
+ * Private constructor
+ *
+ * @param root Root hash directory.
+ */
+ private HTree( HashDirectory root ) {
+ _root = root;
+ }
+
+
+ /**
+ * Create a persistent hashtable.
+ *
+ * @param recman Record manager used for persistence.
+ */
+ public static HTree createInstance( RecordManager recman )
+ throws IOException
+ {
+ HashDirectory root;
+ long recid;
+
+ root = new HashDirectory( (byte) 0 );
+ recid = recman.insert( root );
+ root.setPersistenceContext( recman, recid );
+
+ return new HTree( root );
+ }
+
+
+ /**
+ * Load a persistent hashtable
+ *
+ * @param recman RecordManager used to store the persistent hashtable
+ * @param root_recid Record id of the root directory of the HTree
+ */
+ public static HTree load( RecordManager recman, long root_recid )
+ throws IOException
+ {
+ HTree tree;
+ HashDirectory root;
+
+ root = (HashDirectory) recman.fetch( root_recid );
+ root.setPersistenceContext( recman, root_recid );
+ tree = new HTree( root );
+ return tree;
+ }
+
+
+ /**
+ * Associates the specified value with the specified key.
+ *
+ * @param key key with which the specified value is to be assocated.
+ * @param value value to be associated with the specified key.
+ */
+ public synchronized void put(Object key, Object value)
+ throws IOException
+ {
+ _root.put(key, value);
+ }
+
+
+ /**
+ * Returns the value which is associated with the given key. Returns
+ * <code>null</code> if there is not association for this key.
+ *
+ * @param key key whose associated value is to be returned
+ */
+ public synchronized Object get(Object key)
+ throws IOException
+ {
+ return _root.get(key);
+ }
+
+
+ /**
+ * Remove the value which is associated with the given key. If the
+ * key does not exist, this method simply ignores the operation.
+ *
+ * @param key key whose associated value is to be removed
+ */
+ public synchronized void remove(Object key)
+ throws IOException
+ {
+ _root.remove(key);
+ }
+
+
+ /**
+ * Returns an enumeration of the keys contained in this
+ */
+ public synchronized FastIterator keys()
+ throws IOException
+ {
+ return _root.keys();
+ }
+
+
+ /**
+ * Returns an enumeration of the values contained in this
+ */
+ public synchronized FastIterator values()
+ throws IOException
+ {
+ return _root.values();
+ }
+
+
+ /**
+ * Get the record identifier used to load this hashtable.
+ */
+ public long getRecid()
+ {
+ return _root.getRecid();
+ }
+
+}
+