ca.sqlpower.architect.profile
Class ProfileManagerImpl

java.lang.Object
  extended by ca.sqlpower.architect.profile.ProfileManagerImpl
All Implemented Interfaces:
ProfileManager

public class ProfileManagerImpl
extends java.lang.Object
implements ProfileManager

The default ProfileManager implementation. Creates profiles of tables, optionally using a separate worker thread.

Version:
$Id: ProfileManagerImpl.java 2099 2008-03-25 14:38:28Z jeffrey@sqlpower.ca $

Constructor Summary
ProfileManagerImpl(ArchitectSession session)
           
 
Method Summary
 void addProfileChangeListener(ProfileChangeListener listener)
          Adds the given listener to this profile manager.
 java.util.Collection<java.util.concurrent.Future<TableProfileResult>> asynchCreateProfiles(java.util.Collection<SQLTable> tables)
          Creates TableProfileResult objects for each of the tables in the given list, then adds them to this ProfileManager in an unpopulated state.
 void clear()
          Removes all contents of the list of TableProfileResults that this ProfileManager keeps track of and fires a ProfileChanged event.
 void close()
          Closes the Executor service.
 TableProfileResult createProfile(SQLTable table)
          Creates a new profile result for the given table, and adds it to this ProfileManager.
 TableProfileCreator getCreator()
          Returns the current profile creator in use.
 ProfileSettings getDefaultProfileSettings()
          Returns the current default settings for new profile runs in this Profile Manager.
 java.util.List<TableProfileCreator> getProfileCreators()
          Returns a list of the different types of profile creators.
 java.util.List<TableProfileResult> getResults()
          Returns an unmodifiable snapshot of the list of all TableProfileResults that this ProfileManager keeps track of.
 java.util.List<TableProfileResult> getResults(SQLTable t)
          Returns an unmodifiable list of all TableProfileResults for the given table.
 void loadResult(ProfileResult pr)
          This is a hook designed so the SwingUIProject can insert profile results into this profile manager as it is reading in a project file.
 boolean removeProfile(TableProfileResult victim)
          Removes a single TableProfileResult from the List of TableProfileResults that this ProfileManager keeps track of.
 void removeProfileChangeListener(ProfileChangeListener listener)
          Removes the given listener.
 java.util.concurrent.Future<TableProfileResult> scheduleProfile(TableProfileResult result)
          Schedules a profile to be populated on a separate worker thread.
 void setCreator(TableProfileCreator tpc)
          Sets the profile manager to use the given profile creator.
 void setDefaultProfileSettings(ProfileSettings settings)
          Sets the defaults for new profiles created by this profile manager.
 void setProcessingOrder(java.util.List<TableProfileResult> tpr)
          Modifies the order in which profile results will be calculated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProfileManagerImpl

public ProfileManagerImpl(ArchitectSession session)
Method Detail

createProfile

public TableProfileResult createProfile(SQLTable table)
                                 throws ArchitectException
Description copied from interface: ProfileManager
Creates a new profile result for the given table, and adds it to this ProfileManager. The act of adding a profile causes this ProfileManager to fire a profileAdded event.

This method operates synchronously, so it will not return until the profile has been created (which could be several seconds to several minutes). For use from a Swing GUI, consider ProfileManager.asynchCreateProfiles(Collection).

Specified by:
createProfile in interface ProfileManager
Throws:
ArchitectException

asynchCreateProfiles

public java.util.Collection<java.util.concurrent.Future<TableProfileResult>> asynchCreateProfiles(java.util.Collection<SQLTable> tables)
Description copied from interface: ProfileManager
Creates TableProfileResult objects for each of the tables in the given list, then adds them to this ProfileManager in an unpopulated state. Then starts a new worker thread which will populate the results one after the other. It is likely that none of the profiles will be populated yet by the time this method returns.

Specified by:
asynchCreateProfiles in interface ProfileManager

scheduleProfile

public java.util.concurrent.Future<TableProfileResult> scheduleProfile(TableProfileResult result)
Description copied from interface: ProfileManager
Schedules a profile to be populated on a separate worker thread. You will not normally need to call this method, since it is done for you by ProfileManager.asynchCreateProfiles(Collection). The use case is for re-trying profile results that have been canceled by the user before they managed to fully populate.

Specified by:
scheduleProfile in interface ProfileManager
Parameters:
result - The result object to reschedule for profiling. It must already be owned by this profile manager, and must not be in the process of profiling, and also not already finished profiling.

