basicDB
Class TestClient

java.lang.Object
  extended by edu.usc.bg.base.DB
      extended by basicDB.TestClient

public class TestClient
extends DB


Constructor Summary
TestClient()
           
 
Method Summary
 int acceptFriend(int invitorID, int inviteeID)
          This function is called in the benchmarking phase which is executed with the -t argument.
 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.
 int getCreatedResources(int creatorID, 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 any state for this DB.
 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 invitorID, 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 memberID, 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 memberID, java.util.Vector<java.lang.Integer> pendingIds)
          This function is called in the benchmarking phase which is executed with the -t argument.
 int queryPendingFriendships(int userOffset, int userCount, java.util.HashMap<java.lang.Integer,java.util.Vector<java.lang.Integer>> pendingFrnds)
           
 int rejectFriend(int invitorID, 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>> values, 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
buildIndexes, cleanup, dataAvailable, getProperties, reconstructSchema, schemaCreated, setProperties
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestClient

public TestClient()
Method Detail

init

public boolean init()
             throws DBException
Description copied from class: DB
Initialize any state for this DB. Called once per DB instance; there is one DB instance per client thread. This method should be called once by any thread to start communication with the database. The code written for this function should initiate the thread's communication with the database.

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

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>> values,
                         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.
values - 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.

acceptFriend

public int acceptFriend(int invitorID,
                        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:
invitorID - 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.

rejectFriend

public int rejectFriend(int invitorID,
                        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:
invitorID - 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.

inviteFriend

public int inviteFriend(int invitorID,
                        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:
invitorID - 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.

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.

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.

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.

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.

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.

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.

queryPendingFriendships

public int queryPendingFriendships(int userOffset,
                                   int userCount,
                                   java.util.HashMap<java.lang.Integer,java.util.Vector<java.lang.Integer>> pendingFrnds)

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)

getCreatedResources

public int getCreatedResources(int creatorID,
                               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:
creatorID - 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.

queryPendingFriendshipIds

public int queryPendingFriendshipIds(int memberID,
                                     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:
memberID - 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 memberID,
                                       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:
memberID - 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.