Esempio n. 1
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 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(type: ColumnType.Super)
                    {
                        FamilyName             = "SuperCounters",
                        SuperColumnNameType    = CassandraType.AsciiType,
                        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
);");
                    db.ExecuteNonQuery(@"CREATE INDEX User_Age ON ""Users"" (Age);");

                    db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Cql3List (
    Id int PRIMARY KEY,
    TagList list<text> --list of strings
);");

                    db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Cql3Set (
    Id int PRIMARY KEY,
    TagSet set<uuid> --set of Guids
);");

                    db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Cql3Map (
    Id int PRIMARY KEY,
    TagMap map<bigint,uuid> --map of long integers and Guids
);");
                    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);
                }
        }