예제 #1
0
        public static void Run(string[] args)
        {
            // Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
            var clientConfig = new ClientConfig();

            clientConfig.GetSerializationConfig()
            .AddPortableFactory(PortableFactory.FactoryId, new PortableFactory());
            var hz = HazelcastClient.NewHazelcastClient(clientConfig);
            // Get a Distributed Map called "users"
            var users = hz.GetMap <string, User>("users");

            // Add some users to the Distributed Map
            GenerateUsers(users);
            // Create a Predicate from a String (a SQL like Where clause)
            var sqlQuery = Predicates.Sql("active AND age BETWEEN 18 AND 21)");
            // Creating the same Predicate as above but with a builder
            var criteriaQuery = Predicates.And(
                Predicates.IsEqual("active", true),
                Predicates.IsBetween("age", 18, 21)
                );
            // Get result collections using the two different Predicates
            var result1 = users.Values(sqlQuery);
            var result2 = users.Values(criteriaQuery);

            // Print out the results
            Console.WriteLine(result1);
            Console.WriteLine(result2);
            // Shutdown this Hazelcast Client
            hz.Shutdown();
        }
예제 #2
0
        public virtual void TestPredicateExt_And()
        {
            var predicate1 = Predicates.Property("name").Equal("val")
                             .And(Predicates.Property("id").GreaterThan(10));
            var predicate2 = Predicates.And(Predicates.IsEqual("name", "val"), Predicates.IsGreaterThan("id", 10));

            Assert.AreEqual(predicate1, predicate2);
        }
예제 #3
0
        public virtual void TestPredicateExt_complex_chained()
        {
            var predicate = Predicates.Key("id").Equal("id-1").And(Predicates.Property("name").ILike("a%"));

            var predicate2 = Predicates.And(Predicates.IsEqual("__key#id", "id-1"),
                                            Predicates.IsILike("name", "a%")
                                            );

            Assert.AreEqual(predicate, predicate2);
        }
예제 #4
0
        public void MiscPredicatesTests()
        {
            AssertPredicate(Predicates.True(), PredicateDataSerializerHook.TruePredicate);
            AssertPredicate(Predicates.False(), PredicateDataSerializerHook.FalsePredicate);

            AssertPredicate(Predicates.Not(Predicates.True()), PredicateDataSerializerHook.NotPredicate);

            AssertPredicate(Predicates.And(), PredicateDataSerializerHook.AndPredicate);

            AssertPredicate(Predicates.Or(), PredicateDataSerializerHook.OrPredicate);

            AssertPredicate(Predicates.EqualTo("name", 33), PredicateDataSerializerHook.EqualPredicate);
            AssertPredicate(Predicates.Value("name").IsEqualTo(33), PredicateDataSerializerHook.EqualPredicate);
            AssertPredicate(Predicates.NotEqualTo("name", 33), PredicateDataSerializerHook.NotEqualPredicate);
            AssertPredicate(Predicates.Value("name").IsNotEqualTo(33), PredicateDataSerializerHook.NotEqualPredicate);

            AssertPredicate(Predicates.GreaterThan("name", 33), PredicateDataSerializerHook.GreaterLessPredicate);
            AssertPredicate(Predicates.Value("name").IsGreaterThan(33), PredicateDataSerializerHook.GreaterLessPredicate);
            AssertPredicate(Predicates.GreaterThanOrEqualTo("name", 33), PredicateDataSerializerHook.GreaterLessPredicate);
            AssertPredicate(Predicates.Value("name").IsGreaterThanOrEqualTo(33), PredicateDataSerializerHook.GreaterLessPredicate);
            AssertPredicate(Predicates.LessThan("name", 33), PredicateDataSerializerHook.GreaterLessPredicate);
            AssertPredicate(Predicates.Value("name").IsLessThan(33), PredicateDataSerializerHook.GreaterLessPredicate);
            AssertPredicate(Predicates.LessThanOrEqualTo("name", 33), PredicateDataSerializerHook.GreaterLessPredicate);
            AssertPredicate(Predicates.Value("name").IsLessThanOrEqualTo(33), PredicateDataSerializerHook.GreaterLessPredicate);

            AssertPredicate(Predicates.Between("name", 33, 44), PredicateDataSerializerHook.BetweenPredicate);
            AssertPredicate(Predicates.Value("name").IsBetween(33, 44), PredicateDataSerializerHook.BetweenPredicate);

            AssertPredicate(Predicates.In("name", 33, 44), PredicateDataSerializerHook.InPredicate);
            AssertPredicate(Predicates.Value("name").IsIn(33, 44), PredicateDataSerializerHook.InPredicate);

            AssertPredicate(Predicates.Like("name", "expression"), PredicateDataSerializerHook.LikePredicate);
            AssertPredicate(Predicates.Value("name").IsLike("expression"), PredicateDataSerializerHook.LikePredicate);
            AssertPredicate(Predicates.ILike("name", "expression"), PredicateDataSerializerHook.ILikePredicate);
            AssertPredicate(Predicates.Value("name").IsILike("expression"), PredicateDataSerializerHook.ILikePredicate);
            AssertPredicate(Predicates.Match("name", "regex"), PredicateDataSerializerHook.RegexPredicate);
            AssertPredicate(Predicates.Value("name").Matches("regex"), PredicateDataSerializerHook.RegexPredicate);

            AssertPredicate(Predicates.InstanceOf("className"), PredicateDataSerializerHook.InstanceofPredicate);

            AssertPredicate(Predicates.In("name", 1, 2, 3), PredicateDataSerializerHook.InPredicate);

            AssertPredicate(Predicates.Sql("sql"), PredicateDataSerializerHook.SqlPredicate);

            AssertPredicate(Predicates.Key("property").IsILike("expression"), PredicateDataSerializerHook.ILikePredicate);
            AssertPredicate(Predicates.Value().IsILike("expression"), PredicateDataSerializerHook.ILikePredicate);
        }
