public void GlobalSetup() { _client = new Client(Params.Instance.Value.Host).Start(); _cacheA = _client.GetOrCreateCache <int, ModelA>(typeof(ModelA).Name); _cacheB = _client.GetOrCreateCache <int, ModelB>(typeof(ModelB).Name); _cacheC = _client.GetOrCreateCache <int, ModelC>(typeof(ModelC).Name); _cacheD = _client.GetOrCreateCache <int, ModelD>(typeof(ModelD).Name); _cacheE = _client.GetOrCreateCache <int, ModelE>(typeof(ModelE).Name); _cacheF = _client.GetOrCreateCache <AffinityKey, ModelA>(typeof(ModelA).Name + "Affinity"); _cacheG = _client.GetOrCreateCache <AffinityKey, ModelB>(typeof(ModelB).Name + "Affinity"); _cacheH = _client.GetOrCreateCache <AffinityKey, ModelC>(typeof(ModelC).Name + "Affinity"); _cacheI = _client.GetOrCreateCache <AffinityKey, ModelD>(typeof(ModelD).Name + "Affinity"); _cacheJ = _client.GetOrCreateCache <AffinityKey, ModelE>(typeof(ModelE).Name + "Affinity"); _max = Params.Instance.Value.TotalObjects; var data = new Data(); var keys = Enumerable.Range(0, _max).ToArray(); FillCache(_cacheA, keys, data.GetModelsA()); FillCache(_cacheB, keys, data.GetModelsB()); FillCache(_cacheC, keys, data.GetModelsC()); FillCache(_cacheD, keys, data.GetModelsD()); FillCache(_cacheE, keys, data.GetModelsE()); var affinityKeys = Enumerable.Range(0, _max).Select(k => new AffinityKey(k, k / 10)).ToArray(); FillCache(_cacheF, affinityKeys, data.GetModelsA()); FillCache(_cacheG, affinityKeys, data.GetModelsB()); FillCache(_cacheH, affinityKeys, data.GetModelsC()); FillCache(_cacheI, affinityKeys, data.GetModelsD()); FillCache(_cacheJ, affinityKeys, data.GetModelsE()); }
public static void Main() { var cfg = new IgniteClientConfiguration("127.0.0.1"); using (IIgniteClient igniteClient = Ignition.StartClient(cfg)) { Console.WriteLine(); Console.WriteLine(">>> Cache query client example started."); // Configure query entities to enable SQL. var cacheCfg = new CacheClientConfiguration { Name = CacheName, QueryEntities = new[] { new QueryEntity(typeof(int), typeof(Employee)), } }; ICacheClient <int, Employee> cache = igniteClient.GetOrCreateCache <int, Employee>(cacheCfg); // Populate cache with sample data entries. PopulateCache(cache); // Run examples. SqlExample(cache); LinqExample(cache); LinqFieldsExample(cache); } Console.WriteLine(); Console.WriteLine(">>> Example finished, press any key to exit ..."); Console.ReadKey(); }
public static void Main() { using (IIgniteClient ignite = Ignition.StartClient(Utils.GetThinClientConfiguration())) { Console.WriteLine(); Console.WriteLine(">>> Cache scan query example started."); var employeeCache = ignite.GetOrCreateCache <int, Employee>( new CacheClientConfiguration(EmployeeCacheName, new QueryEntity(typeof(int), typeof(Employee)))); Utils.PopulateCache(employeeCache); const int zip = 94109; var qry = employeeCache.Query(new ScanQuery <int, Employee>(new ScanQueryFilter(zip))); Console.WriteLine(); Console.WriteLine(">>> Employees with zipcode {0} (scan):", zip); foreach (var entry in qry) { Console.WriteLine(">>> " + entry.Value); } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine(">>> Example finished, press any key to exit ..."); Console.ReadKey(); }
public static void Main() { var cfg = new IgniteClientConfiguration { Host = "127.0.0.1" }; using (IIgniteClient igniteClient = Ignition.StartClient(cfg)) { Console.WriteLine(); Console.WriteLine(">>> Cache query client example started."); ICacheClient <int, Employee> cache = igniteClient.GetOrCreateCache <int, Employee>(CacheName); // Populate cache with sample data entries. PopulateCache(cache); // Run scan query example. ScanQueryExample(cache); } Console.WriteLine(); Console.WriteLine(">>> Example finished, press any key to exit ..."); Console.ReadKey(); }
public void PopulateEmployees() { List <Employee> messages = new List <Employee> { new Employee { Name = "abc", Salary = 100, EmpId = "1" }, new Employee { Name = "abc-1", Salary = 200, EmpId = "2" }, new Employee { Name = "abc-2", Salary = 400, EmpId = "3" }, new Employee { Name = "abc-3", Salary = 300, EmpId = "4" }, new Employee { Name = "abc-4", Salary = 200, EmpId = "5" }, }; ICacheClient <string, Employee> cache = null; foreach (var mess in messages) { using (IIgniteClient client = Ignition.StartClient(this._igniteClientConfiguration)) { //get cache configuraation cache = client.GetOrCreateCache <string, Employee>(GetOrCreateEmployeeCacheConfig("Employees")); cache.Put(mess.EmpId, mess); Console.WriteLine(cache.Get(mess.EmpId).Name); } } }
public void PopulateMessages() { List <ChatMessege> messages = new List <ChatMessege> { new ChatMessege { Name = "abc", CreatedDateTime = "1562770732" }, new ChatMessege { Name = "abc", CreatedDateTime = "1562770728" }, new ChatMessege { Name = "abc-1", CreatedDateTime = "1562770724" }, new ChatMessege { Name = "abc-3", CreatedDateTime = "1562770742" }, new ChatMessege { Name = "abc-3", CreatedDateTime = "1562770743" } }; foreach (var mess in messages) { using (IIgniteClient client = Ignition.StartClient(this._igniteClientConfiguration)) { //get cache configuraation var cache = client.GetOrCreateCache <string, ChatMessege>(GetOrCreaeMessageCacheConfig("messages")); cache.Put(mess.Name, mess); Console.WriteLine(cache.Get(mess.Name).Name); } } }
public static void Main() { using (IIgniteClient ignite = Ignition.StartClient(Utils.GetThinClientConfiguration())) { Console.WriteLine(); Console.WriteLine(">>> Optimistic transaction example started."); // Create Transactional cache. var cacheCfg = new CacheClientConfiguration(CacheName) { AtomicityMode = CacheAtomicityMode.Transactional }; var cache = ignite.GetOrCreateCache <int, int>(cacheCfg); // Put a value. cache[1] = 0; // Increment a value in parallel within a transaction. var transactions = ignite.GetTransactions(); var task1 = Task.Factory.StartNew(() => IncrementCacheValue(cache, transactions, 1)); var task2 = Task.Factory.StartNew(() => IncrementCacheValue(cache, transactions, 2)); Task.WaitAll(task1, task2); Console.WriteLine(); Console.WriteLine(">>> Resulting value in cache: " + cache[1]); Console.WriteLine(); Console.WriteLine(">>> Example finished, press any key to exit ..."); Console.ReadKey(); } }
public void TestReconnectToOldNodeDisablesPartitionAwareness() { IIgniteClient client = null; var clientConfiguration = new IgniteClientConfiguration(JavaServer.GetClientConfiguration()) { EnablePartitionAwareness = true, Logger = new ListLogger(new ConsoleLogger { MinLevel = LogLevel.Trace }) }; try { using (StartNewServer()) { client = Ignition.StartClient(clientConfiguration); var cache = client.GetOrCreateCache <int, int>(TestContext.CurrentContext.Test.Name); cache.Put(1, 42); Assert.AreEqual(42, cache.Get(1)); Assert.IsTrue(client.GetConfiguration().EnablePartitionAwareness); } Assert.Catch(() => client.GetCacheNames()); using (StartOldServer()) { var cache = client.GetOrCreateCache <int, int>(TestContext.CurrentContext.Test.Name); cache.Put(1, 42); Assert.AreEqual(42, cache.Get(1)); Assert.IsFalse(client.GetConfiguration().EnablePartitionAwareness); var log = ((ListLogger)client.GetConfiguration().Logger).Entries .FirstOrDefault(e => e.Message.StartsWith("Partition")); Assert.IsNotNull(log); Assert.AreEqual("Partition awareness has been disabled: " + "server protocol version 1.0.0 is lower than required 1.4.0", log.Message); } } finally { if (client != null) { client.Dispose(); } } }
/// <summary> /// Gets or creates transactional cache /// </summary> private ICacheClient <int, int> GetTransactionalCache(IIgniteClient client, string cacheName = null) { return(client.GetOrCreateCache <int, int>(new CacheClientConfiguration { Name = cacheName ?? GetCacheName(), AtomicityMode = CacheAtomicityMode.Transactional })); }
public void GlobalSetup() { _client = new Client(Params.Instance.Value.Host).Start(); _cacheA = _client.GetOrCreateCache <int, ModelA>(typeof(ModelA).Name); _cacheB = _client.GetOrCreateCache <int, ModelB>(typeof(ModelB).Name); _cacheC = _client.GetOrCreateCache <int, ModelC>(typeof(ModelC).Name); _cacheD = _client.GetOrCreateCache <int, ModelD>(typeof(ModelD).Name); _cacheE = _client.GetOrCreateCache <int, ModelE>(typeof(ModelE).Name); _cacheF = _client.GetOrCreateCache <AffinityKey, ModelA>(typeof(ModelA).Name + "Affinity"); _cacheG = _client.GetOrCreateCache <AffinityKey, ModelB>(typeof(ModelB).Name + "Affinity"); _cacheH = _client.GetOrCreateCache <AffinityKey, ModelC>(typeof(ModelC).Name + "Affinity"); _cacheI = _client.GetOrCreateCache <AffinityKey, ModelD>(typeof(ModelD).Name + "Affinity"); _cacheJ = _client.GetOrCreateCache <AffinityKey, ModelE>(typeof(ModelE).Name + "Affinity"); _modelsA = new Data().GetModelsA(); _modelsB = new Data().GetModelsB(); _modelsC = new Data().GetModelsC(); _modelsD = new Data().GetModelsD(); _modelsE = new Data().GetModelsE(); _max = Params.Instance.Value.TotalObjects; }
public static void Main() { var cfg = new IgniteClientConfiguration("127.0.0.1"); using (IIgniteClient igniteClient = Ignition.StartClient(cfg)) { Console.WriteLine(); Console.WriteLine(">>> Cache put-get client example started."); ICacheClient <int, Organization> cache = igniteClient.GetOrCreateCache <int, Organization>(CacheName); PutGet(cache); } Console.WriteLine(); Console.WriteLine(">>> Example finished, press any key to exit ..."); Console.ReadKey(); }
public static void Main() { using (IIgniteClient ignite = Ignition.StartClient(Utils.GetThinClientConfiguration())) { Console.WriteLine(); Console.WriteLine(">>> Cache continuous query example started."); var cache = ignite.GetOrCreateCache <int, string>(CacheName); // Clean up caches on all nodes before run. cache.Clear(); const int keyCnt = 20; for (int i = 0; i < keyCnt; i++) { cache.Put(i, i.ToString()); } var qry = new ContinuousQueryClient <int, string> { Listener = new Listener <string>(), Filter = new ContinuousQueryFilter(15) }; // Create new continuous query. using (cache.QueryContinuous(qry)) { // Add a few more keys and watch more query notifications. for (var i = keyCnt; i < keyCnt + 5; i++) { cache.Put(i, i.ToString()); } // Wait for a while while callback is notified about remaining puts. Thread.Sleep(2000); } } Console.WriteLine(); Console.WriteLine(">>> Example finished, press any key to exit ..."); Console.ReadKey(); }
public static ICacheClient <TKey, TData> GetOrCreateCache <TKey, TData>(IIgniteClient ignite, string cacheName, Action <CacheClientConfiguration> extendConfigurationAction = null) { var cacheCfg = new CacheClientConfiguration() { Name = cacheName, CacheMode = CacheMode.Partitioned, GroupName = typeof(TData).FullName, QueryEntities = new[] { new QueryEntity { KeyType = typeof(TKey), ValueType = typeof(TData), } } }; extendConfigurationAction?.Invoke(cacheCfg); return(ignite.GetOrCreateCache <TKey, TData>(cacheCfg)); }
public static void Main() { using (IIgniteClient ignite = Ignition.StartClient(Utils.GetThinClientConfiguration())) { Console.WriteLine(); Console.WriteLine(">>> Cache put-get example started."); // Clean up caches on all nodes before run. ignite.GetOrCreateCache <object, object>(CacheName).Clear(); PutGet(ignite); PutGetBinary(ignite); PutAllGetAll(ignite); PutAllGetAllBinary(ignite); Console.WriteLine(); } Console.WriteLine(); Console.WriteLine(">>> Example finished, press any key to exit ..."); Console.ReadKey(); }
public static void Main() { using (IIgniteClient ignite = Ignition.StartClient(Utils.GetThinClientConfiguration())) { Console.WriteLine(); Console.WriteLine(">>> Binary mode example started."); // Create new cache and configure queries for Person and Company binary types. // Note that there are no such classes defined. var cache0 = ignite.GetOrCreateCache <object, object>(new CacheClientConfiguration { Name = CacheName, QueryEntities = new[] { new QueryEntity { KeyType = typeof(int), ValueTypeName = PersonType, Fields = new[] { new QueryField(NameField, typeof(string)), new QueryField(CompanyIdField, typeof(int)), }, Indexes = new[] { new QueryIndex(false, QueryIndexType.FullText, NameField), new QueryIndex(false, QueryIndexType.Sorted, CompanyIdField) } }, new QueryEntity { KeyType = typeof(int), ValueTypeName = CompanyType, Fields = new[] { new QueryField(IdField, typeof(int)), new QueryField(NameField, typeof(string)) } } } }); // Switch to binary mode to work with data in serialized form. var cache = cache0.WithKeepBinary <int, IBinaryObject>(); // Clean up caches on all nodes before run. cache.Clear(); // Populate cache with sample data entries. PopulateCache(cache, ignite.GetBinary()); // Run read & modify example. ReadModifyExample(cache); // Run SQL query example. SqlQueryExample(cache); // Run SQL query with join example. SqlJoinQueryExample(cache); Console.WriteLine(); } Console.WriteLine(); Console.WriteLine(">>> Example finished, press any key to exit ..."); Console.ReadKey(); }
public static void Main() { using (IIgniteClient ignite = Ignition.StartClient(Utils.GetThinClientConfiguration())) { Console.WriteLine(); Console.WriteLine(">>> Transaction example started."); var cache = ignite.GetOrCreateCache <int, Account>(new CacheClientConfiguration { Name = CacheName, AtomicityMode = CacheAtomicityMode.Transactional }); InitAccounts(cache); Console.WriteLine("\n>>> Transferring with Ignite transaction API..."); // Transfer money between accounts in a single transaction. using (var tx = ignite.GetTransactions().TxStart(TransactionConcurrency.Pessimistic, TransactionIsolation.RepeatableRead)) { Account acc1 = cache.Get(1); Account acc2 = cache.Get(2); acc1.Balance += 100; acc2.Balance -= 100; cache.Put(1, acc1); cache.Put(2, acc2); tx.Commit(); } DisplayAccounts(cache); InitAccounts(cache); Console.WriteLine("\n>>> Transferring with TransactionScope API..."); // Do the same transaction with TransactionScope API. using (var ts = new TransactionScope()) { Account acc1 = cache.Get(1); Account acc2 = cache.Get(2); acc1.Balance += 100; acc2.Balance -= 100; cache.Put(1, acc1); cache.Put(2, acc2); ts.Complete(); } DisplayAccounts(cache); } Console.WriteLine(); Console.WriteLine(">>> Example finished, press any key to exit ..."); Console.ReadKey(); }
public static void Main() { using (IIgniteClient ignite = Ignition.StartClient(Utils.GetThinClientConfiguration())) { Console.WriteLine(); Console.WriteLine(">>> Cache query DDL example started."); // Create dummy cache to act as an entry point for SQL queries (new SQL API which do not require this // will appear in future versions, JDBC and ODBC drivers do not require it already). var cacheCfg = new CacheClientConfiguration("dummy_cache") { SqlSchema = "PUBLIC", CacheMode = CacheMode.Replicated }; ICacheClient <object, object> cache = ignite.GetOrCreateCache <object, object>(cacheCfg); // Create reference City table based on REPLICATED template. cache.Query(new SqlFieldsQuery( "CREATE TABLE city (id LONG PRIMARY KEY, name VARCHAR) WITH \"template=replicated\"")).GetAll(); // Create table based on PARTITIONED template with one backup. cache.Query(new SqlFieldsQuery( "CREATE TABLE person (id LONG, name VARCHAR, city_id LONG, PRIMARY KEY (id, city_id)) " + "WITH \"backups=1, affinity_key=city_id\"")).GetAll(); // Create an index. cache.Query(new SqlFieldsQuery("CREATE INDEX on Person (city_id)")).GetAll(); Console.WriteLine("\n>>> Created database objects."); const string addCity = "INSERT INTO city (id, name) VALUES (?, ?)"; cache.Query(new SqlFieldsQuery(addCity, 1L, "Forest Hill")); cache.Query(new SqlFieldsQuery(addCity, 2L, "Denver")); cache.Query(new SqlFieldsQuery(addCity, 3L, "St. Petersburg")); const string addPerson = "INSERT INTO person (id, name, city_id) values (?, ?, ?)"; cache.Query(new SqlFieldsQuery(addPerson, 1L, "John Doe", 3L)); cache.Query(new SqlFieldsQuery(addPerson, 2L, "Jane Roe", 2L)); cache.Query(new SqlFieldsQuery(addPerson, 3L, "Mary Major", 1L)); cache.Query(new SqlFieldsQuery(addPerson, 4L, "Richard Miles", 2L)); Console.WriteLine("\n>>> Populated data."); IFieldsQueryCursor res = cache.Query(new SqlFieldsQuery( "SELECT p.name, c.name FROM Person p INNER JOIN City c on c.id = p.city_id")); Console.WriteLine("\n>>> Query results:"); foreach (var row in res) { Console.WriteLine("{0}, {1}", row[0], row[1]); } cache.Query(new SqlFieldsQuery("drop table Person")).GetAll(); cache.Query(new SqlFieldsQuery("drop table City")).GetAll(); Console.WriteLine("\n>>> Dropped database objects."); } Console.WriteLine(); Console.WriteLine(">>> Example finished, press any key to exit ..."); Console.ReadKey(); }
public virtual void GlobalSetup() { Client = new Client(Params.Instance.Value.Host).Start(); Cache = Client.GetOrCreateCache <int, TestModel>(GetType().Name); }