ca.sqlpower.architect
Class ArchitectUtils

java.lang.Object
  extended by ca.sqlpower.architect.ArchitectUtils

public class ArchitectUtils
extends java.lang.Object

Collection of static utility methods for Architect.


Method Summary
static SQLTable addSimulatedTable(SQLDatabase db, java.lang.String catalog, java.lang.String schema, java.lang.String name)
          Creates a SQLTable in the given database, optionally under a catalog and/or schema.
static void addUndoListenerToHierarchy(UndoCompoundEventListener listener, SQLObject source)
          Adds listener to source's listener list and all of source's children's listener lists recursively.
static void addUndoListenerToHierarchy(UndoCompoundEventListener listener, SQLObject[] sources)
          Calls listenToHierarchy on each element in the sources array.
static boolean areEqual(java.lang.Object o1, java.lang.Object o2)
          Does a generic object comparison where one or both of the objects could be null.
static boolean columnsDiffer(SQLColumn targetColumn, SQLColumn sourceColumn)
          Checks if the definitions of two columns are materially different.
static boolean columnTypesDiffer(int t1, int t2)
          Checks if the given column types materially differ.
static void configureLog4j()
          Sets up the log4j logging framework.
static int countTables(SQLObject so)
          Recursively count tables in the project, but only consider tables that have been expanded.
static int countTablesSnapshot(SQLObject so)
          Recursively count tables in the project, including ones that have not been expanded in the DBTree.
static java.util.List<SQLColumn> findColumnsSourcedFromDatabase(SQLDatabase target, SQLDatabase source)
          Searches for all columns in the target database which are marked as having source columns in the given source database.
static
<T extends SQLObject>
java.util.List<T>
findDescendentsByClass(SQLObject so, java.lang.Class<T> clazz, java.util.List<T> addTo)
          Keep in mind that if you go after anything lower than SQLTable, you will invoke a potentially expensive populate() method multiple times.
static
<T extends SQLObject>
T
getAncestor(SQLObject so, java.lang.Class<T> ancestorType)
          Returns the parent database of so or null if so doesn't have an ancestor whose class is ancestorType.
static SQLObject getTableContainer(SQLDatabase db, java.lang.String catName, java.lang.String schemaName)
          Returns the object that contains tables in the given database.
static boolean isCompatibleWithHierarchy(SQLDatabase db, java.lang.String catalog, java.lang.String schema, java.lang.String name)
          Returns true if and only if the given set of arguments would result in a successful call to addSimulatedTable(SQLDatabase, String, String, String).
static void listenToHierarchy(SQLObjectListener listener, SQLObject source)
          Adds listener to source's listener list and all of source's children's listener lists recursively.
static void listenToHierarchy(SQLObjectListener listener, SQLObject[] sources)
          Calls listenToHierarchy on each element in the sources array.
static java.lang.String quoteCSV(java.lang.Object val)
          Double quotes input string for CSV if needed: string contains ", \n, \r, ','
static java.lang.String quoteCSVStr(java.lang.String val)
           
static void startup()
          Performs startup tasks for the architect system.
static java.lang.String toQualifiedName(SQLObject obj)
          Creates a dot-separated string of the name of the given SQLObject and the names of each of its ancestors.
static java.lang.String toQualifiedName(SQLObject obj, java.lang.Class<? extends SQLObject> stopAt)
          Creates a dot-separated string of the name of the given SQLObject and the names of each of its ancestors, stopping at the first ancestor of the given type.
static java.lang.String truncateString(java.lang.String s)
          Chop long strings down to size for display purposes
static void undoUnlistenToHierarchy(UndoCompoundEventListener listener, SQLObject source)
          Removes listener from source's listener list and all of source's children's listener lists recursively.
static void undoUnlistenToHierarchy(UndoCompoundEventListener listener, SQLObject[] sources)
          Calls unlistenToHierarchy on each element in the sources array.
static void unlistenToHierarchy(SQLObjectListener listener, SQLObject source)
          Removes listener from source's listener list and all of source's children's listener lists recursively.
static void unlistenToHierarchy(SQLObjectListener listener, SQLObject[] sources)
          Calls unlistenToHierarchy on each element in the sources array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

startup

public static void startup()
Performs startup tasks for the architect system. You should call this when starting the Architect.


configureLog4j

public static void configureLog4j()
Sets up the log4j logging framework.


