public void ResetDatabase()
		{
			using (var session = new CassandraSession(ConnectionBuilder))
			using (var db = new CassandraContext(session))
			{
				db.ThrowErrors = true;
				db.TryDropKeyspace(Keyspace);

				var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema {
					Name = Keyspace
				}, 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(new CassandraColumnFamilySchema {
					FamilyName = "StandardDecimalType",
					ColumnNameType = CassandraType.DecimalType
				});
				keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
					FamilyName = "StandardCompositeType",
					ColumnNameType = CassandraType.CompositeType(new[] { CassandraType.AsciiType, CassandraType.DoubleType })
				});
				keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
					FamilyName = "StandardDynamicCompositeType",
					ColumnNameType = CassandraType.DynamicCompositeType(new Dictionary<char, CassandraType> { { 'a', CassandraType.AsciiType }, { 'd', CassandraType.DoubleType } })
				});

				db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Users (
	Id int PRIMARY KEY,
	Name ascii,
	Email ascii,
	Age int
);");
				db.ExecuteNonQuery(@"CREATE INDEX User_Age ON Users (Age);");
				db.Keyspace.ClearCachedKeyspaceSchema();

				var family = db.GetColumnFamily<AsciiType>("Standard");
				var superFamily = db.GetColumnFamily<AsciiType, AsciiType>("Super");
				var userFamily = db.GetColumnFamily("Users");

				ResetFamily(family);
				ResetSuperFamily(superFamily);
				ResetUsersFamily(userFamily);
			}
		}
Пример #2
0
        private static void SetupKeyspace()
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {
                if (db.KeyspaceExists(KeyspaceName))
                    db.DropKeyspace(KeyspaceName);

                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
                {
                    Name = KeyspaceName,
                }, db);

                keyspace.TryCreateSelf();

                // create column family using CQL
                db.ExecuteNonQuery(@"
                CREATE COLUMNFAMILY Posts (
                KEY ascii PRIMARY KEY,
                Title text,
                Body text,
                Author text,
                PostedOn timestamp
                );");

                // create column family using API
                keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
                {
                    FamilyName = "Tags",
                    KeyValueType = CassandraType.AsciiType,
                    ColumnNameType = CassandraType.Int32Type,
                    DefaultColumnValueType = CassandraType.UTF8Type
                });

                // create super column family using API
                keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
                {
                    FamilyName = "Comments",
                    FamilyType = ColumnType.Super,
                    KeyValueType = CassandraType.AsciiType,
                    SuperColumnNameType = CassandraType.DateType,
                    ColumnNameType = CassandraType.UTF8Type,
                    DefaultColumnValueType = CassandraType.UTF8Type
                });
            }
        }
Пример #3
0
        public void ResetDatabase()
        {
            using (var session = new CassandraSession(ConnectionBuilder))
                using (var db = new CassandraContext(session))
                {
                    db.ThrowErrors = true;
                    db.TryDropKeyspace(Keyspace);

                    var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
                    {
                        Name = Keyspace
                    }, 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(new CassandraColumnFamilySchema
                    {
                        FamilyName     = "StandardCompositeType",
                        ColumnNameType = CassandraType.CompositeType(new[] { CassandraType.AsciiType, CassandraType.DoubleType })
                    });
                    keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
                    {
                        FamilyName     = "StandardDynamicCompositeType",
                        ColumnNameType = CassandraType.DynamicCompositeType(new Dictionary <char, CassandraType> {
                            { 'a', CassandraType.AsciiType }, { 'd', CassandraType.DoubleType }
                        })
                    });

                    db.ExecuteNonQuery(string.Format(@"
CREATE TABLE {0} (
	id int ,
	name ascii,
	email ascii,
	age int,
    PRIMARY KEY(id)
);", toLowerIf(toLower, "Users")));

                    //db.ExecuteNonQuery(@"CREATE INDEX User_Age ON users (Age);");
                    db.Keyspace.ClearCachedKeyspaceSchema();

                    var family      = db.GetColumnFamily <AsciiType>("Standard");
                    var superFamily = db.GetColumnFamily <AsciiType, AsciiType>("Super");
                    var userFamily  = db.GetColumnFamily(toLowerIf(toLower, "Users"));

                    ResetFamily(family);
                    ResetSuperFamily(superFamily);
                    ResetUsersFamily(userFamily);
                }
        }
        public _CassandraSetup()
        {
            var keyspaceName = "Testing";
            var server = new Server("localhost");

            if (CassandraSession.KeyspaceExists(server, keyspaceName))
                CassandraSession.DropKeyspace(server, keyspaceName);

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

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

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

            Family.RemoveAllRows();
            SuperFamily.RemoveAllRows();

            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);
        }
        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();
            }
        }
Пример #6
0
        public void ResetDatabase()
        {
            using (var session = new CassandraSession(ConnectionBuilder))
                using (var db = new CassandraContext(session))
                {
                    db.ThrowErrors = true;
                    db.TryDropKeyspace(Keyspace);

                    var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema {
                        Name = Keyspace
                    }, 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(new CassandraColumnFamilySchema()
                    {
                        FamilyName             = "Counters",
                        ColumnNameType         = CassandraType.AsciiType,
                        DefaultColumnValueType = CassandraType.CounterColumnType
                    });
                    keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
                        FamilyName     = "StandardDecimalType",
                        ColumnNameType = CassandraType.DecimalType
                    });
                    keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
                        FamilyName     = "StandardCompositeType",
                        ColumnNameType = CassandraType.CompositeType(new[] { CassandraType.AsciiType, CassandraType.DoubleType })
                    });
                    keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
                        FamilyName     = "StandardDynamicCompositeType",
                        ColumnNameType = CassandraType.DynamicCompositeType(new Dictionary <char, CassandraType> {
                            { 'a', CassandraType.AsciiType }, { 'd', CassandraType.DoubleType }
                        })
                    });

                    db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Users (
	Id int PRIMARY KEY,
	Name ascii,
	Email ascii,
	Age int
);", CqlVersion.Cql);
                    db.ExecuteNonQuery(@"CREATE INDEX User_Age ON Users (Age);", CqlVersion.Cql);
                    db.Keyspace.ClearCachedKeyspaceSchema();

                    var family        = db.GetColumnFamily <AsciiType>("Standard");
                    var superFamily   = db.GetColumnFamily <AsciiType, AsciiType>("Super");
                    var userFamily    = db.GetColumnFamily("Users");
                    var counterFamily = db.GetColumnFamily("Counters");

                    ResetFamily(family);
                    ResetSuperFamily(superFamily);
                    ResetUsersFamily(userFamily);
                    ResetCounterColumnFamily(counterFamily);
                }
        }