User Tools

Site Tools


magik-demo:developer:class:core:query

This is an old revision of the document!


A PCRE internal error occured. This might be caused by a faulty plugin

====== 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) {{ :magik-demo:developer:schema2.png?nolink&600 |}} ===== Class Attributes ===== <code java> 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 </code> ===== Class Constructors ===== ==== Query ==== <code java> public Query () </code> Default constructor //Called by:// * it.unibz.inf.magik.core.TCQCReasoner * it.unibz.inf.magik.core.QueryGeneralization * it.unibz.inf.magik.core.QuerySpecialization ---- ==== Query ==== <code java> public Query (java.lang.String name, java.util.ArrayList<Atom> atoms, java.util.ArrayList<Term> outputVariables, java.lang.String description) </code> 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 ==== <code java> public Query (java.lang.String name, java.lang.String SQLString, java.lang.String description, Schema schema) throws ParseSQLQueryException, ContextException </code> 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 ==== <code java> private void applyCondition (java.lang.String termOld, java.lang.String termNew, java.util.HashMap<java.lang.String, java.lang.String> termEquality) throws ParseSQLQueryException </code> 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 ==== <code java> private boolean checkSQLGroupBy (java.lang.String SQLString, java.lang.String attrSelect, java.util.HashMap<java.lang.String, java.lang.String> relations) throws ParseSQLQueryException </code> 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 ==== <code java> public void convertToSQLQuery (Schema s) </code> Convert a query into SQL code **Parameters:** * s - schema of the database related to the query\\ ---- ==== getAttributesByRelationName ==== <code java> public java.lang.String getAttributesByRelationName (java.lang.String relName, java.lang.String alias, Schema schema) throws ParseSQLQueryException </code> 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 ==== <code java> private int getAttrPos (java.util.ArrayList<List<java.lang.String>> queryTerms, java.lang.String attr) </code> 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 ==== <code java> private Relation getRelation (java.lang.String relation, java.util.ArrayList<Relation> relations) </code> 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 ==== <code java> public boolean isAtomsContainingTerms() </code> 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 ==== <code java> public Query MinimizeQuery() </code> method for calling the query minimalization **Returns:** * query minimized ---- ==== parseAtomStrings ==== <code java> public java.util.ArrayList<String> parseAtomStrings(java.util.HashMap<java.lang.String, java.lang.String> relations) { </code> 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 ==== <code java> public void parseConditions (java.lang.String conditions, java.util.HashMap<java.lang.String, java.lang.String> relations) throws ParseSQLQueryException </code> 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 ==== <code java> public java.lang.String parseOutputVariables(java.lang.String outputVars, java.util.HashMap<java.lang.String, java.lang.String> relations) throws ParseSQLQueryException </code> 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 ==== <code java> public java.util.LinkedHashMap<java.lang.String, java.lang.String> parseRelations(java.lang.String relations, Schema schema) throws ParseSQLQueryException </code> 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 ==== <code java> public boolean parseSQLCount (java.lang.String SQLSelect) throws ParseSQLQueryException </code> Parse the COUNT clause **Parameters:** * SQLSelect - string of SQL query **Returns:** * //true// if the query as CONUT(*), //false// otherwise **Throws:** * ParseSQLQueryException ---- ==== parseSQLFrom ==== <code java> public java.lang.String parseSQLFrom(java.lang.String SQLString) throws ParseSQLQueryException </code> Parse the FROM clause of an SQL query **Parameters:** * SQLString - string of SQL query **Returns:** * String contains the FROM clause **Throws:** * ParseSQLQueryException ---- ==== parseSQLQuery ==== <code java> public void parseSQLQuery (java.lang.String SQLString, Schema schema) throws ParseSQLQueryException, ContextException </code> 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 ==== <code java> public java.lang.String parseSQLSelect(java.lang.String SQLString) throws ParseSQLQueryException </code> Parse the SELECT clause of an SQL query **Parameters:** * SQLString - string of SQL query **Returns:** * String contains the SELECT clause **Throws:** * ParseSQLQueryException ---- ---- ==== parseSQLWhere ==== <code java> public java.lang.String parseSQLWhere(java.lang.String SQLString) throws ParseSQLQueryException </code> Parse the WHERE clause of an SQL query **Parameters:** * SQLString - string of SQL query **Returns:** * String contains the WHERE clause **Throws:** * ParseSQLQueryException ---- ==== parseTermName ==== <code java> public java.lang.String parseTermName(java.lang.String sTerm, java.util.HashMap<java.lang.String, java.lang.String> relations) throws ParseSQLQueryException </code> Change the term name (e.g., ''p1.name'' -> ''P1_name'') **Parameters:** * sTerm - string of terms * relations - hashmap <ALIAS, RELATION>, all relations in the FROM clause **Returns:** * String with terms changed **Throws:** * ParseSQLQueryException ---- ==== printArrAtom ==== <code java> public java.lang.String printArrAtom() </code> Print array of atoms of the query **Returns:** * String that contains atoms of the query ---- ==== printArrTerm ==== <code java> public java.lang.String printArrTerm() </code> Print array of terns of the query **Returns:** * String that contains terms of the query ---- ==== printHTML ==== <code java> public java.lang.String printHTML() </code> Print the query in a most compact way **Returns:** * String query in this format ''table(attr1, attr2)'' ---- ==== printSQLHTML ==== <code java> public java.lang.String printSQLHTML(boolean isVirtualSchema) </code> 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 ==== <code java> public void replaceTerm (java.lang.String termOld, java.lang.String termNew) throws ParseSQLQueryException </code> 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 ==== <code java> 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) </code> [[magik-demo:developer:class:core:query|Back to Top]] | [[magik-demo:start|Back to Home Page]]

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