User Tools

Site Tools


magik-demo:developer:class:db:databaseconnector

Database Connector

public class DatabaseConnector
extends java.lang.Object

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.

Functions:

  • Read schemas relations, and foreign keys from database
  • Add/Edit/Delete schema (and relation)
  • Get and add remote database connection information (only for remote database schema)
  • Evaluate SQL query (only for remote database schema)
  • Validate and add user
  • Initialize required tables in installation process (for localhost application version)

Deprecated functions:

  • Read foreign keys, finite domain constraints, TC statements, and queries from database
  • Add/Edit/Delete foreign keys, finite domain constraints, TC statements, and queries in database
  • Copy and restore schema from/to database

Class Attributes

private java.sql.Connection connection

Class Constructors

DatabaseConnector

public DatabaseConnector()
                  throws java.sql.SQLException

Constructor (for test only).

Throws:

  • java.sql.SQLException

DatabaseConnector

public DatabaseConnector(boolean webApp,
                 java.lang.String appPath)
                  throws java.sql.SQLException,
                         java.lang.ClassNotFoundException,
                         java.io.IOException

Constructor.

Called in index.jsp.

Parameters:

  • webApp - true if web application, false otherwise
  • appPath - application path

Throws:

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

DatabaseConnector

public DatabaseConnector(java.lang.String dbUrl,
                 java.lang.String dbUsername,
                 java.lang.String dbPassword)
                  throws java.sql.SQLException,
                         java.lang.ClassNotFoundException

Constructor.

Called by:

Parameters:

  • dbUrl - database url
  • dbUsername - database username
  • dbPassword - database password

Throws:

  • java.sql.SQLException
  • java.lang.ClassNotFoundException

Class Methods

getSchemaType

private java.lang.String getSchemaType(boolean localSchema)

Get schema type.

Parameters:

  • localSchema - true if virtual schema, false if remote schema

Returns:

  • String “local” if localSchema is true, “remote” otherwise

getSchemas

public java.util.ArrayList<java.lang.String> getSchemas(boolean localSchema,
                                               java.lang.String username)
                                                 throws java.sql.SQLException

Get list of schemas.

Called by: readDBSchemas(boolean) : void - it.unibz.inf.magik.web.SessionControl

Parameters:

  • localSchema - true if virtual schema, false if remote schema
  • username -

Returns:

  • list of schema names

Throws:

  • java.sql.SQLException

getDbSchemas

public java.util.ArrayList<java.lang.String> getDbSchemas()
                                                   throws java.sql.SQLException

Get list of schemas from remote database connection.

Called by: addDbConnection(String, String, String) : void - it.unibz.inf.magik.web.SessionControl

Returns:

  • list of schema names

Throws:

  • java.sql.SQLException

getSchema

public Schema getSchema(java.lang.String schemaName,
               boolean localSchema)

Initialize new schema.

Called by: readDBSchemas(boolean) : void - it.unibz.inf.magik.web.SessionControl

Parameters:

  • schemaName - schema name
  • localSchema - true if virtual schema, false if remote schema

Returns:

  • Schema new schema

readRelation

public java.util.ArrayList<Relation> readRelation(java.lang.String schema,
                                         java.lang.String username)
                                           throws java.sql.SQLException

Read relations from virtual schema (in local database).

Called by: readDBSchemas(boolean) : void - it.unibz.inf.magik.web.SessionControl

Parameters:

  • schema - schema name
  • username -

Returns:

  • arrRel list of relations

Throws:

  • java.sql.SQLException

readRelation

public java.util.ArrayList<Relation> readRelation(java.lang.String schemaName)
                                           throws java.sql.SQLException

Read relations from remote database schema.

Called by: readDBSchemas(boolean) : void - it.unibz.inf.magik.web.SessionControl

Parameters:

  • schemaName - schema name

Returns:

  • arrRel list of relations

Throws:

  • java.sql.SQLException

readForeignKeys

public java.util.ArrayList<ForeignKey> readForeignKeys(java.lang.String schemaNm,
                                              Schema schema,
                                              java.lang.String username)
                                                throws java.sql.SQLException

Read database schema foreign key.

Called by: readFK() : ArrayList - it.unibz.inf.magik.web.SessionControl

Parameters:

  • schemaNm - schema name
  • schema -
  • username -

Returns:

  • list of foreign keys

Throws:

  • java.sql.SQLException

addRelation

private void addRelation(Relation r,
               java.lang.String schema,
               java.lang.String username)
                  throws java.sql.SQLException

Add relation to the schema.

Called by: addSchema(Schema, String) : void - it.unibz.inf.magik.db.DatabaseConnector

Parameters:

  • r - relation to be added
  • schema -
  • username -

Throws:

  • java.sql.SQLException

addSchema

public void addSchema(Schema schema,
             java.lang.String username)
               throws java.sql.SQLException

Add schema to database.

Called by:

Parameters:

  • schema -
  • username -

Throws:

  • java.sql.SQLException

deleteSchema

public void deleteSchema(Schema schema,
                java.lang.String username)
                  throws java.sql.SQLException

Delete schema from database.

Called by:

Parameters:

  • schema -
  • username -

Throws:

  • java.sql.SQLException

updateSchema

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

Update schema in database.

Called by: updateSchema(Schema, String) : void - it.unibz.inf.magik.web.SessionControl

Parameters:

  • schema -
  • newSchemaName -
  • username -

Throws:

  • java.sql.SQLException

getDbUrl

public java.lang.String getDbUrl(java.lang.String schema,
                        java.lang.String username)
                          throws java.sql.SQLException

Get string of database url information (for remote database schema) from database.

Called by:

Parameters:

  • schema -
  • username -

Throws:

  • java.sql.SQLException

getDbUser

public java.lang.String getDbUser(java.lang.String schema,
                         java.lang.String username)
                           throws java.sql.SQLException

Get string of database username information (for remote database schema) from database.

Called by:

Parameters:

  • schema -
  • username -

Throws:

  • java.sql.SQLException

getDbPassword

public java.lang.String getDbPassword(java.lang.String schema,
                             java.lang.String username)
                               throws java.sql.SQLException

Get string of database password information (for remote database schema) from database.

Called by:

Parameters:

  • schema -
  • username -

Throws:

  • java.sql.SQLException

addDbConnection

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

Add remote database connection details to local database.

Called by: addDbConnection(String, String, String) : void - it.unibz.inf.magik.web.SessionControl

Parameters:

  • schemaName -
  • username -
  • dbUrl - database url
  • dbUser - database username
  • dbPassword - database password

Throws:

  • java.sql.SQLException

evaluateQuery

public java.util.ArrayList<java.lang.String> evaluateQuery(Query q,
                                                  java.lang.String schemaName)
                                                    throws java.sql.SQLException

Evaluate SQL query.

Called by: printQueryResultHTML(SessionSchema, int) : String - it.unibz.inf.magik.web.SessionControl

Parameters:

  • q - SQL query
  • schemaName - schema name

Throws:

  • java.sql.SQLException

installation

public void installation()
                  throws java.sql.SQLException

Initialize required tables in installation process (for localhost application version).

Throws:

  • java.sql.SQLException

closeConnection

public void closeConnection()
                     throws java.sql.SQLException

Close database connection.

Throws:

  • java.sql.SQLException

Back to Top | Back to Home Page

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