Ehcache
Class EhcacheClient

java.lang.Object
  extended by edu.usc.bg.base.DB
      extended by Ehcache.EhcacheClient
All Implemented Interfaces:
EhcacheClientConstants

public class EhcacheClient
extends DB
implements EhcacheClientConstants

A class that wraps a JDBC compliant database to allow it to be interfaced with BG Core Classes. This class extends DB and implements the database interface used by BG client.
Each client will have its own instance of this class. This client is thread safe.
This interface expects a schema ... All attributes are of type VARCHAR. All accesses are through the primary key. Therefore, only one index on the primary key is needed.

The following options must be passed when using this database client.

Author: Shahram Ghandeharizadeh


Field Summary
 
Fields inherited from interface Ehcache.EhcacheClientConstants
CONNECTION_PASSWD, CONNECTION_URL, CONNECTION_USER, DRIVER_CLASS, FS_PATH, MAX_CACHE_MEMORY_DEFAULT, MAX_CACHE_MEMORY_PROPERTY, SUCCESS
 
Constructor Summary
EhcacheClient()
           
 
Method Summary
 int acceptFriend(int inviterID, int inviteeID)
          This function is called in the benchmarking phase which is executed with the -t argument.
 void buildIndexes(java.util.Properties props)
          This function is called in the load with index creation phase which is executed with the -loadindex argument.
 void cleanup(boolean warmup)
          Cleanup any state for this DB.
 int CreateFriendship(int memberA, int memberB)
          This function is called in the load phase which is executed using the -load or -loadindex argument Creates a confirmed friendship between friendid1 and friendid2.
 void createSchema(java.util.Properties props)
          This function is called in the schema creation phase which is executed with the -schema argument.
 int delCommentOnResource(int resourceCreatorID, int resourceID, int manipulationID)
          This function is called in the benchmarking phase executed with the -t argument.
static void dropIndex(java.sql.Statement st, java.lang.String idxName)
           
static void dropSequence(java.sql.Statement st, java.lang.String seqName)
           
static void dropTable(java.sql.Statement st, java.lang.String tableName)
           
 int getCreatedResources(int resourceCreatorID, java.util.Vector<java.util.HashMap<java.lang.String,ByteIterator>> result)
          This function is called in the benchmarking phase which is executed with the -t argument.
 java.util.HashMap<java.lang.String,java.lang.String> getInitialStats()
          This function is called in the load phase which is executed using the -load or -loadindex argument returns DB's initial statistics.
 boolean init()
          Initialize the database connection and set it up for sending requests to the database.
 int insertEntity(java.lang.String entitySet, java.lang.String entityPK, java.util.HashMap<java.lang.String,ByteIterator> values, boolean insertImage)
          This function is called in the load phase which is executed using the -load or -loadindex argument.
 int inviteFriend(int inviterID, int inviteeID)
          This function is called both in the benchmarking phase executed with the -t argument and the load phase executed either using -load or the -loadindex argument.
 int listFriends(int requesterID, int profileOwnerID, java.util.Set<java.lang.String> fields, java.util.Vector<java.util.HashMap<java.lang.String,ByteIterator>> result, boolean insertImage, boolean testMode)
          This function is called in the benchmarking phase which is executed with the -t argument.
 int postCommentOnResource(int commentCreatorID, int profileOwnerID, int resourceID, java.util.HashMap<java.lang.String,ByteIterator> commentValues)
          This function is called in the benchmarking phase executed with the -t argument.
 int queryConfirmedFriendshipIds(int profileId, java.util.Vector<java.lang.Integer> confirmedIds)
          This function is called in the benchmarking phase which is executed with the -t argument.
 int queryPendingFriendshipIds(int inviteeid, java.util.Vector<java.lang.Integer> pendingIds)
          This function is called in the benchmarking phase which is executed with the -t argument.
 int rejectFriend(int inviterID, int inviteeID)
          This function is called in the benchmarking phase which is executed with the -t argument.
 int thawFriendship(int friendid1, int friendid2)
          This function is called in the benchmarking phase which is executed with the -t argument.
 int viewCommentOnResource(int requesterID, int profileOwnerID, int resourceID, java.util.Vector<java.util.HashMap<java.lang.String,ByteIterator>> result)
          This function is called in the benchmarking phase which is executed with the -t argument.
 int viewFriendReq(int profileOwnerID, java.util.Vector<java.util.HashMap<java.lang.String,ByteIterator>> result, boolean insertImage, boolean testMode)
          This function is called in the benchmarking phase which is executed with the -t argument.
 int viewProfile(int requesterID, int profileOwnerID, java.util.HashMap<java.lang.String,ByteIterator> result, boolean insertImage, boolean testMode)
          This function is called in the benchmarking phase which is executed with the -t argument.
 int viewTopKResources(int requesterID, int profileOwnerID, int k, java.util.Vector<java.util.HashMap<java.lang.String,ByteIterator>> result)
          This function is called in the benchmarking phase which is executed with the -t argument.
 
