ca.sqlpower.wabit.enterprise.client
Class WabitClientSession

java.lang.Object
  extended by ca.sqlpower.wabit.WabitSessionImpl
      extended by ca.sqlpower.wabit.enterprise.client.WabitClientSession
All Implemented Interfaces:
ca.sqlpower.util.SPSession, WabitSession

public class WabitClientSession
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
WabitClientSession(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(ca.sqlpower.enterprise.client.SPServerInfo serviceInfo)
           
static WorkspaceLocation createNewServerSession(ca.sqlpower.enterprise.client.SPServerInfo serviceInfo)
          Sends an HTTP request to a Wabit Enterprise Server to create a new remote Wabit Workspace on that server.
 void deleteServerWorkspace()
           
static org.apache.http.client.CookieStore getCookieStore()
          Exposes the shared cookie store so we don't spawn useless sessions through the client.
 ca.sqlpower.sql.DataSourceCollection<ca.sqlpower.sql.SPDataSource> getDataSources()
          Returns the server's data source list, retrieving it from the server if that has not already been done during this session.
 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(ca.sqlpower.enterprise.client.SPServerInfo 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 WabitClientSession openServerSession(WabitSessionContext context, WorkspaceLocation workspaceLoc)
          Finds and opens a specific Wabit Workspace from the given WorkspaceLocation.
static java.util.List<WabitClientSession> openServerSessions(WabitSessionContext context, ca.sqlpower.enterprise.client.SPServerInfo serverInfo)
          Finds and opens all visible Wabit workspaces on the given Wabit Enterprise Server.
 void persistWorkspaceToServer()
           
 void runInForeground(java.lang.Runnable runner)
           
 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

WabitClientSession

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

createHttpClient

public static org.apache.http.client.HttpClient createHttpClient(ca.sqlpower.enterprise.client.SPServerInfo 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()
Returns the server's data source list, retrieving it from the server if that has not already been done during this session. Changes made to this data source collection will be sent back to the server, but the changes will not be applied on the server side unless the user has the appropriate permissions.

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(ca.sqlpower.enterprise.client.SPServerInfo 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(ca.sqlpower.enterprise.client.SPServerInfo 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 SPServerInfo 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 WabitClientSession 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<WabitClientSession> openServerSessions(WabitSessionContext context,
                                                                    ca.sqlpower.enterprise.client.SPServerInfo 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 ca.sqlpower.dao.SPPersistenceException
Throws:
ca.sqlpower.dao.SPPersistenceException

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)
Specified by:
runInForeground in interface ca.sqlpower.util.SPSession
Overrides:
runInForeground in class WabitSessionImpl

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:

getCookieStore

public static org.apache.http.client.CookieStore getCookieStore()
Exposes the shared cookie store so we don't spawn useless sessions through the client.



Copyright © 2009. All Rights Reserved.