org.d2rq.values
Class TemplateValueMaker
java.lang.Object
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)
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
TemplateValueMaker
public TemplateValueMaker(String[] literalParts,
ColumnName[] columns,
TemplateValueMaker.ColumnFunction[] functions)
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 valuetable
- The table to which the expression will be applicablevendor
- 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
ProjectionSpec
s containing data necessary
for this ValueSource.
- Specified by:
projectionSpecs
in interface ValueMaker
- Returns:
- a set of
ProjectionSpec
s
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.)