This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
magik-demo:developer:class:sessioncontrol [2013/07/17 11:35] alex [updateSQLQuery] |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | \\ | ||
- | ''** package [[magik-demo:developer:class:sessioncontrol|it.unibz.inf.magik.web]]**'' | ||
- | ====== Class SessionControl ====== | ||
- | **''public class SessionControl''**\\ | ||
- | **''extends java.lang.Object''**\\ | ||
- | \\ | ||
- | 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.\\ | ||
- | Functions: | ||
- | * Read/write schemas from/to database | ||
- | * Write objects to database (via Hibernate) | ||
- | * Add/edit/delete schema | ||
- | * Add/edit/delete relation of the schema | ||
- | * Add/edit/delete foreign key of the schema | ||
- | * Add/edit/delete finite domain constraint | ||
- | * Add/edit/delete TC statement | ||
- | * Add/edit/delete query | ||
- | * Displaying information of query reasoning result | ||
- | * User login/logout/register functions | ||
- | * Import pre-defined sample schema | ||
- | Deprecated functions: | ||
- | * Read/write schemas from/to file | ||
- | * Restore saved schema | ||
- | |||
- | ===== Class Attributes ===== | ||
- | <code java> | ||
- | private java.util.ArrayList<SessionSchema> sessionLocalSchemas | ||
- | private java.util.ArrayList<SessionSchema> sessionRemoteSchemas | ||
- | |||
- | private java.lang.String fileStorageUrl | ||
- | |||
- | private DatabaseConnector dbConnector | ||
- | private HibernateConnector hibernateConnector | ||
- | private java.util.ArrayList<DatabaseConnector> remoteDbConnector | ||
- | |||
- | private java.util.ArrayList<TCStatement> tcSuggestions | ||
- | |||
- | private SessionSchema currentSchema | ||
- | private java.lang.String currentUser | ||
- | |||
- | private long executionTime | ||
- | private boolean webApp | ||
- | private java.lang.String dlvPath | ||
- | </code> | ||
- | ===== Class Constructors ===== | ||
- | ==== SessionControl==== | ||
- | <code java> | ||
- | public SessionControl() | ||
- | throws javax.naming.NamingException | ||
- | </code> | ||
- | **Throws:** | ||
- | * javax.naming.NamingException | ||
- | |||
- | ===== Class Methods ===== | ||
- | |||
- | ==== readDBSchemas==== | ||
- | <code java> | ||
- | public void readDBSchemas(boolean localSchema) | ||
- | throws java.lang.ClassNotFoundException, | ||
- | java.io.IOException | ||
- | </code> | ||
- | Read saved schemas from database, then set session schemas (sessionLocalSchemas & sessionRemoteSchemas).\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#schema/index.jsp|schema/index.jsp]].//\\ | ||
- | **Throws:** | ||
- | * java.lang.ClassNotFoundException | ||
- | * java.io.IOException | ||
- | |||
- | ---- | ||
- | ==== addDbConnection==== | ||
- | <code java> | ||
- | public void addDbConnection(java.lang.String dbUrl, | ||
- | java.lang.String dbUser, | ||
- | java.lang.String dbPassword) | ||
- | throws java.sql.SQLException, | ||
- | java.lang.ClassNotFoundException | ||
- | </code> | ||
- | Establish remote database connection, read all available schemas under that remote database, then add the schemas into local database.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#schema/index.jsp|schema/index.jsp]], action: adddb.//\\ | ||
- | **Throws:** | ||
- | * java.lang.ClassNotFoundException | ||
- | * java.io.IOException | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | |||
- | ==== addDbSchema==== | ||
- | <code java> | ||
- | public void addDbSchema(it.unibz.inf.magik.web.SessionSchema ss) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Add the remote schema into local database. \\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#schema/editRelation.jsp|schema/editRelation.jsp]], action: connect.//\\ | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== hibernateSaveObject==== | ||
- | <code java> | ||
- | private void hibernateSaveObject(java.lang.Object o) | ||
- | </code> | ||
- | Write objects to database via Hibernate.\\ | ||
- | **Parameters:** | ||
- | * o - object to be saved | ||
- | |||
- | ---- | ||
- | ==== deleteSchema==== | ||
- | <code java> | ||
- | public void deleteSchema(java.lang.String schemaName) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Find schema by name then delete it from the list of schemas.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#schema/index.jsp|schema/index.jsp]], action: delete.//\\ | ||
- | **Parameters:** | ||
- | * schemaName - schema name | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== addSchema==== | ||
- | <code java> | ||
- | public void addSchema(SessionSchema currSchema, | ||
- | java.lang.String newSchemaName) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Add new schema.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#schema/index.jsp|schema/index.jsp]], action: add.//\\ | ||
- | **Parameters:** | ||
- | * currSchema - schema to be added | ||
- | * newSchemaName - new schema name | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== updateSchema==== | ||
- | <code java> | ||
- | public void updateSchema(Schema currSchema, | ||
- | java.lang.String newSchemaName) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Find schema by name then update it.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#schema/index.jsp|schema/index.jsp]], action: edit.//\\ | ||
- | **Parameters:** | ||
- | * currSchema - schema to be updated | ||
- | * newSchemaName - new schema name | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== deleteRelation==== | ||
- | <code java> | ||
- | public void deleteRelation(java.lang.String relName) | ||
- | </code> | ||
- | Find relation by name then delete it from the list of relations.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#schema/edit.jsp|schema/edit.jsp]], action: delete.//\\ | ||
- | **Parameters:** | ||
- | * relName - name of relation | ||
- | |||
- | ---- | ||
- | ==== addRelation==== | ||
- | <code java> | ||
- | public void addRelation(java.lang.String relName, | ||
- | java.lang.String keys, | ||
- | java.lang.String description) | ||
- | throws ContextException | ||
- | </code> | ||
- | Add new relation.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#schema/edit.jsp|schema/edit.jsp]], action: addrel.//\\ | ||
- | **Parameters:** | ||
- | * relName - relation name | ||
- | * keys - relation keys | ||
- | * desc - relation description | ||
- | **Throws:** | ||
- | * ContextException | ||
- | |||
- | ---- | ||
- | ==== updateRelation==== | ||
- | <code java> | ||
- | public void updateRelation(java.lang.String oldRelName, | ||
- | java.lang.String relName, | ||
- | java.lang.String keys, | ||
- | java.lang.String description) | ||
- | throws ContextException | ||
- | </code> | ||
- | Find relation by name then update it.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#schema/edit.jsp|schema/edit.jsp]], action: editrel.//\\ | ||
- | **Parameters:** | ||
- | * oldRelName - relation name to be updated | ||
- | * relName - new relation name | ||
- | * keys - new relation keys | ||
- | * desc - new relation description | ||
- | **Throws:** | ||
- | * ContextException | ||
- | |||
- | ---- | ||
- | ==== deleteForeignKey==== | ||
- | <code java> | ||
- | public void deleteForeignKey(int fkidx) | ||
- | </code> | ||
- | Delete foreign key from array of foreign keys, by index.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: delete.//\\ | ||
- | **Parameters:** | ||
- | * fkidx - index of foreign key to be deleted | ||
- | |||
- | ---- | ||
- | ==== addForeignKey==== | ||
- | <code java> | ||
- | public void addForeignKey(int sourceRelIdx, | ||
- | int targetRelIdx, | ||
- | java.lang.String sourceAttr) | ||
- | throws ContextException | ||
- | </code> | ||
- | Add new foreign key.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: addfk.//\\ | ||
- | **Parameters:** | ||
- | * sourceRel - source relation | ||
- | * targetRel - target relation | ||
- | * sourceAttr - source attribute | ||
- | **Throws:** | ||
- | * ContextException | ||
- | |||
- | ---- | ||
- | ==== updateForeignKey==== | ||
- | <code java> | ||
- | public void updateForeignKey(int fkIdx, | ||
- | int sourceRelIdx, | ||
- | int targetRelIdx, | ||
- | java.lang.String sourceAttr) | ||
- | throws ContextException | ||
- | </code> | ||
- | Update existing foreign key.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: editfk.//\\ | ||
- | **Parameters:** | ||
- | * fkIdx - index of foreign key to be updated | ||
- | * sourceRel - new source relation | ||
- | * targetRel - new target relation | ||
- | * sourceAttr - new source attribute | ||
- | **Throws:** | ||
- | * ContextException | ||
- | |||
- | ---- | ||
- | ==== readFK==== | ||
- | <code java> | ||
- | public java.util.ArrayList<ForeignKey> readFK() | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Read foreign keys (from database schema and virtual foreign keys added by user).\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/showFK.jsp|constraints/showFK.jsp]].//\\ | ||
- | **Returns:** | ||
- | * arrFK list of foreign keys | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== deleteFDC==== | ||
- | <code java> | ||
- | public void deleteFDC(int fdcIdx) | ||
- | </code> | ||
- | Delete finite domain constraint from array of finite domain constraints, by index.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: delete.//\\ | ||
- | **Parameters:** | ||
- | * fkidx - index of finite domain constraint to be deleted | ||
- | |||
- | ---- | ||
- | ==== addFDC==== | ||
- | <code java> | ||
- | public void addFDC(int relIdx, | ||
- | java.lang.String column, | ||
- | java.lang.String values) | ||
- | throws ContextException | ||
- | </code> | ||
- | Add new finite domain constraint.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: addfdc.//\\ | ||
- | **Parameters:** | ||
- | * relIdx - relation index over which finite domain constraint is defined | ||
- | * column - position of the constrained argument in the containing relation | ||
- | * values - values allowed for the argument | ||
- | **Throws:** | ||
- | * ContextException | ||
- | |||
- | ---- | ||
- | ==== updateFDC==== | ||
- | <code java> | ||
- | public void updateFDC(int fdcIdx, | ||
- | int relIdx, | ||
- | java.lang.String column, | ||
- | java.lang.String values) | ||
- | throws ContextException | ||
- | </code> | ||
- | Update existing finite domain constraint.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: editfdc.//\\ | ||
- | **Parameters:** | ||
- | * fdcIdx - index of finite domain constraint to be updated | ||
- | * relIdx - relation index over which finite domain constraint is defined | ||
- | * column - position of the constrained argument in the containing relation | ||
- | * values - values allowed for the argument | ||
- | **Throws:** | ||
- | * ContextException | ||
- | |||
- | ---- | ||
- | ==== readFDC==== | ||
- | <code java> | ||
- | public java.util.ArrayList<FiniteDomainConstraint> readFDC() | ||
- | </code> | ||
- | Read finite domain constraints.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/showFDC.jsp|constraints/showFDC.jsp]].//\\ | ||
- | **Returns:** | ||
- | * arrFDC list of finite domain constraints | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== deleteTCStatement ==== | ||
- | <code java> | ||
- | public void deleteTCStatement(int tcidx) | ||
- | </code> | ||
- | Delete TC statement from array of TC statements, by index.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: delete.//\\ | ||
- | **Parameters:** | ||
- | * tcidx - index of TC statement to be deleted | ||
- | |||
- | ---- | ||
- | ==== addTCStatement ==== | ||
- | <code java> | ||
- | public void addTCStatement(int relIdx, | ||
- | java.lang.String headTerms, | ||
- | java.lang.String condition, | ||
- | java.lang.String description, | ||
- | java.lang.String name) | ||
- | throws ContextException | ||
- | </code> | ||
- | Add new TC Statement.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: addtc.//\\ | ||
- | **Parameters:** | ||
- | * relIdx - relation over which the TC statement is defined | ||
- | * headTerms - head SimpleTerms x of the relation R | ||
- | * condition - condition G of the TC statement | ||
- | * description - description of the TC statement | ||
- | * name - name of the TC statement | ||
- | **Throws:** | ||
- | * ContextException | ||
- | |||
- | ---- | ||
- | ==== addTCStatement ==== | ||
- | <code java> | ||
- | public void addTCStatement(TCStatement tcs) | ||
- | </code> | ||
- | Add new TC Statement (add the suggested TCStatement after reasoning).\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: reason.//\\ | ||
- | **Parameters:** | ||
- | * tcs - TCStatement to be added | ||
- | |||
- | ---- | ||
- | ==== updateTCStatement ==== | ||
- | <code java> | ||
- | public void updateTCStatement(int tcIdx, | ||
- | int relIdx, | ||
- | java.lang.String headTerms, | ||
- | java.lang.String condition, | ||
- | java.lang.String description, | ||
- | java.lang.String tcName) | ||
- | throws ContextException | ||
- | </code> | ||
- | Update existing TC statement.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: edittc.//\\ | ||
- | **Parameters:** | ||
- | * tcIdx - index of TC statement to be updated | ||
- | * relIdx - relation over which the TC statement is defined | ||
- | * headTerms - head SimpleTerms x of the relation R | ||
- | * condition - condition G of the TC statement | ||
- | * description description of the TC statement | ||
- | * tcName name of the TC statement | ||
- | **Throws:** | ||
- | * ContextException | ||
- | |||
- | ---- | ||
- | ==== readTCS==== | ||
- | <code java> | ||
- | public java.util.ArrayList<TCStatement> readTCS() | ||
- | </code> | ||
- | Read TC statements.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/showTC.jsp|constraints/showTC.jsp]].//\\ | ||
- | **Returns:** | ||
- | * arrTC list of TC statements | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== deleteQuery ==== | ||
- | <code java> | ||
- | public void deleteQuery(int qidx) | ||
- | </code> | ||
- | Delete query from array of queries, by index.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: delete.//\\ | ||
- | **Parameters:** | ||
- | * qidx - index of query to be deleted | ||
- | |||
- | ---- | ||
- | ==== addSQLQuery==== | ||
- | <code java> | ||
- | public void addSQLQuery(java.lang.String qName, | ||
- | java.lang.String values, | ||
- | java.lang.String desc) | ||
- | throws ParseSQLQueryException, ContextException | ||
- | </code> | ||
- | Add new query (from SQL format).\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: addq.//\\ | ||
- | **Parameters:** | ||
- | * qName - name of the query | ||
- | * values - body of the query (SQL) | ||
- | * desc - description of the query | ||
- | **Throws:** | ||
- | * ParseSQLQueryException | ||
- | * ContextException | ||
- | |||
- | ---- | ||
- | ==== updateSQLQuery==== | ||
- | <code java> | ||
- | public void updateSQLQuery(int qIdx, | ||
- | java.lang.String qName, | ||
- | java.lang.String values, | ||
- | java.lang.String desc) | ||
- | throws ParseSQLQueryException, ContextException | ||
- | </code> | ||
- | Update existing query (from SQL format).\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: editq.//\\ | ||
- | **Parameters:** | ||
- | * qIdx - index of query to be updated | ||
- | * qName - name of the query | ||
- | * values - body of the query (SQL) | ||
- | * desc - description of the query | ||
- | **Throws:** | ||
- | * ParseSQLQueryException | ||
- | * ContextException | ||
- | |||
- | ---- | ||
- | ==== readQuery==== | ||
- | <code java> | ||
- | public java.util.ArrayList<Query> readQuery() | ||
- | throws ParseSQLQueryException | ||
- | </code> | ||
- | Read queries.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/showQuery.jsp|constraints/showQuery.jsp]].//\\ | ||
- | **Returns:** | ||
- | * arrQ list of queries | ||
- | **Throws:** | ||
- | * ParseSQLQueryException | ||
- | |||
- | ---- | ||
- | ==== encodingProgram==== | ||
- | <code java> | ||
- | public java.lang.String encodingProgram(SessionSchema currSchema, | ||
- | Schema reasonSchema, | ||
- | int selQueryIdx) | ||
- | throws it.unical.mat.wrapper.DLVInvocationException, | ||
- | java.io.IOException, | ||
- | CycleException, | ||
- | PrimaryKeyViolationException | ||
- | </code> | ||
- | Get the encoding program.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: reason.//\\ | ||
- | **Returns:** | ||
- | * result string of encoding program | ||
- | **Throws:** | ||
- | * it.unical.mat.wrapper.DLVInvocationException | ||
- | * java.io.IOException | ||
- | * CycleException | ||
- | * PrimaryKeyViolationException | ||
- | |||
- | ---- | ||
- | ==== printQueryResultHTML==== | ||
- | <code java> | ||
- | public java.lang.String printQueryResultHTML(SessionSchema currSchema, | ||
- | int selQueryIdx) | ||
- | throws java.sql.SQLException, | ||
- | java.lang.ClassNotFoundException | ||
- | </code> | ||
- | Display the result of evaluating SQL query.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: reason.//\\ | ||
- | **Returns:** | ||
- | * result string of query evaluation result displayed in HTML table | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | * java.lang.ClassNotFoundException | ||
- | |||
- | ---- | ||
- | ==== isQueryComplete==== | ||
- | <code java> | ||
- | public boolean isQueryComplete(SessionSchema currSchema, | ||
- | Schema reasonSchema, | ||
- | int selQueryIdx) | ||
- | throws it.unical.mat.wrapper.DLVInvocationException, | ||
- | java.io.IOException, | ||
- | CycleException, | ||
- | PrimaryKeyViolationException | ||
- | </code> | ||
- | Get the result of query completeness reasoning.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#constraints/index.jsp|constraints/index.jsp]], action: reason.//\\ | ||
- | **Returns:** | ||
- | * isComplete true if query is complete, false otherwise | ||
- | **Throws:** | ||
- | * it.unical.mat.wrapper.DLVInvocationException | ||
- | * java.io.IOException | ||
- | * CycleException | ||
- | * PrimaryKeyViolationException | ||
- | |||
- | ---- | ||
- | ==== login==== | ||
- | <code java> | ||
- | public boolean login(java.lang.String username, | ||
- | java.lang.String password) | ||
- | </code> | ||
- | User login function, match username and password with users in the database. Set the current session user.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#login.jsp|login.jsp]], action: login.//\\ | ||
- | **Parameters:** | ||
- | * username - | ||
- | * password - | ||
- | **Returns:** | ||
- | * boolean true if login is successful, false otherwise | ||
- | |||
- | ---- | ||
- | ==== logout==== | ||
- | <code java> | ||
- | public void logout() | ||
- | </code> | ||
- | User logout function. Set the current session user as null.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#login.jsp|login.jsp]], action: logout.// | ||
- | |||
- | ---- | ||
- | ==== register==== | ||
- | <code java> | ||
- | public boolean register(java.lang.String username, | ||
- | java.lang.String password, | ||
- | java.lang.String email) | ||
- | </code> | ||
- | User register function. Add user to the database.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#login.jsp|login.jsp]], action: register.//\\ | ||
- | **Parameters:** | ||
- | * username - | ||
- | * password - | ||
- | * email - | ||
- | **Returns:** | ||
- | * boolean true if register is successful, false otherwise | ||
- | |||
- | ---- | ||
- | ==== importSampleSchema==== | ||
- | <code java> | ||
- | public void importSampleSchema(java.lang.String appPath) | ||
- | throws java.sql.SQLException, | ||
- | ContextException, | ||
- | ParseSQLQueryException, | ||
- | java.io.IOException | ||
- | </code> | ||
- | Import pre-defined sample schema (school schema), including the sample constraints.\\ | ||
- | //Called in [[magik-demo:developer:magik-business-logic#schema/index.jsp|schema/index.jsp]], action: import.//\\ | ||
- | **Parameters:** | ||
- | * appPath - application path | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | * ContextException | ||
- | * ParseSQLQueryException | ||
- | * java.io.IOException | ||
- | |||
- | |||
- | [[magik-demo:developer:class:sessioncontrol|Back to Top]] | [[magik-demo:start|Back to Home Page]] |