org.gersteinlab.tyna.webapp.data
Class RDBDataStore

java.lang.Object
  extended by org.gersteinlab.tyna.webapp.data.RDBDataStore

public class RDBDataStore
extends java.lang.Object

        This class is the agent for accessing databases. It hides the subtle
        details about database access from the client classes, and also restrict
        the actions that can be taken by them.
        

Version:
1.0 (October 1, 2005) Change History: 1.0 - Initial version
Author:
Kevin Yuk-Lap Yip

Field Summary
protected  java.sql.Connection conn
          The database connection.
 java.lang.String OWNED
          Owned resource (networks/categories).
 java.lang.String PRIVATE
          Private resource (networks/categories).
 java.lang.String PUBLIC_OR_OWNED
          Public or owned resource (networks/categories).
protected  SecurityController sc
          Security controller
 
Constructor Summary
RDBDataStore(javax.servlet.http.HttpSession session)
          This method is used to get a connection to the database with configurations specified in the configuration file.
 
Method Summary
 void close()
          Close the connection.
 void commit()
          Commit the current transaction.
 void deleteCategory(int id)
          Delete a category from the database.
 void deleteNetwork(int id)
          Delete a network from the database.
 void deleteNetworkByUser(int id)
          Delete a network from the database based on the current user's privilege.
 boolean existUser(java.lang.String name)
          Check if a user name is already in use.
protected  void finalize()
          Free unfreed resources.
 Category getCategory(int id)
          Get a category.
 Network getNetwork(int id)
          Get a network.
 NetworkFormat getNetworkFormat(int id)
          Get a network format.
 User getUser(java.lang.String name, java.lang.String password)
          Get the information of a user, based on the login name and password of the user.
 int insertCategory(Category category)
          Insert a new category into the database.
 int insertNetwork(Network network)
          Insert a new network into the database.
 int insertNetworkAttr(NetworkAttr networkAttr)
          Insert a new network attribute into the database.
 int insertUser(User user, java.lang.String password)
          Insert a new user into the database.
 java.util.List listCategories(java.lang.String name, java.lang.String listType, java.lang.String order)
          List categories.
 java.util.List listNetworkAttrs(int type, java.lang.String order)
          List network attributes of a network type.
 java.util.List listNetworkFormats()
          List network formats.
 java.util.List listNetworks(java.lang.String name, java.lang.String listType, java.lang.String listNetworkType, java.lang.String listNetworkAttrName, java.lang.String listNetworkAttrValue, java.lang.String order)
          List networks.
 java.util.List listNetworkTypes(java.lang.String order)
          List network types.
 void rollback()
          Rollback the current transaction.
 void setAutoCommit(boolean autoCommit)
          Set auto commit of the connection.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRIVATE

public final java.lang.String PRIVATE
Private resource (networks/categories).

See Also:
Constant Field Values

OWNED

public final java.lang.String OWNED
Owned resource (networks/categories).

See Also:
Constant Field Values

PUBLIC_OR_OWNED

public final java.lang.String PUBLIC_OR_OWNED
Public or owned resource (networks/categories).

See Also:
Constant Field Values

conn

protected java.sql.Connection conn
The database connection.


sc

protected SecurityController sc
Security controller

Constructor Detail

RDBDataStore

public RDBDataStore(javax.servlet.http.HttpSession session)
             throws ConfigException,
                    java.sql.SQLException
This method is used to get a connection to the database with configurations specified in the configuration file. The close() method should be called when the connection is not to be used any more. By default, the auto commit flag is set to true.

Parameters:
session - The current HTTP session
Throws:
ConfigException - If there is any problem with the system configuration
java.sql.SQLException - If there is any problem with the database
Method Detail

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws java.sql.SQLException
Set auto commit of the connection.

Parameters:
autoCommit - Whether to auto commit
Throws:
java.sql.SQLException - If there is any problem in setting the auto commit flag

commit

public void commit()
            throws java.sql.SQLException
Commit the current transaction.

Throws:
java.sql.SQLException - If there is any problem in committing the transaction

rollback

public void rollback()
              throws java.sql.SQLException
Rollback the current transaction.

Throws:
java.sql.SQLException - If there is any problem in rolling back the transaction

close

public void close()
Close the connection.


getUser

public User getUser(java.lang.String name,
                    java.lang.String password)
             throws java.sql.SQLException
Get the information of a user, based on the login name and password of the user.

Parameters:
name - The login name of the user
password - The passoword of the user
Returns:
The user information, null if not found
Throws:
java.sql.SQLException - If there is any problem in executing the query

existUser

public boolean existUser(java.lang.String name)
                  throws java.sql.SQLException
Check if a user name is already in use.

Parameters:
name - The login name of the user
Returns:
Whether the user name exists in the database.
Throws:
java.sql.SQLException - If there is any problem in executing the query

insertUser

public int insertUser(User user,
                      java.lang.String password)
               throws java.sql.SQLException
