Example #1
0
        public FluentColumnFamily <AsciiType> Create()
        {
            var post = _family.CreateRecord(Guid.NewGuid());

            Database.Attach(post);

            return(post);
        }
Example #2
0
        public FluentColumnFamily <AsciiType> Create(Guid postKey)
        {
            dynamic comment = _family.CreateRecord(Guid.NewGuid());

            comment.PostKey = postKey;

            return(comment);
        }
        public void Save(Dummy dummy)
        {
            dynamic d = _dummies.CreateRecord(dummy.Id);

            d.Blob = dummy.Blob;
            _context.Attach(d);
            _context.SaveChanges();
        }
        public void ResetUsersFamily(CassandraColumnFamily userFamily = null)
        {
            userFamily = userFamily ?? UserFamily;

            var db = userFamily.Context;

            userFamily.RemoveAllRows();

            foreach (var user in Users)
            {
                dynamic record = userFamily.CreateRecord(user.Id);
                record.Name  = user.Name;
                record.Email = user.Email;
                record.Age   = user.Age;

                db.Attach(record);
            }

            db.SaveChanges();
        }
		public void ResetUsersFamily(CassandraColumnFamily userFamily = null)
		{
			userFamily = userFamily ?? UserFamily;

			var db = userFamily.Context;
			userFamily.RemoveAllRows();

			foreach (var user in Users)
			{
				dynamic record = userFamily.CreateRecord(user.Id);
				record.Name = user.Name;
				record.Email = user.Email;
				record.Age = user.Age;

				db.Attach(record);
			}

			db.SaveChanges();
		}
        public CassandraDatabaseSetup(bool volitile = false)
        {
            var keyspaceName = "Testing";
            var server = new Server("localhost");

            DB = new CassandraContext(keyspaceName, server);
            DB.ThrowErrors = true;

            var exists = DB.KeyspaceExists(keyspaceName);
            Users = new[] {
                new User { Id = 1, Name = "Darren Gemmell", Email = "*****@*****.**", Age = 32 },
                new User { Id = 2, Name = "Fernando Laubscher", Email = "*****@*****.**", Age = 23 },
                new User { Id = 3, Name = "Cody Millhouse", Email = "*****@*****.**", Age = 56 },
                new User { Id = 4, Name = "Emilia Thibert", Email = "*****@*****.**", Age = 67 },
                new User { Id = 5, Name = "Allyson Schurr", Email = "*****@*****.**", Age = 21 }
            };

            Family = DB.GetColumnFamily<AsciiType>("Standard");
            SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");
            UserFamily = DB.GetColumnFamily("Users");

            if (exists && !volitile)
                return;

            using (var session = DB.OpenSession())
            {
                if (exists)
                    DB.DropKeyspace(keyspaceName);

                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema { Name = keyspaceName, Strategy = CassandraKeyspaceSchema.ReplicaPlacementStrategySimple, ReplicationFactor = 1 }, DB);
                DB.Keyspace = keyspace;

                keyspace.TryCreateSelf();
                keyspace.TryCreateColumnFamily<AsciiType>("Standard");
                keyspace.TryCreateColumnFamily<AsciiType, AsciiType>("Super");
                keyspace.TryCreateColumnFamily<AsciiType>("StandardAsciiType");
                keyspace.TryCreateColumnFamily<BytesType>("StandardBytesType");
                keyspace.TryCreateColumnFamily<IntegerType>("StandardIntegerType");
                keyspace.TryCreateColumnFamily<LexicalUUIDType>("StandardLexicalUUIDType");
                keyspace.TryCreateColumnFamily<LongType>("StandardLongType");
                keyspace.TryCreateColumnFamily<TimeUUIDType>("StandardTimeUUIDType");
                keyspace.TryCreateColumnFamily<UTF8Type>("StandardUTF8Type");
                keyspace.TryCreateColumnFamily<UUIDType>("StandardUUIDType");
                keyspace.TryCreateColumnFamily<CompositeType<LongType, UTF8Type>>("StandardCompositeType");
                keyspace.TryCreateColumnFamily<DynamicCompositeType>("StandardDynamicCompositeType");

                Family = DB.GetColumnFamily<AsciiType>("Standard");
                SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");

                Family.InsertColumn(TestKey1, "Test1", Math.PI);
                Family.InsertColumn(TestKey1, "Test2", Math.PI);
                Family.InsertColumn(TestKey1, "Test3", Math.PI);

                SuperFamily.InsertColumn(TestKey1, TestSuperName, "Test1", Math.PI);
                SuperFamily.InsertColumn(TestKey1, TestSuperName, "Test2", Math.PI);
                SuperFamily.InsertColumn(TestKey1, TestSuperName, "Test3", Math.PI);

                Family.InsertColumn(TestKey2, "Test1", Math.PI);
                Family.InsertColumn(TestKey2, "Test2", Math.PI);
                Family.InsertColumn(TestKey2, "Test3", Math.PI);

                SuperFamily.InsertColumn(TestKey2, TestSuperName, "Test1", Math.PI);
                SuperFamily.InsertColumn(TestKey2, TestSuperName, "Test2", Math.PI);
                SuperFamily.InsertColumn(TestKey2, TestSuperName, "Test3", Math.PI);

                DB.ExecuteNonQuery(@"
            CREATE COLUMNFAMILY Users (
            KEY int PRIMARY KEY,
            Name ascii,
            Email ascii,
            Age int
            );");
                DB.ExecuteNonQuery(@"CREATE INDEX User_Age ON Users (Age);");
                DB.Keyspace.ClearCachedKeyspaceSchema();
                UserFamily = DB.GetColumnFamily("Users");

                foreach (var user in Users)
                {
                    dynamic record = UserFamily.CreateRecord(user.Id);
                    record.Name = user.Name;
                    record.Email = user.Email;
                    record.Age = user.Age;

                    DB.Attach(record);
                }
                DB.SaveChanges();
            }
        }