ca.sqlpower.wabit
Class WabitSessionContextImpl

java.lang.Object
  extended by ca.sqlpower.wabit.WabitSessionContextImpl
All Implemented Interfaces:
ca.sqlpower.sqlobject.SQLDatabaseMapping, ca.sqlpower.util.UserPrompterFactory, OlapConnectionMapping, WabitSessionContext

public class WabitSessionContextImpl
extends java.lang.Object
implements WabitSessionContext

This is the canonical headless implementation of WabitSessionContext interface. Other session context implementations that cover more specialized use cases can either extend this one or delegate certain operations to it.


Nested Class Summary
 
Nested classes/interfaces inherited from interface ca.sqlpower.util.UserPrompterFactory
ca.sqlpower.util.UserPrompterFactory.UserPromptType
 
Field Summary
protected  java.util.List<WabitSession> childSessions
           
protected  javax.jmdns.JmDNS jmdns
           
protected  java.util.prefs.Preferences prefs
          This prefs node stores context specific prefs.
static java.lang.String PREFS_PL_INI_PATH
          This is a preference that stores the location of the pl.ini.
protected  boolean terminateWhenLastSessionCloses
          If this flag is true, this session context will halt the VM when its last session closes.
 
Fields inherited from interface ca.sqlpower.wabit.WabitSessionContext
DISABLE_QUERY_AUTO_EXECUTE, NEW_WORKSPACE_URL, WABIT_ENTERPRISE_SERVER_MDNS_TYPE
 
Constructor Summary
WabitSessionContextImpl(boolean terminateWhenLastSessionCloses, boolean useJmDNS, ca.sqlpower.sql.DataSourceCollection<ca.sqlpower.sql.SPDataSource> initialCollection, java.lang.String dataSourceCollectionPath, boolean writeDSCollectionPathToPrefs)
          Creates a new Wabit session context.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
           
 void addServer(WabitServerInfo serverInfo)
          Adds a new user-configured server specification to this context.
 void addServerListListener(ServerListListener l)
          This listener will be notified when server information is added or removed from the server list.
 java.sql.Connection borrowConnection(ca.sqlpower.sql.JDBCDataSource dataSource)
          Borrows a connection to the given data source from this session's connection pool.
 void close()
          This will attempt to close all of the currently opened sessions and stop the app.
 org.olap4j.OlapConnection createConnection(ca.sqlpower.sql.Olap4jDataSource dataSource)
          This method returns an OlapConnection that has been mapped to an Olap4jDataSource.
 ca.sqlpower.util.UserPrompter createDatabaseUserPrompter(java.lang.String question, java.util.List<java.lang.Class<? extends ca.sqlpower.sql.SPDataSource>> dsTypes, ca.sqlpower.util.UserPrompter.UserPromptOptions optionType, ca.sqlpower.util.UserPrompter.UserPromptResponse defaultResponseType, java.lang.Object defaultResponse, ca.sqlpower.sql.DataSourceCollection<ca.sqlpower.sql.SPDataSource> dsCollection, java.lang.String... buttonNames)
           
 WabitSession createServerSession(WabitServerInfo serverInfo)
          This will create an appropriate server session for the current context.
 WabitSession createSession()
          This will create an appropriate local session for the current context.
 ca.sqlpower.util.UserPrompter createUserPrompter(java.lang.String question, ca.sqlpower.util.UserPrompterFactory.UserPromptType responseType, ca.sqlpower.util.UserPrompter.UserPromptOptions optionType, ca.sqlpower.util.UserPrompter.UserPromptResponse defaultResponseType, java.lang.Object defaultResponse, java.lang.String... buttonNames)
          Returns a user prompter that always gives the default response, since this is a headless session context and there is no user to ask.
 void endLoading()
          The DAO can tell this context that it's no longer being configured based on a workspace file being loaded.
 WabitSession getActiveSession()
          Returns the session that the user is currently viewing or editing.
 ca.sqlpower.sqlobject.SQLDatabase getDatabase(ca.sqlpower.sql.JDBCDataSource dataSource)
           
 ca.sqlpower.sql.DataSourceCollection<ca.sqlpower.sql.SPDataSource> getDataSources()
          Tries to read the plDotIni if it hasn't been done already.
 java.util.List<WabitServerInfo> getEnterpriseServers(boolean includeDiscovered)
          Returns the list of currently-known enterprise servers.
 javax.jmdns.JmDNS getJmDNS()
          Returns the JmDNS instance in this session context.
 java.lang.String getName()
          Returns the name for this session context.
 java.util.prefs.Preferences getPrefs()
          Returns the preferences node used by this session context.
 int getRowLimit()
          Returns the number of rows that should be retrieved from the database for any result set.
 int getSessionCount()
          Returns the number of active sessions in the context.
 java.util.List<WabitSession> getSessions()
          Returns an unmodifiable list of the active sessions in the context.
 boolean isLoading()
          Tells whether or not this session is currently being configured by a DAO.
 boolean isMacOSX()
          returns true if the OS is Mac
 void registerChildSession(WabitSession child)
          Adds the given Wabit session to the list of child sessions for this context.
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
           
 void removeServer(WabitServerInfo serverInfo)
          Removes a new user-configured server specification from this context.
 void removeServerListListener(ServerListListener l)
          This listener will stop being notified when server information is added or removed from the server list.
 void setActiveSession(WabitSession activeSession)
          Sets the active session that is being viewed or modified.
