Exemplo n.º 1
0
        public UserCountsRepository(ICassandraSession session, IMapper mapper)
        {
            _session = session;
            _mapper = mapper;

            // Preparing statements
            TableAttribute tableAttribute = typeof (UserCountsEntity).GetCustomAttributes(typeof (TableAttribute), true).Select(a => (TableAttribute)a).First();
            string entityName = tableAttribute.Name;

            string userIdPropertyName = NameOfHelper.PropertyName<UserCountsEntity>(x => x.UserId);
            string likesPropertyName = NameOfHelper.PropertyName<UserCountsEntity>(x => x.Likes);
            string dislikesPropertyName = NameOfHelper.PropertyName<UserCountsEntity>(x => x.Dislikes);
            string viewsPropertyName = NameOfHelper.PropertyName<UserCountsEntity>(x => x.Views);
            string abusesPropertyName = NameOfHelper.PropertyName<UserCountsEntity>(x => x.Abuses);

            _getStatement = new Lazy<PreparedStatement>(() => _session.Get().Prepare(string.Format("SELECT * FROM \"{0}\" WHERE \"{1}\" = ?", entityName, userIdPropertyName)));
            _incViewsStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("UPDATE  \"{0}\" SET \"{2}\" = \"{2}\" + 1 WHERE \"{1}\" = ?", entityName, userIdPropertyName, viewsPropertyName)));
            _incLikesStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("UPDATE  \"{0}\" SET \"{2}\" = \"{2}\" + 1 WHERE \"{1}\" = ?", entityName, userIdPropertyName, likesPropertyName)));
            _incDislikesStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("UPDATE  \"{0}\" SET \"{2}\" = \"{2}\" + 1 WHERE \"{1}\" = ?", entityName, userIdPropertyName, dislikesPropertyName)));
            _decLikesStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("UPDATE  \"{0}\" SET \"{2}\" = \"{2}\" - 1 WHERE \"{1}\" = ?", entityName, userIdPropertyName, likesPropertyName)));
            _decDislikesStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("UPDATE  \"{0}\" SET \"{2}\" = \"{2}\" - 1 WHERE \"{1}\" = ?", entityName, userIdPropertyName, dislikesPropertyName)));
            _incAbuseStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("UPDATE  \"{0}\" SET \"{2}\" = \"{2}\" + 1 WHERE \"{1}\" = ?", entityName, userIdPropertyName, abusesPropertyName)));
        }
