本文整理汇总了C#中CassandraContext.KeyspaceExists方法的典型用法代码示例。如果您正苦于以下问题:C# CassandraContext.KeyspaceExists方法的具体用法?C# CassandraContext.KeyspaceExists怎么用?C# CassandraContext.KeyspaceExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CassandraContext
的用法示例。
在下文中一共展示了CassandraContext.KeyspaceExists方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompatibilityCassandraDatabaseSetup
public CompatibilityCassandraDatabaseSetup(bool reset = false, bool toLower = false, bool toLower2 = false)
{
this.toLower = toLower;
this.toLower2 = toLower2;
ConnectionBuilder = new ConnectionBuilder(keyspace: Keyspace, server: Server, cqlVersion: CqlVersion.Cql3);
DB = new CassandraContext(ConnectionBuilder);
if (DB.KeyspaceExists(Keyspace))
DB.DropKeyspace(Keyspace);
var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
{
Name = Keyspace,
}, DB);
var exists = DB.KeyspaceExists(Keyspace);
if(!exists)
keyspace.TryCreateSelf();
Family = DB.GetColumnFamily<AsciiType>("Standard");
SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");
UserFamily = DB.GetColumnFamily(toLowerIf(toLower,"Users"));
if (exists && !reset)
return;
ResetDatabase();
}
示例2: GenericDatabaseSetup
public GenericDatabaseSetup(bool reset = false)
{
ConnectionBuilder = new ConnectionBuilder(keyspace: Keyspace, server: Server, cqlVersion: CqlVersion.Cql3);
DB = new CassandraContext(ConnectionBuilder);
if (DB.KeyspaceExists(Keyspace))
DB.DropKeyspace(Keyspace);
var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
{
Name = Keyspace,
}, DB);
var exists = DB.KeyspaceExists(Keyspace);
if (!exists)
keyspace.TryCreateSelf();
if (exists && !reset)
return;
ResetDatabase();
}
示例3: CassandraDatabaseSetup
public CassandraDatabaseSetup(bool reset = false)
{
ConnectionBuilder = new ConnectionBuilder(keyspace: Keyspace, server: Server);
DB = new CassandraContext(ConnectionBuilder);
var exists = DB.KeyspaceExists(Keyspace);
Family = DB.GetColumnFamily<AsciiType>("Standard");
SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");
UserFamily = DB.GetColumnFamily("Users");
if (exists && !reset)
return;
ResetDatabase();
}
示例4: SetupKeyspace
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
});
}
}
示例5: Init
public void Init()
{
_context = new CassandraContext(keyspace: DummiesKeySpace, host: "localhost");
if (!_context.KeyspaceExists(DummiesKeySpace))
{
var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
{
Name = DummiesKeySpace,
}, _context);
keyspace.TryCreateSelf();
_context.ExecuteQuery(
@"
CREATE COLUMNFAMILY Dummies (
KEY ascii PRIMARY KEY,
Blob blob
);");
_context.SaveChanges();
}
_dummies = _context.GetColumnFamily("Dummies");
}
示例6: CassandraDatabaseSetup
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 = "[email protected]", Age = 32 },
new User { Id = 2, Name = "Fernando Laubscher", Email = "[email protected]", Age = 23 },
new User { Id = 3, Name = "Cody Millhouse", Email = "[email protected]", Age = 56 },
new User { Id = 4, Name = "Emilia Thibert", Email = "[email protected]", Age = 67 },
new User { Id = 5, Name = "Allyson Schurr", Email = "[email protected]", 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();
}
}
示例7: SetupKeyspace
private static void SetupKeyspace()
{
using (var db = new CassandraContext(keyspace: keyspaceName, server: server))
{
if (!db.KeyspaceExists(keyspaceName))
db.AddKeyspace(new KsDef {
Name = keyspaceName,
Replication_factor = 1,
Strategy_class = "org.apache.cassandra.locator.SimpleStrategy",
Cf_defs = new List<CfDef>()
});
if (!db.Keyspace.ColumnFamilyExists("Posts"))
db.AddColumnFamily(new CfDef {
Name = "Posts",
Keyspace = keyspaceName,
Column_type = "Super",
Comparator_type = "UTF8Type",
Subcomparator_type = "UTF8Type",
Comment = "Used for blog posts."
});
}
}
示例8: Test
public static void Test()
{
int TestTimeInMinutes = 10;
int ThreadCount = 50;
int ThreadCount2 = 10;
int TimeOut_Sec = 5;
bool usePooling = true;
object alive_monitor = new object();
bool alive_condition = true;
List<Thread> threads = new List<Thread>();
int thrStarted_cnt = 0;
object thrStarted_monitor = new object();
//initialize
CassandraContext main_db = new CassandraContext(new ConnectionBuilder(keyspace: KeyspaceName, server: Server, cqlVersion: CqlVersion.Cql3, pooling: usePooling));
{
if (main_db.KeyspaceExists(KeyspaceName))
main_db.DropKeyspace(KeyspaceName);
var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
{
Name = KeyspaceName,
}, main_db);
keyspace.TryCreateSelf();
CreateTablesIfNotExists(main_db);
}
for (int tI = 0; tI < ThreadCount; tI++)
{
int thrNo = tI;
var thr = new Thread(() =>
{
Console.Write("(*" + thrNo + ")");
try
{
CassandraContext db = new CassandraContext(new ConnectionBuilder(keyspace: KeyspaceName, server: Server, cqlVersion: CqlVersion.Cql3, pooling: usePooling));
lock (thrStarted_monitor)
{
thrStarted_cnt++;
Monitor.PulseAll(thrStarted_monitor);
}
while (true)
{
var job = GetJob(db, 10);
if (job != null)
{
Console.Write("-");
if (job.GetLogic() == null || job.GetCommand() == null)
Console.WriteLine("Error");
DeleteJob(db, job);
}
else
{
lock (alive_monitor)
{
if (!alive_condition)
return;
else
Monitor.Wait(alive_monitor, TimeOut_Sec * 1000);
}
}
}
}
finally
{
Console.Write("(~" + thrNo + ")");
}
});
threads.Add(thr);
thr.Start();
}
for (int tI = 0; tI < ThreadCount2; tI++)
{
int thrNo = tI;
var thr = new Thread(() =>
{
Console.Write("<*" + thrNo + ">");
try
{
CassandraContext db = new CassandraContext(new ConnectionBuilder(keyspace: KeyspaceName, server: Server, cqlVersion: CqlVersion.Cql3, pooling: usePooling));
lock (thrStarted_monitor)
{
thrStarted_cnt++;
Monitor.PulseAll(thrStarted_monitor);
}
while (true)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 100; i++)
sb.AppendLine(Guid.NewGuid().ToString());
AddJob(db, sb.ToString(), Guid.NewGuid().ToString());
//.........这里部分代码省略.........