protected  void setPlDotIniPath(java.lang.String plDotIniPath)
           
 void startLoading()
          The DAO can tell this context that it's currently being configured based on a workspace file being loaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PREFS_PL_INI_PATH

public static final java.lang.String PREFS_PL_INI_PATH
This is a preference that stores the location of the pl.ini.

See Also:
Constant Field Values

jmdns

protected javax.jmdns.JmDNS jmdns

childSessions

protected final java.util.List<WabitSession> childSessions

terminateWhenLastSessionCloses

protected boolean terminateWhenLastSessionCloses
If this flag is true, this session context will halt the VM when its last session closes.


prefs

protected final java.util.prefs.Preferences prefs
This prefs node stores context specific prefs. At current this is the pl.ini location.

Constructor Detail

WabitSessionContextImpl

public WabitSessionContextImpl(boolean terminateWhenLastSessionCloses,
                               boolean useJmDNS,
                               ca.sqlpower.sql.DataSourceCollection<ca.sqlpower.sql.SPDataSource> initialCollection,
                               java.lang.String dataSourceCollectionPath,
                               boolean writeDSCollectionPathToPrefs)
                        throws java.io.IOException,
                               ca.sqlpower.sqlobject.SQLObjectException
Creates a new Wabit session context.

Parameters:
terminateWhenLastSessionCloses - If this flag is true, this session context will halt the VM when its last session closes.
useJmDNS - If this flag is true, then this session will create a JmDNS instance for searching for Wabit servers.
initialCollection - The default collection of data sources for this context.
dataSourceCollectionPath - The path to the file representing the data source collection. This will be used to write changes to the collection to save the collection's state. If this is null then no data source collection files will be modified.
writeDSCollectionPathToPrefs - If true the location of the data source collection file will be saved to Java Prefs. If false the current location of the data source collection file will be left as is.
Throws:
java.io.IOException - If the startup configuration files can't be read
ca.sqlpower.sqlobject.SQLObjectException - If the pl.ini is invalid.
Method Detail

registerChildSession

public void registerChildSession(WabitSession child)
Adds the given Wabit session to the list of child sessions for this context. This is normally done by the sessions themselves, so you shouldn't need to call this method from your own code.

Specified by:
registerChildSession in interface WabitSessionContext

getDataSources

public ca.sqlpower.sql.DataSourceCollection<ca.sqlpower.sql.SPDataSource> getDataSources()
Tries to read the plDotIni if it hasn't been done already. If it can't be read, returns null and leaves the plDotIni property as null as well. See #plDotIni.

Specified by:
getDataSources in interface WabitSessionContext

isMacOSX

public boolean isMacOSX()
returns true if the OS is Mac

Specified by:
isMacOSX in interface WabitSessionContext
Returns:

createSession

public WabitSession createSession()
Description copied from interface: WabitSessionContext
This will create an appropriate local session for the current context. Registering the session with the context should be done immediately or shortly after creating the session.

Specified by:
createSession in interface WabitSessionContext

setPlDotIniPath

protected void setPlDotIniPath(java.lang.String plDotIniPath)

