User Tools

Site Tools


magik-demo:developer:class:web:sessioncontrol

Session Control

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

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

Class Constructors

SessionControl

public SessionControl()
               throws javax.naming.NamingException

Throws:

  • javax.naming.NamingException

Class Methods

readDBSchemas

public void readDBSchemas(boolean localSchema)
                   throws java.lang.ClassNotFoundException,
                          java.io.IOException

Read saved schemas from database, then set session schemas (sessionLocalSchemas & sessionRemoteSchemas).
Called in schema/index.jsp.
Throws:

  • java.lang.ClassNotFoundException
  • java.io.IOException

addDbConnection

public void addDbConnection(java.lang.String dbUrl,
                   java.lang.String dbUser,
                   java.lang.String dbPassword)
                     throws java.sql.SQLException,
                            java.lang.ClassNotFoundException

Establish remote database connection, read all available schemas under that remote database, then add the schemas into local database.
Called in schema/index.jsp, action: adddb.
Throws:

  • java.lang.ClassNotFoundException
  • java.io.IOException
  • java.sql.SQLException

addDbSchema

public void addDbSchema(it.unibz.inf.magik.web.SessionSchema ss) 
                     throws java.sql.SQLException

Add the remote schema into local database.
Called in schema/editRelation.jsp, action: connect.
Throws:

  • java.sql.SQLException

hibernateSaveObject

private void hibernateSaveObject(java.lang.Object o)

Write objects to database via Hibernate.
Parameters:

  • o - object to be saved

deleteSchema

public void deleteSchema(java.lang.String schemaName)
                  throws java.sql.SQLException

Find schema by name then delete it from the list of schemas.
Called in schema/index.jsp, action: delete.
Parameters:

  • schemaName - schema name

Throws:

  • java.sql.SQLException

addSchema

public void addSchema(SessionSchema currSchema,
             java.lang.String newSchemaName)
               throws java.sql.SQLException

Add new schema.
Called in schema/index.jsp, action: add.
Parameters:

  • currSchema - schema to be added
  • newSchemaName - new schema name

Throws:

  • java.sql.SQLException

updateSchema

public void updateSchema(Schema currSchema,
                java.lang.String newSchemaName)
                  throws java.sql.SQLException

Find schema by name then update it.
Called in schema/index.jsp, action: edit.
Parameters:

  • currSchema - schema to be updated
  • newSchemaName - new schema name

Throws:

  • java.sql.SQLException

deleteRelation

public void deleteRelation(java.lang.String relName)

Find relation by name then delete it from the list of relations.
Called in schema/edit.jsp, action: delete.
Parameters:

  • relName - name of relation

addRelation

public void addRelation(java.lang.String relName,
               java.lang.String keys,
               java.lang.String description)
                 throws ContextException

Add new relation.
Called in schema/edit.jsp, action: addrel.
Parameters:

  • relName - relation name
  • keys - relation keys
  • desc - relation description

Throws:

  • ContextException

updateRelation

public void updateRelation(java.lang.String oldRelName,
                  java.lang.String relName,
                  java.lang.String keys,
                  java.lang.String description)
                    throws ContextException

Find relation by name then update it.
Called in 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

public void deleteForeignKey(int fkidx)

Delete foreign key from array of foreign keys, by index.
Called in constraints/index.jsp, action: delete.
Parameters:

  • fkidx - index of foreign key to be deleted

addForeignKey

public void addForeignKey(int sourceRelIdx,
                 int targetRelIdx,
                 java.lang.String sourceAttr)
                   throws ContextException

Add new foreign key.
Called in constraints/index.jsp, action: addfk.
Parameters:

  • sourceRel - source relation
  • targetRel - target relation
  • sourceAttr - source attribute

Throws:

  • ContextException

updateForeignKey

public void updateForeignKey(int fkIdx,
                    int sourceRelIdx,
                    int targetRelIdx,
                    java.lang.String sourceAttr)
                      throws ContextException

Update existing foreign key.
Called in 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

public java.util.ArrayList<ForeignKey> readFK()
                                       throws java.sql.SQLException

Read foreign keys (from database schema and virtual foreign keys added by user).
Called in constraints/showFK.jsp.
Returns:

  • arrFK list of foreign keys

Throws:

  • java.sql.SQLException

deleteFDC

public void deleteFDC(int fdcIdx)

Delete finite domain constraint from array of finite domain constraints, by index.
Called in constraints/index.jsp, action: delete.
Parameters:

  • fkidx - index of finite domain constraint to be deleted

addFDC

public void addFDC(int relIdx,
          java.lang.String column,
          java.lang.String values)
            throws ContextException

Add new finite domain constraint.
Called in 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

public void updateFDC(int fdcIdx,
             int relIdx,
             java.lang.String column,
             java.lang.String values)
               throws ContextException

Update existing finite domain constraint.
Called in 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

public java.util.ArrayList<FiniteDomainConstraint> readFDC()

Read finite domain constraints.
Called in constraints/showFDC.jsp.
Returns:

  • arrFDC list of finite domain constraints

Throws:

  • java.sql.SQLException

deleteTCStatement

public void deleteTCStatement(int tcidx)

