====== 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:class:core:query.png?nolink&600 |}} ===== Class Attributes ===== private long id private java.lang.String name private java.util.ArrayList atoms private java.util.ArrayList 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 atoms, java.util.ArrayList 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 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 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> 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 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 parseAtomStrings(java.util.HashMap relations) { Parse the string of relations to create list of atoms (still in string format) **Parameters:** * relations - all the relations in the FROM clause () **Returns:** * list of atoms (in string format) ---- ==== parseConditions ==== public void parseConditions (java.lang.String conditions, java.util.HashMap 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 ) **Throws:** * ParseSQLQueryException ---- ==== parseOutputVariables ==== public java.lang.String parseOutputVariables(java.lang.String outputVars, java.util.HashMap 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 of all relations in the FROM clause **Returns:** * output variables in the new format ---- ==== parseRelations ==== public java.util.LinkedHashMap 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 () **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 relations) throws ParseSQLQueryException Change the term name (e.g., ''p1.name'' -> ''P1_name'') **Parameters:** * sTerm - string of terms * relations - hashmap , 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 getAtoms() public void setAtoms(java.util.ArrayList atoms) public java.lang.String getDescription() public void setDescription(java.lang.String description) public java.util.ArrayList getOutputVariables() public void setOutputVariables(java.util.ArrayList outputVariables) public java.lang.String getSql() public void setSql(java.lang.String sql) public long getId() public void setId(long id) [[magik-demo:developer:class:core:query|Back to Top]] | [[magik-demo:start|Back to Home Page]]