getSessionCount

public int getSessionCount()
Description copied from interface: WabitSessionContext
Returns the number of active sessions in the context.

Specified by:
getSessionCount in interface WabitSessionContext

close

public void close()
Description copied from interface: WabitSessionContext
This will attempt to close all of the currently opened sessions and stop the app. Each session will close independently and if any one session does not close successfully then the closing operation will stop. Once all sessions have been properly closed the app will terminate. If not all sessions are properly closed the app will not terminate.

Specified by:
close in interface WabitSessionContext

getJmDNS

public javax.jmdns.JmDNS getJmDNS()
Returns the JmDNS instance in this session context. Note that if this session context was initialzed not to use JmDNS, it will return null.

Specified by:
getJmDNS in interface WabitSessionContext

getEnterpriseServers

public java.util.List<WabitServerInfo> getEnterpriseServers(boolean includeDiscovered)
Description copied from interface: WabitSessionContext
Returns the list of currently-known enterprise servers. This list will change over time, and may be empty for the first few seconds after startup.

Specified by:
getEnterpriseServers in interface WabitSessionContext
Parameters:
includeDiscovered - if true, all known servers will be returned whether they were configured explicitly or discovered dynamically. If false, only the explicitly configured servers will be listed.
Returns:
contact information for the known enterprise servers

addServer

public void addServer(WabitServerInfo serverInfo)
Description copied from interface: WabitSessionContext
Adds a new user-configured server specification to this context. The information will be added to the WabitSessionContext.getEnterpriseServers(boolean) list immediately, and also stored persistently so it will be included in the enterprise server list in future incarnations of WabitSessionContext.

Specified by:
addServer in interface WabitSessionContext
Parameters:
serverInfo - The serverInfo object to add.

removeServer

public void removeServer(WabitServerInfo serverInfo)
Description copied from interface: WabitSessionContext
Removes a new user-configured server specification from this context. The information will be removed immediately in the current context, and also from persistent storage.

Specified by:
removeServer in interface WabitSessionContext

addServerListListener

public void addServerListListener(ServerListListener l)
Description copied from interface: WabitSessionContext
This listener will be notified when server information is added or removed from the server list.

Specified by:
addServerListListener in interface WabitSessionContext

removeServerListListener

public void removeServerListListener(ServerListListener l)
Description copied from interface: WabitSessionContext
This listener will stop being notified when server information is added or removed from the server list.

Specified by:
removeServerListListener in interface WabitSessionContext

getPrefs

public java.util.prefs.Preferences getPrefs()
Returns the preferences node used by this session context. This should not normally be used by client code; it is primarily intended for use by alternative session and session context implementations.

Specified by:
getPrefs in interface WabitSessionContext

getName

public java.lang.String getName()
Description copied from interface: WabitSessionContext
Returns the name for this session context. If this is server session, then return the server's name, returns "Local" otherwise.

Specified by:
getName in interface WabitSessionContext

createUserPrompter

public ca.sqlpower.util.UserPrompter createUserPrompter(java.lang.String question,
                                                        ca.sqlpower.util.UserPrompterFactory.UserPromptType responseType,
                                                        ca.sqlpower.util.UserPrompter.UserPromptOptions optionType,
                                                        ca.sqlpower.util.UserPrompter.UserPromptResponse defaultResponseType,
                                                        java.lang.Object defaultResponse,
                                                        java.lang.String... buttonNames)
Returns a user prompter that always gives the default response, since this is a headless session context and there is no user to ask.

Specified by:
createUserPrompter in interface ca.sqlpower.util.UserPrompterFactory

getSessions

public java.util.List<WabitSession> getSessions()
Description copied from interface: WabitSessionContext
Returns an unmodifiable list of the active sessions in the context.

Specified by:
getSessions in interface WabitSessionContext

borrowConnection

public java.sql.Connection borrowConnection(ca.sqlpower.sql.JDBCDataSource dataSource)
                                     throws ca.sqlpower.sqlobject.SQLObjectException
Description copied from interface: WabitSessionContext
Borrows a connection to the given data source from this session's connection pool. You must call Connection.close() on the returned object as soon as you are finished with it.

Design note: Equivalent to #getDatabase(SPDataSource) .getConnection(). Normally we discourage adding convenience methods to an interface, and this is indeed a convenience method on an interface. The reason for this method is to reinforce the idea that connections to data sources must be obtained via the SQLDatabase object held in the session.

Specified by:
borrowConnection in interface WabitSessionContext
Parameters:
dataSource - The data source this connection comes from.
Returns:
A connection to the given data source, which has been obtained from a connection pool that this session owns.
Throws:
ca.sqlpower.sqlobject.SQLObjectException - if it is not currently possible to connect to the given data source. This could be due to the remote database being unavailable, or an incorrect username or password, a missing JDBC driver, or many other things.

getRowLimit

public int getRowLimit()
Description copied from interface: WabitSessionContext
Returns the number of rows that should be retrieved from the database for any result set.

Specified by:
getRowLimit in interface WabitSessionContext

isLoading

public boolean isLoading()
Description copied from interface: WabitSessionContext
Tells whether or not this session is currently being configured by a DAO. It's not normally necessary to know this from outside the session, but this method had to be public because it's part of the interface.

Specified by:
isLoading in interface WabitSessionContext

startLoading

public void startLoading()
Description copied from interface: WabitSessionContext
The DAO can tell this context that it's currently being configured based on a workspace file being loaded. When this is the case, certain things (such as GUI updates) will not be performed. If you're not a DAO, it's not necessary or desirable for you to call this method!

Specified by:
startLoading in interface WabitSessionContext

endLoading

public void endLoading()
Description copied from interface: WabitSessionContext
The DAO can tell this context that it's no longer being configured based on a workspace file being loaded. When this is the case, certain things (such as GUI updates) will not be performed. If you're not a DAO, it's not necessary or desirable for you to call this method!

Specified by:
endLoading in interface WabitSessionContext

getDatabase

public ca.sqlpower.sqlobject.SQLDatabase getDatabase(ca.sqlpower.sql.JDBCDataSource dataSource)
Specified by:
getDatabase in interface ca.sqlpower.sqlobject.SQLDatabaseMapping

createConnection

public org.olap4j.OlapConnection createConnection(ca.sqlpower.sql.Olap4jDataSource dataSource)
                                           throws java.sql.SQLException,
                                                  java.lang.ClassNotFoundException,
                                                  javax.naming.NamingException
Description copied from interface: OlapConnectionMapping
This method returns an OlapConnection that has been mapped to an Olap4jDataSource. This connection should not be closed as other objects may be using it to access the data source.

Specified by:
createConnection in interface OlapConnectionMapping
Throws:
java.sql.SQLException
java.lang.ClassNotFoundException
javax.naming.NamingException

createDatabaseUserPrompter

public ca.sqlpower.util.UserPrompter createDatabaseUserPrompter(java.lang.String question,
                                                                java.util.List<java.lang.Class<? extends ca.sqlpower.sql.SPDataSource>> dsTypes,
                                                                ca.sqlpower.util.UserPrompter.UserPromptOptions optionType,
                                                                ca.sqlpower.util.UserPrompter.UserPromptResponse defaultResponseType,
                                                                java.lang.Object defaultResponse,
                                                                ca.sqlpower.sql.DataSourceCollection<ca.sqlpower.sql.SPDataSource> dsCollection,
                                                                java.lang.String... buttonNames)
Specified by:
createDatabaseUserPrompter in interface ca.sqlpower.util.UserPrompterFactory

getActiveSession

public WabitSession getActiveSession()
Description copied from interface: WabitSessionContext
Returns the session that the user is currently viewing or editing.

Specified by:
getActiveSession in interface WabitSessionContext

setActiveSession

public void setActiveSession(WabitSession activeSession)
Description copied from interface: WabitSessionContext
Sets the active session that is being viewed or modified. Some events that depend on a session will act on the active session.

Specified by:
setActiveSession in interface WabitSessionContext

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Specified by:
addPropertyChangeListener in interface WabitSessionContext

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Specified by:
removePropertyChangeListener in interface WabitSessionContext

createServerSession

public WabitSession createServerSession(WabitServerInfo serverInfo)
Description copied from interface: WabitSessionContext
This will create an appropriate server session for the current context. Registering the session with the context should be done immediately or shortly after creating the session.

Specified by:
createServerSession in interface WabitSessionContext


Copyright © 2009. All Rights Reserved.