//private ExecutorService executor;

        public VideoDbBasicImpl(List<String> contactPoints, String keyspace) 
        {
		    cluster = Cluster
			        .Builder()
			        .AddContactPoints(contactPoints.ToArray())
			        .WithRetryPolicy(Policies.DefaultRetryPolicy)
			        .Build();

		    session = cluster.Connect(keyspace);

		    getUserByNamePreparedStatement = session.Prepare(GET_USER_BY_USERNAME);
		    setUser = session.Prepare(SET_USER);
		    getVideosByUsernamePreparedStatement = session
				    .Prepare(GET_VIDEOS_BY_USERNAME);
            getVideoByIDPreparedStatement = session.Prepare(GET_VIDEO_BY_ID);
            getVideosByTagPreparedStatement = session.Prepare(GET_VIDEOS_BY_TAG);
		    getRatingByVideoPreparedStatement = session
                    .Prepare(GET_RATING_BY_VIDEO);
            setCommentByVideo = session.Prepare(SET_COMMENT_BY_VIDEO);
            setCommentByUsername = session.Prepare(SET_COMMENT_BY_USERNAME);
            getCommentByUsername = session.Prepare(GET_COMMENT_BY_USERNAME);
            getCommentByVideoId = session.Prepare(GET_COMMENT_BY_VIDEOID);

		    timeOfDayRetryPolicy = new TimeOfDayRetryPolicy(9, 17);

		    // Create a thread pool equal to the number of cores
            /*
		    executor = Executors.newFixedThreadPool(Runtime.getRuntime()
				    .availableProcessors());
             */
	    }
示例#2
0
        /// <summary>
        /// Create a new instance of the repository with the session as a dependency
        /// </summary>
        public ForumRepository(ISession session)
        {
            this.Session = session;

            _insertTopicStatement = Session.Prepare("INSERT INTO topics (topic_id, topic_title, topic_date) VALUES (?, ?, ?)");
            _insertMessageStatement = Session.Prepare("INSERT INTO messages (topic_id, message_date, message_body) VALUES (?, ?, ?)");
        }
示例#3
0
        public virtual int GetActiveNumberOfUsersForSub(Guid subId)
        {
            if (_countStatement == null)
                _countStatement = _session.Prepare("SELECT COUNT(*) FROM ActivityBySub WHERE subId = ?");

            var bound = _countStatement.Bind(subId);

            return (int)_session.Execute(bound).GetRows().First().GetValue<long>("count");
        }
示例#4
0
        public virtual void MarkSubActive(Guid userId, Guid subId)
        {
            if (_insertStatement == null)
                _insertStatement = _session.Prepare(
                "INSERT INTO ActivityBySub (subId, accountId) " +
                "VALUES (?, ?) USING TTL ?;");

            var bound = _insertStatement.Bind(subId, userId, _subSettings.Settings.ActivityExpirationSeconds);
            _session.Execute(bound);
        }
示例#5
0
 /// <summary>
 ///  Creates a new <c>BoundStatement</c> from the provided prepared
 ///  statement.
 /// </summary>
 /// <param name="statement"> the prepared statement from which to create a <c>BoundStatement</c>.</param>
 public BoundStatement(PreparedStatement statement)
 {
     _preparedStatement = statement;
     _routingKey = statement.RoutingKey;
     SetConsistencyLevel(statement.ConsistencyLevel);
     if (statement.IsIdempotent != null)
     {
         SetIdempotence(statement.IsIdempotent.Value);
     }
 }
示例#6
0
 /// <summary>
 ///  Creates a new <c>BoundStatement</c> from the provided prepared
 ///  statement.
 /// </summary>
 /// <param name="statement"> the prepared statement from which to create a <c>BoundStatement</c>.</param>
 public BoundStatement(PreparedStatement statement)
 {
     _statement = statement;
     _routingKey = statement.RoutingKey;
 }
示例#7
0
 /// <summary>
 ///  Creates a new <c>BoundStatement</c> from the provided prepared
 ///  statement.
 /// </summary>
 /// <param name="statement"> the prepared statement from which to create a <c>BoundStatement</c>.</param>
 public BoundStatement(PreparedStatement statement)
 {
     _statement  = statement;
     _routingKey = statement.RoutingKey;
 }
 private static void PrepareStatementIfNeeded()
 {
     if (_secondsPreparedStatement != null)
         return;
     _secondsPreparedStatement = _session.Prepare(_secondsStatement);
 }
 /// <summary>
 ///  Creates a new <code>BoundStatement</code> from the provided prepared
 ///  statement.
 /// </summary>
 /// <param name="statement"> the prepared statement from which to create a <code>BoundStatement</code>.</param>
 public BoundStatement(PreparedStatement statement)
 {
     this._statement = statement;
 }