Methods inherited from class edu.usc.bg.base.DB
dataAvailable, getProperties, reconstructSchema, schemaCreated, setProperties
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EhcacheClient

public EhcacheClient()
Method Detail

init

public boolean init()
             throws DBException
Initialize the database connection and set it up for sending requests to the database. This must be called once per client.

Overrides:
init in class DB
Returns:
true if the connection to the data store was successful.
Throws:
DBException

cleanup

public void cleanup(boolean warmup)
Description copied from class: DB
Cleanup any state for this DB.

Overrides:
cleanup in class DB
Parameters:
warmup - This flag identifies if the thread calling it is in the warm up phase. In the warm up phase the threads do not issue updates, this phase can be used for warming up caches. If the warm up is set to true, the cache would not be restarted at the end of the warmup phase and only the warm up thread's connections to the database will be recycled. Called once per DB instance; there is one DB instance per client thread. This method should be called once the thread needs to end its communication with the data store. The code written for this function should close up the connection of the thread with the database and clean up the database instance.

acceptFriend

public int acceptFriend(int inviterID,
                        int inviteeID)
Description copied from class: DB
This function is called in the benchmarking phase which is executed with the -t argument. Accepts a pending friend request. This action can only be done by the invitee.

Specified by:
acceptFriend in class DB
Parameters:
inviterID - The unique identifier of the inviter (the user who generates the friend request).
inviteeID - The unique identifier of the invitee (the person who receives the friend request).
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. The code written for this function should accept the friendship request and generate a friendship relationship between inviteeID and inviterID. The friendship relationship is symmetric, so if A is friends with B, B also should be friends with A.

insertEntity

public int insertEntity(java.lang.String entitySet,
                        java.lang.String entityPK,
                        java.util.HashMap<java.lang.String,ByteIterator> values,
                        boolean insertImage)
Description copied from class: DB
This function is called in the load phase which is executed using the -load or -loadindex argument. It is used for inserting users and resources. Any field/value pairs in the values HashMap for an entity will be written into the specified entity set with the specified entity key.

Specified by:
insertEntity in class DB
Parameters:
entitySet - The name of the entity set with the following two possible values: users and resources. BG passes these values in lower case. The implementation may manipulate the case to tailor it for the purposes of a data store.
entityPK - The primary key of the entity to insert.
values - A HashMap of field/value pairs to insert for the entity, these pairs are the other attributes for an entity and their values. The profile image is identified with the "pic" key attribute and the thumbnail image is identified with the "tpic" key attribute.
insertImage - Identifies if images should be inserted for users. if set to true the code should populate each entity with an image; the size of the image is specified using the imagesize parameter.
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. The code written for this function call should insert the entity and its attributes. The code is responsible for inserting the PK and the other attributes in the appropriate order.

viewProfile

public int viewProfile(int requesterID,
                       int profileOwnerID,
                       java.util.HashMap<java.lang.String,ByteIterator> result,
                       boolean insertImage,
                       boolean testMode)
Description copied from class: DB
This function is called in the benchmarking phase which is executed with the -t argument. Get the profile object for a user.

