com.bigdata.sparse
Class TPS

java.lang.Object
  extended by com.bigdata.sparse.TPS
All Implemented Interfaces:
IRowStoreConstants, ITPS, Externalizable, Serializable

public class TPS
extends Object
implements ITPS, Externalizable, IRowStoreConstants

Default implementation.

Version:
$Id: TPS.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
See Also:
Serialized Form

Nested Class Summary
protected static class TPS.TP
          A {property, timestamp} tuple.
static class TPS.TPV
          Helper class models a single property value as of a given timestamp.
protected static class TPS.TPVComparator
          Imposes ordering based on schema, property name, and timestamp.
 
Field Summary
protected static boolean DEBUG
           
protected static boolean INFO
           
protected static org.apache.log4j.Logger log
           
 
Fields inherited from interface com.bigdata.sparse.IRowStoreConstants
AUTO_TIMESTAMP, AUTO_TIMESTAMP_UNIQUE, CURRENT_ROW, MAX_TIMESTAMP, MIN_TIMESTAMP
 
Constructor Summary
TPS()
          De-serialization constructor.
TPS(Schema schema, long timestamp)
           
 
Method Summary
 Map<String,Object> asMap()
          Return a copy of the tuples showing only the most recent value for each property.
 Map<String,Object> asMap(long timestamp)
          Return a copy of the tuples showing only the most recent value for each property whose timestamp is not greater than the given timestamp.
 LinkedHashMap<String,Object> asMap(long timestamp, INameFilter filter)
          Note: A LinkedHashMap is returned to reduce the overhead with iterators while preserving the ordering imposed by tuples.
 TPS currentRow()
          Filters for the current row (most recent bindings)
 TPS currentRow(INameFilter filter)
          Filters for the current row (most recent bindings)
 TPS filter(INameFilter filter)
          Filters for only those bindings that satisify the given filter.
 TPS filter(long fromTime, long toTime)
          Filters for only those bindings whose timestamp is GTE to the given timestamp.
 TPS filter(long fromTime, long toTime, INameFilter filter)
          Filters for only those bindings whose timestamp is GTE to the given timestamp and which satisify the optional property name filter.
 ITPV get(String name)
          Return the most recent value for the named property.
 ITPV get(String name, long timestamp)
          Return the most recent value for the named property whose timestamp is not greater than the specified timestamp.
 Object getPrimaryKey()
          The value of the primary key.
 Schema getSchema()
          The Schema name.
 long getWriteTimestamp()
          The timestamp assigned by an atomic write operation (for atomic readback only).
 boolean isPreconditionOk()
          true unless an atomic write operation specified an IPrecondition and that IPrecondition was not satisified.
 Iterator<ITPV> iterator()
          Visits all tuples in order by ascending timestamp.
 void readExternal(ObjectInput in)
           
 void set(String name, long timestamp, Object value)
          Set the value of the named property as of the specified timestamp.
 int size()
          The #of tuples - each tuple is an ITPV.
 String toString()
           
 void writeExternal(ObjectOutput out)
          FIXME use compression for the names and timestamps, refactoring the logic already in AbstractKeyArrayIndexProcedure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final transient org.apache.log4j.Logger log

INFO

protected static final transient boolean INFO

DEBUG

protected static final transient boolean DEBUG
Constructor Detail

TPS

public TPS()
De-serialization constructor.


TPS

public TPS(Schema schema,
           long timestamp)
Parameters:
schema - The schema.
timestamp - When the data were read back as part of an atomic write, then this MUST be the timestamp of the atomic write. That can be either a caller given timestamp or a server assigned timestamp. Regardless the value will be returned by getWriteTimestamp(). When the operation was an atomic read, then the timestamp MUST be ZERO (0L).
Method Detail

isPreconditionOk

public boolean isPreconditionOk()
true unless an atomic write operation specified an IPrecondition and that IPrecondition was not satisified.


getPrimaryKey

public Object getPrimaryKey()
The value of the primary key.

