ca.sqlpower.architect.olap
Class OLAPUtil

java.lang.Object
  extended by ca.sqlpower.architect.olap.OLAPUtil

public class OLAPUtil
extends java.lang.Object

A collection of static utility methods for working with the OLAP classes.


Method Summary
static MondrianModel.Cube findReferencedCube(MondrianModel.VirtualCube vCube, MondrianModel.CubeUsage cu)
          Finds and returns the Cube that the given CubeUsage references.
static MondrianModel.Dimension findReferencedDimension(MondrianModel.CubeDimension cubeDim)
          Finds and returns the base Dimension that the given CubeDimension references.
static java.util.List<SQLTable> getAvailableTables(OLAPObject obj)
          Compiles a list of all accessible tables in the database being used by this OLAP object's session.
static java.lang.String getQualifier(SQLTable t)
          Mondrian uses a single string as a table name qualifier, so this method helps by finding the parent schema and/or catalog and produces the correct Mondrian qualifier for the given table.
static OLAPSession getSession(OLAPObject oo)
          Finds the OLAPSession that owns the given OLAPObject, by following parent pointers successively until an ancestor of type OLAPSession is encountered.
static SQLTable getSQLTableFromOLAPTable(SQLDatabase database, MondrianModel.Table table)
          Search the database and retrieve the matching SQLTable(Relational) object thats logically equivalent to the given Table(OLAP representation)
static boolean isNameUnique(OLAPObject parent, java.lang.Class<? extends OLAPObject> type, java.lang.String name)
          Checks if the name is unique for an OLAPObject, relies on OLAPObject.getName() for name comparisons, case insensitive.
static void listenToHierarchy(OLAPObject root, OLAPChildListener ocl, java.beans.PropertyChangeListener pcl)
          Adds the given OLAPChildListener and optional PropertyChangeListener to the given root object and all of its descendants.
static void listenToHierarchy(OLAPObject root, OLAPChildListener ocl, java.beans.PropertyChangeListener pcl, CompoundEditListener cel)
          Adds the given OLAPChildListener and optional PropertyChangeListener to the given root object and all of its descendants.
static java.lang.String nameFor(OLAPObject obj)
          OLAPObject.getName() does not always return the correct name so this method helps by finding the proper name for those exceptions and returns the correct value.
static SQLTable tableForCube(MondrianModel.Cube cube)
          Retrieves the SQLTable that represents the data source for the given cube.
static SQLTable tableForHierarchy(MondrianModel.Hierarchy hier)
          Retrieves the SQLTable that represents the data source for the given hierarchy.
static void unlistenToHierarchy(OLAPObject root, OLAPChildListener ocl, java.beans.PropertyChangeListener pcl)
          Removes the given OLAPChildListener and optional PropertyChangeListener from the given root object and all of its descendants.
static void unlistenToHierarchy(OLAPObject root, OLAPChildListener ocl, java.beans.PropertyChangeListener pcl, CompoundEditListener cel)
          Removes the given OLAPChildListener and optional PropertyChangeListener from the given root object and all of its descendants.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSession

public static OLAPSession getSession(OLAPObject oo)
Finds the OLAPSession that owns the given OLAPObject, by following parent pointers successively until an ancestor of type OLAPSession is encountered. If there is no OLAPSession ancestor, returns null.

Note that when we say ancestor in this doc comment, we include the given oo object as an "ancestor" of itself. In other words, if you pass in an OLAPSession, you will get that same object back.

Parameters:
oo - The object to start searching at
Returns:
The nearest ancestor of type OLAPObject, or null if there is no such ancestor.

getQualifier

public static java.lang.String getQualifier(SQLTable t)
Mondrian uses a single string as a table name qualifier, so this method helps by finding the parent schema and/or catalog and produces the correct Mondrian qualifier for the given table.


listenToHierarchy

public static void listenToHierarchy(OLAPObject root,
                                     OLAPChildListener ocl,
                                     java.beans.PropertyChangeListener pcl,
                                     CompoundEditListener cel)
Adds the given OLAPChildListener and optional PropertyChangeListener to the given root object and all of its descendants.

Parameters:
ocl - The OLAPChildListener to add to the subtree of OLAPObjects rooted at root.
pcl - The PropertyChangeListener to add to the subtree of OLAPObjects rooted at root. If you don't want to know about property changes to the nodes themselves, you can leave this parameter as null.
cel - The CompoundEditListener to add to the subtree of OLAPObjects rooted at root. If you don't want to know about compound edit groupings, you can leave this parameter as null.

listenToHierarchy

public static void listenToHierarchy(OLAPObject root,
                                     OLAPChildListener ocl,
                                     java.beans.PropertyChangeListener pcl)
Adds the given OLAPChildListener and optional PropertyChangeListener to the given root object and all of its descendants.

Parameters:
ocl - The OLAPChildListener to add to the subtree of OLAPObjects rooted at root.
pcl - The PropertyChangeListener to add to the subtree of OLAPObjects rooted at root. If you don't want to know about property changes to the nodes themselves, you can leave this parameter as null.

unlistenToHierarchy

public static void unlistenToHierarchy(OLAPObject root,
                                       OLAPChildListener ocl,
                                       java.beans.PropertyChangeListener pcl,
                                       CompoundEditListener cel)
