{{:magik-demo:magik_logo.png?nolink&500|}}
====== MAGIK Architecture ======
Content:
* [[#Overall Architecture|Overall Architecture]]
* 3 Layers
* [[#Interface Layer|Interface Layer]]
* [[#Reasoning Layer|Reasoning Layer]]
* [[#Data Layer|Data Layer]]
* [[#Misc|Misc]]
[[magik-demo:user:query approximation:generalization|Query Approximation]]
===== Overall Architecture =====
{{ :magik-demo:developer:magik.png?nolink&700 }}
=== Interface ===
* **Web interface**: JavaServer Pages (JSP) that allow users to interact with the system. Related package: ''[[#WebContent|WebContent]]''.
* **JavaBeans**: the //Model// component in Model-View-Controller (MVC) architecture, that connects //View// component (JSP) with //Controller// component (Java). Related package: ''[[#it.unibz.inf.magik.beans|it.unibz.inf.magik.beans]]''.
=== Reasoning ===
* **MAGIK business logic**: the //Controller// component that process users input, run the reasoner (DLV engine), run the Prolog code using TuProlog, read/write to/from data layer (database), and return an output to users. Related package: ''[[#it.unibz.inf.magik.web|it.unibz.inf.magik.web]]''.
* **Core**: module which contains all related classes to encode TC-QC Java objects that is needed by DLV engine, and analyzes the returned answer set program by DLV engine. Also contains all related classes to encode schema, query and TC-statements for generating input file for the Prolog code that return the possible specializations of the query. Related packages: ''[[#it.unibz.inf.magik.core|it.unibz.inf.magik.core]]'', ''[[#it.unibz.inf.magik.additional|it.unibz.inf.magik.additional]]''.
=== Data ===
* **Database connector**: module to manage database connection, including read/write database schema & relation and evaluate SQL queries. Related package: ''[[#it.unibz.inf.magik.db|it.unibz.inf.magik.db]]''.
* **Hibernate**: module to accomodate [[http://www.hibernate.org/|Hibernate]] that provides the storage and retrieval of Java objects via Object/Relational Mapping. Related package: ''[[#it.unibz.inf.magik.hibernate|it.unibz.inf.magik.hibernate]]''.
=== Other ===
* **[[http://www.dlvsystem.com/dlvsystem/index.php/DLV_WRAPPER|DLV Wrapper]]**: a Java library that wraps the DLV system inside an external application, allowing to embed disjunctive logic programs inside Object-Oriented source code.
* **[[http://jdbc.postgresql.org/|PostgreSQL JDBC Driver]]**: a Java library that allows Java programs to connect to a PostgreSQL database using standard, database independent Java code.
* **Exception handler**: module to handle exceptions that may occur within the system. Related package: ''[[#it.unibz.inf.magik.exception|it.unibz.inf.magik.exception]]''.
* **Test**: JUnit testing module to verify/validate the core classes. Related package: ''[[#it.unibz.inf.magik.test|it.unibz.inf.magik.test]]''.
[[magik-demo:developer:magik-architecture|Back to Top]] | [[magik-demo:start|Back to Home Page]]
===== Interface Layer =====
== WebContent ==
* ''[[magik-demo:developer:magik-business-logic#index.jsp|index.jsp]]''
* ''schema/''
* ''[[magik-demo:developer:magik-business-logic#schema/index.jsp|index.jsp]]'' that includes:
* ''viewRelation.jsp''
* ''[[magik-demo:developer:magik-business-logic#schema/edit.jsp|edit.jsp]]'' that includes:
* ''showRelations.jsp''
* ''[[magik-demo:developer:magik-business-logic#schema/editConnection.jsp|editConnection.jsp]]''
* ''[[magik-demo:developer:magik-business-logic#schema/editRelation.jsp|editRelation.jsp]]''
* ''constraints/''
* ''[[magik-demo:developer:magik-business-logic#constraints/index.jsp|index.jsp]]'' that includes:
* ''showFDC.jsp''
* ''showFK.jsp''
* ''showQuery.jsp ''
* ''showTC.jsp''
* ''showQuerySuggestion.jsp''
* ''showTCSuggestion.jsp''
* ''[[magik-demo:developer:magik-business-logic#constraints/editFK.jsp|editFK.jsp]]''
* ''[[magik-demo:developer:magik-business-logic#constraints/editFDC.jsp|editFDC.jsp]]''
* ''[[magik-demo:developer:magik-business-logic#constraints/editTC.jsp|editTC.jsp]]''
* ''[[magik-demo:developer:magik-business-logic#constraints/editQuery.jsp|editQuery.jsp]]''
== it.unibz.inf.magik.beans ==
Each JavaBeans class corresponds with the HTML form in the JavaServlet Pages.
* ''ShowSchemaBean'', to get the selected schema to be processed (''[[magik-demo:developer:magik-business-logic#schema/index.jsp|schema/index.jsp]]'')
* ''EditSchemaBean'', to get the schema name (''[[magik-demo:developer:magik-business-logic#schema/edit.jsp|schema/edit.jsp]]'')
* ''EditRelationBean'', to get the attributes of relation (''[[magik-demo:developer:magik-business-logic#schema/editRelation.jsp|schema/editRelation.jsp]]'')
* ''EditConnectionBean'', to get the information of database connection details (''[[magik-demo:developer:magik-business-logic#schema/editConnection.jsp|schema/editConnection.jsp]]'')
* ''ShowContraintsBean'', to get the selected constraints and query to be processed (''[[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]]'')
* ''EditForeignKeyBean'', to get the attributes of foreign key (''[[magik-demo:developer:magik-business-logic#constraints/editFK.jsp|constraints/editFK.jsp]]'')
* ''EditFiniteDomainBean'', to get the attributes of finite domain constraint (''[[magik-demo:developer:magik-business-logic#constraints/editFDC.jsp|constraints/editFDC.jsp]]'')
* ''EditTCStatementBean'', to get the attributes of TC statement (''[[magik-demo:developer:magik-business-logic#constraints/editTC.jsp|constraints/editTC.jsp]]'')
* ''EditQueryBean'', to get the attributes of query (''[[magik-demo:developer:magik-business-logic#constraints/editQuery.jsp|constraints/editQuery.jsp]]'')
[[magik-demo:developer:magik-architecture|Back to Top]] | [[magik-demo:start|Back to Home Page]]
===== Reasoning Layer =====
== it.unibz.inf.magik.web ==
* ''[[magik-demo:developer:class:web:sessioncontrol|SessionControl]]'' → Class for controlling the active session of the application, including process users input, run the reasoner (DLV engine), read/write to/from data layer (database), and return an output to users.
* Read/write schemas from/to database : ''[[magik-demo:developer:class:web:sessioncontrol#readDBSchemas|readDBSchemas]]'', ''[[magik-demo:developer:class:web:sessioncontrol#addDbConnection|addDbConnection]]'', ''[[magik-demo:developer:class:web:sessioncontrol#addDbSchema|addDbSchema]]''
* Write objects to database (via Hibernate) : ''[[magik-demo:developer:class:web:sessioncontrol#hibernateSaveObject|hibernateSaveObject]]''
* Add/edit/delete schema : ''[[magik-demo:developer:class:web:sessioncontrol#addSchema|addSchema]]'', ''[[magik-demo:developer:class:web:sessioncontrol#updateSchema|updateSchema]]'', ''[[magik-demo:developer:class:web:sessioncontrol#deleteSchema|deleteSchema]]''
* Add/edit/delete relation of the schema : ''[[magik-demo:developer:class:web:sessioncontrol#addRelation|addRelation]]'', ''[[magik-demo:developer:class:web:sessioncontrol#updateRelation|updateRelation]]'', ''[[magik-demo:developer:class:web:sessioncontrol#deleteRelation|deleteRelation]]''
* Add/edit/delete foreign key of the schema : ''[[magik-demo:developer:class:web:sessioncontrol#addForeignKey|addForeignKey]]'', ''[[magik-demo:developer:class:web:sessioncontrol#updateForeignKey|updateForeignKey]]'', ''[[magik-demo:developer:class:web:sessioncontrol#deleteForeignKey|deleteForeignKey]]''
* Add/edit/delete finite domain constraint : ''[[magik-demo:developer:class:web:sessioncontrol#addFDC|addFDC]]'', ''[[magik-demo:developer:class:web:sessioncontrol#updateFDC|updateFDC]]'', ''[[magik-demo:developer:class:web:sessioncontrol#deleteFDC|deleteFDC]]''
* Add/edit/delete TC statement : ''[[magik-demo:developer:class:web:sessioncontrol#addTCStatement|addTCStatement]]'', ''[[magik-demo:developer:class:web:sessioncontrol#updateTCStatement|updateTCStatement]]'', ''[[magik-demo:developer:class:web:sessioncontrol#deleteTCStatement|deleteTCStatement]]''
* Add/edit/delete query : ''[[magik-demo:developer:class:web:sessioncontrol#addSQLQuery|addSQLQuery]]'', ''[[magik-demo:developer:class:web:sessioncontrol#updateSQLQuery|updateSQLQuery]]'', ''[[magik-demo:developer:class:web:sessioncontrol#deleteQuery|deleteQuery]]''
* Displaying information of query reasoning result : ''[[magik-demo:developer:class:web:sessioncontrol#encodingProgram|encodingProgram]]'', ''[[magik-demo:developer:class:web:sessioncontrol#printQueryResultHTML|printQueryResultHTML]]'', ''[[magik-demo:developer:class:web:sessioncontrol#isQueryComplete|isQueryComplete]]'', ''[[magik-demo:developer:class:web:sessioncontrol#approximateQuery|approximateQuery]]''
* Import pre-defined sample schema : ''[[magik-demo:developer:class:web:sessioncontrol#importSampleSchema|importSampleSchema]]''
* ''[[magik-demo:developer:class:web:sessionschema|SessionSchema]]'' extends ''[[magik-demo:developer:class:core:schema|Schema]]'', with the information of selected foreign keys, finite domain constraints, and table completeness statements in the active session, also the information of database connection details (only for remote schema).
== it.unibz.inf.magik.core ==
* ''[[magik-demo:developer:class:core:term|Term]]'' → Class for term (variable or constant)
* ''[[magik-demo:developer:class:core:atom|Atom]]'' → Class for atom (array of terms)
* ''[[magik-demo:developer:class:core:query|Query]]'' → Class for query that can be logically seen as a conjunction of relations.
* ''[[magik-demo:developer:class:core:tcstatement|TC-Statement]]'' → Class for table completeness statement as it is defined by Razniewski&Nutt(VLDB2011).
* ''[[magik-demo:developer:class:core:schema|Schema]]'' → Class for SQL schema with a set of relations, over which over finite domain and foreign key constraints can be defined.
* ''[[magik-demo:developer:class:core:relation|Relation]]'' → Class for SQL relation defined with name, arity, and primary key definition.
* ''[[magik-demo:developer:class:core:foreignkey|Foreign Key]]'' → Class for foreign key dependency between two relations from the common schema (sourceRelation[sourceAttr] → targetRelation[targetKey]).
* ''[[magik-demo:developer:class:core:finitedomainconstraints|Finite Domain Constraints]]'' → Class for finite domain constraint defined over a single attribute in a relation.
* ''[[magik-demo:developer:class:core:querygeneralization|QueryGeneralization]]'' → Class for generating (if exists) the least specific specialization query of the given query. [[magik-demo:developer:generalization-howitworks|How it works]]
* ''[[magik-demo:developer:class:core:queryspecialization|QuerySpecialization]]'' → Class for generating (if exists) the most specific generalization query(ies) of the given query.
* ''[[magik-demo:developer:class:core:programgenerator|ProgramGenerator]]'' → Class for translating the schema, constraints and query into DLV format
* ''ConjunctiveQuery'' → Class for traslating query into a conjunctive query.
* ''TCSuggestions'' → Class for suggested table completeness statements over a query so that the query will be complete.
* ''AuxiliaryFunctions'' → Class for auxiliary functions used by some java classes.
* ''CycleDetector'' → Class for detecting cycle inside foreign keys.
* ''DLV_Engine'' → Class for setting and running the DLV library.
* ''Preprocessor'' → Class for preprocessing the query in order to find (possibly) error or violations
* ''QueryMinimizer''
[[magik-demo:developer:magik-architecture|Back to Top]] | [[magik-demo:start|Back to Home Page]]
===== Data Layer =====
== it.unibz.inf.magik.db ==
* ''[[magik-demo:developer:class:db:databaseconnector|DatabaseConnector]]'' → Class for database connection. Database connection is established with PostgreSQL JDBC Driver, a Java library that allows Java programs to connect to a PostgreSQL database.
* Read schemas relations, and foreign keys from database : ''[[magik-demo:developer:class:db:databaseconnector#getSchemaType|getSchemaType]]'', ''[[magik-demo:developer:class:db:databaseconnector#getSchemas|getSchemas]]'', ''[[magik-demo:developer:class:db:databaseconnector#getDbSchemas|getDbSchemas]]'', ''[[magik-demo:developer:class:db:databaseconnector#getSchema|getSchema]]'', ''[[magik-demo:developer:class:db:databaseconnector#readRelation|readRelation]]'', ''[[magik-demo:developer:class:db:databaseconnector#readForeignKeys|readForeignKeys]]''
* Add/Edit/Delete schema (and relation) : ''[[magik-demo:developer:class:db:databaseconnector#addRelation|addRelation]]'', ''[[magik-demo:developer:class:db:databaseconnector#addSchema|addSchema]]'', ''[[magik-demo:developer:class:db:databaseconnector#deleteSchema|deleteSchema]]'', ''[[magik-demo:developer:class:db:databaseconnector#updateSchema|updateSchema]]''
* Get and add remote database connection information (only for remote database schema) : ''[[magik-demo:developer:class:db:databaseconnector#getDbUrl|getDbUrl]]'', ''[[magik-demo:developer:class:db:databaseconnector#getDbUser|getDbUser]]'', ''[[magik-demo:developer:class:db:databaseconnector#getDbPassword|getDbPassword]]'', ''[[magik-demo:developer:class:db:databaseconnector#addDbConnection|addDbConnection]]''
* Evaluate SQL query (only for remote database schema) : ''[[magik-demo:developer:class:db:databaseconnector#evaluateQuery|evaluateQuery]]''
* Validate and add user : ''[[magik-demo:developer:class:db:databaseconnector#validateUser|validateUser]]'', ''[[magik-demo:developer:class:db:databaseconnector#addUser|addUser]]''
* Initialize required tables in installation process (for localhost application version) : ''[[magik-demo:developer:class:db:databaseconnector#installation|installation]]''
== it.unibz.inf.magik.hibernate ==
* ''HibernateConnector'' → Class for Hibernate connection.
* ''MagikNamingStrategy'' → Class for custom naming strategy for table name in the database (in the format of ''''), with provided ''username'' and ''schemaName'', which is used to store objects.
* Configuration files:
* ''FiniteDomainConstraint.hbm.xml'' → configuration file for storing finite domain constraints
* ''ForeignKey.hbm.xml'' → configuration file for storing foreign keys
* ''Query.hbm.xml'' → configuration file for storing queries
* ''TCStatement.hbm.xml'' → configuration file for storing table completeness statements
* ''hibernate.cfg.xml'' → configuration file for Hibernate connection
[[magik-demo:developer:magik-architecture|Back to Top]] | [[magik-demo:start|Back to Home Page]]
===== Misc =====
==it.unibz.inf.magik.exception==
* ''ContextException'' → Class for exception handler for adding/updating relation, foreign key, finite domain constraint, and table completeness statement.
* ''ParseSQLQueryException'' → Class for exception handler for SQL query parsing.
* ''CycleException'' → Class for exception handler for cycle detection.
* ''PrimaryKeyViolationException'' → Class for exception handler for primary key violation detection.
==it.unibz.inf.magik.test==
* ''AllTests''
* ''CycleDetectionTest''
* ''TestAtomClass''
* ''TestDatabaseConnectorClass''
* ''TestFK''
* ''TestFK2''
* ''TestHardCaseFDCandFK''
* ''TestPreprocessor''
* ''TestPrimaryViolation''
* ''TestQueryClass''
* ''TestQueryGeneralization''
* ''TestQueryToSQL''
* ''TestSimpleComparison''
* ''TestTCQCReasonerBlackWhiteExample''
* ''TestTCQCReasonerFKandFD''
* ''TestTCQCReasonerPlainCompanyEx''
* ''TestTCQCReasonerPlainSchoolEx''
* ''TestTCQCReasonerTCSuggestions''
* ''TestTCQCReasonerUnderFDC''
* ''TestTermClass''
* ''TestValQueryProblem.''
* ''UnificationTest''
[[magik-demo:developer:magik-architecture|Back to Top]] | [[magik-demo:start|Back to Home Page]]