Note: This looks up and returns the value of the Schema.getPrimaryKeyName() property

Specified by:
getPrimaryKey in interface ITPS
Returns:
The value of the primary key -or- null if there is no property value bound for the property named by Schema.getName().

getWriteTimestamp

public long getWriteTimestamp()
Description copied from interface: ITPS
The timestamp assigned by an atomic write operation (for atomic readback only).

Specified by:
getWriteTimestamp in interface ITPS
Returns:
The timestamp.

size

public int size()
Description copied from interface: ITPS
The #of tuples - each tuple is an ITPV.

Specified by:
size in interface ITPS

set

public void set(String name,
                long timestamp,
                Object value)
Set the value of the named property as of the specified timestamp.

Parameters:
name - The property name.
timestamp - The timestamp.
value - The property value -or- null if the property was deleted as of the given timestamp.

get

public ITPV get(String name,
                long timestamp)
Description copied from interface: ITPS
Return the most recent value for the named property whose timestamp is not greater than the specified timestamp.

Specified by:
get in interface ITPS
Parameters:
name - The property name.
timestamp - The timestamp.
Returns:
An object representing value of the property as of the indicated timestamp and never null.

get

public ITPV get(String name)
Description copied from interface: ITPS
Return the most recent value for the named property.

Specified by:
get in interface ITPS
Parameters:
name - The propery name.
Returns:
An object representing value of the property as of the indicated timestamp and never null. If no value was found for the named property, then ITPV.getValue() will return null and ITPV.getTimestamp() will return 0L.

getSchema

public Schema getSchema()
Description copied from interface: ITPS
The Schema name.

Specified by:
getSchema in interface ITPS

iterator

public Iterator<ITPV> iterator()
Description copied from interface: ITPS
Visits all tuples in order by ascending timestamp.

Specified by:
iterator in interface ITPS

currentRow

public TPS currentRow()
Filters for the current row (most recent bindings)


currentRow

public TPS currentRow(INameFilter filter)
Filters for the current row (most recent bindings)

Parameters:
filter - An optional property name filter.

filter

public TPS filter(long fromTime,
                  long toTime)
Filters for only those bindings whose timestamp is GTE to the given timestamp.


filter

public TPS filter(INameFilter filter)
Filters for only those bindings that satisify the given filter.

Parameters:
filter - An optional filter.

filter

public TPS filter(long fromTime,
                  long toTime,
                  INameFilter filter)
Filters for only those bindings whose timestamp is GTE to the given timestamp and which satisify the optional property name filter.


asMap

public Map<String,Object> asMap()
Description copied from interface: ITPS
Return a copy of the tuples showing only the most recent value for each property.

Specified by:
asMap in interface ITPS

asMap

public Map<String,Object> asMap(long timestamp)
Description copied from interface: ITPS
Return a copy of the tuples showing only the most recent value for each property whose timestamp is not greater than the given timestamp.

Specified by:
asMap in interface ITPS
Parameters:
timestamp - The timestamp (use Long.MAX_VALUE to read the most recent value for each property).
Returns:
A map containing a copy of the selected property values. A deleted property will not be contained in the map.

asMap

public LinkedHashMap<String,Object> asMap(long timestamp,
                                          INameFilter filter)
Note: A LinkedHashMap is returned to reduce the overhead with iterators while preserving the ordering imposed by tuples.

Specified by:
asMap in interface ITPS
Parameters:
timestamp - The timestamp (use Long.MAX_VALUE to read the most recent value for each property).
filter - An optional filter that may be used to select only specific property names.
Returns:
A map containing a copy of the selected property values. A deleted property will not be contained in the map.

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
FIXME use compression for the names and timestamps, refactoring the logic already in AbstractKeyArrayIndexProcedure.

Specified by:
writeExternal in interface Externalizable
Throws:
IOException
TODO:
use huffman compression for the name and timestamp dictionaries (fewer bits for the more frequent symbols, but at what added cost)?

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.