Delete TC statement from array of TC statements, by index.
Called in constraints/index.jsp, action: delete.
Parameters:

  • tcidx - index of TC statement to be deleted

addTCStatement

public void addTCStatement(int relIdx,
                  java.lang.String headTerms,
                  java.lang.String condition,
                  java.lang.String description,
                  java.lang.String name)
                    throws ContextException

Add new TC Statement.
Called in 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

public void addTCStatement(TCStatement tcs)

Add new TC Statement (add the suggested TCStatement after reasoning).
Called in constraints/index.jsp, action: reason.
Parameters:

  • tcs - TCStatement to be added

updateTCStatement

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

Update existing TC statement.
Called in 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

public java.util.ArrayList<TCStatement> readTCS()

Read TC statements.
Called in constraints/showTC.jsp.
Returns:

  • arrTC list of TC statements

Throws:

  • java.sql.SQLException

deleteQuery

public void deleteQuery(int qidx)

Delete query from array of queries, by index.
Called in constraints/index.jsp, action: delete.
Parameters:

  • qidx - index of query to be deleted

addSQLQuery

public void addSQLQuery(java.lang.String qName,
               java.lang.String values,
               java.lang.String desc)
                 throws ParseSQLQueryException, ContextException

Add new query (from SQL format).
Called in 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

addSQLQuery

public void addSQLQuery(Query q)

Add new query (add the suggested query after reasoning).
Called in constraints/index.jsp, action: reason.
Parameters:

  • q - query to add

updateSQLQuery

public void updateSQLQuery(int qIdx,
                  java.lang.String qName,
                  java.lang.String values,
                  java.lang.String desc)
                    throws ParseSQLQueryException, ContextException

Update existing query (from SQL format).
Called in 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

public java.util.ArrayList<Query> readQuery()
                                     throws ParseSQLQueryException

Read queries.
Called in constraints/showQuery.jsp.
Returns:

  • arrQ list of queries

Throws:

  • ParseSQLQueryException

encodingProgram

public java.lang.String encodingProgram(SessionSchema currSchema,
                               Schema reasonSchema,
                               int selQueryIdx)
                                 throws it.unical.mat.wrapper.DLVInvocationException,
                                        java.io.IOException,
                                        CycleException,
                                        PrimaryKeyViolationException

Get the encoding program.
Called in constraints/index.jsp, action: reason.
Returns:

  • result string of encoding program

Throws:

  • it.unical.mat.wrapper.DLVInvocationException
  • java.io.IOException
  • CycleException
  • PrimaryKeyViolationException

printQueryResultHTML

public java.lang.String printQueryResultHTML(SessionSchema currSchema,
                                    int selQueryIdx)
                                      throws java.sql.SQLException,
                                             java.lang.ClassNotFoundException

Display the result of evaluating SQL query.
Called in constraints/index.jsp, action: reason.
Returns:

  • result string of query evaluation result displayed in HTML table

Throws:

  • java.sql.SQLException
  • java.lang.ClassNotFoundException
  • java.IO.IOException

isQueryComplete

public boolean isQueryComplete(SessionSchema currSchema,
                      Schema reasonSchema,
                      int selQueryIdx, 
                      int maxQSpecSize)
                        throws it.unical.mat.wrapper.DLVInvocationException,
                               java.io.IOException,
                               CycleException,
                               PrimaryKeyViolationException
                               ContextException 
	                       ParseSQLQueryException 

Get the result of query completeness reasoning.
Called in constraints/index.jsp, action: reason.
Parameters

  • currSchema - current Schema
  • reasonSchema - schema on where it has to reason
  • selQueryIdx - id of the selected query that we want to analyze
  • maxQSpecSize - max difference of depth between original query and the specialize query

Returns:

  • isComplete true if query is complete, false otherwise

Throws:

  • it.unical.mat.wrapper.DLVInvocationException
  • java.io.IOException
  • CycleException
  • PrimaryKeyViolationException
  • ContextException
  • ParseSQLQueryException

approximateQuery

public void approximateQuery(Query q,
                      Schema currSchema,
                      int maxQSpecSize)
                        throws it.unical.mat.wrapper.DLVInvocationException,
                               java.io.IOException,
                               CycleException,
                               PrimaryKeyViolationException
                               ContextException 
	                       ParseSQLQueryException 

Get the complete query approximations of incomplete query.
Parameters

  • q - incomplete query
  • currSchema - current Schema
  • maxQSpecSize max difference of depth between original query and the specialize query

Throws:

  • it.unical.mat.wrapper.DLVInvocationException
  • java.io.IOException
  • CycleException
  • PrimaryKeyViolationException
  • ContextException
  • ParseSQLQueryException

importSampleSchema

public void importSampleSchema(java.lang.String appPath)
                        throws java.sql.SQLException,
                               ContextException,
                               ParseSQLQueryException,
                               java.io.IOException

Import pre-defined sample schema (school schema), including the sample constraints.
Called in schema/index.jsp, action: import.
Parameters:

  • appPath - application path

Throws:

  • java.sql.SQLException
  • ContextException
  • ParseSQLQueryException
  • java.io.IOException

Back to Top | Back to Home Page

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