com.bigdata.rdf.model
Class BigdataValueFactoryImpl

java.lang.Object
  extended by com.bigdata.rdf.model.BigdataValueFactoryImpl
All Implemented Interfaces:
BigdataValueFactory, ValueFactory

public class BigdataValueFactoryImpl
extends Object
implements BigdataValueFactory

An implementation using BigdataValues and BigdataStatements. Values constructed using this factory do NOT have term identifiers assigned. Statements constructed using this factory do NOT have statement identifiers assigned. Those metadata can be resolved against the various indices and then set on the returned values and statements.

Version:
$Id: BigdataValueFactoryImpl.java 6036 2012-02-17 14:07:48Z thompsonbry $
Author:
Bryan Thompson
TODO:
Consider a WeakValueCache on this factory to avoid duplicate values., Consider a WeakValueCache to shortcut recently used statements?

Field Summary
static String NAMESPACE_XSD
           
static String xsd
           
 
Method Summary
 BigdataBNode asValue(BNode v)
          Strongly typed for BNodes.
 BigdataLiteral asValue(Literal v)
          Strongly typed for Literals.
 BigdataResource asValue(Resource v)
          Strongly typed for Resources.
 BigdataURI asValue(URI v)
          Strongly typed for URIs.
 BigdataValue asValue(Value v)
          Converts a Value into a BigdataValue.
 BigdataBNodeImpl createBNode()
          Returns a new blank node with a globally unique blank node ID based on a UUID.
 BigdataBNodeImpl createBNode(String id)
           
 BigdataLiteralImpl createLiteral(boolean arg0)
           
 BigdataLiteralImpl createLiteral(byte arg0)
           
 BigdataLiteralImpl createLiteral(byte arg0, boolean unsigned)
           
 BigdataLiteralImpl createLiteral(double arg0)
           
 BigdataLiteralImpl createLiteral(float arg0)
           
 BigdataLiteralImpl createLiteral(int arg0)
           
 BigdataLiteralImpl createLiteral(int arg0, boolean unsigned)
           
 BigdataLiteralImpl createLiteral(long arg0)
           
 BigdataLiteralImpl createLiteral(long arg0, boolean unsigned)
           
 BigdataLiteralImpl createLiteral(short arg0)
           
 BigdataLiteralImpl createLiteral(short arg0, boolean unsigned)
           
 BigdataLiteralImpl createLiteral(String label)
           
 BigdataLiteralImpl createLiteral(String label, String language)
           
 BigdataLiteralImpl createLiteral(String label, URI datatype)
           
 BigdataLiteralImpl createLiteral(XMLGregorianCalendar arg0)
           
 BigdataStatementImpl createStatement(Resource s, URI p, Value o)
          Create a statement whose StatementEnum is NOT specified.
 BigdataStatementImpl createStatement(Resource s, URI p, Value o, Resource c)
          Create a statement whose StatementEnum is NOT specified.
 BigdataStatementImpl createStatement(Resource s, URI p, Value o, Resource c, StatementEnum type)
          Create a statement (core impl).
 BigdataStatementImpl createStatement(Resource s, URI p, Value o, Resource c, StatementEnum type, boolean userFlag)
          Create a statement (core impl).
 BigdataURIImpl createURI(String uriString)
           
 BigdataURIImpl createURI(String namespace, String localName)
           
static BigdataValueFactory getInstance(String namespace)
          Return the instance associated with the namespace.
 String getNamespace()
          The namespace of the KB instance associated with the value factory.
 BigdataValueSerializer<BigdataValue> getValueSerializer()
          An object that can efficiently (de-)serialize Values using this ValueFactory.
 BNodeContextFactory newBNodeContext()
          Returns a factory that will assign its blank node IDs within a globally unique namespace.
protected  String nextID()
          Returns a blank node identifier (ID) based on a random UUID.
 void remove()
          Remove a BigdataValueFactoryImpl from the canonicalizing mapping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAMESPACE_XSD

public static final transient String NAMESPACE_XSD
See Also:
Constant Field Values

xsd

public static final transient String xsd
See Also:
Constant Field Values
Method Detail

getNamespace

public String getNamespace()
Description copied from interface: BigdataValueFactory
The namespace of the KB instance associated with the value factory.

Specified by:
getNamespace in interface BigdataValueFactory

getInstance

