edu.jhu.tmaj.beans.manytomany
Class ManyToManyBean

java.lang.Object
  extended by edu.jhu.tmaj.beans.manytomany.ManyToManyBean
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
PapersSessionsBean, ProjectsArraySlidesBean, UsersArrayBlocksBean, UsersProjectsBean, UsersUsersBean

public abstract class ManyToManyBean
extends java.lang.Object
implements java.io.Serializable

This Bean represents Many-To-Many tables. ManyToMany Tables link the PrimaryKeys of two other tables. For example, the table UsersProjects links UserIDs to ProjectIDs. This bean is abstract, and must implement methods that give information about SQL statements to initialize the bean. The information in this bean is reversible. So for example, lets say the table is "UsersProjects". You can view all projects to which an individual user has access, as well as seeing all users given an individual project. This is accomplished by having two LinkGroups. One LinkGroup links projects to arrayslides, and the other linkGroup links arraySlides to projects. See LinkGroup class for details.

See Also:
Serialized Form

Constructor Summary
ManyToManyBean(java.lang.String key1Name, java.lang.String key2Name, java.lang.String tableName)
          Constructs this object.
 
Method Summary
(package private)  java.util.Set<java.lang.Integer> getAllKey1s()
           
(package private)  java.util.Set<java.lang.Integer> getAllKey2s()
           
 java.util.Set<java.lang.Integer> getKeySetForKey(int key, boolean isReversed)
          Gets the Set of IDs that are linked to the given key.
(package private) abstract  java.lang.String getSQL()
          Returns a SQL statement that will initialize the bean with every record in the ManyToMany table
(package private) abstract  java.lang.String getSQL(int userID)
          Returns a SQL statement that will initialize the bean with limited records for which the user needs access
 void initialize()
          Initializes the bean with all the records found in the ManyToMany table
 void initialize(int userID)
          Initializes the bean for a particular user, which includes only some of the records in the ManyToMany table.
 void setKeySet(int key, java.util.Set<java.lang.Integer> newKeySet, boolean isReversed)
           
 void syncDatabase(int key, java.util.Set<java.lang.Integer> newKeySet, java.util.Set<java.lang.Integer> usersFullKeySet, boolean isReversed)
          Writes the database for the new keys assigned to the individual key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ManyToManyBean

ManyToManyBean(java.lang.String key1Name,
               java.lang.String key2Name,
               java.lang.String tableName)
Constructs this object.

Parameters:
key1Name - name of the first primary key. For example, in UsersProjects, "UserID".
key2Name - name of the second primary key. For example, in UsersProjects, "ProjectID".
tableName - the tableName of the ManyToMany table. For example, "UsersProjects"
Method Detail

getKeySetForKey

public java.util.Set<java.lang.Integer> getKeySetForKey(int key,
                                                        boolean isReversed)
Gets the Set of IDs that are linked to the given key.

Parameters:
key - the ID
isReversed - if true, 'key' is actually the Key2Name, and set returned is the set of associated key1's. if false, 'key' is the Key1Name, and the set returned is a set of associated key2's.

getAllKey1s

java.util.Set<java.lang.Integer> getAllKey1s()

getAllKey2s

java.util.Set<java.lang.Integer> getAllKey2s()

initialize

public final void initialize(int userID)
                      throws java.sql.SQLException
Initializes the bean for a particular user, which includes only some of the records in the ManyToMany table. For example, in the case of UsersProjects, a user can not see what projects another user can access.

Throws:
java.sql.SQLException

initialize

public final void initialize()
                      throws java.sql.SQLException
Initializes the bean with all the records found in the ManyToMany table

Throws:
java.sql.SQLException

setKeySet

public final void setKeySet(int key,
                            java.util.Set<java.lang.Integer> newKeySet,
                            boolean isReversed)

syncDatabase

public final void syncDatabase(int key,
                               java.util.Set<java.lang.Integer> newKeySet,
                               java.util.Set<java.lang.Integer> usersFullKeySet,
                               boolean isReversed)
                        throws java.sql.SQLException
Writes the database for the new keys assigned to the individual key.

Throws:
java.sql.SQLException

getSQL

abstract java.lang.String getSQL()
Returns a SQL statement that will initialize the bean with every record in the ManyToMany table


getSQL

abstract java.lang.String getSQL(int userID)
Returns a SQL statement that will initialize the bean with limited records for which the user needs access