uk.ac.ic.doc.automed.p2p.qproc.planner
Class QueryPlannerResult

java.lang.Object
  extended by uk.ac.ic.doc.automed.p2p.qproc.planner.QueryPlannerResult
All Implemented Interfaces:
java.io.Serializable

public class QueryPlannerResult
extends java.lang.Object
implements java.io.Serializable

See Also:
Serialized Form

Nested Class Summary
 class QueryPlannerResult.Accounting
          Represents a class to keep records of different time parameters
e.g.
static class QueryPlannerResult.CoverageSet
          A class to encapsulate a set of statistics about a coverage set
static class QueryPlannerResult.EdgeMap
           
 class QueryPlannerResult.MappingStorageHandler
          An implementation of the SQLMapEntry interface for materialising mappings to the database
 
Field Summary
private  QueryPlannerResult.Accounting account
           
private  java.util.List coverageSets
           
private  QueryMapping currMapping
           
private  ArrayKeyMap e2P
           
private  java.util.Map edgeMaps
           
(package private)  java.lang.String ESCAPE_DOLLAR
          Return a Postgres-friendly stringn for an IQL expression
private static java.lang.String HDM_PREFIX
           
private static int IDCOUNTER
           
private  SQLableMap jMap
           
private  java.lang.String name
           
private  java.util.Map nodeEdgeIDMap
           
private  RuntimeParameters params
           
private static java.util.Map peerCache
          remember the descriptions of the peer locations that have been wrapped
private  boolean processed
           
private  Graph qGraph
           
private  java.lang.String qpeer
           
private  java.util.List queryMappings
           
private  Schema schema
           
private  java.util.Map schemaEdgeMap
           
private  java.util.Map schemaMap
           
private  java.lang.String schemaName
           
private static int section
           
private  java.util.Map seenIDs
          mapping coverage-set -> List of all the unseen mapping IDs of a coverage-set
private static long serialVersionUID
           
