net.sf.farrago.session
Class FarragoSessionVariables

java.lang.Object
  extended by net.sf.farrago.session.FarragoSessionVariables
All Implemented Interfaces:
Cloneable

public class FarragoSessionVariables
extends Object
implements Cloneable

FarragoSessionVariables defines global variable settings for a Farrago session. It has two types of variables, plain old Java object fields, and variables stored in a generic name to value map. Plain old Java object fields are accessed directly, while mapped fields are accessed with set(String, String) and get(String). Validation is handled in FarragoSessionPersonality.


 Example:
 FarragoSessionVariables sessionVars = ...;
 String catalogName = sessionVars.catalogName;
 sessionVars.set("newVar", "value"); // registers and sets value in map
 String newVar = sessionVars.get("newVar"); // gets mapped value only
 

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/session/FarragoSessionVariables.java#23 $
Author:
John V. Sichi

Field Summary
 String catalogName
          The name of the default catalog qualifier, changed by SET CATALOG.
 String currentRoleName
          Value of SQL expression CURRENT_ROLE.
 String currentUserName
          Value of SQL expression CURRENT_USER.
static String LOG_DIR
          Name of session variable defining directory for log files; this is not currently used by the default Farrago personality, but it serves as a canonical name across all other personalities which need a similar concept.
 long processId
          Client process Id.
 String programName
          Client program name.
 String schemaName
          The name of the default schema qualifier, changed by SET SCHEMA.
 List<SqlIdentifier> schemaSearchPath
          Value of SQL expression CURRENT_PATH as a list of schemas.
 String sessionName
          Session name.
 String sessionUserName
          Value of SQL expression SESSION_USER.
 String systemUserFullName
          Full user name, e.g.
 String systemUserName
          Value of SQL expression SYSTEM_USER.
private  Map<String,String> valueMap
          Additional variables
 
Constructor Summary
FarragoSessionVariables()
           
 
Method Summary
 FarragoSessionVariables cloneVariables()
           
 boolean containsVariable(String name)
          Tests whether a session variable is defined in this map.
protected  void copyVariables(FarragoSessionVariables baseVariables)
          Copy the values in baseVariables to this instance.
 String get(String name)
          Gets the value of variable in a generic value map.
 Boolean getBoolean(String name)
          Gets the value of a variable, casted to a Boolean
 String getFormattedSchemaSearchPath(DatabaseMetaData databaseMetadata)
          Format the schema search path as required by the SQL99 standard.
 Integer getInteger(String name)
          Gets the value of a variable, casted to an Integer
 Long getLong(String name)
          Gets the value of a variable, casted to a Long
 Map<String,String> getMap()
          Retrieves a read only map from parameter name to parameter value.
 void set(String name, String value)
          Sets the value of a variable in a generic value map.
 void setBoolean(String name, Boolean value)
          Sets the value of a variable, expressed as an boolean
 void setDefault(String name, String value)
          Sets the default value for a variable.
 void setInteger(String name, Integer value)
          Sets the value of a variable, expressed as an integer
 void setLong(String name, Long value)
          Sets the value of a variable, expressed as a long
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_DIR

public static final String LOG_DIR
Name of session variable defining directory for log files; this is not currently used by the default Farrago personality, but it serves as a canonical name across all other personalities which need a similar concept. It may be used by the default Farrago personality in the future.

See Also:
Constant Field Values

catalogName

public String catalogName
The name of the default catalog qualifier, changed by SET CATALOG. Can never be null.


schemaName

public String schemaName
The name of the default schema qualifier, changed by SET SCHEMA. Can be null to indicate no default schema has been set yet.


systemUserName

public String systemUserName
Value of SQL expression SYSTEM_USER.


sessionUserName

public String sessionUserName
Value of SQL expression SESSION_USER.


currentUserName

public String currentUserName
Value of SQL expression CURRENT_USER.


currentRoleName

public String currentRoleName
Value of SQL expression CURRENT_ROLE.


schemaSearchPath

public List<SqlIdentifier> schemaSearchPath
Value of SQL expression CURRENT_PATH as a list of schemas. Each entry is a SqlIdentifier (catalog.schema). This list is immutable to prevent accidental aliasing.


systemUserFullName

public String systemUserFullName
Full user name, e.g. "Joe Smith". Can be null. TODO: Value of SQL expression SYSTEM_USER_FULLNAME?.


sessionName

public String sessionName
Session name. Can be null if session has no name. TODO: Value of SQL expression SESSION_NAME?


programName

public String programName
Client program name. Can be null. TODO: Value of SQL expression PROGRAM_NAME?


processId

public long processId
Client process Id. TODO: Value of SQL expression PROCESS_ID?


valueMap

private Map<String,String> valueMap
Additional variables

Constructor Detail

FarragoSessionVariables

public FarragoSessionVariables()
Method Detail

cloneVariables

public FarragoSessionVariables cloneVariables()

getFormattedSchemaSearchPath

public String getFormattedSchemaSearchPath(DatabaseMetaData databaseMetadata)
Format the schema search path as required by the SQL99 standard.

Parameters:
databaseMetadata - current database metadata
Returns:
formated schema search path, as per the SQL standard
Reference to SQL:1999 standard:
Part 2 Section 6.3 General Rule 10

copyVariables

protected void copyVariables(FarragoSessionVariables baseVariables)
Copy the values in baseVariables to this instance. Allows extensions projects to provide extend FarragoSessionVariables and those new session variables to values from an existing FarragoSessionVariables.

Parameters:
baseVariables - an existing FarragoSessionVariables to copy into this.

set

public void set(String name,
                String value)
Sets the value of a variable in a generic value map. This method does not affect any variables explictly materialized as a public members.

Parameters:
name - the name of a session variable
value - the value to set, expressed as a string

get

public String get(String name)
Gets the value of variable in a generic value map.

Parameters:
name - the name of a session variable
Throws:
IllegalArgumentException - if the variable is not in the map

containsVariable

public boolean containsVariable(String name)
Tests whether a session variable is defined in this map.

Parameters:
name - variable name to check
Returns:
true if variable is defined

setInteger

public void setInteger(String name,
                       Integer value)
Sets the value of a variable, expressed as an integer

See Also:
set(String, String)

getInteger

public Integer getInteger(String name)
Gets the value of a variable, casted to an Integer

Parameters:
name - the name of a session variable
Throws:
IllegalArgumentException - if the variable is not in the map
NumberFormatException - if the value cannot be casted to an Integer
See Also:
get(String)

setLong

public void setLong(String name,
                    Long value)
Sets the value of a variable, expressed as a long

See Also:
set(String, String)

getLong

public Long getLong(String name)
Gets the value of a variable, casted to a Long

Parameters:
name - the name of a session variable
Throws:
IllegalArgumentException - if the variable is not in the map
NumberFormatException - if the value cannot be casted to a Long
See Also:
get(String)

setBoolean

public void setBoolean(String name,
                       Boolean value)
Sets the value of a variable, expressed as an boolean

See Also:
set(String, String)

getBoolean

public Boolean getBoolean(String name)
Gets the value of a variable, casted to a Boolean

Parameters:
name - the name of a session variable
Throws:
IllegalArgumentException - if the variable is not in the map
See Also:
get(String)

setDefault

public void setDefault(String name,
                       String value)
Sets the default value for a variable. Does nothing if the variable has already been initialized.

Parameters:
name - the name of the variable
value - the default value of a variable

getMap

public Map<String,String> getMap()
Retrieves a read only map from parameter name to parameter value. Parameter values are expressed as strings. This map contains values of the generic value map. It also contains public fields of FarragoSessionVariables(). The public fields take precedence.