Exemplo n.º 2
0
        public ItemSignalsRepository(ICassandraSession session, IMapper mapper)
        {
            _session = session;
            _mapper = mapper;

            // Preparing statements
            TableAttribute tableAttribute = typeof (ItemSignalsEntity).GetCustomAttributes(typeof (TableAttribute), true).Select(a => (TableAttribute)a).First();
            string entityName = tableAttribute.Name;

            string rowKeyPropertyName = NameOfHelper.PropertyName<ItemSignalsEntity>(x => x.ItemIdSignalType);
            string isAnticolumnPropertyName = NameOfHelper.PropertyName<ItemSignalsEntity>(x => x.IsAnticolumn);
            string userIdPropertyName = NameOfHelper.PropertyName<ItemSignalsEntity>(x => x.UserId);
            string dateTimePropertyName = NameOfHelper.PropertyName<ItemSignalsEntity>(x => x.DateTime);

            _insertStatement =
                new Lazy<PreparedStatement>(
                    () =>
                        _session.Get()
                            .Prepare(string.Format("INSERT INTO \"{0}\" (\"{1}\",\"{2}\",\"{3}\",\"{4}\") VALUES(?,false,?,?)", entityName, rowKeyPropertyName, isAnticolumnPropertyName,
                                userIdPropertyName,
                                dateTimePropertyName)));
            _getStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("SELECT * FROM \"{0}\" WHERE \"{1}\" = ? AND \"{2}\" = ?", entityName, rowKeyPropertyName, isAnticolumnPropertyName)));
            _deleteStatement =
                new Lazy<PreparedStatement>(
                    () =>
                        _session.Get()
                            .Prepare(string.Format("INSERT INTO \"{0}\" (\"{1}\",\"{2}\",\"{3}\",\"{4}\") VALUES(?,true,?,?)", entityName, rowKeyPropertyName, isAnticolumnPropertyName,
                                userIdPropertyName,
                                dateTimePropertyName)));
        }
        public AffinityGroupItemCountsRepository(ICassandraSession session, IMapper mapper)
        {
            _session = session;
            _mapper = mapper;

            // Preparing statements
            TableAttribute tableAttribute = typeof (AffinityGroupItemCountsEntity).GetCustomAttributes(typeof (TableAttribute), true).Select(a => (TableAttribute)a).First();
            string entityName = tableAttribute.Name;

            string rowKeyPropertyName = NameOfHelper.PropertyName<AffinityGroupItemCountsEntity>(x => x.AffinityGroupSignalType);
            string itemIdPropertyName = NameOfHelper.PropertyName<AffinityGroupItemCountsEntity>(x => x.ItemId);
            string countPropertyName = NameOfHelper.PropertyName<AffinityGroupItemCountsEntity>(x => x.Count);

            _getByIdStatement =
                new Lazy<PreparedStatement>(() => _session.Get().Prepare(string.Format("SELECT * FROM \"{0}\" WHERE \"{1}\" = ? AND \"{2}\" = ?", entityName, rowKeyPropertyName, itemIdPropertyName)));
            _getStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("SELECT * FROM \"{0}\" WHERE \"{1}\" = ?", entityName, rowKeyPropertyName)));
            _incStatement =
                new Lazy<PreparedStatement>(
                    () =>
                        _session.Get()
                            .Prepare(string.Format("UPDATE  \"{0}\" SET \"{1}\" = \"{1}\" + 1 WHERE \"{2}\" = ? AND \"{3}\" = ?", entityName, countPropertyName, rowKeyPropertyName, itemIdPropertyName)));
            _decStatement =
                new Lazy<PreparedStatement>(
                    () =>
                        _session.Get()
                            .Prepare(string.Format("UPDATE  \"{0}\" SET \"{1}\" = \"{1}\" - 1 WHERE \"{2}\" = ? AND \"{3}\" = ?", entityName, countPropertyName, rowKeyPropertyName, itemIdPropertyName)));
        }
        public AffinityGroupMostSignaledRepository(ICassandraSession session, IMapper mapper)
        {
            _session = session;
            _mapper = mapper;

            // Preparing statements
            TableAttribute tableAttribute = typeof (AffinityGroupMostSignaledEntity).GetCustomAttributes(typeof (TableAttribute), true).Select(a => (TableAttribute)a).First();
            string entityName = tableAttribute.Name;

            string rowKeyPropertyName = NameOfHelper.PropertyName<AffinityGroupMostSignaledEntity>(x => x.AffinityGroupSignalType);
            string countPropertyName = NameOfHelper.PropertyName<AffinityGroupMostSignaledEntity>(x => x.Count);
            string itemIdPropertyName = NameOfHelper.PropertyName<AffinityGroupMostSignaledEntity>(x => x.ItemId);

            _insertStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("INSERT INTO \"{0}\" (\"{1}\",\"{2}\",\"{3}\") VALUES(?,?,?)", entityName, rowKeyPropertyName, countPropertyName, itemIdPropertyName)));
            _getStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("SELECT * FROM \"{0}\" WHERE \"{1}\" = ? ORDER BY \"{2}\" DESC", entityName, rowKeyPropertyName, countPropertyName)));
            _deleteStatement =
                new Lazy<PreparedStatement>(
                    () =>
                        _session.Get()
                            .Prepare(string.Format("DELETE FROM \"{0}\" WHERE \"{1}\" = ?", entityName, rowKeyPropertyName)));
        }
        public AffinityGroupMostSignaledVersionRepository(ICassandraSession session, IMapper mapper)
        {
            _session = session;
            _mapper = mapper;

            // Preparing statements
            TableAttribute tableAttribute = typeof (AffinityGroupMostSignaledVersionEntity).GetCustomAttributes(typeof (TableAttribute), true).Select(a => (TableAttribute)a).First();
            string entityName = tableAttribute.Name;

            string rowKeyPropertyName = NameOfHelper.PropertyName<AffinityGroupMostSignaledVersionEntity>(x => x.AffinityGroupSignalType);
            string versionPropertyName = NameOfHelper.PropertyName<AffinityGroupMostSignaledVersionEntity>(x => x.Version);

            _updateStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("UPDATE \"{0}\" SET \"{1}\" = ? WHERE \"{2}\" = ?", entityName, versionPropertyName, rowKeyPropertyName)));
            _getStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("SELECT * FROM \"{0}\" WHERE \"{1}\" = ?", entityName, rowKeyPropertyName)));
        }
        public TimeSeriesRawRepository(ICassandraSession session, IMapper mapper)
        {
            _session = session;
            _mapper = mapper;

            // Preparing statements
            TableAttribute tableAttribute = typeof (TimeSeriesRawEntity).GetCustomAttributes(typeof (TableAttribute), true).Select(a => (TableAttribute)a).First();
            string entityName = tableAttribute.Name;

            string rowKeyPropertyName = NameOfHelper.PropertyName<TimeSeriesRawEntity>(x => x.EventIdYymmddhh);
            string dateTimePropertyName = NameOfHelper.PropertyName<TimeSeriesRawEntity>(x => x.DateTime);
            string payloadPropertyName = NameOfHelper.PropertyName<TimeSeriesRawEntity>(x => x.Payload);

            _insertStatement =
                new Lazy<PreparedStatement>(
                    () =>
                        _session.Get().Prepare(string.Format("INSERT INTO \"{0}\" (\"{1}\",\"{2}\",\"{3}\") VALUES(?,?,?)", entityName, rowKeyPropertyName, dateTimePropertyName, payloadPropertyName)));
            _getStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("SELECT * FROM \"{0}\" WHERE \"{1}\" = ? AND \"{2}\" >= ? AND \"{2}\" <= ?", entityName, rowKeyPropertyName, dateTimePropertyName)));
        }
        public TimeSeriesRollupsDayRepository(ICassandraSession session, IMapper mapper)
        {
            _session = session;
            _mapper = mapper;

            // Preparing statements
            TableAttribute tableAttribute = typeof (TimeSeriesRollupsDayEntity).GetCustomAttributes(typeof (TableAttribute), true).Select(a => (TableAttribute)a).First();
            string entityName = tableAttribute.Name;

            string rowKeyPropertyName = NameOfHelper.PropertyName<TimeSeriesRollupsDayEntity>(x => x.EventId);
            string dayPropertyName = NameOfHelper.PropertyName<TimeSeriesRollupsDayEntity>(x => x.Day);
            string countPropertyName = NameOfHelper.PropertyName<TimeSeriesRollupsDayEntity>(x => x.Count);

            _getStatement =
                new Lazy<PreparedStatement>(
                    () => _session.Get().Prepare(string.Format("SELECT * FROM \"{0}\" WHERE \"{1}\" = ? AND \"{2}\" >= ? AND \"{2}\" <= ?", entityName, rowKeyPropertyName, dayPropertyName)));
            _incStatement =
                new Lazy<PreparedStatement>(
                    () =>
                        _session.Get()
                            .Prepare(string.Format("UPDATE  \"{0}\" SET \"{1}\" = \"{1}\" + 1 WHERE \"{2}\" = ? AND \"{3}\" = ?", entityName, countPropertyName, rowKeyPropertyName, dayPropertyName)));
        }