de.fuberlin.wiwiss.d2rq.rdql
Class TablePrefixer

java.lang.Object
  extended byde.fuberlin.wiwiss.d2rq.rdql.TablePrefixer

public class TablePrefixer
extends java.lang.Object

A class for collecting database table information and for creating table aliases.

Author:
jgarbers

Field Summary
protected  java.util.Map aliasMap
          given alias map from String (aliased Table) to Alias
protected static java.util.regex.Pattern allowedTablePattern
           
private static java.lang.Class[] intParameterTypes
           
static boolean mayPrefixPrefixedString
           
private static java.lang.Class[] noneParameterTypes
           
protected  java.util.Map prefixedAliasMap
          new aliases.
protected static java.lang.String prefixSeparator
           
static int prefixStringContinuation
           
protected  java.util.Set referedTables
          Database table names (Strings) in their alias form.
protected  java.lang.String tablePrefix
          The common prefix to use in aliasing.
protected  int tablePrefixLength
           
protected static java.lang.String triplePrefix
           
 
Constructor Summary
TablePrefixer()
          use without tablePrefixing
TablePrefixer(int tripleNumber)
          produce a uniform tablePrefix based on a number.
TablePrefixer(java.lang.String prefix)
          set a arbitrary tablePrefix
 
Method Summary
static java.util.Collection createCollectionFromCollectionWithMap(java.util.Collection collection, java.util.Map map)
          Creates a filtered collection that contains the mapped values of collection.
 java.util.Map getAliasMap()
           
 java.util.Map getPrefixedAliasMap()
           
 java.util.Set getReferedTables()
           
 boolean mayChangeID()
          optimization information for Prefixable objects.
static java.util.Collection newEmptyCollection(java.util.Collection oldType)
          Creates a collection of same type as oldType
 java.lang.Object prefix(java.util.Collection obj)
           
 java.lang.Object prefix(Column obj)
           
 java.lang.Object prefix(Join obj)
           
 java.lang.Object prefix(java.lang.Object obj)
          Prefixes an object based on its interface declarations.
 java.lang.Object prefix(PropertyBridge obj)
           
 java.lang.Object prefix(java.lang.String obj)
          Strings are assumed to be tables.
protected  java.lang.String prefixAndReferTable(java.lang.String tableName)
          Prefixes a table name and makes sure a FROM-Term exists.
 java.util.Collection prefixCollection(java.util.Collection collection)
           
 java.util.Collection prefixCollectionAndMap(java.util.Collection collection, java.util.Map map)
          puts previous and result into map while prefixing a collection.
 java.util.Collection prefixCollectionIntoCollectionAndMap(java.util.Collection collection, java.util.Collection results, java.util.Map map)
          Iterates over a collection and stores the results into both a collection and a map (unprefixed -> prefixed).
 Column prefixColumn(Column column)
           
 java.util.Map prefixColumnColumnMap(java.util.Map map)
           
 java.util.Set prefixConditions(java.util.Set conditions)
           
 java.lang.Object prefixIfPrefixable(java.lang.Object obj)
          this is used in handling NodeMaker and ValueSource classes some of which do not implement Prefixable
 Join prefixJoin(Join join)
           
 NodeMaker prefixNodeMaker(NodeMaker obj)
           
 Prefixable prefixPrefixable(Prefixable obj)
          Prefixes an object that adheres to Prefixable interface.
 PropertyBridge prefixPropertyBridge(PropertyBridge propertyBridge)
           
 java.util.Set prefixSet(java.util.Set collection)
          Creates a new HashSet of prefixed values.
 java.lang.String prefixString(java.lang.String table)
          Actual prefixing method with some plausibility checks.
 java.lang.String prefixTable(java.lang.String table)
          Tables are refered to and prefixed
 ValueSource prefixValueSource(ValueSource obj)
           
protected  java.lang.String replaceTablesInExpression(java.lang.String expression)
          Tries to prefix table names in expression.
 void setAliasMap(java.util.Map aliasMap)
           
 void setReferedTables(java.util.Set referedTables)
           
 void setTablePrefix(java.lang.String newPrefix)
          sets up tablePrefix including prefixSeparator and initializes prefixedAliasMap.
 void setTablePrefixToTripleNumber(int n)
           
protected  java.lang.String substituteIfTable(java.lang.String identifier)
          Just substitutes argument if it is known to be a table name (seen before).
 java.util.Map unprefixedColumnNameNumberMap(java.util.Map columnNameNumber)
          Extracts keys matching this tablePrefix and renames them.
 java.lang.String unprefixString(java.lang.String table)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tablePrefix

protected java.lang.String tablePrefix
The common prefix to use in aliasing. If null, collects info only but leave everything identical.


tablePrefixLength

protected int tablePrefixLength

prefixSeparator

protected static final java.lang.String prefixSeparator
See Also:
Constant Field Values

triplePrefix

protected static final java.lang.String triplePrefix
See Also:
Constant Field Values

aliasMap

protected java.util.Map aliasMap
given alias map from String (aliased Table) to Alias


referedTables

protected java.util.Set referedTables
Database table names (Strings) in their alias form.


prefixedAliasMap

protected java.util.Map prefixedAliasMap
new aliases. created during prefixing


mayPrefixPrefixedString

public static boolean mayPrefixPrefixedString

