User Tools

Site Tools


magik-demo:developer:class:core:query

Query

public class Query
implements Serializable

This class describes a query that can be logically seen as a conjunction of relations (with equalities between attributes but without comparisons)

Class Attributes

private long id
private java.lang.String name
private java.util.ArrayList<Atom> atoms
private java.util.ArrayList<Term> outputVariables
private java.lang.String description
private java.lang.String sql
private boolean sematincs
private java.util.LinkedHashMap relationsMap
private boolean countExists

Class Constructors

Query

public Query ()

Default constructor

Called by:

  • it.unibz.inf.magik.core.TCQCReasoner
  • it.unibz.inf.magik.core.QueryGeneralization
  • it.unibz.inf.magik.core.QuerySpecialization

Query

public Query (java.lang.String name, 
              java.util.ArrayList<Atom> atoms,
	      java.util.ArrayList<Term> outputVariables, 
              java.lang.String description) 

Constructor for creating a query with the most important fields not empty.

Called by:

  • it.unibz.inf.magik.additional.InvolvedVariablesDetector
  • it.unibz.inf.magik.core.QueryMinimizer
  • it.unibz.inf.magik.core.PreProcessor
  • it.unibz.inf.magik.test.TestFK
  • it.unibz.inf.magik.test.TestFK2
  • it.unibz.inf.magik.test.TestHardCaseFDCandFK
  • it.unibz.inf.magik.test.TestPrimaryVioation
  • it.unibz.inf.magik.test.TestQueryClass
  • it.unibz.inf.magik.test.TestQueryGeneralization
  • it.unibz.inf.magik.test.TestQueryToSQL
  • it.unibz.inf.magik.test.TestSimpleComparison
  • it.unibz.inf.magik.test.TestTCQCReasonerBlackWhiteExample
  • it.unibz.inf.magik.test.TestTCQCReasonerFKandFD
  • it.unibz.inf.magik.test.TestTCQCReasonerPlainCompanyEx
  • it.unibz.inf.magik.test.TestTCQCReasonerPlainSchoolEx
  • it.unibz.inf.magik.test.TestTCQCReasonerTCSuggestions
  • it.unibz.inf.magik.test.TestTCQCReasonerUnderFDC
  • it.unibz.inf.magik.test.TestValQueryProblem
  • it.unibz.inf.magik.test.UnificationTest

Parameters:

  • name - name of query
  • atoms - atoms of the query
  • outputVariables - terms that we want to see in output of the query
  • description - description of what query does

Query

public Query (java.lang.String name, 
              java.lang.String SQLString, 
              java.lang.String description, 
              Schema schema) 
       throws ParseSQLQueryException, 
              ContextException

Constructor for creating a query by parsing SQL string.

Called by:

  • it.unibz.inf.magik.web.SessionControl
  • it.unibz.inf.magik.test.TestQueryClass
  • it.unibz.inf.magik.test.TestQueryToSQL

Parameters:

  • name - name of query
  • SQLString - string that contains Query in SQL code
  • outputVariables - terms that we want to see in output of the query
  • description - description of what query does

Throws:

  • ParseSQLQueryException
  • ContextException

Class Methods

applyCondition

private void applyCondition (java.lang.String termOld, 
                             java.lang.String termNew, 
                             java.util.HashMap<java.lang.String, java.lang.String> termEquality) 
                      throws ParseSQLQueryException 

Apply one or more conditions to a query

Parameters:

  • termOld - original term
  • termNew - new term
  • termEquality - map for knowing which term are equal

Throws:

  • ParseSQLQueryException

checkSQLGroupBy

private boolean checkSQLGroupBy (java.lang.String SQLString, 
                                 java.lang.String attrSelect, 
                                 java.util.HashMap<java.lang.String, java.lang.String> relations) 
                          throws ParseSQLQueryException

Check the GROUP BY clause

Parameters:

  • SQLString - string of the SQL Query
  • attrSelect - string of the attribute names in SELECT
  • relations - map of the relations of the schema

Throws:

  • ParseSQLQueryException

convertToSQLQuery

public void convertToSQLQuery (Schema s)

Convert a query into SQL code

Parameters:

  • s - schema of the database related to the query

getAttributesByRelationName

public java.lang.String getAttributesByRelationName (java.lang.String relName, 
                                                     java.lang.String alias, 
                                                     Schema schema) 
                                             throws ParseSQLQueryException

Find whether the relation name can be found in the schema

Parameters:

  • relName - relation name
  • alias - alias of the relation
  • schema - schema of database

Returns:

  • attribute names, separated by comma in the case of relation has alias name, change attribute name (e.g.: name → P1_name)

Throws:

  • ParseSQLQueryException

getAttributesByRelationName

private int getAttrPos (java.util.ArrayList<List<java.lang.String>> queryTerms, 
                        java.lang.String attr)

Used by convertToSQLQuery for searching inside the ArrayList of list of queryTerms the position of an attribute

Parameters:

  • queryTerms - array list of terms inside the query
  • attr - attribute that we want to find inside queryTerms

Returns:

  • position inside the arrayList or -1 if not in the queryTerms

getRelation

private Relation getRelation (java.lang.String relation, 
                              java.util.ArrayList<Relation> relations)

Used in convertToSQLQuery for finding the relation from the set of relations

Parameters:

  • relation - relation to find
  • relations - list of the relations available in the schema

Returns:

  • relation is exists, null otherwise

getRelation

public boolean isAtomsContainingTerms()

Check whether list of atoms contain list of terms in output variables

Returns:

  • true, if some atom is contained in the output variables, false otherwise

MinimizeQuery