Specified by:
viewProfile in class DB
Parameters:
requesterID - Unique identifier for the requester.
profileOwnerID - unique profile owner's identifier.
result - A HashMap with all data returned. These data are different user information within the profile such as friend count, friend request count, etc.
insertImage - Identifies if the users have images in the database. If set to true the images for the users will be retrieved.
testMode - If set to true images will be retrieved and stored on the file system. While running benchmarks this field should be set to false.
Returns:
0 on success a non-zero error code on error. See this class's description for a discussion of error codes. The code written for this function retrieves the user's profile details, friendcount (number of friends for that user) and resourcecount (number of resources inserted on that user's wall). In addition if the requesterID is equal to the profileOwnerID, the pendingcount (number of pending friend requests) needs to be returned as well. If the insertImage is set to true, the image for the profileOwnerID will be rertrieved. The insertImage should be set to true only if the user entity has an image in the database. The friendcount, resourcecount, pendingcount should be put into the results HashMap with the following keys: "friendcount", "resourcecount" and "pendingcount", respectively. Lack of these attributes or not returning the attribute keys in lower case causes BG to raise exceptions. In addition, all other attributes of the profile need to be added to the result hashmap with the attribute names being the keys and the attribute values being the values in the hashmap. If images exist for users, they should be converted to bytearrays and added to the result hashmap.

listFriends

public int listFriends(int requesterID,
                       int profileOwnerID,
                       java.util.Set<java.lang.String> fields,
                       java.util.Vector<java.util.HashMap<java.lang.String,ByteIterator>> result,
                       boolean insertImage,
                       boolean testMode)
Description copied from class: DB
This function is called in the benchmarking phase which is executed with the -t argument. gets the list of friends for a member.

Specified by:
listFriends in class DB
Parameters:
requesterID - The unique identifier of the user who wants to view profile owners friends.
profileOwnerID - The id of the profile for which the friends are listed.
fields - Contains the attribute names required for each friend. This can be set to null to retrieve all the friend information.
result - A Vector of HashMaps, where each HashMap is a set field/value pairs for one friend.
insertImage - If set to true the thumbnail images for the friends will be retrieved from the data store.
testMode - If set to true the thumbnail images of friends will be written to the file system.
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. The code written for this function should retrieve the list of friends for the profileOwnerID. The information retrieved per friend depends on the fields specified in the fields set. if fields is set to null all profile information for the friends is retrieved and the result hashmap is populated. The friend's unique id should be inserted with the "userid" key into the result hashmap. The lack of this attribute or the lack of the attribute key in lower case causes BG to raise exceptions. In addition if the insertImage flag is set to true, the thumbnails for each friend's profile should be retrieved and inserted into the result hashmap using the "pic" key.

viewFriendReq

public int viewFriendReq(int profileOwnerID,
                         java.util.Vector<java.util.HashMap<java.lang.String,ByteIterator>> result,
                         boolean insertImage,
                         boolean testMode)
Description copied from class: DB
This function is called in the benchmarking phase which is executed with the -t argument. gets the list of pending friend requests for a member. These are the requests that are generated for the profileOwnerID but have not been accepted or rejected.

Specified by:
viewFriendReq in class DB
Parameters:
profileOwnerID - The profile owner's unique identifier.
result - A vector of hashmaps where every hashmap belongs to one inviter.
insertImage - If set to true the images for the friends will be retrieved from the data store.
testMode - If set to true the thumbnail images of friends will be written to the file system.
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. The code written for this function should retrieve the list of pending invitations for the profileOwnerID's profile, all profile information for the pending friends is retrieved and the result hashmap is populated. The unique id of the friend generating the request should be added using the "userid" key to the hasmap. The lack of this attribute or the lack of the attribute key in lower case causes BG to raise exceptions. In addition if the insertImage flag is set to true, the thumbnails for each pending friend profile should be retrieved and inserted into the result hashmap.

rejectFriend

public int rejectFriend(int inviterID,
                        int inviteeID)
Description copied from class: DB
This function is called in the benchmarking phase which is executed with the -t argument. Rejects a pending friend request. This action can only be done by the invitee.

Specified by:
rejectFriend in class DB
Parameters:
inviterID - The unique identifier of the inviter (The person who generates the friend request).
inviteeID - The unique identifier of the invitee (The person who receives the friend request).
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. The code written for this function should remove the friend request generated by the inviterID without creating any friendship relationship between the inviterID and the inviteeID.

CreateFriendship

public int CreateFriendship(int memberA,
                            int memberB)
Description copied from class: DB
This function is called in the load phase which is executed using the -load or -loadindex argument Creates a confirmed friendship between friendid1 and friendid2.

Specified by:
CreateFriendship in class DB
Parameters:
memberA - The unique identifier of the first member.
memberB - The unique identifier of the second member.
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. The code written in this function generates a friendship relationship between friendid1 and friendid2 The friendship relationship is symmetric, so if A is friends with B, B is also friends with A.

inviteFriend

public int inviteFriend(int inviterID,
                        int inviteeID)
Description copied from class: DB
This function is called both in the benchmarking phase executed with the -t argument and the load phase executed either using -load or the -loadindex argument. Generates a friend request which can be considered as generating a pending friendship.

Specified by:
inviteFriend in class DB
Parameters:
inviterID - The unique identifier of the inviter (the person who generates the friend request).
inviteeID - The unique identifier of the invitee (the person who receives the friend request).
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. The code written for this function should generate a friend request invitation which is extended by the inviterID to the inviteeID.

thawFriendship

public int thawFriendship(int friendid1,
                          int friendid2)
Description copied from class: DB
This function is called in the benchmarking phase which is executed with the -t argument. Thaws a friendship.

Specified by:
thawFriendship in class DB
Parameters:
friendid1 - The unique identifier of the person who wants to remove a friend.
friendid2 - The unique identifier of the friend to be removed.
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. The code written in this function terminates the friendship relationship between friendid1 and friendid2. The friendship relationship should be removed for both friendid1 and friendid2. The friendship/thaw friendship relationship is symmetric so if A is not friends with B, B also will not be friends with A.

viewTopKResources

public int viewTopKResources(int requesterID,
                             int profileOwnerID,
                             int k,
                             java.util.Vector<java.util.HashMap<java.lang.String,ByteIterator>> result)
Description copied from class: DB
This function is called in the benchmarking phase which is executed with the -t argument. gets the top k resources posted on a member's wall. These can be created by the user on her own wall or by other users on this user's wall.

Specified by:
viewTopKResources in class DB
Parameters:
requesterID - The unique identifier of the user who wants to view profile owners resources.
profileOwnerID - The profile owner's unique identifier.
k - The number of resources requested.
result - A vector of all the resource entities, every resource entity is a hashmap containing resource attributes. This hashmap should have the resource id identified by "rid" and the wall user id identified by "walluserid". The lack of these attributes or not having these keys in lower case may cause BG to raise exceptions.
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.

getCreatedResources

public int getCreatedResources(int resourceCreatorID,
                               java.util.Vector<java.util.HashMap<java.lang.String,ByteIterator>> result)
Description copied from class: DB
This function is called in the benchmarking phase which is executed with the -t argument. gets the resources created by a user, the created resources may be posted either on the user's wall or on another user's wall.

Specified by:
getCreatedResources in class DB
Parameters:
resourceCreatorID - The unique identifier of the user who created the resources.
result - A vector of all the resource entities, every entity is a hashmap containing the attributes of a resource and their values without considering the comments on the resource. Every resource should have a unique identifier which will be copied into the hashmap using the "rid" key and a unique creator which will be copied into the "creatorid" key. Lack of this key in lower case may cause BG to raise exceptions.
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.

viewCommentOnResource

public int viewCommentOnResource(int requesterID,
                                 int profileOwnerID,
                                 int resourceID,
                                 java.util.Vector<java.util.HashMap<java.lang.String,ByteIterator>> result)
Description copied from class: DB
This function is called in the benchmarking phase which is executed with the -t argument. gets the comments for a resource and all the comment's details.

Specified by:
viewCommentOnResource in class DB
Parameters:
requesterID - The unique identifier of the user who wants to view the comments posted on the profileOwnerID's resource.
profileOwnerID - The profile owner's unique identifier (owner of the resource).
resourceID - The resource's unique identifier.
result - A vector of all the comment entities for a specific resource, each comment and its details are specified as a hashmap.
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. The code written for this function, gets the resourceid of a resource and returns all the comments posted on that resource and their details. This information should be put into the results Vector.

postCommentOnResource

public int postCommentOnResource(int commentCreatorID,
                                 int profileOwnerID,
                                 int resourceID,
                                 java.util.HashMap<java.lang.String,ByteIterator> commentValues)
Description copied from class: DB
This function is called in the benchmarking phase executed with the -t argument. posts/creates a comment on a specific resource. Every comment created is inserted into the manipulation entity set.

Specified by:
postCommentOnResource in class DB
Parameters:
commentCreatorID - The unique identifier of the user who is creating the comment.
profileOwnerID - The resource creator's unique identifier (owner of the resource).
resourceID - The resource's unique identifier.
commentValues - The values for the comment which contains the unique identifier of the comment identified by "mid".
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. The code written in this function, creates a comment on the resource identified with resourceID and created by profileOwnerID.

getInitialStats

public java.util.HashMap<java.lang.String,java.lang.String> getInitialStats()
Description copied from class: DB
This function is called in the load phase which is executed using the -load or -loadindex argument returns DB's initial statistics. These statistics include number of users, average number of friends per user, average number of pending friend requests per user, and number of resources per user. The initial statistics are queried and inserted into a hashmap. This hashmap should contain the following attributes: "usercount", "resourcesperuser", "avgfriendsperuser", "avgpendingperuser" The lack of these attributes or the lack of the keys in lower case causes BG to raise exceptions.

Specified by:
getInitialStats in class DB
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.

queryPendingFriendshipIds

public int queryPendingFriendshipIds(int inviteeid,
                                     java.util.Vector<java.lang.Integer> pendingIds)
Description copied from class: DB
This function is called in the benchmarking phase which is executed with the -t argument. Queries the inviterid's of pending friendship requests for a member specified by memberID.

Specified by:
queryPendingFriendshipIds in class DB
Parameters:
inviteeid - The unique identifier of the user.
pendingIds - Is a vector of all the member ids that have created a friendship invitation for memberID.
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.

queryConfirmedFriendshipIds

public int queryConfirmedFriendshipIds(int profileId,
                                       java.util.Vector<java.lang.Integer> confirmedIds)
Description copied from class: DB
This function is called in the benchmarking phase which is executed with the -t argument. Queries the friendids of confirmed friendships for a member specified by memberID.

Specified by:
queryConfirmedFriendshipIds in class DB
Parameters:
profileId - The unique identifier of the user.
confirmedIds - Is a vector of all the member ids that have a friendship relationship with memberID.
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.

createSchema

public void createSchema(java.util.Properties props)
Description copied from class: DB
This function is called in the schema creation phase which is executed with the -schema argument. Creates the data store schema which will then be populated in the load phase. Depending on the type of datastore, the code for creating index structures may also be provided within this function call.

Specified by:
createSchema in class DB
Parameters:
props - The properties of BG. BG dictates a fixed conceptual schema. This schema consists of three entity sets: users, resources, manipulations The attributes for each entity set are as follows; 1) users (userid, username, pw, fname, lname, gender, dob, jdate, ldate, address, email, tel, tpic, pic) tpic and pic are available if there are images inserted for users. 2) resources (rid, creatorid, walluserid, type, body, doc) 3) manipulations (mid, creatorid, rid, modifierid, timestamp, type, content)

buildIndexes

public void buildIndexes(java.util.Properties props)
Description copied from class: DB
This function is called in the load with index creation phase which is executed with the -loadindex argument. May be used with data stores that support creation of indexes after the load phase is completed.

Overrides:
buildIndexes in class DB
Parameters:
props - The properties of BG.

dropSequence

public static void dropSequence(java.sql.Statement st,
                                java.lang.String seqName)

dropIndex

public static void dropIndex(java.sql.Statement st,
                             java.lang.String idxName)

dropTable

public static void dropTable(java.sql.Statement st,
                             java.lang.String tableName)

delCommentOnResource

public int delCommentOnResource(int resourceCreatorID,
                                int resourceID,
                                int manipulationID)
Description copied from class: DB
This function is called in the benchmarking phase executed with the -t argument. deletes a specific comment on a specific resource.

Specified by:
delCommentOnResource in class DB
Parameters:
resourceCreatorID - The resource creator's unique identifier (owner of the resource).
resourceID - The resource's unique identifier.
manipulationID - The unique identifier of the comment to be deleted.
Returns:
Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. The code written in this function, deletes a comment identified by manipulationID on the resource identified with resourceID and created by the resourceCreatorID.