Insert a new user into the database.

Parameters:
user - The user to be inserted
password - The password of the user
Returns:
The ID of the user
Throws:
java.sql.SQLException - If there is any problem in executing the insertion

listNetworkFormats

public java.util.List listNetworkFormats()
                                  throws java.sql.SQLException
List network formats.

Returns:
The list of network formats
Throws:
java.sql.SQLException - If there is any problem in executing the query

getNetworkFormat

public NetworkFormat getNetworkFormat(int id)
                               throws java.sql.SQLException
Get a network format.

Parameters:
id - The ID of the network format
Returns:
The network format if found, null otherwise
Throws:
java.sql.SQLException - If there is any problem in executing the query

listNetworks

public java.util.List listNetworks(java.lang.String name,
                                   java.lang.String listType,
                                   java.lang.String listNetworkType,
                                   java.lang.String listNetworkAttrName,
                                   java.lang.String listNetworkAttrValue,
                                   java.lang.String order)
                            throws java.sql.SQLException
List networks.

Parameters:
name - Name of user, null if not logged in.
listType - List type: PRIVATE for private ones (must be owned) only OWNED for owned ones (public or private) only PUBLIC_OR_OWNED for owned or public
listNetworkType - Type of networks to list: "" for all ID of the specific network type otherwise
listNetworkAttrName - Attribute name of networks to list: "" for not specified Name of the specific network attribute otherwise
listNetworkAttrValue - Attribute value of networks to list: "" for not specified Value of the specific network attribute otherwise
order - The ordering attribute
Returns:
The list of networks
Throws:
java.sql.SQLException - If there is any problem in executing the query

getNetwork

public Network getNetwork(int id)
                   throws java.sql.SQLException
Get a network.

Parameters:
id - The ID of the network
Returns:
The network if found, null otherwise
Throws:
java.sql.SQLException - If there is any problem in executing the query

insertNetwork

public int insertNetwork(Network network)
                  throws java.sql.SQLException
Insert a new network into the database.

Parameters:
network - The network to be inserted
Returns:
The ID of the network
Throws:
java.sql.SQLException - If there is any problem in executing the insertion

deleteNetwork

public void deleteNetwork(int id)
                   throws java.sql.SQLException
Delete a network from the database.

Parameters:
id - The ID of the network to be deleted
Throws:
java.sql.SQLException - If there is any problem in executing the deletion

deleteNetworkByUser

public void deleteNetworkByUser(int id)
                         throws java.sql.SQLException,
                                SecurityException
Delete a network from the database based on the current user's privilege.

Parameters:
id - The ID of the network to be deleted
Throws:
java.sql.SQLException - If there is any problem in executing the deletion
SecurityException - If the current user does not have the permission to delete the network

listNetworkTypes

public java.util.List listNetworkTypes(java.lang.String order)
                                throws java.sql.SQLException
List network types.

Parameters:
order - The ordering attribute
Returns:
The list of network types
Throws:
java.sql.SQLException - If there is any problem in executing the query

listNetworkAttrs

public java.util.List listNetworkAttrs(int type,
                                       java.lang.String order)
                                throws java.sql.SQLException
List network attributes of a network type.

Parameters:
type - The network type
order - The ordering attribute
Returns:
The list of network attributes
Throws:
java.sql.SQLException - If there is any problem in executing the query

insertNetworkAttr

public int insertNetworkAttr(NetworkAttr networkAttr)
                      throws java.sql.SQLException
Insert a new network attribute into the database.

Parameters:
networkAttr - The network attribute to be inserted
Returns:
The ID of the network attribute
Throws:
java.sql.SQLException - If there is any problem in executing the insertion

listCategories

public java.util.List listCategories(java.lang.String name,
                                     java.lang.String listType,
                                     java.lang.String order)
                              throws java.sql.SQLException
List categories.

Parameters:
name - Owner of the owned networks. Null for excluding owned ones.
listType - List type: "private" for private ones (must be owned) only "owned" for owned ones (public or private) only "" for owned or public
order - The ordering attribute
Returns:
The list of categories
Throws:
java.sql.SQLException - If there is any problem in executing the query

getCategory

public Category getCategory(int id)
                     throws java.sql.SQLException
Get a category.

Parameters:
id - The ID of the category
Returns:
The category if found, null otherwise
Throws:
java.sql.SQLException - If there is any problem in executing the query

insertCategory

public int insertCategory(Category category)
                   throws java.sql.SQLException
Insert a new category into the database.

Parameters:
category - The category to be inserted
Returns:
The ID of the category
Throws:
java.sql.SQLException - If there is any problem in executing the insertion

deleteCategory

public void deleteCategory(int id)
                    throws java.sql.SQLException
Delete a category from the database.

Parameters:
id - The ID of the category to be deleted
Throws:
java.sql.SQLException - If there is any problem in executing the deletion

finalize

protected void finalize()
Free unfreed resources.

Overrides:
finalize in class java.lang.Object