clear

public void clear()
Description copied from interface: ProfileManager
Removes all contents of the list of TableProfileResults that this ProfileManager keeps track of and fires a ProfileChanged event.

Specified by:
clear in interface ProfileManager

getResults

public java.util.List<TableProfileResult> getResults()
Description copied from interface: ProfileManager
Returns an unmodifiable snapshot of the list of all TableProfileResults that this ProfileManager keeps track of. You may get multiple ProfileResults for one table since you are allowed to have multiple profiles of a single table that come from different times the profiling was done.

Specified by:
getResults in interface ProfileManager

getResults

public java.util.List<TableProfileResult> getResults(SQLTable t)
Description copied from interface: ProfileManager
Returns an unmodifiable list of all TableProfileResults for the given table. You may get multiple ProfileResults for one table since you are allowed to have multiple profiles of a single table that come from different times the profiling was done. Returns an empty list if there are no profiles for the given table.

Specified by:
getResults in interface ProfileManager

removeProfile

public boolean removeProfile(TableProfileResult victim)
Description copied from interface: ProfileManager
Removes a single TableProfileResult from the List of TableProfileResults that this ProfileManager keeps track of. If the remove was successful then this method will fire a ProfileRemoved event and return true.

Specified by:
removeProfile in interface ProfileManager

getDefaultProfileSettings

public ProfileSettings getDefaultProfileSettings()
Description copied from interface: ProfileManager
Returns the current default settings for new profile runs in this Profile Manager.

Specified by:
getDefaultProfileSettings in interface ProfileManager

setDefaultProfileSettings

public void setDefaultProfileSettings(ProfileSettings settings)
Description copied from interface: ProfileManager
Sets the defaults for new profiles created by this profile manager.

Specified by:
setDefaultProfileSettings in interface ProfileManager

setProcessingOrder

public void setProcessingOrder(java.util.List<TableProfileResult> tpr)
Description copied from interface: ProfileManager
Modifies the order in which profile results will be calculated.

Specified by:
setProcessingOrder in interface ProfileManager
Parameters:
tpr - A list of pending profile results that were already part of this profile manager, but have not been calculated yet.

loadResult

public void loadResult(ProfileResult pr)
This is a hook designed so the SwingUIProject can insert profile results into this profile manager as it is reading in a project file. It is not appropriate to use otherwise.

This method fires an event every time it adds a table profile result, because not doing so makes it necessary to create the profile manager view after loading in the profile results, and it is impossible to guarantee that policy from here.

The idea is, the SwingUIProject stores all profile results in a flat space (table and column results are sibling elements) so it needs our help to put everything back together into the original hierarchy. This method hangs onto all TableProfileResult objects given to it, and ignores all other result types, assuming the client code will do the appropriate hookups.

You might be asking yourself, "why not store the profile results in the same hierarchy as they had when they were originally created, so we don't need any more error-prone code to recreate what we already had and then threw away? Beside reducing bugs, it would eliminate the need for this public method and accompanying docs that warn you against using it." If so, please apply to SQL Power at hr (@) sqlpower.ca.


addProfileChangeListener

public void addProfileChangeListener(ProfileChangeListener listener)
Adds the given listener to this profile manager. The listener will be notified of additions and removals of results in this profile manager.

Specified by:
addProfileChangeListener in interface ProfileManager

removeProfileChangeListener

public void removeProfileChangeListener(ProfileChangeListener listener)
Removes the given listener. After removal, the listener will no longer be notified of changes to this profile manager.

Specified by:
removeProfileChangeListener in interface ProfileManager

close

public void close()
Description copied from interface: ProfileManager
Closes the Executor service. This stops it from running any further jobs.

Specified by:
close in interface ProfileManager

getProfileCreators

public java.util.List<TableProfileCreator> getProfileCreators()
Description copied from interface: ProfileManager
Returns a list of the different types of profile creators.

Specified by:
getProfileCreators in interface ProfileManager
Returns:
a List of the possible profile creators

getCreator

public TableProfileCreator getCreator()
Description copied from interface: ProfileManager
Returns the current profile creator in use.

Specified by:
getCreator in interface ProfileManager
Returns:
the currently used profile creator object

setCreator

public void setCreator(TableProfileCreator tpc)
Description copied from interface: ProfileManager
Sets the profile manager to use the given profile creator.

Specified by:
setCreator in interface ProfileManager
Parameters:
tpc - the profile creator to use, must not be null.


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