listenToHierarchy

public static void listenToHierarchy(SQLObjectListener listener,
                                     SQLObject source)
                              throws ArchitectException
Adds listener to source's listener list and all of source's children's listener lists recursively.

Throws:
ArchitectException

addUndoListenerToHierarchy

public static void addUndoListenerToHierarchy(UndoCompoundEventListener listener,
                                              SQLObject source)
                                       throws ArchitectException
Adds listener to source's listener list and all of source's children's listener lists recursively.

Throws:
ArchitectException

addUndoListenerToHierarchy

public static void addUndoListenerToHierarchy(UndoCompoundEventListener listener,
                                              SQLObject[] sources)
                                       throws ArchitectException
Calls listenToHierarchy on each element in the sources array. Does nothing if sources is null.

Throws:
ArchitectException

listenToHierarchy

public static void listenToHierarchy(SQLObjectListener listener,
                                     SQLObject[] sources)
                              throws ArchitectException
Calls listenToHierarchy on each element in the sources array. Does nothing if sources is null.

Throws:
ArchitectException

undoUnlistenToHierarchy

public static void undoUnlistenToHierarchy(UndoCompoundEventListener listener,
                                           SQLObject source)
                                    throws ArchitectException
Removes listener from source's listener list and all of source's children's listener lists recursively.

Throws:
ArchitectException

undoUnlistenToHierarchy

public static void undoUnlistenToHierarchy(UndoCompoundEventListener listener,
                                           SQLObject[] sources)
                                    throws ArchitectException
Calls unlistenToHierarchy on each element in the sources array. Does nothing if sources is null.

Throws:
ArchitectException

unlistenToHierarchy

public static void unlistenToHierarchy(SQLObjectListener listener,
                                       SQLObject source)
                                throws ArchitectException
Removes listener from source's listener list and all of source's children's listener lists recursively.

Throws:
ArchitectException

unlistenToHierarchy

public static void unlistenToHierarchy(SQLObjectListener listener,
                                       SQLObject[] sources)
                                throws ArchitectException
Calls unlistenToHierarchy on each element in the sources array. Does nothing if sources is null.

Throws:
ArchitectException

areEqual

public static boolean areEqual(java.lang.Object o1,
                               java.lang.Object o2)
Does a generic object comparison where one or both of the objects could be null. If both objects are null, they are considered equal; if only one is null, they are not equal; otherwise they are compared using o1.equals(o2).


findColumnsSourcedFromDatabase

public static java.util.List<SQLColumn> findColumnsSourcedFromDatabase(SQLDatabase target,
                                                                       SQLDatabase source)
                                                                throws ArchitectException
Searches for all columns in the target database which are marked as having source columns in the given source database.

Parameters:
target - The database to search. All columns of all tables in this database are searched.
source - The database to look for in the target database's columns.
Returns:
A list of all columns in the target database whose source database is the same as the given source object. Every item in the list will be of type SQLColumn.
Throws:
ArchitectException

countTablesSnapshot

public static int countTablesSnapshot(SQLObject so)
                               throws ArchitectException
Recursively count tables in the project, including ones that have not been expanded in the DBTree.

Parameters:
source - the source object (usually the database)
Throws:
ArchitectException

findDescendentsByClass

public static <T extends SQLObject> java.util.List<T> findDescendentsByClass(SQLObject so,
                                                                             java.lang.Class<T> clazz,
                                                                             java.util.List<T> addTo)
                                                                  throws ArchitectException
Keep in mind that if you go after anything lower than SQLTable, you will invoke a potentially expensive populate() method multiple times.

Parameters:
source - the source object (usually the database)
Throws:
ArchitectException

truncateString

public static java.lang.String truncateString(java.lang.String s)
Chop long strings down to size for display purposes

Parameters:
s - the input string
Returns:
the truncated string

countTables

public static int countTables(SQLObject so)
                       throws ArchitectException
Recursively count tables in the project, but only consider tables that have been expanded. This might be undercounting a little bit because I think this suppresses the Target Database (playpen) entries.

Parameters:
source - the source object (usually the database)
Throws:
ArchitectException

quoteCSV

public static java.lang.String quoteCSV(java.lang.Object val)
Double quotes input string for CSV if needed: string contains ", \n, \r, ','


quoteCSVStr

public static java.lang.String quoteCSVStr(java.lang.String val)

