/// <summary>
 /// Creates a new BoundStatement object and bind its variables to the provided
 /// values.
 /// <para>
 /// Specify the parameter values by the position of the markers in the query or by name, 
 /// using a single instance of an anonymous type, with property names as parameter names.
 /// </para>
 /// <para>
 /// Note that while no more <c>values</c> than bound variables can be provided, it is allowed to
 /// provide less <c>values</c> that there is variables.
 /// </para>
 /// </summary>
 /// <param name="values"> the values to bind to the variables of the newly
 ///  created BoundStatement. </param>
 /// <returns>the newly created <c>BoundStatement</c> with its variables
 ///  bound to <c>values</c>. </returns>
 public virtual BoundStatement Bind(params object[] values)
 {
     var bs = new BoundStatement(this, _serializer);
     bs.SetRoutingKey(_routingKey);
     if (values == null)
     {
         return bs;
     }
     var valuesByPosition = values;
     var useNamedParameters = values.Length == 1 && Utils.IsAnonymousType(values[0]);
     if (useNamedParameters)
     {
         //Using named parameters
         //Reorder the params according the position in the query
         valuesByPosition = Utils.GetValues(Metadata.Columns.Select(c => c.Name), values[0]).ToArray();
     }
     bs.SetValues(valuesByPosition);
     bs.CalculateRoutingKey(useNamedParameters, RoutingIndexes, _routingNames, valuesByPosition, values);
     return bs;
 }
 /// <summary>
 /// Creates a new BoundStatement object and bind its variables to the provided
 /// values.
 /// <para>
 /// Specify the parameter values by the position of the markers in the query or by name, 
 /// using a single instance of an anonymous type, with property names as parameter names.
 /// </para>
 /// <para>
 /// Note that while no more <c>values</c> than bound variables can be provided, it is allowed to
 /// provide less <c>values</c> that there is variables.
 /// </para>
 /// </summary>
 /// <param name="values"> the values to bind to the variables of the newly
 ///  created BoundStatement. </param>
 /// <returns>the newly created <c>BoundStatement</c> with its variables
 ///  bound to <c>values</c>. </returns>
 public BoundStatement Bind(params object[] values)
 {
     var bs = new BoundStatement(this);
     if (values != null && values.Length == 1 && Utils.IsAnonymousType(values[0]))
     {
         //Using named params
         //Reorder the params according the position in the query
         values = Utils.GetValues(Metadata.Columns.Select(c => c.Name), values[0]).ToArray();
     }
     bs.SetValues(values);
     return bs;
 }
