org.gcube.common.searchservice.searchlibrary.resultset
Class ResultSet

java.lang.Object
  extended by org.gcube.common.searchservice.searchlibrary.resultset.ResultSet

public class ResultSet
extends java.lang.Object

The ResultSet element provides a container for placing produced records and for consuming them. It organizes them in a chain of parts explicitly created by the producer. It provides incremental population of the results through the chain of parts. The contents of the result set parts are immutable once created

Author:
UoA

Constructor Summary
ResultSet(CreationParams params)
          Creates a new ResultSet
ResultSet(java.lang.String filename)
          Creates a new ResultSet
ResultSet(java.lang.String[] properties, boolean dataFlow)
          Creates a new ResultSet
ResultSet(java.lang.String properties, boolean dataFlow)
          Creates a new ResultSet
ResultSet(java.lang.String filename, int noDecrypt)
          Creates a new ResultSet
ResultSet(java.lang.String filename, java.security.PrivateKey privkey)
          Creates a new ResultSet
 
Method Summary
 boolean addResults(java.lang.String[] results)
          Adds teh provided results to the underlying buffer
 boolean addText(java.lang.String[] results)
          Adds teh provided text records in the underlying buffer
 void addWSEPR(java.lang.String epr)
          Adds a WS-EPR serialization to the head properties container
 void clear()
          Clears underlying structures
 java.lang.String cloneRS()
          Clones the implied ResultSet
 void disableAccessLeasing()
           
 void disableTimeLeasing()
           
 void endAuthoring()
          Stops the authoring of the current part and makes it available
 java.lang.String executeQueryOnDocument(java.lang.String xPath)
          Evaluates the provided xPath expression against the head part document and returns the output as a serialized string.
 java.lang.String executeQueryOnHead(java.lang.String xPath)
          Evaluates the provided xPath expression against the head part document and returns the output as a serialized string.
 java.lang.String[] executeQueryOnResults(java.lang.String xPath)
          Evaluates the provided expression against each of the results in the current payload part and if it produces output the entire result serialization is considered as output.
 void extendAccessLeasing(int extend)
          Extend the access leasing
 boolean extendTimeLeasing(java.util.Date extend)
          Extend the time leasing
 java.lang.String filterRS(java.lang.String xPath)
          Performs a filtering operation based on an provided xPath on the referenced ResultSet returning the name of the local file that holds the head part of the new ResultSet.
 java.lang.String filterRS(java.lang.String xPath, java.lang.String[] properties)
          Performs a filtering operation based on an provided xPath on the referenced ResultSet returning the name of the local file that holds the head part of the new ResultSet.
 int getAccessLeasing()
          Get the access leasing
 java.lang.String getCurrentContentPartName()
          Retrieves the name of the current payload part
 java.lang.String getCurrentContentPartPayload()
          Retrieves the payload of the current content part
 byte[] getEncKey()
          Get the encryption key
 java.lang.String getFileContent(java.lang.String filename)
          Retrieves the content of the provided local file
 boolean getFirstPart()
          Sets the current part to be the first payload part
 org.gcube.common.searchservice.searchlibrary.resultset.security.HeadMnemonic getHeadMnemonic()
          Get security properties
 java.lang.String getHeadName()
          Retrieves the name of the head part containing file
 java.lang.String getHostIP()
          Retrieves the IP address of the host that the ResultSet receides in
 java.lang.String getHostName()
          Retrieves the name of the host that the ResultSet receides in
 org.gcube.common.searchservice.searchlibrary.resultset.security.Mnemonic getMnemonic()
          Get security properties
 boolean getNextPart(int waitMax)
          Sets the next part in the chain as the current one waiting at most the provided amount of time in milliseconds for it to become available
 int getNumberOfResults(java.lang.String type)
          Retrieves the number of results stored in a payload part of the ResultSet
 boolean getPreviousPart()
          Sets the current part to be the previous part
 java.lang.String[] getProperties(java.lang.String type)
          Retrieves the properties of the provided type
 java.lang.String getResult(int index)
          Retrieves the result that has the specified index in the current payload part
 java.lang.String[] getResults()
          Retrieves all the results that are in the current payload part
 java.lang.String[] getResults(int from, int to)
          Retrieves all the results that are in the current payload part that have an index in the specified index span
 ResultSetRef getRSRef()
          Retrieves the container of the ResultSet info
 java.util.Date getTimeLeasing()
          Get the time leasing
 boolean isFirst()
          Checks if the current part is the first payload part
 boolean isForward()
          Is the RS forward reading only.
 boolean isLast()
          Checks if the current part is the last payload part
 java.lang.String keepTop(int count, short type)
          Performs a keep top operation on the implied ResultSet chain and creates a bew ResultSet with the top kept.
 java.lang.String keepTop(java.lang.String[] properties, int count, short type)
          Performs a keep top operation on the implied ResultSet chain and creates a bew ResultSet with the top kept
 RSConstants.CONTROLFLOW more(long time)
          /** Checks whether or not more results should be produced.
 boolean nextAvailable()
          Checks without blocking if the next part in this chain is available
 void overrideProperties(PropertyElementBase[] properties)
          removes any existing properties and sets the new ones
 void overrideProperties(java.lang.String properties)
          removes any existing properties and sets the new ones
 boolean removePreviousPart()
          Sets the current part to be the previous part
 java.lang.String retrieveCustomProperties()
          Retrieves a serialization of the head custom properties
 boolean setForward(boolean f)
          Set an RS to be forward
 java.lang.String[] splitClear()
          Splits the current payload part in sized defined by the RSConstants.partSize property
 java.lang.String[] splitEncoded()
          Splits the current payload part in sized defined by the RSConstants.partSize property and encdes them using Base64 encoding
 void startNewPart()
          Starts a new part in the chain of parts, making the part that was currently authored available
 java.lang.String transformByXSLT(java.lang.String xslt)
          Performs an xslt transformation against the current payload part
 java.lang.String transformByXSLTAndPersist(java.lang.String xslt)
          Performs an xslt transformation against the current payload part
 java.lang.String transformByXSLTAndPersist(javax.xml.transform.Templates xslt)
          Performs an xslt transformation against the current payload part
 java.lang.String transformRS(java.lang.String transformation)
          Performs an xslt transfromation against the payload part of the implied ResultSet and creates a new ResultSet with payload the output of each transformation.
 java.lang.String transformRS(java.lang.String transformation, java.lang.String[] properties)
          Performs an xslt transfromation against the payload part of the implied ResultSet and creates a new ResultSet with payload the output of each transformation.
 void wrapFile(java.lang.String filename)
          Wraps the provided file content
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultSet

public ResultSet(CreationParams params)
          throws java.lang.Exception
Creates a new ResultSet

Parameters:
params - RS creation params
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

ResultSet

public ResultSet(java.lang.String[] properties,
                 boolean dataFlow)
          throws java.lang.Exception
Creates a new ResultSet

Parameters:
properties - The properties this ResultSet should have
dataFlow - wheteher or not this ResultSet should enable rcord production on demand
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

ResultSet

public ResultSet(java.lang.String properties,
                 boolean dataFlow)
          throws java.lang.Exception
Creates a new ResultSet

Parameters:
properties - The properties this ResultSet should have
dataFlow - wheteher or not this ResultSet should enable rcord production on demand
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

ResultSet

public ResultSet(java.lang.String filename)
          throws java.lang.Exception
Creates a new ResultSet

Parameters:
filename - The file that holds the head of the existing ResultSet chain to point to
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

ResultSet

public ResultSet(java.lang.String filename,
                 int noDecrypt)
          throws java.lang.Exception
Creates a new ResultSet

Parameters:
filename - The file that holds the head of the existing ResultSet chain to point to
noDecrypt - Flag saying to do a decrypt
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

ResultSet

public ResultSet(java.lang.String filename,
                 java.security.PrivateKey privkey)
          throws java.lang.Exception
Creates a new ResultSet

Parameters:
filename - The file that holds the head of the existing ResultSet chain to point to
privkey - Private key to be used with the RS
Throws:
java.lang.Exception - An unrecoverable for the operation error occurred
Method Detail

addWSEPR

public void addWSEPR(java.lang.String epr)
              throws java.lang.Exception
Adds a WS-EPR serialization to the head properties container

Parameters:
epr - The WS-EPR to add
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

getHeadName

public java.lang.String getHeadName()
                             throws java.lang.Exception
Retrieves the name of the head part containing file

Returns:
The name of the file
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

clear

public void clear()
           throws java.lang.Exception
Clears underlying structures

Throws:
java.lang.Exception - An unrecoverable for the operation error occured

getRSRef

public ResultSetRef getRSRef()
Retrieves the container of the ResultSet info

Returns:
The info container

addResults

public boolean addResults(java.lang.String[] results)
                   throws java.lang.Exception
Adds teh provided results to the underlying buffer

Parameters:
results - to add
Returns:
true if all the results were successfully added, false otherwise
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

addText

public boolean addText(java.lang.String[] results)
                throws java.lang.Exception
Adds teh provided text records in the underlying buffer

Parameters:
results - The records to add
Returns:
true if all the records were successfully written, false otherwise
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

more

public RSConstants.CONTROLFLOW more(long time)
                             throws java.lang.Exception
/** Checks whether or not more results should be produced. THis operation blocks until an answer can be produced. This answer will define either that more results are nessecary, or the producer can relinguish any resources it has for producing more results because the ResultSet is no longer used, or the timeout the user specified has been reached

Parameters:
time - The timeout for the answer
Returns:
The answer
Throws:
java.lang.Exception - An unrecoverabvle for the operation error has occured

startNewPart

public void startNewPart()
                  throws java.lang.Exception
Starts a new part in the chain of parts, making the part that was currently authored available

Throws:
java.lang.Exception - An unrecoverable for the operation error occured

endAuthoring

public void endAuthoring()
                  throws java.lang.Exception
Stops the authoring of the current part and makes it available

Throws:
java.lang.Exception - An unrecoverable for the operation error occured

overrideProperties

public void overrideProperties(PropertyElementBase[] properties)
                        throws java.lang.Exception
removes any existing properties and sets the new ones

Parameters:
properties - teh proeprties to set
Throws:
java.lang.Exception - An unrecoverable for the operatiuon error occured

overrideProperties

public void overrideProperties(java.lang.String properties)
                        throws java.lang.Exception
removes any existing properties and sets the new ones

Parameters:
properties - teh proeprties to set
Throws:
java.lang.Exception - An unrecoverable for the operatiuon error occured

wrapFile

public void wrapFile(java.lang.String filename)
              throws java.lang.Exception
Wraps the provided file content

Parameters:
filename - Teh filename to wrap
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

getProperties

public java.lang.String[] getProperties(java.lang.String type)
                                 throws java.lang.Exception
Retrieves the properties of the provided type

Parameters:
type - The type of properties to retrieve
Returns:
The retrieved properties
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

nextAvailable

public boolean nextAvailable()
                      throws java.lang.Exception
Checks without blocking if the next part in this chain is available

Returns:
true if it is, false otherwise
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

getNextPart

public boolean getNextPart(int waitMax)
                    throws java.lang.Exception
Sets the next part in the chain as the current one waiting at most the provided amount of time in milliseconds for it to become available

Parameters:
waitMax - T he amount of time to wait for the next part to become available. If this is negative, a default amount of time defiened in RSConstants.sleepMax is used
Returns:
true if there is a next part and it has become the current one, false if there is no next part
Throws:
java.lang.Exception - An unrecoverable for the operation error occured or the timer expired

getFirstPart

public boolean getFirstPart()
                     throws java.lang.Exception
Sets the current part to be the first payload part

Returns:
true if the operation was successful,false otehrwise
Throws:
java.lang.Exception - An unrecoverable for the operation error occured or the timer expired

getPreviousPart

public boolean getPreviousPart()
                        throws java.lang.Exception
Sets the current part to be the previous part

Returns:
true if the operation was successful,false otehrwise
Throws:
java.lang.Exception - An unrecoverable for the operation error occured or the timer expired

removePreviousPart

public boolean removePreviousPart()
                           throws java.lang.Exception
Sets the current part to be the previous part

Returns:
true if the operation was successful,false otehrwise
Throws:
java.lang.Exception - An unrecoverable for the operation error occured or the timer expired

isFirst

public boolean isFirst()
                throws java.lang.Exception
Checks if the current part is the first payload part

Returns:
true if it is, false otherwise
Throws:
java.lang.Exception - An unrecoverable for the operation error occured or the timer expired

isLast

public boolean isLast()
               throws java.lang.Exception
Checks if the current part is the last payload part

Returns:
true if it is, false otherwise
Throws:
java.lang.Exception - An unrecoverable for the operation error occured or the timer expired

getNumberOfResults

public int getNumberOfResults(java.lang.String type)
                       throws java.lang.Exception
Retrieves the number of results stored in a payload part of the ResultSet

Parameters:
type - The type of the RS part whose records should be conted
Returns:
The number of results
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

getCurrentContentPartPayload

public java.lang.String getCurrentContentPartPayload()
                                              throws java.lang.Exception
Retrieves the payload of the current content part

Returns:
The payload of the current payload part
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

getResult

public java.lang.String getResult(int index)
                           throws java.lang.Exception
Retrieves the result that has the specified index in the current payload part

Parameters:
index - The index of the result to be retrieved
Returns:
The result serialization
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

getResults

public java.lang.String[] getResults()
                              throws java.lang.Exception
Retrieves all the results that are in the current payload part

Returns:
An array of all the serialized results of the current payload part
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

getResults

public java.lang.String[] getResults(int from,
                                     int to)
                              throws java.lang.Exception
Retrieves all the results that are in the current payload part that have an index in the specified index span

Parameters:
from - the starting index
to - the ending index
Returns:
An array of all the serialized results of the current payload part that have an index in the specified index span
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

getHostIP

public java.lang.String getHostIP()
                           throws java.lang.Exception
Retrieves the IP address of the host that the ResultSet receides in

Returns:
The IP address
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

getHostName

public java.lang.String getHostName()
                             throws java.lang.Exception
Retrieves the name of the host that the ResultSet receides in

Returns:
The host name
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

splitEncoded

public java.lang.String[] splitEncoded()
                                throws java.lang.Exception
Splits the current payload part in sized defined by the RSConstants.partSize property and encdes them using Base64 encoding

Returns:
An array with the parts names
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

splitClear

public java.lang.String[] splitClear()
                              throws java.lang.Exception
Splits the current payload part in sized defined by the RSConstants.partSize property

Returns:
An array with the parts names
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

getFileContent

public java.lang.String getFileContent(java.lang.String filename)
                                throws java.lang.Exception
Retrieves the content of the provided local file

Parameters:
filename - The file whose content must e retrieved
Returns:
The file content
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

retrieveCustomProperties

public java.lang.String retrieveCustomProperties()
                                          throws java.lang.Exception
Retrieves a serialization of the head custom properties

Returns:
The custom properties
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

cloneRS

public java.lang.String cloneRS()
                         throws java.lang.Exception
Clones the implied ResultSet

Returns:
The name of the head file pointing to the new chain of parts
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

keepTop

public java.lang.String keepTop(int count,
                                short type)
                         throws java.lang.Exception
Performs a keep top operation on the implied ResultSet chain and creates a bew ResultSet with the top kept. The new ResultSet has the same properties with the current one

Parameters:
count - The number of top elements to keep
type - The type of operation to perform. This can be one of KeepTopThreadGeneric.PERPART, KeepTopThreadGeneric.PERRECORD
Returns:
The name of the head part of the new ResultSet
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

keepTop

public java.lang.String keepTop(java.lang.String[] properties,
                                int count,
                                short type)
                         throws java.lang.Exception
Performs a keep top operation on the implied ResultSet chain and creates a bew ResultSet with the top kept

Parameters:
properties - The properties the new ResultSet must have
count - The number of top elements to keep
type - The type of operation to perform. This can be one of KeepTopThreadGeneric.PERPART, KeepTopThreadGeneric.PERRECORD
Returns:
The name of the head part of the new ResultSet
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

getCurrentContentPartName

public java.lang.String getCurrentContentPartName()
                                           throws java.lang.Exception
Retrieves the name of the current payload part

Returns:
The file name
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

executeQueryOnHead

public java.lang.String executeQueryOnHead(java.lang.String xPath)
                                    throws java.lang.Exception
Evaluates the provided xPath expression against the head part document and returns the output as a serialized string.

Parameters:
xPath - The xPath to be evaluated
Returns:
The serialization of the evaluation output
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

executeQueryOnDocument

public java.lang.String executeQueryOnDocument(java.lang.String xPath)
                                        throws java.lang.Exception
Evaluates the provided xPath expression against the head part document and returns the output as a serialized string.

Parameters:
xPath - The xPath to be evaluated
Returns:
The serialization of the evaluation output
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

executeQueryOnResults

public java.lang.String[] executeQueryOnResults(java.lang.String xPath)
                                         throws java.lang.Exception
Evaluates the provided expression against each of the results in the current payload part and if it produces output the entire result serialization is considered as output.

Parameters:
xPath - The xPath expression to be evaluated. it must start evaluation under the current node
Returns:
The results that produced output for the provided expression
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

filterRS

public java.lang.String filterRS(java.lang.String xPath)
                          throws java.lang.Exception
Performs a filtering operation based on an provided xPath on the referenced ResultSet returning the name of the local file that holds the head part of the new ResultSet. The xPath is applied to each result and should begin referencing the current node

Parameters:
xPath - The xpath to apply to the referenced ResultSet results to create the new one
Returns:
The name of the file that holds the head part of the created ResultSet
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

filterRS

public java.lang.String filterRS(java.lang.String xPath,
                                 java.lang.String[] properties)
                          throws java.lang.Exception
Performs a filtering operation based on an provided xPath on the referenced ResultSet returning the name of the local file that holds the head part of the new ResultSet. The xPath is applied to each result and should begin referencing the current node

Parameters:
xPath - The xpath to apply to the referenced ResultSet results to create the new one
properties - The properties the new ResultSet should have
Returns:
The name of the file that holds the head part of the created ResultSet
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

transformByXSLT

public java.lang.String transformByXSLT(java.lang.String xslt)
                                 throws java.lang.Exception
Performs an xslt transformation against the current payload part

Parameters:
xslt - The xslt to apply
Returns:
The output of the transformation
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

transformByXSLTAndPersist

public java.lang.String transformByXSLTAndPersist(java.lang.String xslt)
                                           throws java.lang.Exception
Performs an xslt transformation against the current payload part

Parameters:
xslt - The xslt to apply
Returns:
The name of the file that holds the output
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

transformByXSLTAndPersist

public java.lang.String transformByXSLTAndPersist(javax.xml.transform.Templates xslt)
                                           throws java.lang.Exception
Performs an xslt transformation against the current payload part

Parameters:
xslt - The xslt to apply
Returns:
The name of the file that holds the output
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

transformRS

public java.lang.String transformRS(java.lang.String transformation)
                             throws java.lang.Exception
Performs an xslt transfromation against the payload part of the implied ResultSet and creates a new ResultSet with payload the output of each transformation. The new ResultSet has as properties the properties of the current one

Parameters:
transformation - The tranformation to apply
Returns:
The name of the file holding the new ResultSet head part
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

transformRS

public java.lang.String transformRS(java.lang.String transformation,
                                    java.lang.String[] properties)
                             throws java.lang.Exception
Performs an xslt transfromation against the payload part of the implied ResultSet and creates a new ResultSet with payload the output of each transformation. The new ResultSet has as properties the properties of the current one

Parameters:
transformation - The tranformation to apply
properties - The properties the new ResultSet must have
Returns:
The name of the file holding the new ResultSet head part
Throws:
java.lang.Exception - An unrecoverable for the operation error occured

disableAccessLeasing

public void disableAccessLeasing()
                          throws java.lang.Exception
Throws:
java.lang.Exception - when access leasing cannot be disabled

extendAccessLeasing

public void extendAccessLeasing(int extend)
                         throws java.lang.Exception
Extend the access leasing

Parameters:
extend - Extend for how much
Throws:
java.lang.Exception - when extending failed

getAccessLeasing

public int getAccessLeasing()
                     throws java.lang.Exception
Get the access leasing

Returns:
the access leasing
Throws:
java.lang.Exception - when retriving the access leasing failed

isForward

public boolean isForward()
                  throws java.lang.Exception
Is the RS forward reading only.

Returns:
true if rs is of forward reading type
Throws:
java.lang.Exception - when information retrival failed

setForward

public boolean setForward(boolean f)
                   throws java.lang.Exception
Set an RS to be forward

Parameters:
f - true if to set forward
Returns:
true on success
Throws:
java.lang.Exception - when seting forward failed

getTimeLeasing

public java.util.Date getTimeLeasing()
                              throws java.lang.Exception
Get the time leasing

Returns:
the time leasing
Throws:
java.lang.Exception - when retriving the time leasing failed

extendTimeLeasing

public boolean extendTimeLeasing(java.util.Date extend)
                          throws java.lang.Exception
Extend the time leasing

Parameters:
extend - Extend for how long
Returns:
true if successfull
Throws:
java.lang.Exception - when extending failed

disableTimeLeasing

public void disableTimeLeasing()
                        throws java.lang.Exception
Throws:
java.lang.Exception - when time leasing cannot be disabled

getMnemonic

public org.gcube.common.searchservice.searchlibrary.resultset.security.Mnemonic getMnemonic()
Get security properties

Returns:
the security related class

getHeadMnemonic

public org.gcube.common.searchservice.searchlibrary.resultset.security.HeadMnemonic getHeadMnemonic()
Get security properties

Returns:
the security related class for the header

getEncKey

public byte[] getEncKey()
                 throws java.lang.Exception
Get the encryption key

Returns:
the key
Throws:
java.lang.Exception - An error occurred