Class DatabaseTools

java.lang.Object
com.isomorphic.tools.DatabaseTools

public class DatabaseTools extends Object
This class implements database-related tools and utility functions. These can be called directly from server-side code, and some of them are also used by Admin Console and built-in RPC methods.
  • Method Details

    • getDefinedDatabases

      public static List getDefinedDatabases() throws Exception
      Returns a List of Maps containing information about defined database connections. Note, this override of the API does not test connections
      Returns:
      List of Maps containing information about defined database connections
      Throws:
      Exception
    • getDefinedDatabases

      public static List getDefinedDatabases(boolean testConnection) throws Exception
      Returns a List of Maps containing information about defined database connections
      Parameters:
      testConnection - If true, attempts to connect to each defined database and run some queries, to determine the current status of the connection
      Returns:
      List of Maps containing information about defined database connections
      Throws:
      Exception
    • getDefinedDatabases

      public static List getDefinedDatabases(boolean testConnection, Map criteria) throws Exception
      Returns a List of Maps containing information about defined database connections
      Parameters:
      testConnection - If true, attempts to connect to each defined database and run some queries, to determine the current status of the connection
      criteria - Optionally, a Map representing either simple or advanced criteria to filter the derived list of databases
      Returns:
      List of Maps containing information about defined database connections
      Throws:
      Exception
    • getDefinedDatabases

      public static List getDefinedDatabases(boolean testConnection, AdvancedCriteria criteria) throws Exception
      Returns a List of Maps containing information about defined database connections
      Parameters:
      testConnection - If true, attempts to connect to each defined database and run some queries, to determine the current status of the connection
      criteria - Optionally, an AdvancedCriteria to filter the derived list of databases
      Returns:
      List of Maps containing information about defined database connections
      Throws:
      Exception
    • getTables

      public static List getTables(String serverType, String dbName, boolean includeTables, boolean includeViews, String schema, List include, List exclude) throws Exception
      Returns a list of table and/or view names
      Parameters:
      serverType - "sql" or "hibernate", determines the database connection strategy
      dbName - Optionally, the name of the database - if null, uses the default
      includeTables - If true, includes tables in the returned list
      includeViews - If true, includes views in the returned list
      schema - Optionally, the schema name to use to restrict the list. If null, searches all schemata.
      include - Optionally, a list of partial table names to perform substring checking against. Tables will be included where the table name matches any of the supplied substrings. The matching is not case sensitive.
      exclude - Optionally, a list of partial table names to perform substring checking against. Tables will be excluded where the table name matches any of the supplied substrings. The matching is not case sensitive. Note that if you specify both include and exclude criteria and they conflict (ie, according to the criteria you set, a table should be both included and excluded), exclude wins.
      Returns:
      List of table names and remarks
      Throws:
      Exception
    • getTables

      public static List getTables(AdvancedCriteria criteria) throws Exception
      Returns a list of table and view names for the default server type "sql" database, for all schemas, optionally matching the supplied criteria
      Parameters:
      criteria - Optionally, an AdvancedCriteria which will be used to filter the full list of tables
      Returns:
      List of table names and remarks
      Throws:
      Exception
    • getTables

      public static List getTables(String dbName) throws Exception
      Returns a list of table and view names for the named database (server type "sql"), for all schemas
      Parameters:
      dbName - The name of the database - if null, uses the default
      Returns:
      List of table names and remarks
      Throws:
      Exception
    • getTables

      public static List getTables(String dbName, AdvancedCriteria criteria) throws Exception
      Returns a list of table and view names for the named database (server type "sql"), for all schemas, optionally matching the supplied criteria
      Parameters:
      dbName - The name of the database - if null, uses the default
      criteria - Optionally, an AdvancedCriteria which will be used to filter the full list of tables
      Returns:
      List of table names and remarks
      Throws:
      Exception
    • getTables

      public static List getTables(String dbName, String schema, AdvancedCriteria criteria) throws Exception
      Returns a list of table and view names for the named database (server type "sql"), for a named schema, optionally matching the supplied criteria
      Parameters:
      dbName - The name of the database - if null, uses the default
      schema - The name of the schema - if null, uses all schemas
      criteria - Optionally, an AdvancedCriteria which will be used to filter the full list of tables
      Returns:
      List of table names and remarks
      Throws:
      Exception
    • getTables

      public static List getTables(String serverType, String dbName, boolean includeTables, boolean includeViews, String schema, AdvancedCriteria criteria) throws Exception
      Returns a list of table and/or view names
      Parameters:
      serverType - "sql" or "hibernate", determines the database connection strategy
      dbName - Optionally, the name of the database - if null, uses the default
      includeTables - If true, includes tables in the returned list
      includeViews - If true, includes views in the returned list
      schema - Optionally, the schema name to use to restrict the list. If null, searches all schemas
      criteria - Optionally, an AdvancedCriteria which will be used to filter the full list of tables
      Returns:
      List of table names and remarks
      Throws:
      Exception
    • getSchemas

      public static List getSchemas(String serverType, String dbName, Map criteria) throws Exception
      Returns a list of schemas for the supplied server type and database, optionally matching the supplied criteria
      Parameters:
      serverType - "sql" or "hibernate", determines the database connection strategy
      dbName - Optionally, the name of the database - if null, uses the default
      criteria - Optionally, a Map specifying advanced criteria, which will be used to filter the full list of schemas
      Returns:
      List of schemas
      Throws:
      Exception
    • getSchemas

      public static List getSchemas(String serverType, String dbName, AdvancedCriteria ac) throws Exception
      Returns a list of schemas for the supplied server type and database, optionally matching the supplied AdvancedCriteria
      Parameters:
      serverType - "sql" or "hibernate", determines the database connection strategy
      dbName - Optionally, the name of the database - if null, uses the default
      ac - Optionally, an AdvancedCriteria which will be used to filter the full list of schemas
      Returns:
      List of schemas
      Throws:
      Exception
    • getDataSourceJSONFromTable

      public static String getDataSourceJSONFromTable(String tableName, String serverType, String dbName, String ID, Map properties, String schema) throws Exception
      Returns DataSource configuration as a string of JSON, derived from the table provided. If the serverType is "sql", dbName specifies which database configuration to use, with null meaning the default database configuration. If serverType is "hibernate", database information comes from Hibernate instead.
      Parameters:
      tableName - The name of the table.
      serverType - "sql" or "hibernate"
      dbName - Optionally, the name of the database - if null, uses the default
      ID - Optionally, the ID of the DataSource - if null, uses the tableName
      properties - An optional Map of properties to apply to the derived DataSource
      schema - The name of the schema in which the table will be found. If null, we use the schema declared in the database config block; if no such schema is declared, we use null, which means "all schemas"
      Returns:
      DataSource derived from the table
      Throws:
      Exception
    • getDataSourceFromTable

      public static DataSource getDataSourceFromTable(String tableName, String serverType, String dbName, String ID) throws Exception
      Returns a DataSource derived from the table provided. If the serverType is "sql", dbName specifies which database configuration to use, with null meaning the default database configuration. If serverType is "hibernate", database information comes from Hibernate instead.
      Parameters:
      tableName - The name of the table.
      serverType - "sql" or "hibernate"
      dbName - Optionally, the name of the database - if null, uses the default
      ID - Optionally, the ID of the DataSource - if null, uses the tableName
      Returns:
      DataSource derived from the table
      Throws:
      Exception
    • getDataSourceFromTable

      public static DataSource getDataSourceFromTable(String tableName, String serverType, String dbName, String ID, Map properties, String schema) throws Exception
      Returns a DataSource derived from the table provided. If the serverType is "sql", dbName specifies which database configuration to use, with null meaning the default database configuration. If serverType is "hibernate", database information comes from Hibernate instead.
      Parameters:
      tableName - The name of the table.
      serverType - "sql" or "hibernate"
      dbName - Optionally, the name of the database - if null, uses the default
      ID - Optionally, the ID of the DataSource - if null, uses the tableName
      properties - An optional Map of properties to apply to the derived DataSource
      schema - The name of the schema in which the table will be found. If null, we use the schema declared in the database config block; if no such schema is declared, we use null, which means "all schemas"
      Returns:
      DataSource derived from the table
      Throws:
      Exception
    • getDataSourceJSONFromHibernateMapping

      public static String getDataSourceJSONFromHibernateMapping(String entityName, String ID) throws Exception
      Returns the JSON representation of a DataSource derived from the entity provided.
      Parameters:
      entityName - The name of the Hibernate mapped entity.
      ID - The ID to use for the derived DataSource
      Returns:
      The JSON representation of the DataSource derived from the mapped entity
      Throws:
      Exception
    • getDataSourceFromHibernateMapping

      public static DataSource getDataSourceFromHibernateMapping(String entityName, String ID) throws Exception
      Returns a DataSource derived from the Hibernate entity provided.
      Parameters:
      entityName - The name of the Hibernate mapped entity.
      ID - The ID to use for the derived DataSource
      Returns:
      DataSource derived from the mapped entity
      Throws:
      Exception
    • getFieldsFromTable

      public static List getFieldsFromTable(String tableName, String schema, String serverType, String dbName) throws Exception
      Returns a list of fields in the passed in table, with properties such as type and length inferred from the database metadata.
      Parameters:
      tableName - The name of the table.
      schema - Optionally, the name of the database schema to use (not all databases require - or even recognize the concept of - a schema). If null, looks for the named table in all schemas, and uses the first one it finds if a table of that name exists in more than one schema
      serverType - "sql" or "hibernate", determines the database connection strategy
      dbName - Optionally, the name of the database if serverType is "sql". If null, uses the default
      Returns:
      List of fields in the supplied table
      Throws:
      Exception
    • getDefaultDatabase

      public static String getDefaultDatabase() throws Exception
      Returns the "dbName" os the current default database (server type "sql"), as defined by the server.properties setting sql.defaultDatabase
      Returns:
      String containing the default database dbName
      Throws:
      Exception