public Query MinimizeQuery()

method for calling the query minimalization

Returns:

  • query minimized

parseAtomStrings

public java.util.ArrayList<String> parseAtomStrings(java.util.HashMap<java.lang.String, java.lang.String> relations) {

Parse the string of relations to create list of atoms (still in string format)

Parameters:

  • relations - all the relations in the FROM clause (<alias, relation>)

Returns:

  • list of atoms (in string format)

parseConditions

public void parseConditions (java.lang.String conditions, 
                             java.util.HashMap<java.lang.String, java.lang.String> relations) 
                      throws ParseSQLQueryException

Parse conditions from the WHERE clause

Parameters:

  • conditions - string of list of conditions, separated by 'AND'
  • relations - all the relations in the FROM clause (express as <ALIAS, RELATION>)

Throws:

  • ParseSQLQueryException

parseOutputVariables

public java.lang.String parseOutputVariables(java.lang.String outputVars, 
                                             java.util.HashMap<java.lang.String, java.lang.String> relations) 
                                      throws ParseSQLQueryException

Parse the string of output variables in the case of output variable contains alias name (e.g. p1.name changed into P1_name)

Parameters:

  • outputVars - string of all output variables in the SELECT clause, separated by comma
  • relations - hashmap <alias, relation> of all relations in the FROM clause

Returns:

  • output variables in the new format

parseRelations

public java.util.LinkedHashMap<java.lang.String, java.lang.String> parseRelations(java.lang.String relations, 
                                                                                  Schema schema) 
                                                                           throws ParseSQLQueryException

Parse the relations and their aliases (if any)

Parameters:

  • relations - all the relations in the FROM clause separated by comma in String format
  • schema - database schema

Returns:

  • map of all the relations (<ALIAS, RELATION>)

Throws:

  • ParseSQLQueryException

parseSQLCount

public boolean parseSQLCount (java.lang.String SQLSelect) 
                       throws ParseSQLQueryException

Parse the COUNT clause

Parameters:

  • SQLSelect - string of SQL query

Returns:

  • true if the query as CONUT(*), false otherwise

Throws:

  • ParseSQLQueryException

parseSQLFrom

public java.lang.String parseSQLFrom(java.lang.String SQLString) 
                       throws ParseSQLQueryException

Parse the FROM clause of an SQL query

Parameters:

  • SQLString - string of SQL query

Returns:

  • String contains the FROM clause

Throws:

  • ParseSQLQueryException

parseSQLQuery

public void parseSQLQuery (java.lang.String SQLString, 
                           Schema schema) 
                    throws ParseSQLQueryException, 
                           ContextException

Parse the SQL statement of the query to set the output variables and list of atoms

Parameters:

  • SQLString - SQL query in string format
  • schema - database schema

Throws:

  • ParseSQLQueryException
  • ContextException

parseSQLSelect

public java.lang.String parseSQLSelect(java.lang.String SQLString) 
                                throws ParseSQLQueryException

Parse the SELECT clause of an SQL query

Parameters:

  • SQLString - string of SQL query

Returns:

  • String contains the SELECT clause

Throws:

  • ParseSQLQueryException


parseSQLWhere

public java.lang.String parseSQLWhere(java.lang.String SQLString) 
                               throws ParseSQLQueryException

Parse the WHERE clause of an SQL query

Parameters:

  • SQLString - string of SQL query

Returns:

  • String contains the WHERE clause

Throws:

  • ParseSQLQueryException

parseTermName

public java.lang.String parseTermName(java.lang.String sTerm, 
                                      java.util.HashMap<java.lang.String, java.lang.String> relations) 
                               throws ParseSQLQueryException

Change the term name (e.g., p1.nameP1_name)

Parameters:

  • sTerm - string of terms
  • relations - hashmap <ALIAS, RELATION>, all relations in the FROM clause

Returns:

  • String with terms changed

Throws:

  • ParseSQLQueryException

printArrAtom

public java.lang.String printArrAtom()

Print array of atoms of the query

Returns:

  • String that contains atoms of the query

printArrTerm

public java.lang.String printArrTerm()

Print array of terns of the query

Returns:

  • String that contains terms of the query

printHTML

public java.lang.String printHTML()

Print the query in a most compact way

Returns:

  • String query in this format table(attr1, attr2)

printSQLHTML

public java.lang.String printSQLHTML(boolean isVirtualSchema)

Print the query in a most compact way

Parameters:

  • isVirtualSchema - true if the schema is virtual, false otherwise

Returns:

  • String query in SQL format

replaceTerm

public void replaceTerm (java.lang.String termOld, 
                         java.lang.String termNew) 
                  throws ParseSQLQueryException

Apply condition to list of atoms and also terms (output variables)

Parameters:

  • termOld - string of term to be replaced
  • termNew - string of term to replace with

Throws:

  • ParseSQLQueryException

getters and setters methods

public boolean getSemantics() 
public void setSemantics(boolean semantics) 
 
public java.lang.String getName() {
public void setName(java.lang.String name) 
 
public java.util.ArrayList<Atom> getAtoms() 
public void setAtoms(java.util.ArrayList<Atom> atoms) 
 
public java.lang.String getDescription() 
public void setDescription(java.lang.String description) 
 
public java.util.ArrayList<Term> getOutputVariables() 
public void setOutputVariables(java.util.ArrayList<Term> outputVariables) 
 
public java.lang.String getSql() 
public void setSql(java.lang.String sql) 
 
public long getId()
public void setId(long id) 

Back to Top | Back to Home Page

magik-demo/developer/class/core/query.txt · Last modified: 2017/07/06 15:24 (external edit)