private static StringMatcher smatcher
           
 
Constructor Summary
QueryPlannerResult()
           
 
Method Summary
 void addCoveredEdge(Edge e)
          Insert an edge into the map to indicate that it is covered by some procesing node (i.e.
 void addEdges2Peer(java.util.Map e2P)
           
 void addMapping(Edge e, HDMGraph g)
           
 void addMappings(java.lang.Object key, java.util.Collection omappings)
           
 void addMappings(java.lang.Object key, java.util.Collection omappings, boolean memOnly)
           
 void addMappings(QueryPlannerResult qpresult, int topK, boolean memOnly)
          Copy mappings from one result object to another.
 void addPeerLocations(HDMObject eo, boolean source, int mid, java.util.Map lm)
          Save peer locations to the database.
 void addQueryMapping(QueryMapping qmapping)
          Add one query mapping to the result.
 void addQueryMappings(java.util.Collection qmappings)
          Add a collection of query mappings to the result.
 void cacheMappings(Edge e, java.util.Collection mappings)
          A memory-cache of the mappings of a given k-edge.
 void clear()
           
 void clear(boolean alsoMappingsInRep)
           
 void clearAll()
          Clear all SMR tables
private  void clearCommon()
           
 void clearQuery()
          Remove everything in the storage that are associated to a given k-query
 void clearTopK()
           
 void copyAccounting(QueryPlannerResult qpresult)
          Transfer accountingn from the input object to this object
private  java.lang.String escapeIQL(java.lang.String iqlStr)
           
 QueryPlannerResult.Accounting getAccounting()
          Return an accounting object used for recording the time statistics of different methods.
 java.util.Collection getCachedMappings(Edge e)
          Look up mappings of an edge in the edge map (see method getEdgeMetadata())
private  java.lang.String getCoverageSetID(java.lang.String schema, java.lang.String peer)
           
 java.util.Collection getCoverageSets()
          Return the coverage sets
 java.util.Collection getCoverageSets(Edge kedge)
          Obtain statistics about all s-coverage sets of a given k-edge in the AutoMed repository of the peer that owns this result object.
A s-coverage set is represented by QueryPlannerResult.CoverageSet class, which has the following fields: k-edge(Edge) of the k-query to which the set belongs coverageSetName which is a string delimited by '|' each element of which is a string of the form schema:peer.
In essence, this is a set of schema-peer pairs, which cover the source and target objects of at least one mapping of the k-edge.
 QueryMapping getCurrentQueryMapping()
           
 java.util.Map getEdges2Peer()
           
 java.util.Map getEdgesByPeer()
          Return a list of edge entries that are supported by each peer
Returns a Map object: peer -> List, where Object[] is an array of elements: 1st element is the Edge object and second and third elements are possibly null ids of the cached edge and cached query that is mapped to this edge
private  java.util.Collection getGraphObjects(java.lang.String sql)
          A method to retrieve HDMGraph objects from the database.
 java.util.Map getJoinMap()
           
private  java.lang.Integer getK2OMappingID(HDMObject o, int mid, boolean source)
          Returns the knmapid of the k-node-to-object mapping between a k-node and an HDM object.
private  int getLastSeqID(java.lang.String sequence)
          Get the last value of a number sequence
 java.util.Map getMappingContainer()
           
 java.util.Map getMappings()
          Return a map containing all mappings: edge->TreeSet<ObjectMapping>
 java.util.Collection getMappings(Edge kedge)
          Get all mappings of a given k-edge of the query that is represented by this result object.
 java.util.Collection getMappings(Edge kedge, java.lang.String mid)
          Get a mapping object from the database given its id
private  java.util.Collection getMappings(java.lang.Object[] key, int startRID, int topK)
          Get top-m mappings of a given edge
 java.util.Collection getMappings(java.lang.Object kedge, java.lang.Object qid, java.lang.String peerName, int startRID, int topK)
          Get all mappings of a given edge of a given query.
 java.util.Collection getMappings(java.lang.String sourceObj, java.lang.String sourceSchema, java.lang.String sourcePeer, java.lang.String targetObj, java.lang.String targetSchema, java.lang.String targetPeer)
          Query the object mappings
 java.util.Collection getMappingsTopK(Edge e, long eid, java.lang.String kqid, java.lang.String qpeer, java.lang.String csetid, int fetchSize)
          Obtain a top-m mapping set of a coverage set (identified by key) of a given k-edge (identified by eid).
 java.lang.Object getParameter(java.lang.String paramName)
           
 RuntimeParameters getParams()
           
 java.util.Map getPeerCache()
           
 java.util.Map getPeerLocations(HDMObject o, java.lang.String schema)
          Get a hash map[peer:schema->val-summary] of a given HDM object in the AutoMed repository.
private  java.lang.Integer getPSchemaID(java.lang.String sname, java.lang.String pname)
          Get the id of the peer-schema pair given the peer and schema names.
 Graph getQueryGraph()
           
 int getQueryID()
           
 QueryMapping getQueryMapping(java.lang.String qid)
          Retrieve a query mapping given its id
 java.util.List getQueryMappings()
          Return the collection of query mappings
 java.lang.String getQueryPeer()
           
 java.util.Map getSchemaImplementation()
          Return a hash map of schema and the nodes
 Schema getSelectedSchema()
           
private static java.lang.Object getSQL(java.lang.String sql)
          Get objects by executing a custom SQL command.
 boolean hasMapping()
           
 boolean isCoveringEdge(Edge e)
          Check whether or not an edge is covered by this result set.
A result set covers an edge if either it has mappings for that edge or that there is some peer claimed to have mappings for it.
 boolean isCoveringQuery()
          Check coverage mapping depending whether or not there were peers recorded to have processed every edge of this query
 boolean isDiskOnly()
           
 boolean isEmpty()
           
 boolean isMemory()
          Returns true if this objects store the result mappings in memory
 boolean isMemoryOnly()
           
 boolean isProcessed()
           
 boolean isQueryComplete(QueryMapping qmap)
           
 boolean isQuerySaved()
          Returns true if the query has been saved into the database
 java.util.Set keySet()
          Return the key set of the k-edge map
private static java.lang.Object putSQL(java.lang.String sql, boolean ignoreError)
          Put objects by executing an SQL statement
private static java.lang.Object putSQL(java.lang.String sql, boolean ignoreError, java.lang.Object obj)
          This is used to execute an SQL statement, in which one element is an object
private  void readObject(java.io.ObjectInputStream in)
           
 void removeAllMappings(java.lang.Object key)
          Remove mappings that by source and target k-nodes of given k-edge
 void removeMappings()
          Remove the existing mappings of the current query from the local repository.
This is invoked by the top-k component before it is re-run in order to obtain
fresh copies of the mappings from the remote peers.
 void removeMappings(java.lang.Object key)
          Remove mappings by k-edge id
private  boolean removeSQL(java.lang.String sql, boolean ignoreError)
          Remove entries from storage using an SQL query
private  void resetCoverageSets()
          Reset the coverage set objects to their original values
 void resetTopK()
          Reset top-k status to the point before the mappings were fetched to the local peer.
private  void saveQueryGraph()
          Store the k-query into the database
 void setCoverageSets(java.util.Collection csets)
           
 void setCurrentQueryMapping(QueryMapping qmap)
           
 void setEdge2Peer(java.lang.Object key, java.lang.Object value)
          Add a mapping between a k-edge and the peer that processes it
 void setIsProcessed(boolean processed)
           
 void setParameters(RuntimeParameters params)
           
 void setQueryGraph(Graph qGraph, java.lang.String qpeer, boolean store)
           
 void setSelectedSchema(Schema s)
           
 java.lang.String toString()
           
private  void writeObject(java.io.ObjectOutputStream out)
          customise serialisable so that we can also serialise the static id counter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

name

private java.lang.String name

section

private static final int section
See Also:
Constant Field Values

qGraph

private Graph qGraph

jMap

private SQLableMap jMap

seenIDs

private transient java.util.Map seenIDs
mapping coverage-set -> List of all the unseen mapping IDs of a coverage-set


coverageSets

private transient java.util.List coverageSets

schema

private transient Schema schema

schemaEdgeMap

private transient java.util.Map schemaEdgeMap

schemaMap

private transient java.util.Map schemaMap

edgeMaps

private transient java.util.Map edgeMaps

nodeEdgeIDMap

private transient java.util.Map nodeEdgeIDMap

smatcher

private static final transient StringMatcher smatcher

peerCache

private static java.util.Map peerCache
remember the descriptions of the peer locations that have been wrapped


e2P

private ArrayKeyMap e2P

params

private RuntimeParameters params

schemaName

private java.lang.String schemaName

processed

private boolean processed

queryMappings

private java.util.List queryMappings

currMapping

private QueryMapping currMapping

IDCOUNTER

private static transient int IDCOUNTER

qpeer

private java.lang.String qpeer

HDM_PREFIX

private static final java.lang.String HDM_PREFIX
See Also:
Constant Field Values

ESCAPE_DOLLAR

final java.lang.String ESCAPE_DOLLAR
Return a Postgres-friendly stringn for an IQL expression

See Also:
Constant Field Values

account

private QueryPlannerResult.Accounting account
Constructor Detail

QueryPlannerResult

public QueryPlannerResult()
Method Detail

setParameters

public void setParameters(RuntimeParameters params)

setQueryGraph

public void setQueryGraph(Graph qGraph,
                          java.lang.String qpeer,
                          boolean store)

isQuerySaved

public boolean isQuerySaved()
Returns true if the query has been saved into the database

Returns:

saveQueryGraph

private void saveQueryGraph()
Store the k-query into the database


isQueryComplete

public boolean isQueryComplete(QueryMapping qmap)

setEdge2Peer

public void setEdge2Peer(java.lang.Object key,
                         java.lang.Object value)
Add a mapping between a k-edge and the peer that processes it

Parameters:
key - is the edge
value - is the peer

getEdgesByPeer

public java.util.Map getEdgesByPeer()
Return a list of edge entries that are supported by each peer
Returns a Map object: peer -> List, where Object[] is an array of elements: 1st element is the Edge object and second and third elements are possibly null ids of the cached edge and cached query that is mapped to this edge

Parameters:
e -
Returns:

getEdges2Peer

public java.util.Map getEdges2Peer()

addEdges2Peer

public void addEdges2Peer(java.util.Map e2P)

addQueryMapping

public void addQueryMapping(QueryMapping qmapping)
Add one query mapping to the result.

Parameters:
qmapping -

addQueryMappings

public void addQueryMappings(java.util.Collection qmappings)
Add a collection of query mappings to the result.

Parameters:
qmappings -

getCurrentQueryMapping

public QueryMapping getCurrentQueryMapping()

setCurrentQueryMapping

public void setCurrentQueryMapping(QueryMapping qmap)

getQueryMappings

public java.util.List getQueryMappings()
Return the collection of query mappings

Returns:

getQueryMapping

public QueryMapping getQueryMapping(java.lang.String qid)
Retrieve a query mapping given its id

Parameters:
qid -
Returns:

isProcessed

public boolean isProcessed()

setIsProcessed

public void setIsProcessed(boolean processed)

getQueryGraph

public Graph getQueryGraph()

getQueryID

public int getQueryID()

getQueryPeer

public java.lang.String getQueryPeer()

getJoinMap

public java.util.Map getJoinMap()

isEmpty

public boolean isEmpty()

getMappings

public java.util.Map getMappings()
Return a map containing all mappings: edge->TreeSet<ObjectMapping>

Returns:

isMemory

public boolean isMemory()
Returns true if this objects store the result mappings in memory

Returns:

isDiskOnly

public boolean isDiskOnly()

isMemoryOnly

public boolean isMemoryOnly()

setSelectedSchema

public void setSelectedSchema(Schema s)

getSelectedSchema

public Schema getSelectedSchema()

addCoveredEdge

public void addCoveredEdge(Edge e)
Insert an edge into the map to indicate that it is covered by some procesing node (i.e. there are mappings found for this edge).
It is used by the intermediate peers in the case when this object is configured to work in a disk-only mode where and there is a need to return result quickly to the query peer.

Parameters:
e -

addMapping

public void addMapping(Edge e,
                       HDMGraph g)

addMappings

public void addMappings(java.lang.Object key,
                        java.util.Collection omappings)

addMappings

public void addMappings(java.lang.Object key,
                        java.util.Collection omappings,
                        boolean memOnly)

addMappings

public void addMappings(QueryPlannerResult qpresult,
                        int topK,
                        boolean memOnly)
Copy mappings from one result object to another. Note that if top-k option is set then only copy top-k result

Parameters:
qpresult -

addPeerLocations

public void addPeerLocations(HDMObject eo,
                             boolean source,
                             int mid,
                             java.util.Map lm)
Save peer locations to the database.

Parameters:
locMap - A HashMap of object->Map[peer->val-summary]

getPSchemaID

private java.lang.Integer getPSchemaID(java.lang.String sname,
                                       java.lang.String pname)
Get the id of the peer-schema pair given the peer and schema names.

Parameters:
sname -
pname -
Returns:

getK2OMappingID

private java.lang.Integer getK2OMappingID(HDMObject o,
                                          int mid,
                                          boolean source)
Returns the knmapid of the k-node-to-object mapping between a k-node and an HDM object.

Parameters:
schemeDef -
Returns:

getLastSeqID

private int getLastSeqID(java.lang.String sequence)
Get the last value of a number sequence

Parameters:
sequence -
Returns:

getPeerLocations

public java.util.Map getPeerLocations(HDMObject o,
                                      java.lang.String schema)
Get a hash map[peer:schema->val-summary] of a given HDM object in the AutoMed repository.

Parameters:
o - and edge-type HDM object
Returns:

keySet

public java.util.Set keySet()
Return the key set of the k-edge map

Returns:

getMappings

public java.util.Collection getMappings(java.lang.Object kedge,
                                        java.lang.Object qid,
                                        java.lang.String peerName,
                                        int startRID,
                                        int topK)
Get all mappings of a given edge of a given query.

Parameters:
key -
Returns:

getMappings

public java.util.Collection getMappings(Edge kedge)
Get all mappings of a given k-edge of the query that is represented by this result object.

Parameters:
kedge -
Returns:

getMappings

private java.util.Collection getMappings(java.lang.Object[] key,
                                         int startRID,
                                         int topK)
Get top-m mappings of a given edge

Parameters:
key -
Returns:

removeMappings

public void removeMappings(java.lang.Object key)
Remove mappings by k-edge id

Parameters:
key -

removeMappings

public void removeMappings()
Remove the existing mappings of the current query from the local repository.
This is invoked by the top-k component before it is re-run in order to obtain
fresh copies of the mappings from the remote peers.


removeAllMappings

public void removeAllMappings(java.lang.Object key)
Remove mappings that by source and target k-nodes of given k-edge

Parameters:
key -

getMappingsTopK

public java.util.Collection getMappingsTopK(Edge e,
                                            long eid,
                                            java.lang.String kqid,
                                            java.lang.String qpeer,
                                            java.lang.String csetid,
                                            int fetchSize)
Obtain a top-m mapping set of a coverage set (identified by key) of a given k-edge (identified by eid).

Parameters:
eid -
key -
fetchSize -
Returns:

getMappings

public java.util.Collection getMappings(Edge kedge,
                                        java.lang.String mid)
Get a mapping object from the database given its id

Parameters:
mid -
Returns:

getMappings

public java.util.Collection getMappings(java.lang.String sourceObj,
                                        java.lang.String sourceSchema,
                                        java.lang.String sourcePeer,
                                        java.lang.String targetObj,
                                        java.lang.String targetSchema,
                                        java.lang.String targetPeer)
Query the object mappings

Parameters:
sourceObj -
sourceSchema -
sourcePeer -
targetObj -
targetSchema -
targetPeer -
Returns:

getCachedMappings

public java.util.Collection getCachedMappings(Edge e)
Look up mappings of an edge in the edge map (see method getEdgeMetadata())

Parameters:
e -
Returns:

cacheMappings

public void cacheMappings(Edge e,
                          java.util.Collection mappings)
A memory-cache of the mappings of a given k-edge.
It is used for the purpose of quick look-up of mappings to be displayed on the query GUI.

Parameters:
e -
mappings -

getSchemaImplementation

public java.util.Map getSchemaImplementation()
Return a hash map of schema and the nodes

Parameters:
deep - if true then return a deep hash map (i.e. including mapping objects)
Returns:

isCoveringQuery

public boolean isCoveringQuery()
Check coverage mapping depending whether or not there were peers recorded to have processed every edge of this query

Returns:

isCoveringEdge

public boolean isCoveringEdge(Edge e)
Check whether or not an edge is covered by this result set.
A result set covers an edge if either it has mappings for that edge or that there is some peer claimed to have mappings for it.

Parameters:
e -
Returns:

hasMapping

public boolean hasMapping()

getParameter

public java.lang.Object getParameter(java.lang.String paramName)

getParams

public RuntimeParameters getParams()

getPeerCache

public java.util.Map getPeerCache()

putSQL

private static java.lang.Object putSQL(java.lang.String sql,
                                       boolean ignoreError)
Put objects by executing an SQL statement

Parameters:
sql -
ignoreError -
Returns:

putSQL

private static java.lang.Object putSQL(java.lang.String sql,
                                       boolean ignoreError,
                                       java.lang.Object obj)
This is used to execute an SQL statement, in which one element is an object

Parameters:
sql -
ignoreError -
Returns:

getSQL

private static java.lang.Object getSQL(java.lang.String sql)
Get objects by executing a custom SQL command.

Parameters:
sql -
Returns:

removeSQL

private boolean removeSQL(java.lang.String sql,
                          boolean ignoreError)
Remove entries from storage using an SQL query

Parameters:
sql -
ignoreError -
Returns:

clearCommon

private void clearCommon()

clearTopK

public void clearTopK()

resetTopK

public void resetTopK()
Reset top-k status to the point before the mappings were fetched to the local peer.


resetCoverageSets

private void resetCoverageSets()
Reset the coverage set objects to their original values


clear

public void clear(boolean alsoMappingsInRep)
Parameters:
alsoMappingsInRep - whether or not to also clear mappings that are stored iin the repository.

clear

public void clear()

clearQuery

public void clearQuery()
Remove everything in the storage that are associated to a given k-query


clearAll

public void clearAll()
Clear all SMR tables


getMappingContainer

public java.util.Map getMappingContainer()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setCoverageSets

public void setCoverageSets(java.util.Collection csets)

getCoverageSets

public java.util.Collection getCoverageSets()
Return the coverage sets

Returns:

getCoverageSets

public java.util.Collection getCoverageSets(Edge kedge)
Obtain statistics about all s-coverage sets of a given k-edge in the AutoMed repository of the peer that owns this result object.
A s-coverage set is represented by QueryPlannerResult.CoverageSet class, which has the following fields:

Parameters:
key -
eid -
qid -
Returns:

getCoverageSetID

private java.lang.String getCoverageSetID(java.lang.String schema,
                                          java.lang.String peer)

writeObject

private void writeObject(java.io.ObjectOutputStream out)
                  throws java.io.IOException
customise serialisable so that we can also serialise the static id counter

Parameters:
out -
Throws:
java.io.IOException

readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

getGraphObjects

private java.util.Collection getGraphObjects(java.lang.String sql)
A method to retrieve HDMGraph objects from the database.

Parameters:
sql -
Returns:

escapeIQL

private java.lang.String escapeIQL(java.lang.String iqlStr)

getAccounting

public QueryPlannerResult.Accounting getAccounting()
Return an accounting object used for recording the time statistics of different methods.

Returns:

copyAccounting

public void copyAccounting(QueryPlannerResult qpresult)
Transfer accountingn from the input object to this object

Parameters:
qpresult -