public static BigdataValueFactory getInstance(String namespace)
Return the instance associated with the namespace.

Note: This canonicalizing mapping for BigdataValueFactoryImpls is based on the namespace of the LexiconRelation. This makes the instances canonical within a JVM instance, which is all that we care about. The actual assignments of term identifiers to BigdataValue s is performed by the LexiconRelation itself and is globally consistent for a given lexicon.

Parameters:
namespace - The namespace of the LexiconRelation. TODO This method introduces the possibility that two journals in the same JVM would share the same BigdataValueFactory for a kb with the same namespace. This is doubtless not desired. A workaround is to use the UUID of the Journal as part of the namespace of the KB, which would serve to make sure that all KB instances have distinct namespaces.

remove

public void remove()
Remove a BigdataValueFactoryImpl from the canonicalizing mapping.

Entries in this canonicalizing mapping for a LexiconRelation MUST be #remove(String)ed if the LexiconRelation is destroyed in case a distinct lexicon is subsequently creating with the same namespace. There is no need to discard an entry during abort processing.

Specified by:
remove in interface BigdataValueFactory

newBNodeContext

public BNodeContextFactory newBNodeContext()
Description copied from interface: BigdataValueFactory
Returns a factory that will assign its blank node IDs within a globally unique namespace. This factory should be used when processing a document as the generated IDs are clustered and make the ordered writes on the lexicon more efficient since all blank nodes for the same document tend to be directed to the same index partition. All BigdataValues are actually created by this factory, it is only the semantics of blank node ID generation that are overridden.

Specified by:
newBNodeContext in interface BigdataValueFactory
See Also:
BNodeContextFactory

createBNode

public BigdataBNodeImpl createBNode()
Returns a new blank node with a globally unique blank node ID based on a UUID.

Note: Since the blank node IDs are random, they tend to be uniformly distributed across the index partition(s). More efficient ordered writes may be realized using newBNodeContext() to obtain a derived BigdataValueFactory instance that is specific to a document that is being loaded into the RDF DB.

Specified by:
createBNode in interface BigdataValueFactory
Specified by:
createBNode in interface ValueFactory
See Also:
newBNodeContext()

nextID

protected String nextID()
Returns a blank node identifier (ID) based on a random UUID.


createBNode

public BigdataBNodeImpl createBNode(String id)
Specified by:
createBNode in interface BigdataValueFactory
Specified by:
createBNode in interface ValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(String label)
Specified by:
createLiteral in interface BigdataValueFactory
Specified by:
createLiteral in interface ValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(boolean arg0)
Specified by:
createLiteral in interface BigdataValueFactory
Specified by:
createLiteral in interface ValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(byte arg0)
Specified by:
createLiteral in interface BigdataValueFactory
Specified by:
createLiteral in interface ValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(byte arg0,
                                        boolean unsigned)
Specified by:
createLiteral in interface BigdataValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(short arg0)
Specified by:
createLiteral in interface BigdataValueFactory
Specified by:
createLiteral in interface ValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(short arg0,
                                        boolean unsigned)
Specified by:
createLiteral in interface BigdataValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(int arg0)
Specified by:
createLiteral in interface BigdataValueFactory
Specified by:
createLiteral in interface ValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(int arg0,
                                        boolean unsigned)
Specified by:
createLiteral in interface BigdataValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(long arg0)
Specified by:
createLiteral in interface BigdataValueFactory
Specified by:
createLiteral in interface ValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(long arg0,
                                        boolean unsigned)
Specified by:
createLiteral in interface BigdataValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(float arg0)
Specified by:
createLiteral in interface BigdataValueFactory
Specified by:
createLiteral in interface ValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(double arg0)
Specified by:
createLiteral in interface BigdataValueFactory
Specified by:
createLiteral in interface ValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(XMLGregorianCalendar arg0)
Specified by:
createLiteral in interface BigdataValueFactory
Specified by:
createLiteral in interface ValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(String label,
                                        String language)
Specified by:
createLiteral in interface BigdataValueFactory
Specified by:
createLiteral in interface ValueFactory

createLiteral

public BigdataLiteralImpl createLiteral(String label,
                                        URI datatype)
Specified by:
createLiteral in interface BigdataValueFactory
Specified by:
createLiteral in interface ValueFactory

createURI

public BigdataURIImpl createURI(String uriString)
Specified by:
createURI in interface BigdataValueFactory
Specified by:
createURI in interface ValueFactory

