org.d2rq.values
Class TemplateValueMaker

java.lang.Object
  extended by org.d2rq.values.TemplateValueMaker
All Implemented Interfaces:
ValueMaker

public class TemplateValueMaker
extends Object
implements ValueMaker

A template that combines one or more database columns into a String. Often used as an IRI pattern for generating URIs from a column's primary key. Templates consist of alternating literal parts and column references. R2RML and the D2RQ mapping language use different syntaxes for writing patterns down as strings: D2RQ: http://example.com/person/@@ppl.first|urlify@@_@@ppl.last|urlify@@ R2RML: http://example.com/person/{first}_{last} Each column reference can also include an encoding function, an instance of TemplateValueMaker.ColumnFunction, like URLIFY. In R2RML it is always ENCODE for IRI templates and IDENTITY otherwise. In D2RQ, the default encoding function is IDENTITY.

Author:
Richard Cyganiak (richard@cyganiak.de)

Nested Class Summary
static class TemplateValueMaker.Builder
           
static interface TemplateValueMaker.ColumnFunction
           
static class TemplateValueMaker.EncodeFunction
           
 
Field Summary
static TemplateValueMaker.ColumnFunction ENCODE
           
static TemplateValueMaker.ColumnFunction IDENTITY
           
static TemplateValueMaker.ColumnFunction URLENCODE
           
static TemplateValueMaker.ColumnFunction URLIFY
           
 
Fields inherited from interface org.d2rq.values.ValueMaker
NULL
 
Constructor Summary
TemplateValueMaker(String[] literalParts, ColumnName[] columns, TemplateValueMaker.ColumnFunction[] functions)
           
 
Method Summary
static TemplateValueMaker.Builder builder()
           
 ColumnName[] columns()
           
 void describeSelf(NodeSetFilter c)
           
 boolean equals(Object otherObject)
           
 String firstLiteralPart()
           
 TemplateValueMaker.ColumnFunction[] functions()
           
 int hashCode()
           
 boolean isEquivalentTo(TemplateValueMaker p)
           
 String lastLiteralPart()
           
 String[] literalParts()
           
 String makeValue(ResultRow row)
          Constructs a String from the pattern using the given database row.
 boolean matches(String value)
          Indicates whether the node maker is capable of producing a given value, as far as can be told without having access to the actual database.
 List<OrderOp.OrderSpec> orderSpecs(boolean ascending)
           
 Set<ProjectionSpec> projectionSpecs()
          Returns a set of all ProjectionSpecs containing data necessary for this ValueSource.
 ValueMaker rename(Renamer renames)
           
 Expression toExpression()
           
 String toString()
           
 boolean usesColumnFunctions()
           
 Expression valueExpression(String value, DatabaseOp table, Vendor vendor)
          A SQL expression that selects only rows where this value maker produces the specified value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

IDENTITY

public static final TemplateValueMaker.ColumnFunction IDENTITY

URLENCODE

public static final TemplateValueMaker.ColumnFunction URLENCODE

URLIFY

public static final TemplateValueMaker.ColumnFunction URLIFY

ENCODE

public static final TemplateValueMaker.ColumnFunction ENCODE
Constructor Detail

TemplateValueMaker

public TemplateValueMaker(String[] literalParts,
                          ColumnName[] columns,
                          TemplateValueMaker.ColumnFunction[] functions)
Method Detail

builder

public static TemplateValueMaker.Builder builder()

literalParts

public String[] literalParts()

columns

public ColumnName[] columns()

functions

public TemplateValueMaker.ColumnFunction[] functions()

firstLiteralPart

public String firstLiteralPart()

lastLiteralPart

public String lastLiteralPart()

describeSelf

public void describeSelf(NodeSetFilter c)
Specified by:
describeSelf in interface ValueMaker

matches

public boolean matches(String value)
Description copied from interface: ValueMaker
Indicates whether the node maker is capable of producing a given value, as far as can be told without having access to the actual database.

Specified by:
matches in interface ValueMaker
Returns:
true iff this node maker is capable of producing the value

valueExpression

public Expression valueExpression(String value,
                                  DatabaseOp table,
                                  Vendor vendor)
Description copied from interface: ValueMaker
A SQL expression that selects only rows where this value maker produces the specified value. Expression.FALSE if this value maker is incapable of producing the value.

Specified by:
valueExpression in interface ValueMaker
Parameters:
value - A value
table - The table to which the expression will be applicable
vendor - A vendor instance for datatyping etc.
Returns:
An expression that selects rows that produce this value

projectionSpecs

public Set<ProjectionSpec> projectionSpecs()
Description copied from interface: ValueMaker
Returns a set of all ProjectionSpecs containing data necessary for this ValueSource.

Specified by:
projectionSpecs in interface ValueMaker
Returns:
a set of ProjectionSpecs

makeValue

public String makeValue(ResultRow row)
Constructs a String from the pattern using the given database row.

Specified by:
makeValue in interface ValueMaker
Parameters:
row - a database row
Returns:
the pattern's value for the given row

orderSpecs

public List<OrderOp.OrderSpec> orderSpecs(boolean ascending)
Specified by:
orderSpecs in interface ValueMaker

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object otherObject)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

isEquivalentTo

public boolean isEquivalentTo(TemplateValueMaker p)
Returns:
true if the pattern is identical or differs only in the column names

rename

public ValueMaker rename(Renamer renames)
Specified by:
rename in interface ValueMaker

toExpression

public Expression toExpression()

usesColumnFunctions

public boolean usesColumnFunctions()
Returns:
TRUE if this pattern uses any column function (encode, urlify, etc.)