Beispiel #3
0
        public static void SetUpKeySpaces(Cluster c)
        {
            try
            {
                Console.WriteLine("====================="); Console.WriteLine("=====================");
                Console.WriteLine("STARTING TO SETUP KEY SPACES");
                Console.WriteLine("====================="); Console.WriteLine("=====================");

                String createkeyspace = "create keyspace if not exists maltmusic WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}";
                String createUserProfile = "CREATE TABLE if not exists maltmusic.userprofiles (\n"
                    + "User_ID text PRIMARY KEY,\n"
                    + "password text,\n"
                    + "bio text,\n"
                    + "first_name text,\n"
                    + "last_name text,\n"
                    + "email text,\n"
                    + "profpic  UUID);";

                String createTracks = "create table if not exists maltmusic.tracks (\n"
                    + "Track_ID UUID, \n"
                    + "track_Name text,\n"
                    + "artist text,\n"
                    + "album text,\n"
                    + "year int, \n"
                    + "length int, \n"
                    + "genre text,\n"
                    + "file_loc text,\n"
                    + "PRIMARY KEY (Track_ID, artist, album, year, genre))";

                String createPlaylist = " create table if not exists maltmusic.playlist(\n"
                    + "Playlist_ID UUID,\n"
                    + "Track_ID UUID,\n"
                    + "Track_Pos int,\n"
                    + "PRIMARY KEY (Playlist_ID, Track_ID))";

                String createVotes = "create table if not exists maltmusic.votecount(\n"
                    + " track_ID UUID Primary Key, \n"
                    + " playcount counter,\n"
                    + "upvotes counter,\n"
                    + "downvotes counter)";

                String createListPlaylist = "create table  if not exists maltmusic.list_playlist(\n"
                    + "playlist_id UUID,\n"
                    + "owner text,\n"
                    + "playlist_name text,"
                    + "PRIMARY KEY (playlist_ID, owner,playlist_name)\n"
                    + ")";

                String createUserVotes = "create table if not exists maltmusic.user_votes(\n"
                    + " track_ID UUID,\n"
                    + " voter text, \n"
                    + " howvoted text,\n"
                    + " Primary Key (track_id, voter)\n"
                    + " ); ";

                String trackTags = "create table if not exists maltmusic.weathertags(\n"
                    + " track_ID UUID Primary Key,\n"
                    + " tags set<text> \n"
                    + " ); ";

                String CreateImage = "CREATE TABLE if not exists maltmusic.images (" +
                " user_id text," +
                " timeadded timestamp," +
                " image blob," +
                " imagelength int," +
                " PRIMARY KEY (user_id,timeadded)" +
                ") WITH CLUSTERING ORDER BY (timeadded DESC);";

                //Cluster cluster = Cluster.Builder().AddContactPoint("127.0.0.1").Build();
                ISession session = c.Connect();

                try {
                    PreparedStatement statement = session.Prepare(createkeyspace);
                    BoundStatement bs = new BoundStatement(statement);
                    RowSet rs = session.Execute(bs);
                     Console.WriteLine("Created Malt ");
                } catch (Exception et) {
                Console.WriteLine("Creation of keyspace broke - " + et);
                }

                try
                {
                    PreparedStatement statement = session.Prepare(CreateImage);
                    BoundStatement bs = new BoundStatement(statement);
                    RowSet rs = session.Execute(bs);
                    Console.WriteLine("Created Image Table ");
                }
                catch (Exception et)
                {
                    Console.WriteLine("Creation of image table broke - " + et);
                }

                try
                {
                    PreparedStatement statement = session.Prepare(createUserProfile);
                    BoundStatement bs = new BoundStatement(statement);
                    RowSet rs = session.Execute(bs);
                    Console.WriteLine("Created user profiles ");
                }
                catch (Exception et)
                {
                    Console.WriteLine("Creation profiles broke - " + et);
                }

                try
                {
                    PreparedStatement statement = session.Prepare(createPlaylist);
                    BoundStatement bs = new BoundStatement(statement);
                    RowSet rs = session.Execute(bs);
                    Console.WriteLine("Created Playlist ");
                }
                catch (Exception et)
                {
                    Console.WriteLine("Creating Playlist broke - " + et);
                }

                try
                {
                    PreparedStatement statement = session.Prepare(createTracks);
                    BoundStatement bs = new BoundStatement(statement);
                    RowSet rs = session.Execute(bs);
                    Console.WriteLine("Created Tracks ");
                }
                catch (Exception et)
                {
                    Console.WriteLine("Creating Tracks broke - " + et);
                }

                try
                {
                    PreparedStatement statement = session.Prepare(createVotes);
                    BoundStatement bs = new BoundStatement(statement);
                    RowSet rs = session.Execute(bs);
                    Console.WriteLine("Created Votes ");
                }
                catch (Exception et)
                {
                    Console.WriteLine("Creating votes broke - " + et);
                }

                try
                {
                    PreparedStatement statement = session.Prepare(createListPlaylist);
                    BoundStatement bs = new BoundStatement(statement);
                    RowSet rs = session.Execute(bs);
                    Console.WriteLine("Created List Playlist ");
                }
                catch (Exception et)
                {
                    Console.WriteLine("Creating List Playlist broke - " + et);
                }

                try
                {
                    PreparedStatement statement = session.Prepare(createUserVotes);
                    BoundStatement bs = new BoundStatement(statement);
                    RowSet rs = session.Execute(bs);
                    Console.WriteLine("Created User Votes ");
                }
                catch (Exception et)
                {
                    Console.WriteLine("Creating User Votes broke - " + et);
                }

                try
                {
                    PreparedStatement statement = session.Prepare(trackTags);
                    BoundStatement bs = new BoundStatement(statement);
                    RowSet rs = session.Execute(bs);
                    Console.WriteLine("Created Track Tags ");
                }
                catch (Exception et)
                {
                    Console.WriteLine("Creating Track Tags broke - " + et);
                }

                //session.End();
                //session.Dispose();
            }
            catch(Exception e)
            {
                Console.WriteLine("Something keyspacey broke - " + e);
            }
        }
 public override void LoadData()
 {
     PreparedStatement statement = Session.Prepare(
           "INSERT INTO simplex.songs " +
           "(id, title, album, artist, tags) " +
           "VALUES (?, ?, ?, ?, ?);");
     BoundStatement boundStatement = new BoundStatement(statement);
     HashSet<String> tags = new HashSet<String>();
     tags.Add("jazz");
     tags.Add("2013");
     Session.Execute(boundStatement.Bind(
           new Guid("756716f7-2e54-4715-9f00-91dcbea6cf50"),
           "La Petite Tonkinoise'",
           "Bye Bye Blackbird'",
           "Joséphine Baker",
           tags)
         );
     tags = new HashSet<String>();
     tags.Add("1996");
     tags.Add("nirds");
     Session.Execute(boundStatement.Bind(
           new Guid("f6071e72-48ec-4fcb-bf3e-379c8a696488"),
           "Die Mösch",
           "In Gold'",
           "Willi Ostermann",
           tags)
         );
     tags = new HashSet<String>();
     tags.Add("1970");
     tags.Add("soundtrack");
     Session.Execute(boundStatement.Bind(
           new Guid("fbdf82ed-0063-4796-9c7c-a3d4f47b4b25"),
           "Memo From Turner",
           "Performance",
           "Mick Jager",
           tags)
         );
     // playlists table
     statement = Session.Prepare(
           "INSERT INTO simplex.playlists " +
           "(id, song_id, title, album, artist) " +
           "VALUES (?, ?, ?, ?, ?);");
     boundStatement = new BoundStatement(statement);
     Session.Execute(boundStatement.Bind(
           new Guid("2cc9ccb7-6221-4ccb-8387-f22b6a1b354d"),
           new Guid("756716f7-2e54-4715-9f00-91dcbea6cf50"),
           "La Petite Tonkinoise",
           "Bye Bye Blackbird",
           "Joséphine Baker"));
     Session.Execute(boundStatement.Bind(
           new Guid("2cc9ccb7-6221-4ccb-8387-f22b6a1b354d"),
           new Guid("f6071e72-48ec-4fcb-bf3e-379c8a696488"),
           "Die Mösch",
           "In Gold",
           "Willi Ostermann"));
     Session.Execute(boundStatement.Bind(
           new Guid("3fd2bedf-a8c8-455a-a462-0cd3a4353c54"),
           new Guid("fbdf82ed-0063-4796-9c7c-a3d4f47b4b25"),
           "Memo From Turner",
           "Performance",
           "Mick Jager"));
 }