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:databaseconnector [2013/07/18 11:59] alex [addUser] |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | \\ | ||
- | ''**package [[magik-demo:developer:class:databaseconnector|it.unibz.inf.magik.db]]**'' | ||
- | ====== Class DatabaseConnector ====== | ||
- | **''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 ===== | ||
- | <code java> | ||
- | private java.sql.Connection connection | ||
- | </code> | ||
- | ===== Class Constructors ===== | ||
- | ==== DatabaseConnector ==== | ||
- | <code java> | ||
- | public DatabaseConnector() | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Constructor (for test only).\\ | ||
- | |||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== DatabaseConnector ==== | ||
- | <code java> | ||
- | public DatabaseConnector(boolean webApp, | ||
- | java.lang.String appPath) | ||
- | throws java.sql.SQLException, | ||
- | java.lang.ClassNotFoundException, | ||
- | java.io.IOException | ||
- | </code> | ||
- | Constructor.\\ | ||
- | |||
- | //Called in [[magik-demo:developer:magik-business-logic#index.jsp|index.jsp]].// | ||
- | |||
- | **Parameters:** | ||
- | * webApp - true if web application, false otherwise | ||
- | * appPath - application path | ||
- | |||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | * java.lang.ClassNotFoundException | ||
- | * java.io.IOException | ||
- | |||
- | ---- | ||
- | ==== DatabaseConnector ==== | ||
- | <code java> | ||
- | public DatabaseConnector(java.lang.String dbUrl, | ||
- | java.lang.String dbUsername, | ||
- | java.lang.String dbPassword) | ||
- | throws java.sql.SQLException, | ||
- | java.lang.ClassNotFoundException | ||
- | </code> | ||
- | Constructor. | ||
- | |||
- | //Called by:// | ||
- | * //[[magik-demo:developer:class:sessioncontrol#addDbConnection|addDbConnection(String, String, String) : void - it.unibz.inf.magik.web.SessionControl]]// | ||
- | * //[[magik-demo:developer:class:sessioncontrol#readDBSchemas|readDBSchemas(boolean) : void - it.unibz.inf.magik.web.SessionControl]]// | ||
- | * //[[magik-demo:developer:class:sessioncontrol#printQueryResultHTML|printQueryResultHTML(SessionSchema, int) : String - it.unibz.inf.magik.web.SessionControl]]// | ||
- | **Parameters:** | ||
- | * dbUrl - database url | ||
- | * dbUsername - database username | ||
- | * dbPassword - database password | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | * java.lang.ClassNotFoundException | ||
- | |||
- | ===== Class Methods ===== | ||
- | ==== getSchemaType==== | ||
- | <code java> | ||
- | private java.lang.String getSchemaType(boolean localSchema) | ||
- | </code> | ||
- | Get schema type. | ||
- | |||
- | **Parameters:** | ||
- | * localSchema - true if virtual schema, false if remote schema | ||
- | **Returns:** | ||
- | * String "local" if localSchema is true, "remote" otherwise | ||
- | |||
- | |||
- | ---- | ||
- | |||
- | ==== getSchemas==== | ||
- | <code java> | ||
- | public java.util.ArrayList<java.lang.String> getSchemas(boolean localSchema, | ||
- | java.lang.String username) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Get list of schemas. | ||
- | |||
- | //Called by: [[magik-demo:developer:class:sessioncontrol#readDBSchemas|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==== | ||
- | <code java> | ||
- | public java.util.ArrayList<java.lang.String> getDbSchemas() | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Get list of schemas from remote database connection. | ||
- | |||
- | //Called by: [[magik-demo:developer:class:sessioncontrol#addDbConnection|addDbConnection(String, String, String) : void - it.unibz.inf.magik.web.SessionControl]]// | ||
- | |||
- | **Returns:** | ||
- | * list of schema names | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== getSchema==== | ||
- | <code java> | ||
- | public Schema getSchema(java.lang.String schemaName, | ||
- | boolean localSchema) | ||
- | </code> | ||
- | Initialize new schema. | ||
- | |||
- | //Called by: [[magik-demo:developer:class:sessioncontrol#readDBSchemas|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==== | ||
- | <code java> | ||
- | public java.util.ArrayList<Relation> readRelation(java.lang.String schema, | ||
- | java.lang.String username) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Read relations from virtual schema (in local database). | ||
- | |||
- | //Called by: [[magik-demo:developer:class:sessioncontrol#readDBSchemas|readDBSchemas(boolean) : void - it.unibz.inf.magik.web.SessionControl]]// | ||
- | |||
- | **Parameters:** | ||
- | * schema - schema name | ||
- | * username - | ||
- | **Returns:** | ||
- | * arrRel list of relations | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== readRelation==== | ||
- | <code java> | ||
- | public java.util.ArrayList<Relation> readRelation(java.lang.String schemaName) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Read relations from remote database schema. | ||
- | |||
- | //Called by: [[magik-demo:developer:class:sessioncontrol#readDBSchemas|readDBSchemas(boolean) : void - it.unibz.inf.magik.web.SessionControl]]// | ||
- | |||
- | **Parameters:** | ||
- | * schemaName - schema name | ||
- | **Returns:** | ||
- | * arrRel list of relations | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== readForeignKeys==== | ||
- | <code java> | ||
- | public java.util.ArrayList<ForeignKey> readForeignKeys(java.lang.String schemaNm, | ||
- | Schema schema, | ||
- | java.lang.String username) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Read database schema foreign key. | ||
- | |||
- | //Called by: [[magik-demo:developer:class:sessioncontrol#readFK|readFK() : ArrayList - it.unibz.inf.magik.web.SessionControl]]// | ||
- | |||
- | **Parameters:** | ||
- | * schemaNm - schema name | ||
- | * schema - | ||
- | * username - | ||
- | **Returns:** | ||
- | * list of foreign keys | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== addRelation==== | ||
- | <code java> | ||
- | private void addRelation(Relation r, | ||
- | java.lang.String schema, | ||
- | java.lang.String username) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Add relation to the schema. | ||
- | |||
- | //Called by: [[#addSchema|addSchema(Schema, String) : void - it.unibz.inf.magik.db.DatabaseConnector]]// | ||
- | |||
- | **Parameters:** | ||
- | * r - relation to be added | ||
- | * schema - | ||
- | * username - | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== addSchema==== | ||
- | <code java> | ||
- | public void addSchema(Schema schema, | ||
- | java.lang.String username) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Add schema to database. | ||
- | |||
- | //Called by:// | ||
- | * //[[magik-demo:developer:class:sessioncontrol#addSchema|addSchema(SessionSchema, String) : void - it.unibz.inf.magik.web.SessionControl]]// | ||
- | * //[[#updateSchema|updateSchema(Schema, String, String) : void - it.unibz.inf.magik.db.DatabaseConnector]]// | ||
- | |||
- | **Parameters:** | ||
- | * schema - | ||
- | * username - | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== deleteSchema==== | ||
- | <code java> | ||
- | public void deleteSchema(Schema schema, | ||
- | java.lang.String username) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Delete schema from database. | ||
- | |||
- | //Called by:// | ||
- | * //[[magik-demo:developer:class:sessioncontrol#deleteSchema|deleteSchema(String) : void - it.unibz.inf.magik.web.SessionControl]]// | ||
- | * //[[#updateSchema|updateSchema(Schema, String, String) : void - it.unibz.inf.magik.db.DatabaseConnector]]// | ||
- | |||
- | **Parameters:** | ||
- | * schema - | ||
- | * username - | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== updateSchema==== | ||
- | <code java> | ||
- | public void updateSchema(Schema schema, | ||
- | java.lang.String newSchemaName, | ||
- | java.lang.String username) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Update schema in database. | ||
- | |||
- | //Called by: [[magik-demo:developer:class:sessioncontrol#updateSchema|updateSchema(Schema, String) : void - it.unibz.inf.magik.web.SessionControl]]// | ||
- | |||
- | **Parameters:** | ||
- | * schema - | ||
- | * newSchemaName - | ||
- | * username - | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== getDbUrl==== | ||
- | <code java> | ||
- | public java.lang.String getDbUrl(java.lang.String schema, | ||
- | java.lang.String username) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Get string of database url information (for remote database schema) from database. | ||
- | |||
- | //Called by:// | ||
- | * //[[magik-demo:developer:class:sessioncontrol#readDBSchemas|readDBSchemas(boolean) : void - it.unibz.inf.magik.web.SessionControl]]// | ||
- | * //[[magik-demo:developer:class:sessioncontrol#printQueryResultHTML|printQueryResultHTML(SessionSchema, int) : String - it.unibz.inf.magik.web.SessionControl]]// | ||
- | |||
- | **Parameters:** | ||
- | * schema - | ||
- | * username - | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== getDbUser==== | ||
- | <code java> | ||
- | public java.lang.String getDbUser(java.lang.String schema, | ||
- | java.lang.String username) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Get string of database username information (for remote database schema) from database. | ||
- | |||
- | //Called by:// | ||
- | * //[[magik-demo:developer:class:sessioncontrol#readDBSchemas|readDBSchemas(boolean) : void - it.unibz.inf.magik.web.SessionControl]]// | ||
- | * //[[magik-demo:developer:class:sessioncontrol#printQueryResultHTML|printQueryResultHTML(SessionSchema, int) : String - it.unibz.inf.magik.web.SessionControl]]// | ||
- | **Parameters:** | ||
- | * schema - | ||
- | * username - | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== getDbPassword==== | ||
- | <code java> | ||
- | public java.lang.String getDbPassword(java.lang.String schema, | ||
- | java.lang.String username) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Get string of database password information (for remote database schema) from database. | ||
- | |||
- | //Called by:// | ||
- | * //[[magik-demo:developer:class:sessioncontrol#readDBSchemas|readDBSchemas(boolean) : void - it.unibz.inf.magik.web.SessionControl]]// | ||
- | * //[[magik-demo:developer:class:sessioncontrol#printQueryResultHTML|printQueryResultHTML(SessionSchema, int) : String - it.unibz.inf.magik.web.SessionControl]]// | ||
- | **Parameters:** | ||
- | * schema - | ||
- | * username - | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== addDbConnection==== | ||
- | <code java> | ||
- | 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 | ||
- | </code> | ||
- | Add remote database connection details to local database. | ||
- | |||
- | //Called by: //[[magik-demo:developer:class:sessioncontrol#addDbConnection|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==== | ||
- | <code java> | ||
- | public java.util.ArrayList<java.lang.String> evaluateQuery(Query q, | ||
- | java.lang.String schemaName) | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Evaluate SQL query. | ||
- | |||
- | //Called by: [[magik-demo:developer:class:sessioncontrol#printQueryResultHTML|printQueryResultHTML(SessionSchema, int) : String - it.unibz.inf.magik.web.SessionControl]]// | ||
- | |||
- | **Parameters:** | ||
- | * q - SQL query | ||
- | * schemaName - schema name | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | |||
- | |||
- | ==== installation==== | ||
- | <code java> | ||
- | public void installation() | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Initialize required tables in installation process (for localhost application version).\\ | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | ---- | ||
- | ==== closeConnection==== | ||
- | <code java> | ||
- | public void closeConnection() | ||
- | throws java.sql.SQLException | ||
- | </code> | ||
- | Close database connection.\\ | ||
- | **Throws:** | ||
- | * java.sql.SQLException | ||
- | |||
- | [[magik-demo:developer:class:databaseconnector|Back to Top]] | [[magik-demo:start|Back to Home Page]] |