示例#10
0
 internal BoundStatement(PreparedStatement statement, Serializer serializer) : this(statement)
 {
     _serializer = serializer;
 }
        public CQLInventoryStorage(string[] contactPoints)
        {
            _cluster = Cluster.Builder().AddContactPoints(contactPoints).Build();
            _session = _cluster.Connect(KEYSPACE_NAME);

            SKEL_SELECT_STMT = _session.Prepare("SELECT * FROM skeletons WHERE user_id = ?;");
            SKEL_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            SKEL_SINGLE_SELECT_STMT = _session.Prepare("SELECT * FROM skeletons WHERE user_id = ? AND folder_id = ?;");
            SKEL_SINGLE_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            SKEL_INSERT_STMT
                = _session.Prepare( "INSERT INTO skeletons (user_id, folder_id, folder_name, parent_id, type, level) " +
                                    "VALUES(?, ?, ?, ?, ?, ?);");
            SKEL_INSERT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_SELECT_STMT = _session.Prepare("SELECT * FROM folder_contents WHERE folder_id = ?;");
            FOLDER_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_ATTRIB_SELECT_STMT = _session.Prepare(   "SELECT * FROM folder_contents WHERE folder_id = ? AND item_id = "
                                                            + FOLDER_MAGIC_ENTRY.ToString() + ";");
            FOLDER_ATTRIB_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_ATTRIB_INSERT_STMT
                = _session.Prepare( "INSERT INTO folder_contents (folder_id, item_id, name, inv_type, creation_date, owner_id) " +
                                    "VALUES (?, ?, ?, ?, ?, ?);");
            FOLDER_ATTRIB_INSERT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_ITEM_INSERT_STMT
                = _session.Prepare( "INSERT INTO folder_contents (folder_id, item_id, name, asset_id, asset_type, " +
                                        "base_permissions, creation_date, creator_id, current_permissions, description, " +
                                        "everyone_permissions, flags, group_id, group_owned, group_permissions, " +
                                        "inv_type, next_permissions, owner_id, sale_type) " +
                                    "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
            FOLDER_ITEM_INSERT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_ITEM_UPDATE_STMT
                = _session.Prepare("UPDATE folder_contents SET name = ?, asset_id = ?, asset_type = ?, " +
                                        "base_permissions = ?, creation_date = ?, creator_id = ?, current_permissions= ?, description = ?, " +
                                        "everyone_permissions = ?, flags = ?, group_id = ?, group_owned = ?, group_permissions = ?, " +
                                        "inv_type = ?, next_permissions = ?, sale_type = ? " +
                                    "WHERE folder_id = ? AND item_id = ?;");
            FOLDER_ITEM_UPDATE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_ITEM_REMOVE_STMT = _session.Prepare("DELETE FROM folder_contents WHERE folder_id = ? AND item_id = ?;");
            FOLDER_ITEM_REMOVE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_VERSION_INC_STMT
                = _session.Prepare("UPDATE folder_versions SET version = version + 1 WHERE user_id = ? AND folder_id = ?;");
            FOLDER_VERSION_INC_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_VERSION_SELECT_STMT = _session.Prepare("SELECT * FROM folder_versions WHERE user_id = ?;");
            FOLDER_VERSION_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_VERSION_SINGLE_SELECT_STMT = _session.Prepare("SELECT * FROM folder_versions WHERE user_id = ? AND folder_id = ?;");
            FOLDER_VERSION_SINGLE_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_UPDATE_STMT = _session.Prepare(  "UPDATE folder_contents SET name = ?, inv_type = ? " +
                                                    "WHERE folder_id = ? AND item_id = " + FOLDER_MAGIC_ENTRY.ToString());
            FOLDER_UPDATE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            SKEL_UPDATE_STMT = _session.Prepare("UPDATE skeletons SET folder_name = ?, type = ? WHERE user_id = ? AND folder_id = ?;");
            SKEL_UPDATE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            SKEL_MOVE_STMT = _session.Prepare("UPDATE skeletons SET parent_id = ? WHERE user_id = ? AND folder_id = ?;");
            SKEL_MOVE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            ITEM_OWNERSHIP_INSERT = _session.Prepare("INSERT INTO item_parents(item_id, parent_folder_id) VALUES(?, ?);");
            ITEM_OWNERSHIP_INSERT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            ITEM_OWNERSHIP_UPDATE = _session.Prepare("UPDATE item_parents SET parent_folder_id = ? WHERE item_id = ?;");
            ITEM_OWNERSHIP_UPDATE.SetConsistencyLevel(ConsistencyLevel.Quorum);

            ITEM_OWNERSHIP_REMOVE = _session.Prepare("DELETE FROM item_parents WHERE item_id = ?;");
            ITEM_OWNERSHIP_REMOVE.SetConsistencyLevel(ConsistencyLevel.Quorum);

            ITEM_OWNERSHIP_SELECT = _session.Prepare("SELECT * FROM item_parents WHERE item_id = ?;");
            ITEM_OWNERSHIP_SELECT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_ITEM_SELECT_STMT = _session.Prepare("SELECT * FROM folder_contents WHERE folder_id = ? AND item_id = ?;");
            FOLDER_ITEM_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_REMOVE_STMT = _session.Prepare("DELETE FROM folder_contents WHERE folder_id = ?;");
            FOLDER_REMOVE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            SKEL_REMOVE_STMT = _session.Prepare("DELETE FROM skeletons WHERE user_id = ? AND folder_id = ?;");
            SKEL_REMOVE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_VERSION_REMOVE_STMT = _session.Prepare("DELETE FROM folder_versions WHERE user_id = ? AND folder_id = ?;");
            FOLDER_VERSION_REMOVE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);
        }
