예제 #1
0
	    public User GetUserByUserNameUsingString(String userName)
        {
		    User user = new User();
		    RowSet rows = session.Execute("SELECT * FROM users WHERE username = '******'");
		    foreach ( Row row in rows.GetRows() )
            {
                user.UserName = userName;
			    user.FirstName = row.GetValue<String>("firstname");
			    user.LastName = row.GetValue<String>("lastname");
			    user.Email = row.GetValue<String>("email");
			    user.Password = row.GetValue<String>("Password");
			    user.CreatedDate = row.GetValue<DateTimeOffset>("created_date");
		    }
		    return user;    
        }
예제 #2
0
        static void Main(string[] args)
        {
            List<String> contactPoints = new List<String>();
            contactPoints.Add("127.0.0.1");
            IVideoDbDAO vdb = new VideoDbBasicImpl(contactPoints, "videodb");
		    // Basic get of a user. This is using the string method of executing CQL
		    User user = vdb.GetUserByUserNameUsingString("tcodd");
		    Console.WriteLine("Get user by using CQL string: " + user);
		    // Get the same user but with a prepared statement
		    user = vdb.GetUserByUserNameUsingPreparedStatement("tcodd");
		    Console.WriteLine("Get user by using prepared statement: " + user);
		    // Add a new user
		    User newUser = new User("cdate", 
                "Chris", 
                "Date", 
                "*****@*****.**",
                "6cb75f65-2a9b-5279-8eb6-cf2201057c73",
                DateTime.Now,
                0, 
                Guids.GenerateTimeBasedGuid());
		    vdb.SetUserByPreparedStatement(newUser);

		    // Get a list of videos. This uses the simple Async Read feature.
		    List<Video> videosByTag = vdb.GetVideosByTagUsingAsyncRead("lol");
		    foreach (Video video in videosByTag)
            {
			    Console.WriteLine("Video by AsyncRead" + video);
		    }
		    // Get a list of videos. This uses a threaded Async Read feature.
		    // This method will take a list of tags to query.
		    List<String> tags = new List<String>();
		    tags.Add("lol");
		    tags.Add("cat");
		    // We'll use the videoID to set a rating of 4
		    vdb.SetRatingForVideo(new Guid("99051fe9-6a9c-46c2-b949-38ef78858dd0"), 4);
		    // Iterate over the same list and get the overall rating
		    foreach (Video video in videosByTag)
            {
			    Console.Write("Video " + video.VideoName
					    + " had an average of ");
			    // We'll use the videoID of each to get a rating
			    Console.WriteLine(vdb.GetRatingForVideo(video.VideoId));
		    }

            /*
		    List<Video> videosByTagList = vdb.GetVideosByTagsUsingAsyncReadThreads(tags);
		    for (Video video : videosByTagList) {
			    Console.WriteLine("Video by AsyncRead Threads" + video);
		    }

		    // Set a comment for one video. The underlying method will set on two
		    // tables at the same time.
		    vdb.GetCommentForVideo(
				    new Guid("99051fe9-6a9c-46c2-b949-38ef78858dd0"),
				    "tcodd", "Worst. Video. Ever.");
            */

		    // Get a list of comments by VideoID, a UUID.
		    List<Comment> comments = vdb.GetCommentsByVideoIdUsingPreparedStatement(
                new Guid("99051fe9-6a9c-46c2-b949-38ef78858dd0"));

		    foreach (Comment comment in comments)
            {
			    Console.WriteLine("Get comments by VideoID: " + comment);
		    }

		    // Get a list of comments by UserName
		    comments = vdb.GetCommentsByUserNameUsingPreparedStatement("tcodd");
		    foreach (Comment comment in comments)
            {
			    Console.WriteLine("Get comments by UserName: "******"99051fe9-6a9c-46c2-b949-38ef78858dd0"),
				    "tcodd");
            Console.WriteLine("Video timestamp of last stop event: " + videoTimestamp);
		

		    // Close our connection and exit. Exit is required since we are running
		    // threads.
		    vdb.Close();
            return;
        }
예제 #3
0
    	public User GetUserByUserNameUsingPreparedStatement(String userName)
        {
            User user = new User();
		    // The BoundStatement is created by the PreparedStatement created above
		    BoundStatement boundStatement = getUserByNamePreparedStatement.Bind(userName);
		    // Custom retry policy
		    boundStatement.SetRetryPolicy(timeOfDayRetryPolicy);
		    RowSet rows = session.Execute(boundStatement);
		    foreach (Row row in rows.GetRows()) 
            {
                user.UserName = userName;
			    user.FirstName = row.GetValue<String>("firstname");
			    user.LastName = row.GetValue<String>("lastname");
			    user.Email = row.GetValue<String>("email");
			    user.Password = row.GetValue<String>("Password");
			    user.CreatedDate = row.GetValue<DateTimeOffset>("created_date");
		    }
		    return user;
        }
예제 #4
0
        public void SetUserByUsingString(User user)
        {
            StringBuilder userInsert = new StringBuilder(
				"INSERT INTO users (username, firstname, lastname, email, password, created_date) VALUES (");
            userInsert.Append("'");
		    userInsert.Append(user.UserName);
            userInsert.Append("', '");
		    userInsert.Append(user.FirstName);
            userInsert.Append("', '");
		    userInsert.Append(user.LastName);
            userInsert.Append("', '");
		    userInsert.Append(user.Email);
            userInsert.Append("', '");
		    userInsert.Append(user.Password);
            userInsert.Append("', '");
		    userInsert.Append(user.CreatedDate.ToString());
            userInsert.Append("'");
		    userInsert.Append(")");
		    session.Execute(userInsert.ToString());
        }
예제 #5
0
    	public void SetUserByPreparedStatement(User user)
        {
            BoundStatement boundStatement = setUser.Bind(
                user.UserName, user.FirstName, user.LastName, user.Email,
                user.Password, user.CreatedDate);
		    session.Execute(boundStatement);
        }