Removes the given OLAPChildListener and optional PropertyChangeListener from the given root object and all of its descendants.

Parameters:
ocl - The OLAPChildListener to remove from the subtree of OLAPObjects rooted at root. It is not an error if the listener is not registered with any or all of the objects in the subtree, so it's safe to call this with the root of the tree if you want.
pcl - The PropertyChangeListener to add to the subtree of OLAPObjects rooted at root. It is not an error if the listener is not registered with any or all of the objects in the subtree, so it's safe to call this with the root of the tree if you want. If you weren't listening for property change events, you can leave this parameter as null. Note that this parameter is pronounced "pockle," not "pickle."
cel - The CompoundEditListener to add to the subtree of OLAPObjects rooted at root. It is not an error if the listener is not registered with any or all of the objects in the subtree, so it's safe to call this with the root of the tree if you want. If you weren't listening for compound edit events, you can leave this parameter as null.

unlistenToHierarchy

public static void unlistenToHierarchy(OLAPObject root,
                                       OLAPChildListener ocl,
                                       java.beans.PropertyChangeListener pcl)
Removes the given OLAPChildListener and optional PropertyChangeListener from the given root object and all of its descendants.

Parameters:
ocl - The OLAPChildListener to remove from the subtree of OLAPObjects rooted at root. It is not an error if the listener is not registered with any or all of the objects in the subtree, so it's safe to call this with the root of the tree if you want.
pcl - The PropertyChangeListener to add to the subtree of OLAPObjects rooted at root. It is not an error if the listener is not registered with any or all of the objects in the subtree, so it's safe to call this with the root of the tree if you want. If you weren't listening for property change events, you can leave this parameter as null. Note that this parameter is pronounced "pockle," not "pickle."

nameFor

public static java.lang.String nameFor(OLAPObject obj)
OLAPObject.getName() does not always return the correct name so this method helps by finding the proper name for those exceptions and returns the correct value.

Parameters:
obj - The object to find the name of.
Returns:
The name of the given object, null if the object is null itself.

tableForHierarchy

public static SQLTable tableForHierarchy(MondrianModel.Hierarchy hier)
                                  throws ArchitectException
Retrieves the SQLTable that represents the data source for the given hierarchy.

Parameters:
hierarchy - the hierarchy whose data source to retrieve
Returns:
The table whose columns represent the columns of hierarchy's source table (or view, inline table, or join), or null if the hierarchy has no table selected.
Throws:
ArchitectException - if populating the necessary SQLObjects fails

tableForCube

public static SQLTable tableForCube(MondrianModel.Cube cube)
                             throws ArchitectException
Retrieves the SQLTable that represents the data source for the given cube.

Parameters:
cube - The cube whose data source to retrieve.
Returns:
The table whose columns represent the columns of cube's source table (or view, inline table, or join), or null if the cube has no table set.
Throws:
ArchitectException - if populating the necessary SQLObjects fails.

getSQLTableFromOLAPTable

public static SQLTable getSQLTableFromOLAPTable(SQLDatabase database,
                                                MondrianModel.Table table)
                                         throws ArchitectException
Search the database and retrieve the matching SQLTable(Relational) object thats logically equivalent to the given Table(OLAP representation)

Parameters:
table - Table object representing a table in a relational database
Returns:
a SQLTable in SQLDatabase representing the given table
Throws:
ArchitectException

getAvailableTables

public static java.util.List<SQLTable> getAvailableTables(OLAPObject obj)
                                                   throws ArchitectException
Compiles a list of all accessible tables in the database being used by this OLAP object's session.

Parameters:
obj - An object in the session you want the table list for.
Returns:
The list of all accessible tables. If the OLAP session doesn't have a database chosen, an empty list is returned.
Throws:
ArchitectException - If there is a problem populating the list of tables (for example, the database might not be reachable).

findReferencedCube

public static MondrianModel.Cube findReferencedCube(MondrianModel.VirtualCube vCube,
                                                    MondrianModel.CubeUsage cu)
Finds and returns the Cube that the given CubeUsage references.

Parameters:
vCube - Parent of the CubeUsage, used to find OLAPSession ancestor.
CubeUsage - The CubeUsage to search by.
Returns:
The Cube that the CubeUsage references, or null if not found.

findReferencedDimension

public static MondrianModel.Dimension findReferencedDimension(MondrianModel.CubeDimension cubeDim)
Finds and returns the base Dimension that the given CubeDimension references. It is safe to call this method with a Dimension as parameter, it will just return the same object.

Parameters:
cubeDim - The CubeDimension to search by, OLAPSession ancestor must not be null.
Returns:
The base Dimension that the CubeDimension represents, or null if not found.

isNameUnique

public static boolean isNameUnique(OLAPObject parent,
                                   java.lang.Class<? extends OLAPObject> type,
                                   java.lang.String name)
Checks if the name is unique for an OLAPObject, relies on OLAPObject.getName() for name comparisons, case insensitive.

Parameters:
parent - The object that will be the parent.
type - The type of the object.
name - The name to check for, can be null.
Returns:
False if any child of the given type from the parent has the given name, true otherwise.


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