예제 #5
0
        protected override void OnClosed(EventArgs e)
        {
            _settings.Services = Array.FindAll(
                textBoxServices.Lines,
                Predicates.And(
                    Predicates.Not <string>(String.IsNullOrEmpty),
                    delegate(string s)
            {
                return(s.Trim().Length > 0);
            }
                    )

                );
            _settings.UpdateInterval = _updates[(string)comboBoxUpdateRate.SelectedItem];

            base.OnClosed(e);
        }
예제 #6
0
        public static async Task Main(string[] args)
        {
            var options = new HazelcastOptionsBuilder()
                          .With(args)
                          .WithConsoleLogger()
                          .Build();

            // create an Hazelcast client and connect to a server running on localhost
            options.Serialization.AddPortableFactory(PortableFactory.FactoryId, new PortableFactory());
            await using var client = await HazelcastClientFactory.StartNewClientAsync(options);

            // Get a Distributed Map called "users"
            await using var users = await client.GetMapAsync <string, User>("users");

            // Add some users to the Distributed Map
            await GenerateUsers(users);

            // Create a Predicate from a String (a SQL like Where clause)
            var sqlQuery = Predicates.Sql("active AND age BETWEEN 18 AND 21)");
            // Creating the same Predicate as above but with a builder
            var criteriaQuery = Predicates.And(
                Predicates.EqualTo("active", true),
                Predicates.Between("age", 18, 21)
                );
            // Get result collections using the two different Predicates
            var result1 = await users.GetValuesAsync(sqlQuery);

            var result2 = await users.GetValuesAsync(criteriaQuery);

            // Print out the results
            Console.WriteLine("Result1:");
            foreach (var result in result1)
            {
                Console.WriteLine(result);
            }
            Console.WriteLine("Result2:");
            foreach (var result in result2)
            {
                Console.WriteLine(result);
            }
        }
예제 #7
0
        public void QuerySyntaxes()
        {
            var p1 = Predicates.EqualTo("attribute", "value");

            Console.WriteLine("p1: " + p1);
            Assert.That(p1.ToString(), Is.EqualTo("(attribute == value)"));

            var p2 = Predicates.Value("attribute").IsEqualTo("value");

            Console.WriteLine("p2: " + p2);
            Assert.That(p2.ToString(), Is.EqualTo("(attribute == value)"));

            var p4 = Predicates.Not(Predicates.EqualTo("attribute", "value"));

            Console.WriteLine("p4: " + p4);
            Assert.That(p4.ToString(), Is.EqualTo("NOT((attribute == value))"));

            var p6 = Predicates.And(
                Predicates.EqualTo("attribute1", "value1"),
                Predicates.Not(Predicates.EqualTo("attribute2", "value2")));

            Console.WriteLine("p6: " + p6);
            Assert.That(p6.ToString(), Is.EqualTo("AND((attribute1 == value1), NOT((attribute2 == value2)))"));
        }