示例#12
0
 internal BoundStatement(PreparedStatement statement, Serializer serializer) : this(statement)
 {
     _serializer = serializer;
 }
示例#13
0
        public override void Prepare()
        {
            if (CqlConnection == null)
            {
                throw new InvalidOperationException("No connection bound to this command!");
            }

            if (!IsPrepared && Parameters.Count > 0)
            {
                // replace all named parameter names to ? before preparing the statement 
                // when binding the parameter values got from GetParameterValues() for executing
                // GetParameterValues() returns the array of parameter values
                // order by the occurence of parameter names in cql
                // so that we could support cases that parameters of the same name occur multiple times in cql
                var cqlQuery = RegexParseParameterName.Replace(CommandText, "?");
                _preparedStatement = CqlConnection.CreatePreparedStatement(cqlQuery);
            }
        }
 private static void PrepareStatementIfNeeded()
 {
     if (_insertPreparedStatement != null)
         return;
     _insertPreparedStatement = _session.Prepare(_insertStatement);
 }
示例#15
0
 public void ExecutePreparedQuery(Session session, PreparedStatement prepared, object[] values, ConsistencyLevel consistency = ConsistencyLevel.Default, string messageInstead = null)
 {
     if (messageInstead != null)
         Console.WriteLine("CQL<\t" + messageInstead);
     else
         Console.WriteLine("CQL< Executing Prepared Query:\t");
     session.Execute(prepared.Bind(values).SetConsistencyLevel(consistency));
     Console.WriteLine("CQL> (OK).");
 }
示例#16
0
 /// <summary>
 ///  Creates a new <c>BoundStatement</c> from the provided prepared
 ///  statement.
 /// </summary>
 /// <param name="statement"> the prepared statement from which to create a <c>BoundStatement</c>.</param>
 public BoundStatement(PreparedStatement statement)
 {
     _preparedStatement = statement;
     _routingKey = statement.RoutingKey;
     SetConsistencyLevel(statement.ConsistencyLevel);
 }
示例#17
0
 private void EnsureStatementsReady()
 {
     if (_adjustStatement == null)
         _adjustStatement = _session.Prepare("UPDATE UserKarma SET karma = karma + ? where user_id = ? and sub_type = ?;");
 }
 /// <summary>
 ///  Creates a new <code>BoundStatement</code> from the provided prepared
 ///  statement.
 /// </summary>
 /// <param name="statement"> the prepared statement from which to create a <code>BoundStatement</code>.</param>
 public BoundStatement(PreparedStatement statement)
 {
     this._statement = statement;
 }
示例#19
0
 private Task<PreparedStatement> SetPrepareTableInfo(PreparedStatement ps)
 {
     const string msgRoutingNotSet = "Routing information could not be set for query \"{0}\"";
     var column = ps.Metadata.Columns.FirstOrDefault();
     if (column == null || column.Keyspace == null)
     {
         //The prepared statement does not contain parameters
         return TaskHelper.ToTask(ps);
     }
     if (ps.Metadata.PartitionKeys != null)
     {
         //The routing indexes where parsed in the prepared response
         if (ps.Metadata.PartitionKeys.Length == 0)
         {
             //zero-length partition keys means that none of the parameters are partition keys
             //the partition key is hard-coded.
             return TaskHelper.ToTask(ps);
         }
         ps.RoutingIndexes = ps.Metadata.PartitionKeys;
         return TaskHelper.ToTask(ps);
     }
     return Cluster.Metadata.GetTableAsync(column.Keyspace, column.Table).ContinueWith(t =>
     {
         if (t.Exception != null)
         {
             Logger.Error("There was an error while trying to retrieve table metadata for {0}.{1}. {2}", column.Keyspace, column.Table, t.Exception.InnerException);
             return ps;
         }
         var table = t.Result;
         if (table == null)
         {
             Logger.Info(msgRoutingNotSet, ps.Cql);
             return ps;
         }
         var routingSet = ps.SetPartitionKeys(table.PartitionKeys);
         if (!routingSet)
         {
             Logger.Info(msgRoutingNotSet, ps.Cql);
         }
         return ps;
     });
 }
 public void prepareStatements()
 {
     insertSongsDataStatement = Session.Prepare(INSERT_SONGS_DATA_PREPARED);
     insertPlaylistsDataStatement = Session.Prepare(INSERT_PLAYLISTS_DATA_PREPARED);
 }