getAncestor

public static <T extends SQLObject> T getAncestor(SQLObject so,
                                                  java.lang.Class<T> ancestorType)
Returns the parent database of so or null if so doesn't have an ancestor whose class is ancestorType.

Parameters:
so - The object for whose ancestor to look. (Thanks, Winston).
Returns:
The nearest ancestor of type ancestorType, or null if no such ancestor exists.

getTableContainer

public static SQLObject getTableContainer(SQLDatabase db,
                                          java.lang.String catName,
                                          java.lang.String schemaName)
                                   throws ArchitectException
Returns the object that contains tables in the given database. Depending on platform, this could be a SQLDatabase, a SQLCatalog, or a SQLSchema. A null catName or schemName argument means that catalogs or schemas are not present in the given database.

Note, all comparisons are done case-insensitively.

Parameters:
db - The database to retrieve the table container from.
catName - The name of the catalog to retrieve. Must be null iff the database does not have catalogs.
schemaName - The name of the schema to retrieve. Must be null iff the database does not have schemas.
Returns:
The appropriate SQLObject under db that is a parent of SQLTable objects, given the catalog and schema name arguments.
Throws:
ArchitectException

isCompatibleWithHierarchy

public static boolean isCompatibleWithHierarchy(SQLDatabase db,
                                                java.lang.String catalog,
                                                java.lang.String schema,
                                                java.lang.String name)
                                         throws ArchitectException
Returns true if and only if the given set of arguments would result in a successful call to addSimulatedTable(SQLDatabase, String, String, String). See that method's documentation for the meaning of the arguments.

Throws:
ArchitectException - if populating any of the relevant SQLObjects fails.

addSimulatedTable

public static SQLTable addSimulatedTable(SQLDatabase db,
                                         java.lang.String catalog,
                                         java.lang.String schema,
                                         java.lang.String name)
                                  throws ArchitectException
Creates a SQLTable in the given database, optionally under a catalog and/or schema.

Parameters:
db - The database to create the table in.
catalog - The catalog that the table (or the table's schema) should be in. If null, it is assumed the given database doesn't have catalogs.
schema - The schema that the table should be in. If null, it is assumed the given database doesn't have schemas.
name - The name of the table to create.
Returns:
The table that was created
Throws:
ArchitectException - If you specify catalog or schema for a database that doesn't support catalogs or schemas; also if the database uses catalogs and schemas but you fail to provide them.

toQualifiedName

public static java.lang.String toQualifiedName(SQLObject obj)
Creates a dot-separated string of the name of the given SQLObject and the names of each of its ancestors. The top-level ancestor's name will be the first name to appear in the string, and the given object's name will be the last. This is the equivalent of calling toQualifiedName(obj, null).


toQualifiedName

public static java.lang.String toQualifiedName(SQLObject obj,
                                               java.lang.Class<? extends SQLObject> stopAt)
Creates a dot-separated string of the name of the given SQLObject and the names of each of its ancestors, stopping at the first ancestor of the given type. The top-level ancestor's name will be the first name to appear in the string, and the given object's name will be the last.

Parameters:
obj - The object whose qualified name you wish to obtain
stopAt - The class of ancestor to stop at. The name of this ancestor will not be included in the returned string. If stopAt is null, or a class which is not an ancestor of the given SQLObject, the returned string will contain all ancestor object names up to the root of the SQLObject tree.

columnsDiffer

public static boolean columnsDiffer(SQLColumn targetColumn,
                                    SQLColumn sourceColumn)
Checks if the definitions of two columns are materially different. Some data types (for example, DECIMAL and NUMERIC) are essentially the same. Also, the precision and scale values on DATE columns are not of much consequence, but different databases report different values.

Parameters:
targetColumn - One of the columns to compare. Must not be null.
sourceColumn - One of the columns to compare. Must not be null.
Returns:
True iff the source and target columns are materially different (as in, they are unlikely to be able to hold the same set of data as each other)

columnTypesDiffer

public static boolean columnTypesDiffer(int t1,
                                        int t2)
Checks if the given column types materially differ. Some data types (for example, DECIMAL and NUMERIC) are essentially the same.

Parameters:
t1 - One of the column types to compare
t2 - One of the column types to compare.
Returns:
True iff the given column types are materially different


Copyright © 2003-2007 SQL Power Group Inc. www.sqlpower.ca