Package com.isomorphic.tools
Class DatabaseTools
java.lang.Object
com.isomorphic.tools.DatabaseTools
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 Summary
Modifier and TypeMethodDescriptionstatic DataSourcegetDataSourceFromHibernateMapping(String entityName, String ID) Returns a DataSource derived from the Hibernate entity provided.static DataSourcegetDataSourceFromTable(String tableName, String serverType, String dbName, String ID) Returns a DataSource derived from the table provided.static DataSourcegetDataSourceFromTable(String tableName, String serverType, String dbName, String ID, Map properties, String schema) Returns a DataSource derived from the table provided.static StringgetDataSourceJSONFromHibernateMapping(String entityName, String ID) Returns the JSON representation of a DataSource derived from the entity provided.static StringgetDataSourceJSONFromTable(String tableName, String serverType, String dbName, String ID, Map properties, String schema) Returns DataSource configuration as a string of JSON, derived from the table provided.static StringReturns the "dbName" os the current default database (server type "sql"), as defined by theserver.propertiessettingsql.defaultDatabasestatic ListReturns a List of Maps containing information about defined database connections.static ListgetDefinedDatabases(boolean testConnection) Returns a List of Maps containing information about defined database connectionsstatic ListgetDefinedDatabases(boolean testConnection, AdvancedCriteria criteria) Returns a List of Maps containing information about defined database connectionsstatic ListgetDefinedDatabases(boolean testConnection, Map criteria) Returns a List of Maps containing information about defined database connectionsstatic ListgetFieldsFromTable(String tableName, String schema, String serverType, String dbName) Returns a list of fields in the passed in table, with properties such as type and length inferred from the database metadata.static ListgetSchemas(String serverType, String dbName, AdvancedCriteria ac) Returns a list of schemas for the supplied server type and database, optionally matching the supplied AdvancedCriteriastatic ListgetSchemas(String serverType, String dbName, Map criteria) Returns a list of schemas for the supplied server type and database, optionally matching the supplied criteriastatic ListgetTables(AdvancedCriteria criteria) Returns a list of table and view names for the default server type "sql" database, for all schemas, optionally matching the supplied criteriastatic ListReturns a list of table and view names for the named database (server type "sql"), for all schemasstatic ListgetTables(String dbName, AdvancedCriteria criteria) Returns a list of table and view names for the named database (server type "sql"), for all schemas, optionally matching the supplied criteriastatic ListgetTables(String serverType, String dbName, boolean includeTables, boolean includeViews, String schema, AdvancedCriteria criteria) Returns a list of table and/or view namesstatic ListgetTables(String serverType, String dbName, boolean includeTables, boolean includeViews, String schema, List include, List exclude) Returns a list of table and/or view namesstatic ListgetTables(String dbName, String schema, AdvancedCriteria criteria) Returns a list of table and view names for the named database (server type "sql"), for a named schema, optionally matching the supplied criteria
-
Method Details
-
getDefinedDatabases
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
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
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 connectioncriteria- 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 connectioncriteria- 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 strategydbName- Optionally, the name of the database - if null, uses the defaultincludeTables- If true, includes tables in the returned listincludeViews- If true, includes views in the returned listschema- 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
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
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
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 defaultcriteria- 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 defaultschema- The name of the schema - if null, uses all schemascriteria- 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 strategydbName- Optionally, the name of the database - if null, uses the defaultincludeTables- If true, includes tables in the returned listincludeViews- If true, includes views in the returned listschema- Optionally, the schema name to use to restrict the list. If null, searches all schemascriteria- Optionally, an AdvancedCriteria which will be used to filter the full list of tables- Returns:
- List of table names and remarks
- Throws:
Exception
-
getSchemas
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 strategydbName- Optionally, the name of the database - if null, uses the defaultcriteria- 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 strategydbName- Optionally, the name of the database - if null, uses the defaultac- 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 defaultID- Optionally, the ID of the DataSource - if null, uses the tableNameproperties- An optional Map of properties to apply to the derived DataSourceschema- 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 defaultID- 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 defaultID- Optionally, the ID of the DataSource - if null, uses the tableNameproperties- An optional Map of properties to apply to the derived DataSourceschema- 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 schemaserverType- "sql" or "hibernate", determines the database connection strategydbName- 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
Returns the "dbName" os the current default database (server type "sql"), as defined by theserver.propertiessettingsql.defaultDatabase- Returns:
- String containing the default database dbName
- Throws:
Exception
-