prefixStringContinuation

public static int prefixStringContinuation

allowedTablePattern

protected static java.util.regex.Pattern allowedTablePattern

intParameterTypes

private static java.lang.Class[] intParameterTypes

noneParameterTypes

private static java.lang.Class[] noneParameterTypes
Constructor Detail

TablePrefixer

public TablePrefixer()
use without tablePrefixing


TablePrefixer

public TablePrefixer(java.lang.String prefix)
set a arbitrary tablePrefix


TablePrefixer

public TablePrefixer(int tripleNumber)
produce a uniform tablePrefix based on a number. the number probably corresponds to the index of a triple in a RDQL query.

Method Detail

mayChangeID

public boolean mayChangeID()
optimization information for Prefixable objects.


setTablePrefix

public void setTablePrefix(java.lang.String newPrefix)
sets up tablePrefix including prefixSeparator and initializes prefixedAliasMap.


setTablePrefixToTripleNumber

public void setTablePrefixToTripleNumber(int n)

getAliasMap

public java.util.Map getAliasMap()

setAliasMap

public void setAliasMap(java.util.Map aliasMap)

getReferedTables

public java.util.Set getReferedTables()

setReferedTables

public void setReferedTables(java.util.Set referedTables)

getPrefixedAliasMap

public java.util.Map getPrefixedAliasMap()

prefixString

public java.lang.String prefixString(java.lang.String table)
Actual prefixing method with some plausibility checks.

Parameters:
table -
Returns:
prefixed string

unprefixString

public java.lang.String unprefixString(java.lang.String table)

unprefixedColumnNameNumberMap

public java.util.Map unprefixedColumnNameNumberMap(java.util.Map columnNameNumber)
Extracts keys matching this tablePrefix and renames them.

Parameters:
columnNameNumber - keys are prefixed.
Returns:
a new map

replaceTablesInExpression

protected java.lang.String replaceTablesInExpression(java.lang.String expression)
Tries to prefix table names in expression. Issues: The code may fail, if there are strings in the expressions that match with table names. Generally we would be better off, to have not unparsed expressions floating around.

Parameters:
expression - an SQL expression like "Tab.Col = 2"
Returns:
a renamed expression

substituteIfTable

protected java.lang.String substituteIfTable(java.lang.String identifier)
Just substitutes argument if it is known to be a table name (seen before).


prefixAndReferTable

protected java.lang.String prefixAndReferTable(java.lang.String tableName)
Prefixes a table name and makes sure a FROM-Term exists.

Returns:
tableName resp. its substitution

prefixIfPrefixable

public java.lang.Object prefixIfPrefixable(java.lang.Object obj)
this is used in handling NodeMaker and ValueSource classes some of which do not implement Prefixable


prefix

public java.lang.Object prefix(java.lang.Object obj)
Prefixes an object based on its interface declarations.


prefixPrefixable

public Prefixable prefixPrefixable(Prefixable obj)
Prefixes an object that adheres to Prefixable interface.


prefixNodeMaker

public NodeMaker prefixNodeMaker(NodeMaker obj)

prefixValueSource

public ValueSource prefixValueSource(ValueSource obj)

prefixCollectionIntoCollectionAndMap

public java.util.Collection prefixCollectionIntoCollectionAndMap(java.util.Collection collection,
                                                                 java.util.Collection results,
                                                                 java.util.Map map)
Iterates over a collection and stores the results into both a collection and a map (unprefixed -> prefixed). Helper method. Both results and map may be null

Parameters:
collection - input collection
results - store collection
map - store map
Returns:
results

prefix

public java.lang.Object prefix(java.util.Collection obj)

prefixCollection

public java.util.Collection prefixCollection(java.util.Collection collection)

newEmptyCollection

public static java.util.Collection newEmptyCollection(java.util.Collection oldType)
Creates a collection of same type as oldType

Parameters:
oldType - a collection exemplar
Returns:
the newly created collection

prefixCollectionAndMap

public java.util.Collection prefixCollectionAndMap(java.util.Collection collection,
                                                   java.util.Map map)
puts previous and result into map while prefixing a collection.


createCollectionFromCollectionWithMap

public static java.util.Collection createCollectionFromCollectionWithMap(java.util.Collection collection,
                                                                         java.util.Map map)
Creates a filtered collection that contains the mapped values of collection.

Parameters:
collection - provides the keys
map - provides the values
Returns:
a new collection of same type as collection

prefixSet

public java.util.Set prefixSet(java.util.Set collection)
Creates a new HashSet of prefixed values.


prefix

public java.lang.Object prefix(java.lang.String obj)
Strings are assumed to be tables.


prefixTable

public java.lang.String prefixTable(java.lang.String table)
Tables are refered to and prefixed


prefix

public java.lang.Object prefix(Column obj)

prefixColumn

public Column prefixColumn(Column column)

prefix

public java.lang.Object prefix(Join obj)

prefixJoin

public Join prefixJoin(Join join)

prefix

public java.lang.Object prefix(PropertyBridge obj)

prefixPropertyBridge

public PropertyBridge prefixPropertyBridge(PropertyBridge propertyBridge)

prefixConditions

public java.util.Set prefixConditions(java.util.Set conditions)

prefixColumnColumnMap

public java.util.Map prefixColumnColumnMap(java.util.Map map)