Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.knowgate.hipergate.datamodel
Class ModelManager

    java.lang.Object
      com.knowgate.hipergate.datamodel.ModelManager

    public class ModelManager

extends java.lang.Object

hipergate Data Model Manager

This class is used for programatically creating the full underlying data model for hipergate Java packages.

It may be used as an alternative method to database dumps for initial data loading, or, also, as a tool for porting the data model to a new DBMS in a structured way.

Constructor Summary
`ModelManager()`

Method Summary
`void` | `bulkLoad(java.lang.String sTableName, java.lang.String sFilePath, java.lang.String sEncoding)` Load a delimited text file into a database table
`void` | `clear()` Clear internal operation log
`void` | `cloneContacts(java.lang.String sContactsFilter, java.lang.String sTargetWorkArea, java.lang.String sNewOwnerId)` Clone a set of Contacts Contacts are cloned by following instructions contained in contact_clon.xml file.
`java.lang.String` | `cloneWorkArea(java.lang.String sOriginWorkArea, java.lang.String sTargetWorkArea)` Create a clone of a WorkArea WorkAreas are cloned by following instructions contained in com/knowgate/hipergate/datamodel/scripts/dbms/workarea_clon.xml file.
`void` | `connect(java.lang.String sDriver, java.lang.String sUrl, java.lang.String sSch, java.lang.String sUsr, java.lang.String sPwd)` Connect to database Connection autocommit is set to ON.
`boolean` | `create(java.lang.String sModuleName)` Create a functional module
`boolean` | `createAll()` Create all modules The created modules will be (in order): kernel, lookups, security, jobs, categories, thesauri, products, addrbook, forums, crm, projtrack, lists, webbuilder, shops, billing, hipermail, training
`java.lang.String` | `createCategoriesForUser(java.lang.String sUserId)` Create default categories for a user Internally executes scripts/user_categories_create.js Java BeanShell Script contained inside JAR file under com/knowgate/hipergate/datamodel.
`boolean` | `createDefaultDatabase()` Create a default database ready for use All modules for the full suite will be created at the new database.
`int` | `createDomain(java.lang.String sDomainNm)` Create New Domain Internally executes scripts/domain_create.js Java BeanShell Script contained inside JAR file under com/knowgate/hipergate/datamodel.
`void` | `disconnect()` Disconnect from database
`boolean` | `drop(java.lang.String sModuleName)` Drop a functional module
`boolean` | `dropAll()` Drop all modules The created modules will be (in order): example, marketing, training, hipermail, billing, shops, webbuilder, lists, projtrack, crm, forums, addrbook, products, thesauri, categories, jobs, security, lookups, kernel
`int` | `dropDomain(java.lang.String sDomainNm)` Drop Domain Drop a Domain, all its WorkAreas and associated data.
`java.lang.String` | `dropWorkArea(java.lang.String sDomainDotWorkAreaNm, java.util.Properties oProps)` Drop WorkArea THIS METHOD DROPS ALL WORKAREA DATA.
`void` | `executeSQLScript(java.lang.String sScriptSource, java.lang.String sDelimiter)`
`int` | `fixTranslationColumns()`
`java.sql.Connection` | `getConnection()` Get reference to opened database connection
`java.lang.String` | `getEncoding()`
`java.lang.String` | `getResourceAsString(java.lang.String sResourcePath, java.lang.String sEncoding)` Get an embedded resource file as a String
`static void` | `main(java.lang.String[] argv)` Method for calling ModelManager from the command line Usage: java com.knowgate.hipergate.datamodel.ModelManager /etc/hipergate.cnf command module [domain_name|domain_name.workarea_name] [verbose] Path "/etc/hipergate.cnf" must point to where hipergate.cnf file is located.
`void` | `recompileOrcl()` Re-compile invalid objects for an Oracle database
`java.lang.String` | `report()` Print internal operation log to a String
`void` | `scriptData(java.lang.String sTableName, java.lang.String sWhere, java.lang.String sFilePath)` Create INSERT SQL statements for the data of a table
`void` | `setConnection(java.sql.Connection oJDBCConn)` Assign an external conenction to ModelManager Use this method when ModelManager must not connect itself to database but reuse an already existing connection.
`void` | `setEncoding(java.lang.String sCharset)`
`boolean` | `stopOnError()` Get whether or not create() and drop() methods will stop on error
`void` | `stopOnError(boolean bStop)` Set whether or not create() and drop() methods should stop on error
`void` | `truncate(java.lang.String sTableName)` Truncate table
`void` | `upgrade(java.lang.String sOldVersion, java.lang.String sNewVersion, java.util.Properties oProps)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ModelManager

    public ModelManager()

Method Detail

### getEncoding

    public java.lang.String getEncoding()

### setEncoding

    public void setEncoding(java.lang.String sCharset)

### stopOnError

    public void stopOnError(boolean bStop)

  Set whether or not create() and drop() methods should stop on error

  Parameters:
    `bStop` - true=stop on error, false=don not stop

### stopOnError

    public boolean stopOnError()

  Get whether or not create() and drop() methods will stop on error

  Returns:
    bStop true=stop on error, false=don not stop

### connect

    public void connect(java.lang.String sDriver,
                        java.lang.String sUrl,
                        java.lang.String sSch,
                        java.lang.String sUsr,
                        java.lang.String sPwd)
                 throws java.sql.SQLException,
                        java.lang.ClassNotFoundException,
                        java.lang.IllegalStateException,
                        java.lang.UnsupportedOperationException

  Connect to database

  Connection autocommit is set to ON.

  Parameters:
    `sDriver` - JDBC driver class name
    `sUrl` - Database URL
    `sUsr` - Database User
    `sPwd` - Database Password
  Throws:
    `java.sql.SQLException`
    `java.lang.ClassNotFoundException` - If class for JDBC driver is not found
    `java.lang.IllegalStateException` - If already connected to database
    `java.lang.UnsupportedOperationException` - If DBMS is not recognized, currently only Oracle, Microsoft SQL Server and PostgreSQL are recognized.

### disconnect

    public void disconnect()
                    throws java.sql.SQLException

  Disconnect from database

  Throws:
    `java.sql.SQLException`

### setConnection

    public void setConnection(java.sql.Connection oJDBCConn)
                       throws java.sql.SQLException,
                              java.lang.UnsupportedOperationException,
                              java.lang.NullPointerException

  Assign an external conenction to ModelManager

  Use this method when ModelManager must not connect itself to database but reuse an already existing connection.

  Parameters:
    `oJDBCConn` - Database Connection
  Throws:
    `java.sql.SQLException`
    `java.lang.UnsupportedOperationException` - If DBMS is not recognized
    `java.lang.NullPointerException` - if oJDBCConn is null

### clear

    public void clear()

  Clear internal operation log

### getConnection

    public java.sql.Connection getConnection()

  Get reference to opened database connection

### report

    public java.lang.String report()

  Print internal operation log to a String

### bulkLoad

    public void bulkLoad(java.lang.String sTableName,
                         java.lang.String sFilePath,
                         java.lang.String sEncoding)
                  throws java.sql.SQLException,
                         java.io.IOException,
                         java.io.FileNotFoundException,
                         java.io.UnsupportedEncodingException,
                         java.lang.NumberFormatException,
                         java.lang.ArrayIndexOutOfBoundsException,
                         java.text.ParseException

  Load a delimited text file into a database table

  Parameters:
    `sTableName` - String Fully qualified table name
    `sFilePath` - String File Path
    `sEncoding` - String File Character encoding
  Throws:
    `java.sql.SQLException`
    `java.text.ParseException`
    `java.lang.NumberFormatException`
    `java.io.IOException`
    `java.io.FileNotFoundException`
    `java.io.UnsupportedEncodingException`
    `java.lang.ArrayIndexOutOfBoundsException`
  Since:
    6.0

### truncate

    public void truncate(java.lang.String sTableName)
                  throws java.sql.SQLException

  Truncate table

  Parameters:
    `sTableName` - String Table name
  Throws:
    `java.sql.SQLException`
  Since:
    6.0

### executeSQLScript

    public void executeSQLScript(java.lang.String sScriptSource,
                                 java.lang.String sDelimiter)
                          throws java.sql.SQLException,
                                 java.lang.InterruptedException,
                                 java.lang.IllegalArgumentException

  Throws:
    `java.sql.SQLException`
    `java.lang.InterruptedException`
    `java.lang.IllegalArgumentException`

### create

    public boolean create(java.lang.String sModuleName)
                   throws java.lang.IllegalStateException,
                          java.sql.SQLException,
                          java.io.FileNotFoundException,
                          java.io.IOException

  Create a functional module

  Parameters:
    `sModuleName` - Name of module to create { kernel | lookups | security | jobs | thesauri | categories | products | addrbook | webbuilder | crm | lists | shops | projtrack | billing | hipermail | marketing }
  Returns:
    true if module was successfully created, false if errors occured during module creation. Even if error occur module may still be partially created at database after calling create()
  Throws:
    `java.lang.IllegalStateException` - If not connected to database
    `java.io.FileNotFoundException` - If any of the internal files for module is not found
    `java.sql.SQLException`
    `java.io.IOException`

### drop

    public boolean drop(java.lang.String sModuleName)
                 throws java.lang.IllegalStateException,
                        java.sql.SQLException,
                        java.io.FileNotFoundException,
                        java.io.IOException

  Drop a functional module

  Parameters:
    `sModuleName` - Name of module to drop { kernel | lookups | security | jobs | thesauri | categories | products | addrbook | webbuilder | crm | lists | shops | projtrack | billing | hipermail }
  Returns:
    true if module was successfully droped, false if errors occured during droping module. Even if error occur module may still be partially droped at database after calling drop()
  Throws:
    `java.lang.IllegalStateException`
    `java.sql.SQLException`
    `java.io.FileNotFoundException`
    `java.io.IOException`

### createAll

    public boolean createAll()
                      throws java.lang.IllegalStateException,
                             java.sql.SQLException,
                             java.io.FileNotFoundException,
                             java.io.IOException

  Create all modules

  The created modules will be (in order): kernel, lookups, security, jobs, categories, thesauri, products, addrbook, forums, crm, projtrack, lists, webbuilder, shops, billing, hipermail, training

  Throws:
    `java.io.FileNotFoundException` - If any of the internal files for modules are not found
    `java.lang.IllegalStateException`
    `java.sql.SQLException`
    `java.io.IOException`

### dropAll

    public boolean dropAll()
                    throws java.lang.IllegalStateException,
                           java.sql.SQLException,
                           java.io.FileNotFoundException,
                           java.io.IOException

  Drop all modules

  The created modules will be (in order): example, marketing, training, hipermail, billing, shops, webbuilder, lists, projtrack, crm, forums, addrbook, products, thesauri, categories, jobs, security, lookups, kernel

  Throws:
    `java.lang.IllegalStateException`
    `java.sql.SQLException`
    `java.io.FileNotFoundException`
    `java.io.IOException`

### createDefaultDatabase

    public boolean createDefaultDatabase()
                                  throws java.io.FileNotFoundException,
                                         java.io.IOException,
                                         java.sql.SQLException,
                                         EvalError,
                                         java.lang.InstantiationException,
                                         java.lang.IllegalAccessException,
                                         java.lang.ClassNotFoundException,
                                         org.xml.sax.SAXException

  Create a default database ready for use

  All modules for the full suite will be created at the new database.
  The new database will contain 5 domains and 5 workareas:
  SYSTEM, MODEL, TEST, DEMO and REAL
  SYSTEM and MODEL domains are for administrative purposed only and should not be used by programmers.
  Domains TEST, DEMO and REAL are intended for development/testing, aceptance/demostration and real/production usage.
  Error messages are written to internal ModelManager log and can be inspected by calling report() method after createDefaultDatabase()

  Throws:
    `java.io.FileNotFoundException` - If any of the internal files for modules are not found
    `EvalError` - Java BeanShell script domain_create.js as a syntax error
    `org.xml.sax.SAXException` - Parsing error at file workarea_clon.xml
    `java.lang.InstantiationException` - SAX parser is not properly installed
    `java.lang.IllegalAccessException` - SAX parser is not properly installed
    `java.lang.ClassNotFoundException` - SAX parser is not properly installed
    `java.io.IOException`
    `java.sql.SQLException`

### scriptData

    public void scriptData(java.lang.String sTableName,
                           java.lang.String sWhere,
                           java.lang.String sFilePath)
                    throws java.sql.SQLException,
                           java.io.IOException

  Create INSERT SQL statements for the data of a table

  Parameters:
    `sTableName` - Table Name
    `sWhere` - SQL filter clause
    `sFilePath` - Path for file where INSERT statements are to be written
  Throws:
    `java.sql.SQLException`
    `java.io.IOException`

### getResourceAsString

    public java.lang.String getResourceAsString(java.lang.String sResourcePath,
                                                java.lang.String sEncoding)
                                         throws java.io.FileNotFoundException,
                                                java.io.IOException

  Get an embedded resource file as a String

  Parameters:
    `sResourcePath` - Relative path at JAR file from com/knowgate/hipergate/datamodel/ModelManager
    `sEncoding` - Character encoding for resource if it is a text file.
    If sEncoding is null then UTF-8 is assumed.
  Returns:
    Readed file
  Throws:
    `java.io.FileNotFoundException`
    `java.io.IOException`

### recompileOrcl

    public void recompileOrcl()
                       throws java.sql.SQLException

  Re-compile invalid objects for an Oracle database

  Throws:
    `java.sql.SQLException`
    `java.io.FileNotFoundException`
    `java.io.IOException`

### cloneContacts

    public void cloneContacts(java.lang.String sContactsFilter,
                              java.lang.String sTargetWorkArea,
                              java.lang.String sNewOwnerId)
                       throws java.sql.SQLException,
                              java.io.IOException,
                              java.lang.InstantiationException,
                              java.lang.IllegalAccessException,
                              java.io.IOException,
                              java.lang.ClassNotFoundException,
                              org.xml.sax.SAXException

  Clone a set of Contacts

  Contacts are cloned by following instructions contained in contact_clon.xml file.

  Parameters:
    `sContactsFilter` - WHERE clause of contacts to be cloned, for cloning just one contact use "gu_contact='GUID_OF_CONTACT'"
    `sTargetWorkArea` - GUID of WorkArea where new contact is to be written
    `sNewOwner` - GUID of user (from k_users table) that will be the new owner of the contact or null
  Throws:
    `java.sql.SQLException`
    `java.io.IOException` - XML definition file for cloning not found
    `java.lang.InstantiationException` - SAX parser is not properly installed
    `java.lang.IllegalAccessException` - SAX parser is not properly installed
    `java.lang.ClassNotFoundException` - SAX parser is not properly installed
    `org.xml.sax.SAXException` - Parsing error at file workarea_clon.xml
    `java.io.IOException`
  Since:
    6.0

### cloneWorkArea

    public java.lang.String cloneWorkArea(java.lang.String sOriginWorkArea,
                                          java.lang.String sTargetWorkArea)
                                   throws java.sql.SQLException,
                                          java.io.IOException,
                                          java.lang.InstantiationException,
                                          java.lang.IllegalAccessException,
                                          java.lang.ClassNotFoundException,
                                          org.xml.sax.SAXException

  Create a clone of a WorkArea

  WorkAreas are cloned by following instructions contained in com/knowgate/hipergate/datamodel/scripts/dbms/workarea_clon.xml file.

  Parameters:
    `sOriginWorkArea` - String of the form domain_name.workarea_name, for example "MODEL.default_workarea"
    `sTargetWorkArea` - String of the form domain_name.workarea_name, for example "TEST1.devel_workarea"
  Returns:
    GUID of new WorkArea or null if clone could not be created.
    Error messages are written to internal ModelManager log and can be inspected by calling report() method after cloneWorkArea()
  Throws:
    `java.sql.SQLException` - Most probably raised because data at model_default workarea is corrupted
    `java.lang.InstantiationException` - SAX parser is not properly installed
    `java.lang.IllegalAccessException` - SAX parser is not properly installed
    `java.lang.ClassNotFoundException` - SAX parser is not properly installed
    `org.xml.sax.SAXException` - Parsing error at file workarea_clon.xml
    `java.io.IOException`
  See Also:
    `WorkArea.delete(JDCConnection,String)`

### dropWorkArea

    public java.lang.String dropWorkArea(java.lang.String sDomainDotWorkAreaNm,
                                         java.util.Properties oProps)
                                  throws java.sql.SQLException,
                                         java.io.IOException,
                                         java.lang.Exception

  Drop WorkArea

  THIS METHOD DROPS ALL WORKAREA DATA. USE IT WITH CARE.

  Parameters:
    `sDomainDotWorkAreaNm` - Domain Name and WorkArea Name with a middle dot. Domain_Name.WorkArea_Name
    `oProps` - Environment properties (as readed from hipergate.cnf)
  Returns:
    GUID of droped WorkArea or null if WorkArea is not found.
  Throws:
    `java.sql.SQLException`
    `java.io.IOException`
    `java.lang.Exception`
  See Also:
    `(JDCConnection,String,java.util.Properties)`

### dropDomain

    public int dropDomain(java.lang.String sDomainNm)
                   throws EvalError,
                          java.sql.SQLException,
                          java.io.IOException

  Drop Domain

  Drop a Domain, all its WorkAreas and associated data.
  Internally executes scripts/domain_drop.js Java BeanShell Script contained inside JAR file under com/knowgate/hipergate/datamodel.
  THIS METHOD DROPS ALL DOMAIN DATA. USE IT WITH CARE.

  Parameters:
    `sDomainNm` - Name of domain to be droped.
  Returns:
    Numeric identifier for droped domain.
  Throws:
    `EvalError`
    `java.sql.SQLException`
    `java.io.IOException`
  See Also:
    `ACLDomain.delete(JDCConnection,int);`

### createDomain

    public int createDomain(java.lang.String sDomainNm)
                     throws EvalError,
                            java.io.IOException,
                            java.io.FileNotFoundException,
                            java.sql.SQLException

  Create New Domain

  Internally executes scripts/domain_create.js Java BeanShell Script contained inside JAR file under com/knowgate/hipergate/datamodel.

  Parameters:
    `sDomainNm` - New Domain Name
  Returns:
    Autogenerated unique numeric identifier for new domain
  Throws:
    `EvalError` - Java BeanShell script domain_create.js as a syntax error
    `java.io.IOException`
    `java.io.FileNotFoundException`
    `java.sql.SQLException`

### createCategoriesForUser

    public java.lang.String createCategoriesForUser(java.lang.String sUserId)
                                             throws java.io.IOException,
                                                    java.io.FileNotFoundException,
                                                    java.sql.SQLException

  Create default categories for a user

  Internally executes scripts/user_categories_create.js Java BeanShell Script contained inside JAR file under com/knowgate/hipergate/datamodel.

  Parameters:
    `sUserId` - User GUID
  Returns:
    GUID of home category for given user
  Throws:
    `EvalError` - Java BeanShell script user_categories_create.js as a syntax error
    `java.io.IOException`
    `java.io.FileNotFoundException`
    `java.sql.SQLException`
  Since:
    4.0

### upgrade

    public void upgrade(java.lang.String sOldVersion,
                        java.lang.String sNewVersion,
                        java.util.Properties oProps)
                 throws java.lang.IllegalStateException,
                        java.sql.SQLException,
                        java.io.FileNotFoundException,
                        java.io.IOException

  Throws:
    `java.lang.IllegalStateException`
    `java.sql.SQLException`
    `java.io.FileNotFoundException`
    `java.io.IOException`

### fixTranslationColumns

    public int fixTranslationColumns()
                              throws java.sql.SQLException

  Throws:
    `java.sql.SQLException`

### main

    public static void main(java.lang.String[] argv)

  Method for calling ModelManager from the command line

  Usage:
  java com.knowgate.hipergate.datamodel.ModelManager /etc/hipergate.cnf command module [domain_name|domain_name.workarea_name] [verbose]
  Path "/etc/hipergate.cnf" must point to where hipergate.cnf file is located.

  Parameters:
    `argv` - Array of Strings with 3 to 6 elements
    argv[0]: (Command) May be { bulkload | create | drop | clone | execute | script | truncate | upgrade }
    argv[1]: (Object) May be { database | a module_name | all | domain | workarea }
    Valid module names are: { { all | kernel | lookups | security | jobs | categories | addrbook | webbuilder | crm | shops | projtrack }
    "all" will create or drop all modules.
    Example for initial database creation :
    java com.knowgate.hipergate.datamodel.ModelManager /etc/hipergate.cnf create database
    Example for version upgrade script:
    java com.knowgate.hipergate.datamodel.ModelManager /etc/hipergate.cnf upgrade 105 110 verbose
    java com.knowgate.hipergate.datamodel.ModelManager /etc/hipergate.cnf execute /tmp/statements.sql verbose
    Example for generating a SQL script for a table :
    java com.knowgate.hipergate.datamodel.ModelManager /etc/hipergate.cnf script k_lu_languages /tmp/langs.sql
    Example for loading a text file delimited by tabs and line feeds into a table :
    java com.knowgate.hipergate.datamodel.ModelManager /etc/hipergate.cnf bulkload k_tablename /tmp/data.txt UTF-8 verbose
    Example for truncating a table :
    java com.knowgate.hipergate.datamodel.ModelManager /etc/hipergate.cnf truncate k_tablename
    Example for fixing missing translation columns :
    java com.knowgate.hipergate.datamodel.ModelManager /etc/hipergate.cnf fixtr

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD