ca.sqlpower.wabit.enterprise.client
Class WabitServerSession

java.lang.Object
  extended by ca.sqlpower.wabit.WabitSessionImpl
      extended by ca.sqlpower.wabit.enterprise.client.WabitServerSession
All Implemented Interfaces:
WabitSession

public class WabitServerSession
extends WabitSessionImpl

A special kind of session that binds itself to a remote Wabit Enterprise Server. Provides database connection information and file storage capability based on the remote server.


Constructor Summary
WabitServerSession(WorkspaceLocation workspaceLocation, WabitSessionContext context)
           
 
Method Summary
 boolean close()
          Ends this session, disposing its frame and releasing any system resources that were obtained explicitly by this session.
static org.apache.http.client.HttpClient createHttpClient(WabitServerInfo serviceInfo)
           
static WorkspaceLocation createNewServerSession(WabitServerInfo serviceInfo)
          Sends an HTTP request to a Wabit Enterprise Server to create a new remote Wabit Workspace on that server.
 void deleteServerWorkspace()
           
 ca.sqlpower.sql.DataSourceCollection<ca.sqlpower.sql.SPDataSource> getDataSources()
          Retrieves the data source list from the server.
 WabitWorkspace getSystemWorkspace()
          Fetches the system workspace from the same server as this session.
 WorkspaceLocation getWorkspaceLocation()
          Returns the location this workspace was loaded from.
static java.util.List<WorkspaceLocation> getWorkspaceNames(WabitServerInfo serviceInfo)
          List all the workspaces on this context's server.
 boolean isEnterpriseServerSession()
          Returns true if the current session is in fact a remote session with the wabit enterprise server.
static WabitServerSession openServerSession(WabitSessionContext context, WorkspaceLocation workspaceLoc)
          Finds and opens a specific Wabit Workspace from the given WorkspaceLocation.
static java.util.List<WabitServerSession> openServerSessions(WabitSessionContext context, WabitServerInfo serverInfo)
          Finds and opens all visible Wabit workspaces on the given Wabit Enterprise Server.
 void persistWorkspaceToServer()
           
 void runInForeground(java.lang.Runnable runner)
          This will force the given runnable to execute in the 'foreground'.
 void startUpdaterThread()
           
 
Methods inherited from class ca.sqlpower.wabit.WabitSessionImpl
addPropertyChangeListener, addSessionLifecycleListener, createUserPrompter, getContext, getWorkspace, isForegroundThread, removePropertyChangeListener, removeSessionLifecycleListener, runInBackground
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WabitServerSession

public WabitServerSession(@Nonnull
                          WorkspaceLocation workspaceLocation,
                          @Nonnull
                          WabitSessionContext context)
Method Detail

createHttpClient

public static org.apache.http.client.HttpClient createHttpClient(WabitServerInfo serviceInfo)

close

public boolean close()
Description copied from interface: WabitSession
Ends this session, disposing its frame and releasing any system resources that were obtained explicitly by this session. Also fires a sessionClosing lifecycle event, so any resources used up by subsystems dependent on this session can be freed by the appropriate parties.

Specified by:
close in interface WabitSession
Overrides:
close in class WabitSessionImpl
Returns:
True if the session was successfully closed. False if the session did not close due to an error or user intervention.

getWorkspaceLocation

public WorkspaceLocation getWorkspaceLocation()
Returns the location this workspace was loaded from.


getDataSources

public ca.sqlpower.sql.DataSourceCollection<ca.sqlpower.sql.SPDataSource> getDataSources()
Retrieves the data source list from the server.

Future plans: In the future, the server will probably be a proxy for all database operations, and we won't actually send the connection information to the client. This has the advantage that it can work over an HTTP firewall or proxy, where the present method would fail.

Specified by:
getDataSources in interface WabitSession
Overrides:
getDataSources in class WabitSessionImpl

getWorkspaceNames

public static java.util.List<WorkspaceLocation> getWorkspaceNames(WabitServerInfo serviceInfo)
                                                           throws java.io.IOException,
                                                                  java.net.URISyntaxException,
                                                                  JSONException
List all the workspaces on this context's server.

Parameters:
serviceInfo -
Returns:
Throws:
java.io.IOException
java.net.URISyntaxException
JSONException

createNewServerSession

public static WorkspaceLocation createNewServerSession(WabitServerInfo serviceInfo)
                                                throws java.net.URISyntaxException,
                                                       org.apache.http.client.ClientProtocolException,
                                                       java.io.IOException,
                                                       JSONException
Sends an HTTP request to a Wabit Enterprise Server to create a new remote Wabit Workspace on that server.

Parameters:
serviceInfo - A WabitServerInfo containing the connection information for that server
Returns:
The WorkspaceLocation of the newly created remote WabitWorkspace
Throws:
java.net.URISyntaxException
org.apache.http.client.ClientProtocolException
java.io.IOException
JSONException

deleteServerWorkspace

public void deleteServerWorkspace()
                           throws java.net.URISyntaxException,
                                  org.apache.http.client.ClientProtocolException,
                                  java.io.IOException
Throws:
java.net.URISyntaxException
org.apache.http.client.ClientProtocolException
java.io.IOException

openServerSession

public static WabitServerSession openServerSession(WabitSessionContext context,
                                                   WorkspaceLocation workspaceLoc)
Finds and opens a specific Wabit Workspace from the given WorkspaceLocation. The new session will keep itself up-to-date by polling the server for new state. Likewise, local changes to the session will be pushed its own updates back to the server.

Parameters:
context - The context to register the new remote WabitSession with
workspaceLoc - A WorkspaceLocation detailing the location of the remote workspace to be opened
Returns:
A remote WabitSession based on the given workspace

openServerSessions

public static java.util.List<WabitServerSession> openServerSessions(WabitSessionContext context,
                                                                    WabitServerInfo serverInfo)
                                                             throws java.io.IOException,
                                                                    java.net.URISyntaxException,
                                                                    JSONException
Finds and opens all visible Wabit workspaces on the given Wabit Enterprise Server. Calling this method essentially constitutes "logging in" to the given server.

Parameters:
context - the context to add the newly-retrieved sessions to
serverInfo - The server to contact.
Returns:
the list of sessions that were opened.
Throws:
JSONException
java.net.URISyntaxException
java.io.IOException

startUpdaterThread

public void startUpdaterThread()

persistWorkspaceToServer

public void persistWorkspaceToServer()
                              throws WabitPersistenceException
Throws:
WabitPersistenceException

getSystemWorkspace

public WabitWorkspace getSystemWorkspace()
Fetches the system workspace from the same server as this session. Returns null if the user doesn't have access to a given workspace.

Specified by:
getSystemWorkspace in interface WabitSession
Overrides:
getSystemWorkspace in class WabitSessionImpl
Returns:

runInForeground

public void runInForeground(java.lang.Runnable runner)
Description copied from interface: WabitSession
This will force the given runnable to execute in the 'foreground'. If something is executed in the foreground then the thread that called this method will pass the runner to the thread that updates the user interface. Once the Runnable has been passed to the UI thread this method will continue executing and the runner will be executed when the UI thread is able to run it.

In cases where there is no UI, the foreground thread will be the same thread as the one calling this method. If this is the case the runner will just have run() called on the same thread. Additionally, if this is called on the foreground thread then it will be run on this thread is they are the same.

If you are calling this from a WabitObject that extends AbstractWabitObject you should use the AbstractWabitObject.runInForeground(Runnable) method instead

Specified by:
runInForeground in interface WabitSession
Overrides:
runInForeground in class WabitSessionImpl
Parameters:
runner - The runnable to run in the foreground.

isEnterpriseServerSession

public boolean isEnterpriseServerSession()
Description copied from interface: WabitSession
Returns true if the current session is in fact a remote session with the wabit enterprise server.

Specified by:
isEnterpriseServerSession in interface WabitSession
Overrides:
isEnterpriseServerSession in class WabitSessionImpl
Returns:


Copyright © 2009. All Rights Reserved.