createURI

public BigdataURIImpl createURI(String namespace,
                                String localName)
Specified by:
createURI in interface BigdataValueFactory
Specified by:
createURI in interface ValueFactory

createStatement

public BigdataStatementImpl createStatement(Resource s,
                                            URI p,
                                            Value o)
Description copied from interface: BigdataValueFactory
Create a statement whose StatementEnum is NOT specified.

Specified by:
createStatement in interface BigdataValueFactory
Specified by:
createStatement in interface ValueFactory

createStatement

public BigdataStatementImpl createStatement(Resource s,
                                            URI p,
                                            Value o,
                                            Resource c)
Description copied from interface: BigdataValueFactory
Create a statement whose StatementEnum is NOT specified.

Specified by:
createStatement in interface BigdataValueFactory
Specified by:
createStatement in interface ValueFactory

createStatement

public BigdataStatementImpl createStatement(Resource s,
                                            URI p,
                                            Value o,
                                            Resource c,
                                            StatementEnum type)
Description copied from interface: BigdataValueFactory
Create a statement (core impl). The s,p,o, and the optional c arguments will be normalized to this BigdataValueFactory using BigdataValueFactory.asValue(Value).

Specified by:
createStatement in interface BigdataValueFactory
Parameters:
s - The subject.
p - The predicate.
o - The object.
c - The context (optional). Note: When non-null and statement identifiers are enabled, then this will be a blank node whose term identifier is the statement identifier.
type - The statement type (optional).

createStatement

public BigdataStatementImpl createStatement(Resource s,
                                            URI p,
                                            Value o,
                                            Resource c,
                                            StatementEnum type,
                                            boolean userFlag)
Description copied from interface: BigdataValueFactory
Create a statement (core impl). The s,p,o, and the optional c arguments will be normalized to this BigdataValueFactory using BigdataValueFactory.asValue(Value).

Specified by:
createStatement in interface BigdataValueFactory
Parameters:
s - The subject.
p - The predicate.
o - The object.
c - The context (optional). Note: When non-null and statement identifiers are enabled, then this will be a blank node whose term identifier is the statement identifier.
type - The statement type (optional).
userFlag - The user flag

asValue

public final BigdataValue asValue(Value v)
Description copied from interface: BigdataValueFactory
Converts a Value into a BigdataValue. If the value is already a BigdataValue and it was allocated by this BigdataValueFactoryImpl then it is returned unchanged. Otherwise a new BigdataValue will be creating using the same data as the given value and the term identifier on the new BigdataValue will be initialized to IRawTripleStore#NULL.

All BigdataValues created by a BigdataValueFactoryImpl internally store a transient reference to the BigdataValueFactoryImpl. This reference is used to decide if a BigdataValue MIGHT have been created by a different lexicon (term identifiers generated by different lexicons CAN NOT be used interchangeably). This has the effect of protecting against incorrect use of the term identifier with a database backed by a different lexicon while allowing reuse of the BigdataValues when possible.

Specified by:
asValue in interface BigdataValueFactory
Parameters:
v - The value.
Returns:
A BigdataValue with the same data. If the value is null then null is returned.

getValueSerializer

public BigdataValueSerializer<BigdataValue> getValueSerializer()
Description copied from interface: BigdataValueFactory
An object that can efficiently (de-)serialize Values using this ValueFactory. When the values are de-serialized they will have a reference to this BigdataValueFactoryImpl. That reference can be used to identify when two BigdataValues MIGHT be from different lexicons.

Specified by:
getValueSerializer in interface BigdataValueFactory
Returns:

asValue

public BigdataResource asValue(Resource v)
Description copied from interface: BigdataValueFactory
Strongly typed for Resources.

Specified by:
asValue in interface BigdataValueFactory

asValue

public BigdataURI asValue(URI v)
Description copied from interface: BigdataValueFactory
Strongly typed for URIs.

Specified by:
asValue in interface BigdataValueFactory

asValue

public BigdataLiteral asValue(Literal v)
Description copied from interface: BigdataValueFactory
Strongly typed for Literals.

Specified by:
asValue in interface BigdataValueFactory

asValue

public BigdataBNode asValue(BNode v)
Description copied from interface: BigdataValueFactory
Strongly typed for BNodes.

Specified by:
asValue in interface BigdataValueFactory


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