public void TestQueryEntityConfiguration() { var cfg = new IgniteConfiguration { JvmOptions = TestUtils.TestJavaOptions(), JvmClasspath = TestUtils.CreateTestClasspath(), BinaryConfiguration = new BinaryConfiguration(typeof(QueryPerson)), CacheConfiguration = new[] { new CacheConfiguration(CacheName, new QueryEntity(typeof(int), typeof(QueryPerson)) { TableName = "CustomTableName", Fields = new[] { new QueryField("Name", typeof(string)), new QueryField("Age", typeof(int)), new QueryField("Birthday", typeof(DateTime)), }, Indexes = new[] { new QueryIndex(false, QueryIndexType.FullText, "Name"), new QueryIndex("Age") } }) } }; using (var ignite = Ignition.Start(cfg)) { var cache = ignite.GetCache <int, QueryPerson>(CacheName); Assert.IsNotNull(cache); cache[1] = new QueryPerson("Arnold", 10); cache[2] = new QueryPerson("John", 20); using (var cursor = cache.Query(new SqlQuery(typeof(QueryPerson), "age > ? and birthday < ?", 10, DateTime.UtcNow))) { Assert.AreEqual(2, cursor.GetAll().Single().Key); } using (var cursor = cache.QueryFields(new SqlFieldsQuery( "select _key from CustomTableName where age > ? and birthday < ?", 10, DateTime.UtcNow))) { Assert.AreEqual(2, cursor.GetAll().Single()[0]); } using (var cursor = cache.Query(new TextQuery(typeof(QueryPerson), "Ar*"))) { Assert.AreEqual(1, cursor.GetAll().Single().Key); } } }
public void TestCustomKeyValueFieldNames() { // Check select * with default config - does not include _key, _val. var cache = Cache(); cache[1] = new QueryPerson("Joe", 48); var row = cache.Query(new SqlFieldsQuery("select * from QueryPerson")).GetAll()[0]; Assert.AreEqual(2, row.Count); Assert.AreEqual(48, row[0]); Assert.AreEqual("Joe", row[1]); // Check select * with custom names - fields are included. cache = GetIgnite().GetOrCreateCache <int, QueryPerson>( new CacheConfiguration("customKeyVal") { QueryEntities = new[] { new QueryEntity(typeof(int), typeof(QueryPerson)) { Fields = new[] { new QueryField("age", "int"), new QueryField("FullKey", "int"), new QueryField("FullVal", "QueryPerson") }, KeyFieldName = "FullKey", ValueFieldName = "FullVal" } } }); cache[1] = new QueryPerson("John", 33); row = cache.Query(new SqlFieldsQuery("select * from QueryPerson")).GetAll()[0]; Assert.AreEqual(3, row.Count); Assert.AreEqual(33, row[0]); Assert.AreEqual(1, row[1]); var person = (QueryPerson)row[2]; Assert.AreEqual("John", person.Name); // Check explicit select. row = cache.Query(new SqlFieldsQuery("select FullKey from QueryPerson")).GetAll()[0]; Assert.AreEqual(1, row[0]); }
public void TestQueryEntityConfiguration() { var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) { BinaryConfiguration = new BinaryConfiguration(typeof(QueryPerson)), CacheConfiguration = new[] { new CacheConfiguration(CacheName, new QueryEntity(typeof(int), typeof(QueryPerson)) { TableName = "CustomTableName", Fields = new[] { new QueryField("Name", typeof(string)), new QueryField("Age", typeof(int)), new QueryField("Birthday", typeof(DateTime)), }, Indexes = new[] { new QueryIndex { InlineSize = 2048, IndexType = QueryIndexType.FullText, Fields = new[] { new QueryIndexField { IsDescending = false, Name = "Name" } } }, new QueryIndex("Age") } }) } }; using (var ignite = Ignition.Start(cfg)) { var cache = ignite.GetCache <int, QueryPerson>(CacheName); Assert.IsNotNull(cache); cache[1] = new QueryPerson("Arnold", 10); cache[2] = new QueryPerson("John", 20); #pragma warning disable 618 using (var cursor = cache.Query(new SqlQuery(typeof(QueryPerson), "age > ? and birthday < ?", #pragma warning restore 618 10, DateTime.UtcNow))) { Assert.AreEqual(2, cursor.GetAll().Single().Key); } using (var cursor = cache.Query(new SqlFieldsQuery( "select _key from CustomTableName where age > ? and birthday < ?", 10, DateTime.UtcNow))) { Assert.AreEqual(2, cursor.GetAll().Single()[0]); } using (var cursor = cache.Query(new TextQuery(typeof(QueryPerson), "Ar*"))) { Assert.AreEqual(1, cursor.GetAll().Single().Key); } } }