You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2017/01/20 10:01:04 UTC

[1/4] ignite git commit: IGNITE-4556 .NET: DML example

Repository: ignite
Updated Branches:
  refs/heads/ignite-2.0 34a978339 -> e8377167b


IGNITE-4556 .NET: DML example

This closes #1439


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/19a7e969
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/19a7e969
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/19a7e969

Branch: refs/heads/ignite-2.0
Commit: 19a7e969434c7de8da4e7a4f64d73d4af364ca38
Parents: 664dc88
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Fri Jan 20 11:51:46 2017 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
Committed: Fri Jan 20 11:51:46 2017 +0300

----------------------------------------------------------------------
 .../Apache.Ignite.Examples.csproj               |   1 +
 .../Datagrid/QueryDmlExample.cs                 | 159 +++++++++++++++++++
 2 files changed, 160 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/19a7e969/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
index 3f7e1dc..ebf9e92 100644
--- a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
+++ b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
@@ -62,6 +62,7 @@
     <Compile Include="Datagrid\PutGetExample.cs" />
     <Compile Include="Datagrid\LinqExample.cs" />
     <Compile Include="Datagrid\BinaryModeExample.cs" />
+    <Compile Include="Datagrid\QueryDmlExample.cs" />
     <Compile Include="Datagrid\QueryExample.cs" />
     <Compile Include="Datagrid\StoreExample.cs" />
     <Compile Include="Datagrid\TransactionDeadlockDetectionExample.cs" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/19a7e969/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/QueryDmlExample.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/QueryDmlExample.cs b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/QueryDmlExample.cs
new file mode 100644
index 0000000..b264a0e
--- /dev/null
+++ b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/QueryDmlExample.cs
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Examples.Datagrid
+{
+    using System;
+    using Apache.Ignite.Core;
+    using Apache.Ignite.Core.Cache;
+    using Apache.Ignite.Core.Cache.Configuration;
+    using Apache.Ignite.Core.Cache.Query;
+    using Apache.Ignite.ExamplesDll.Binary;
+
+    /// <summary>
+    /// This example showcases DML capabilities of Ignite's SQL engine.
+    /// <para />
+    /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build).
+    ///    Apache.Ignite.ExamplesDll.dll must appear in %IGNITE_HOME%/platforms/dotnet/examples/Apache.Ignite.ExamplesDll/bin/${Platform]/${Configuration} folder.
+    /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties ->
+    ///     Application -> Startup object);
+    /// 3) Start example (F5 or Ctrl+F5).
+    /// <para />
+    /// This example can be run with standalone Apache Ignite.NET node:
+    /// 1) Run %IGNITE_HOME%/platforms/dotnet/bin/Apache.Ignite.exe:
+    /// Apache.Ignite.exe -configFileName=platforms\dotnet\examples\apache.ignite.examples\app.config -assembly=[path_to_Apache.Ignite.ExamplesDll.dll]
+    /// 2) Start example.
+    /// </summary>
+    public class QueryDmlExample
+    {
+        /// <summary>Organization cache name.</summary>
+        private const string OrganizationCacheName = "dotnet_cache_query_dml_organization";
+
+        /// <summary>Employee cache name.</summary>
+        private const string EmployeeCacheName = "dotnet_cache_query_dml_employee";
+
+        [STAThread]
+        public static void Main()
+        {
+            using (var ignite = Ignition.StartFromApplicationConfiguration())
+            {
+                Console.WriteLine();
+                Console.WriteLine(">>> Cache query DML example started.");
+
+                var employeeCache = ignite.GetOrCreateCache<int, Employee>(
+                    new CacheConfiguration(EmployeeCacheName, new QueryEntity(typeof(int), typeof(Employee))));
+
+                var organizationCache = ignite.GetOrCreateCache<int, Organization>(new CacheConfiguration(
+                    OrganizationCacheName, new QueryEntity(typeof(int), typeof(Organization))));
+
+                Insert(organizationCache, employeeCache);
+                Select(employeeCache, "Inserted data");
+
+                Update(employeeCache);
+                Select(employeeCache, "Update salary for ASF employees");
+
+                Delete(employeeCache);
+                Select(employeeCache, "Delete non-ASF employees");
+
+                Console.WriteLine();
+            }
+
+            Console.WriteLine();
+            Console.WriteLine(">>> Example finished, press any key to exit ...");
+            Console.ReadKey();
+        }
+
+        /// <summary>
+        /// Selects and displays Employee data.
+        /// </summary>
+        /// <param name="employeeCache">Employee cache.</param>
+        /// <param name="message">Message.</param>
+        private static void Select(ICache<int, Employee> employeeCache, string message)
+        {
+            Console.WriteLine("\n>>> {0}", message);
+
+            var qry = new SqlFieldsQuery(string.Format(
+                "select emp._key, emp.name, org.name, emp.salary " +
+                "from Employee as emp, " +
+                "\"{0}\".Organization as org " +
+                "where emp.organizationId = org._key", OrganizationCacheName));
+
+            using (var cursor = employeeCache.QueryFields(qry))
+            {
+                foreach (var row in cursor)
+                {
+                    Console.WriteLine(">>> {0}: {1}, {2}, {3}", row[0], row[1], row[2], row[3]);
+                }
+            }
+        }
+
+        /// <summary>
+        /// Populate cache with test data.
+        /// </summary>
+        /// <param name="organizationCache">Organization cache.</param>
+        /// <param name="employeeCache">Employee cache.</param>
+        private static void Insert(ICache<int, Organization> organizationCache, ICache<int, Employee> employeeCache)
+        {
+            // Insert organizations.
+            var qry = new SqlFieldsQuery("insert into Organization (_key, name) values (?, ?)", 1, "ASF");
+            organizationCache.QueryFields(qry);
+
+            qry.Arguments = new object[] {2, "Eclipse"};
+            organizationCache.QueryFields(qry);
+
+            // Insert employees.
+            qry = new SqlFieldsQuery("insert into Employee (_key, name, organizationId, salary) values (?, ?, ?, ?)");
+
+            qry.Arguments = new object[] {1, "John Doe", 1, 4000};
+            employeeCache.QueryFields(qry);
+
+            qry.Arguments = new object[] {2, "Jane Roe", 1, 5000};
+            employeeCache.QueryFields(qry);
+
+            qry.Arguments = new object[] {3, "Mary Major", 2, 2000};
+            employeeCache.QueryFields(qry);
+
+            qry.Arguments = new object[] {4, "Richard Miles", 2, 3000};
+            employeeCache.QueryFields(qry);
+        }
+
+        /// <summary>
+        /// Conditional UPDATE query: raise salary for ASF employees.
+        /// </summary>
+        /// <param name="employeeCache">Employee cache.</param>
+        private static void Update(ICache<int, Employee> employeeCache)
+        {
+            var qry = new SqlFieldsQuery("update Employee set salary = salary * 1.1 where organizationId = ?", 1);
+
+            employeeCache.QueryFields(qry);
+        }
+
+        /// <summary>
+        /// Conditional DELETE query: remove non-ASF employees.
+        /// </summary>
+        /// <param name="employeeCache">Employee cache.</param>
+        private static void Delete(ICache<int, Employee> employeeCache)
+        {
+            var qry = new SqlFieldsQuery(string.Format(
+                "delete from Employee where _key in (" +
+                "select emp._key from Employee emp, \"{0}\".Organization org " +
+                "where org.Name != ? and org._key = emp.organizationId)", OrganizationCacheName), "ASF");
+
+            employeeCache.QueryFields(qry);
+        }
+    }
+}


[2/4] ignite git commit: IGNITE-4548 CacheJdbcStore: support mapping of enum types.

Posted by pt...@apache.org.
IGNITE-4548 CacheJdbcStore: support mapping of enum types.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f1fca3ad
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f1fca3ad
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f1fca3ad

Branch: refs/heads/ignite-2.0
Commit: f1fca3ad5bb0a870d94915caf8186e36b165b924
Parents: 19a7e96
Author: Vasiliy Sisko <vs...@gridgain.com>
Authored: Fri Jan 20 16:22:24 2017 +0700
Committer: Andrey Novikov <an...@gridgain.com>
Committed: Fri Jan 20 16:22:24 2017 +0700

----------------------------------------------------------------------
 .../store/jdbc/CacheAbstractJdbcStore.java      | 12 +++++-
 .../store/jdbc/JdbcTypesDefaultTransformer.java | 19 +++++++++
 .../cache/store/jdbc/JdbcTypesTransformer.java  | 17 ++++++++
 .../CacheJdbcPojoStoreAbstractSelfTest.java     | 23 +++++++----
 .../store/jdbc/CacheJdbcPojoStoreTest.java      |  3 ++
 ...eJdbcStoreAbstractMultithreadedSelfTest.java | 17 ++++----
 .../ignite/cache/store/jdbc/model/Gender.java   | 41 ++++++++++++++++++++
 .../ignite/cache/store/jdbc/model/Person.java   | 31 ++++++++++++++-
 .../src/test/config/jdbc-pojo-store-builtin.xml |  8 ++++
 .../src/test/config/jdbc-pojo-store-obj.xml     |  8 ++++
 10 files changed, 162 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f1fca3ad/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
index 4bfd92b..e7ce526 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
@@ -80,6 +80,8 @@ import static java.sql.Statement.SUCCESS_NO_INFO;
 import static org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory.DFLT_BATCH_SIZE;
 import static org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory.DFLT_PARALLEL_LOAD_CACHE_MINIMUM_THRESHOLD;
 import static org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory.DFLT_WRITE_ATTEMPTS;
+import static org.apache.ignite.cache.store.jdbc.JdbcTypesTransformer.NUMERIC_TYPES;
+import static org.apache.ignite.cache.store.jdbc.JdbcTypesTransformer.NUMERIC_TYPES;
 
 /**
  * Implementation of {@link CacheStore} backed by JDBC.
@@ -1393,8 +1395,15 @@ public abstract class CacheAbstractJdbcStore<K, V> implements CacheStore<K, V>,
                             fieldVal = fieldVal.toString();
 
                             break;
+                        default:
+                            // No-op.
                     }
                 }
+                else if (field.getJavaFieldType().isEnum() && fieldVal instanceof Enum) {
+                    Enum val = (Enum)fieldVal;
+                    
+                    fieldVal = NUMERIC_TYPES.contains(field.getDatabaseFieldType()) ? val.ordinal() : val.name();
+                }
 
                 stmt.setObject(idx, fieldVal);
             }
@@ -2068,12 +2077,13 @@ public abstract class CacheAbstractJdbcStore<K, V> implements CacheStore<K, V>,
 
                 int idx = 1;
 
-                for (Object key : keys)
+                for (Object key : keys) {
                     for (JdbcTypeField field : em.keyColumns()) {
                         Object fieldVal = extractParameter(em.cacheName, em.keyType(), em.keyKind(), field.getJavaFieldName(), key);
 
                         fillParameter(stmt, idx++, field, fieldVal);
                     }
+                }
 
                 ResultSet rs = stmt.executeQuery();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/f1fca3ad/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypesDefaultTransformer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypesDefaultTransformer.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypesDefaultTransformer.java
index c32eaa2..c387b77 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypesDefaultTransformer.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypesDefaultTransformer.java
@@ -114,6 +114,25 @@ public class JdbcTypesDefaultTransformer implements JdbcTypesTransformer {
                 return UUID.fromString((String)res);
         }
 
+        if (type.isEnum()) {
+            if (NUMERIC_TYPES.contains(rs.getMetaData().getColumnType(colIdx))) {
+                int ordinal = rs.getInt(colIdx);
+
+                Object[] values = type.getEnumConstants();
+
+                return rs.wasNull() || ordinal >= values.length ? null : values[ordinal];
+            }
+
+            String str = rs.getString(colIdx);
+
+            try {
+                return rs.wasNull() ? null : Enum.valueOf((Class<? extends Enum>) type, str.trim());
+            }
+            catch (IllegalArgumentException ignore) {
+                return null;
+            }
+        }
+
         return rs.getObject(colIdx);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/f1fca3ad/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypesTransformer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypesTransformer.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypesTransformer.java
index 76fb00b..fc0bc88 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypesTransformer.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypesTransformer.java
@@ -20,11 +20,28 @@ package org.apache.ignite.cache.store.jdbc;
 import java.io.Serializable;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.List;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static java.sql.Types.BIGINT;
+import static java.sql.Types.DECIMAL;
+import static java.sql.Types.DOUBLE;
+import static java.sql.Types.FLOAT;
+import static java.sql.Types.INTEGER;
+import static java.sql.Types.NUMERIC;
+import static java.sql.Types.REAL;
+import static java.sql.Types.SMALLINT;
+import static java.sql.Types.TINYINT;
 
 /**
  * API for implementing custom mapping logic for loaded from store data.
  */
 public interface JdbcTypesTransformer extends Serializable {
+    /** Numeric types. */
+    public final List<Integer> NUMERIC_TYPES =
+        U.sealList(TINYINT, SMALLINT, INTEGER, BIGINT, REAL, FLOAT, DOUBLE, NUMERIC, DECIMAL);
+
+
     /**
      * Retrieves the value of the designated column in the current row of this <code>ResultSet</code> object and
      * will convert to the requested Java data type.

http://git-wip-us.apache.org/repos/asf/ignite/blob/f1fca3ad/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreAbstractSelfTest.java
index 368a28e..1de44f7 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreAbstractSelfTest.java
@@ -30,6 +30,7 @@ import javax.cache.integration.CacheLoaderException;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.cache.store.jdbc.dialect.H2Dialect;
 import org.apache.ignite.cache.store.jdbc.model.Person;
+import org.apache.ignite.cache.store.jdbc.model.Gender;
 import org.apache.ignite.cache.store.jdbc.model.PersonKey;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.ConnectorConfiguration;
@@ -112,7 +113,8 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
             " id INTEGER PRIMARY KEY," +
             " org_id INTEGER," +
             " birthday DATE," +
-            " name VARCHAR(50))");
+            " name VARCHAR(50)," +
+            " gender VARCHAR(50))");
 
         conn.commit();
 
@@ -201,7 +203,8 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
             new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"),
             new JdbcTypeField(Types.INTEGER, "ORG_ID", Integer.class, "orgId"),
             new JdbcTypeField(Types.DATE, "BIRTHDAY", Date.class, "birthday"),
-            new JdbcTypeField(Types.VARCHAR, "NAME", String.class, "name"));
+            new JdbcTypeField(Types.VARCHAR, "NAME", String.class, "name"),
+            new JdbcTypeField(Types.VARCHAR, "GENDER", Gender.class, "gender"));
 
         return storeTypes;
     }
@@ -260,7 +263,7 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
         conn.commit();
 
         PreparedStatement prnStmt = conn.prepareStatement(
-            "INSERT INTO Person(id, org_id, birthday, name) VALUES (?, ?, ?, ?)");
+            "INSERT INTO Person(id, org_id, birthday, name, gender) VALUES (?, ?, ?, ?, ?)");
 
         Random rnd = new Random();
 
@@ -269,6 +272,7 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
             prnStmt.setInt(2, i % 100);
             prnStmt.setDate(3, Date.valueOf(String.format("%d-%d-%d", 1970 + rnd.nextInt(50), 1 + rnd.nextInt(11), 1 + rnd.nextInt(27))));
             prnStmt.setString(4, "name" + i);
+            prnStmt.setString(5, Gender.random().toString());
 
             prnStmt.addBatch();
         }
@@ -319,7 +323,7 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
     protected void checkCacheLoadWithSql() {
         IgniteCache<Object, Object> c1 = grid().cache(CACHE_NAME);
 
-        c1.loadCache(null, "org.apache.ignite.cache.store.jdbc.model.PersonKey", "select id, org_id, name, birthday from Person");
+        c1.loadCache(null, "org.apache.ignite.cache.store.jdbc.model.PersonKey", "select id, org_id, name, birthday, gender from Person");
 
         assertEquals(PERSON_CNT, c1.size());
     }
@@ -397,7 +401,9 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
 
         Connection conn = getConnection();
         try {
-            PreparedStatement stmt = conn.prepareStatement("SELECT ID, ORG_ID, BIRTHDAY, NAME FROM PERSON WHERE ID = ?");
+            Random rnd = new Random();
+
+            PreparedStatement stmt = conn.prepareStatement("SELECT ID, ORG_ID, BIRTHDAY, NAME, GENDER FROM PERSON WHERE ID = ?");
 
             stmt.setInt(1, -1);
 
@@ -408,8 +414,9 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
             U.closeQuiet(rs);
 
             Date testDate = Date.valueOf("2001-05-05");
+            Gender testGender = Gender.random();
 
-            Person val = new Person(-1, -2, testDate, "Person-to-test-put-insert", 999);
+            Person val = new Person(-1, -2, testDate, "Person-to-test-put-insert", 999, testGender);
 
             Object key = builtinKeys ? Integer.valueOf(-1) : new PersonKey(-1);
 
@@ -424,6 +431,7 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
             assertEquals(-2, rs.getInt(2));
             assertEquals(testDate, rs.getDate(3));
             assertEquals("Person-to-test-put-insert", rs.getString(4));
+            assertEquals(testGender.toString(), rs.getString(5));
 
             assertFalse("Unexpected more data in result set", rs.next());
 
@@ -432,7 +440,7 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
             // Test put-update.
             testDate = Date.valueOf("2016-04-04");
 
-            c1.put(key, new Person(-1, -3, testDate, "Person-to-test-put-update", 999));
+            c1.put(key, new Person(-1, -3, testDate, "Person-to-test-put-update", 999, testGender));
 
             rs = stmt.executeQuery();
 
@@ -442,6 +450,7 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
             assertEquals(-3, rs.getInt(2));
             assertEquals(testDate, rs.getDate(3));
             assertEquals("Person-to-test-put-update", rs.getString(4));
+            assertEquals(testGender.toString(), rs.getString(5));
 
             assertFalse("Unexpected more data in result set", rs.next());
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/f1fca3ad/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreTest.java
index 4a0b1da..849cab7 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreTest.java
@@ -25,6 +25,7 @@ import java.sql.Timestamp;
 import java.sql.Types;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Random;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import javax.cache.integration.CacheWriterException;
@@ -233,6 +234,8 @@ public class CacheJdbcPojoStoreTest extends GridAbstractCacheStoreSelfTest<Cache
     public void testLoadCache() throws Exception {
         Connection conn = store.openConnection(false);
 
+        Random rnd = new Random();
+
         PreparedStatement orgStmt = conn.prepareStatement("INSERT INTO Organization(id, name, city) VALUES (?, ?, ?)");
 
         for (int i = 0; i < ORGANIZATION_CNT; i++) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/f1fca3ad/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractMultithreadedSelfTest.java
index e831445..f1a321b 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractMultithreadedSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractMultithreadedSelfTest.java
@@ -33,6 +33,7 @@ import java.util.concurrent.Callable;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cache.CacheTypeMetadata;
+import org.apache.ignite.cache.store.jdbc.model.Gender;
 import org.apache.ignite.cache.store.jdbc.model.Organization;
 import org.apache.ignite.cache.store.jdbc.model.OrganizationKey;
 import org.apache.ignite.cache.store.jdbc.model.Person;
@@ -208,7 +209,7 @@ public abstract class CacheJdbcStoreAbstractMultithreadedSelfTest<T extends Cach
                         cache.put(new OrganizationKey(id), new Organization(id, "Name" + id, "City" + id));
                     else
                         cache.put(new PersonKey(id), new Person(id, rnd.nextInt(),
-                            new Date(System.currentTimeMillis()), "Name" + id, 1));
+                            new Date(System.currentTimeMillis()), "Name" + id, 1, Gender.random()));
                 }
 
                 return null;
@@ -228,7 +229,7 @@ public abstract class CacheJdbcStoreAbstractMultithreadedSelfTest<T extends Cach
                         cache.putIfAbsent(new OrganizationKey(id), new Organization(id, "Name" + id, "City" + id));
                     else
                         cache.putIfAbsent(new PersonKey(id), new Person(id, rnd.nextInt(),
-                            new Date(System.currentTimeMillis()), "Name" + id, i));
+                            new Date(System.currentTimeMillis()), "Name" + id, i, Gender.random()));
                 }
 
                 return null;
@@ -268,7 +269,7 @@ public abstract class CacheJdbcStoreAbstractMultithreadedSelfTest<T extends Cach
                             map.put(new OrganizationKey(id), new Organization(id, "Name" + id, "City" + id));
                         else
                             map.put(new PersonKey(id), new Person(id, rnd.nextInt(),
-                                new Date(System.currentTimeMillis()), "Name" + id, 1));
+                                new Date(System.currentTimeMillis()), "Name" + id, 1, Gender.random()));
                     }
 
                     IgniteCache<Object, Object> cache = jcache();
@@ -294,11 +295,11 @@ public abstract class CacheJdbcStoreAbstractMultithreadedSelfTest<T extends Cach
 
                     try (Transaction tx = grid().transactions().txStart()) {
                         cache.put(new PersonKey(1), new Person(1, rnd.nextInt(),
-                            new Date(System.currentTimeMillis()), "Name" + 1, 1));
+                            new Date(System.currentTimeMillis()), "Name" + 1, 1, Gender.random()));
                         cache.put(new PersonKey(2), new Person(2, rnd.nextInt(),
-                            new Date(System.currentTimeMillis()), "Name" + 2, 2));
+                            new Date(System.currentTimeMillis()), "Name" + 2, 2, Gender.random()));
                         cache.put(new PersonKey(3), new Person(3, rnd.nextInt(),
-                            new Date(System.currentTimeMillis()), "Name" + 3, 3));
+                            new Date(System.currentTimeMillis()), "Name" + 3, 3, Gender.random()));
 
                         cache.get(new PersonKey(1));
                         cache.get(new PersonKey(4));
@@ -306,9 +307,9 @@ public abstract class CacheJdbcStoreAbstractMultithreadedSelfTest<T extends Cach
                         Map<PersonKey, Person> map =  U.newHashMap(2);
 
                         map.put(new PersonKey(5), new Person(5, rnd.nextInt(),
-                            new Date(System.currentTimeMillis()), "Name" + 5, 5));
+                            new Date(System.currentTimeMillis()), "Name" + 5, 5, Gender.random()));
                         map.put(new PersonKey(6), new Person(6, rnd.nextInt(),
-                            new Date(System.currentTimeMillis()), "Name" + 6, 6));
+                            new Date(System.currentTimeMillis()), "Name" + 6, 6, Gender.random()));
 
                         cache.putAll(map);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/f1fca3ad/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/model/Gender.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/model/Gender.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/model/Gender.java
new file mode 100644
index 0000000..8ddb0e2
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/model/Gender.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.jdbc.model;
+
+import java.io.Serializable;
+import java.util.Random;
+
+/**
+ * Person gender enum.
+ */
+public enum Gender implements Serializable {
+    /** */
+    MALE,
+    /** */
+    FEMALE;
+
+    /** */
+    private static final Random RAND = new Random();
+
+    /**
+     * Used for testing purposes.
+     */
+    public static Gender random() {
+        return values()[RAND.nextInt(values().length)];
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f1fca3ad/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/model/Person.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/model/Person.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/model/Person.java
index 52ddfc8..89258b4 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/model/Person.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/model/Person.java
@@ -44,6 +44,9 @@ public class Person implements Serializable {
     /** Value for salary. */
     private Integer salary;
 
+    /** Value of person gender. */
+    private Gender gender;
+
     /**
      * Empty constructor.
      */
@@ -59,13 +62,15 @@ public class Person implements Serializable {
         Integer orgId,
         Date birthday,
         String name,
-        Integer salary
+        Integer salary,
+        Gender gender
     ) {
         this.id = id;
         this.orgId = orgId;
         this.birthday = birthday;
         this.name = name;
         this.salary = salary;
+        this.gender = gender;
     }
 
     /**
@@ -159,6 +164,24 @@ public class Person implements Serializable {
         this.salary = salary;
     }
 
+    /**
+     * Gets gender.
+     *
+     * @return Gender.
+     */
+    public Gender getGender() {
+        return gender;
+    }
+
+    /**
+     * Sets gender.
+     *
+     * @param gender New value for gender.
+     */
+    public void setGender(Gender gender) {
+        this.gender = gender;
+    }
+
     /** {@inheritDoc} */
     @Override public boolean equals(Object o) {
         if (this == o)
@@ -178,6 +201,9 @@ public class Person implements Serializable {
         if (name != null ? !name.equals(that.name) : that.name != null)
             return false;
 
+        if (gender != null ? !gender.equals(that.gender) : that.gender != null)
+            return false;
+
         return true;
     }
 
@@ -189,6 +215,8 @@ public class Person implements Serializable {
 
         res = 31 * res + (name != null ? name.hashCode() : 0);
 
+        res = 31 * res + (gender != null ? gender.hashCode() : 0);
+
         return res;
     }
 
@@ -198,6 +226,7 @@ public class Person implements Serializable {
             ", orgId=" + orgId +
             ", birthday=" + (birthday == null ? null : birthday.getTime()) +
             ", name=" + name +
+            ", gender=" + gender +
             "]";
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/f1fca3ad/modules/spring/src/test/config/jdbc-pojo-store-builtin.xml
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/config/jdbc-pojo-store-builtin.xml b/modules/spring/src/test/config/jdbc-pojo-store-builtin.xml
index dfaf828..bfb109c 100644
--- a/modules/spring/src/test/config/jdbc-pojo-store-builtin.xml
+++ b/modules/spring/src/test/config/jdbc-pojo-store-builtin.xml
@@ -151,6 +151,14 @@
                                                     <property name="javaFieldName" value="orgId"/>
                                                     <property name="javaFieldType" value="java.lang.Integer"/>
                                                 </bean>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="GENDER"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.VARCHAR"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="gender"/>
+                                                    <property name="javaFieldType" value="org.apache.ignite.cache.store.jdbc.model.Gender"/>
+                                                </bean>
                                             </list>
                                         </property>
                                     </bean>

http://git-wip-us.apache.org/repos/asf/ignite/blob/f1fca3ad/modules/spring/src/test/config/jdbc-pojo-store-obj.xml
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/config/jdbc-pojo-store-obj.xml b/modules/spring/src/test/config/jdbc-pojo-store-obj.xml
index 9bc9977..40a14dc 100644
--- a/modules/spring/src/test/config/jdbc-pojo-store-obj.xml
+++ b/modules/spring/src/test/config/jdbc-pojo-store-obj.xml
@@ -151,6 +151,14 @@
                                                     <property name="javaFieldName" value="orgId"/>
                                                     <property name="javaFieldType" value="java.lang.Integer"/>
                                                 </bean>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="GENDER"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.VARCHAR"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="gender"/>
+                                                    <property name="javaFieldType" value="org.apache.ignite.cache.store.jdbc.model.Gender"/>
+                                                </bean>
                                             </list>
                                         </property>
                                     </bean>


[3/4] ignite git commit: IGNITE-4563 .NET: Fix ICache.LoadCache failures on non-primitive arguments

Posted by pt...@apache.org.
IGNITE-4563 .NET: Fix ICache.LoadCache failures on non-primitive arguments


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/83b5bca6
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/83b5bca6
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/83b5bca6

Branch: refs/heads/ignite-2.0
Commit: 83b5bca6bf402d2368d55ae5c7d6314ad7a225b4
Parents: f1fca3a
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Fri Jan 20 12:56:26 2017 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
Committed: Fri Jan 20 12:56:26 2017 +0300

----------------------------------------------------------------------
 .../platform/cache/PlatformCache.java           |  11 +-
 .../Apache.Ignite.Core.Tests.csproj             |   1 +
 .../Cache/Store/CacheParallelLoadStoreTest.cs   |   9 +-
 .../Cache/Store/CacheStoreSessionTest.cs        |  22 +-
 .../Cache/Store/CacheStoreTest.cs               | 333 ++++++++++++-------
 .../Cache/Store/CacheTestStore.cs               |  14 +
 .../Cache/Store/NamedNodeCacheStoreTest.cs      |  34 ++
 .../Apache.Ignite.Core/Impl/Cache/CacheImpl.cs  |  14 +-
 8 files changed, 294 insertions(+), 144 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/83b5bca6/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
index aee317e..cc09f5e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
@@ -816,7 +816,16 @@ public class PlatformCache extends PlatformAbstractTarget {
         if (pred != null)
             filter = platformCtx.createCacheEntryFilter(pred, 0);
 
-        Object[] args = reader.readObjectArray();
+        Object[] args = null;
+
+        int argCnt = reader.readInt();
+
+        if (argCnt > 0) {
+            args = new Object[argCnt];
+
+            for (int i = 0; i < argCnt; i++)
+                args[i] = reader.readObjectDetached();
+        }
 
         if (loc)
             cache.localLoadCache(filter, args);

http://git-wip-us.apache.org/repos/asf/ignite/blob/83b5bca6/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
index e09c682..08352b3 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
@@ -81,6 +81,7 @@
     <Compile Include="Cache\Query\CacheDmlQueriesTest.cs" />
     <Compile Include="Cache\CacheAbstractTransactionalTest.cs" />
     <Compile Include="Cache\Store\CacheStoreAdapterTest.cs" />
+    <Compile Include="Cache\Store\NamedNodeCacheStoreTest.cs" />
     <Compile Include="Collections\MultiValueDictionaryTest.cs" />
     <Compile Include="Collections\ReadOnlyCollectionTest.cs" />
     <Compile Include="Collections\ReadOnlyDictionaryTest.cs" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/83b5bca6/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheParallelLoadStoreTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheParallelLoadStoreTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheParallelLoadStoreTest.cs
index 105dea2..2e74b3f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheParallelLoadStoreTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheParallelLoadStoreTest.cs
@@ -25,7 +25,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
     /// <summary>
     /// Tests for GridCacheParallelLoadStoreAdapter.
     /// </summary>
-    public class CacheParallelLoadStoreTest
+    public sealed class CacheParallelLoadStoreTest
     {
         // object store name
         private const string ObjectStoreCacheName = "object_store_parallel";
@@ -34,11 +34,8 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
         /// Set up test class.
         /// </summary>
         [TestFixtureSetUp]
-        public virtual void BeforeTests()
+        public void BeforeTests()
         {
-            TestUtils.KillProcesses();
-            TestUtils.JvmDebug = true;
-
             Ignition.Start(new IgniteConfiguration
             {
                 JvmClasspath = TestUtils.CreateTestClasspath(),
@@ -55,7 +52,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
         /// Tear down test class.
         /// </summary>
         [TestFixtureTearDown]
-        public virtual void AfterTests()
+        public void AfterTests()
         {
             Ignition.StopAll(true);
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/83b5bca6/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreSessionTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreSessionTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreSessionTest.cs
index 5cc0849..54e0414 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreSessionTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreSessionTest.cs
@@ -22,14 +22,13 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
     using System.Collections.Generic;
     using System.Linq;
     using Apache.Ignite.Core.Cache.Store;
-    using Apache.Ignite.Core.Impl;
     using Apache.Ignite.Core.Resource;
     using NUnit.Framework;
 
     /// <summary>
     /// Tests for store session.
     /// </summary>
-    public class CacheStoreSessionTest
+    public sealed class CacheStoreSessionTest
     {
         /** Grid name. */
         private const string IgniteName = "grid";
@@ -47,7 +46,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
         /// Set up routine.
         /// </summary>
         [TestFixtureSetUp]
-        public virtual void BeforeTests()
+        public void BeforeTests()
         {
             //TestUtils.JVM_DEBUG = true;
 
@@ -71,7 +70,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
         /// Tear down routine.
         /// </summary>
         [TestFixtureTearDown]
-        public virtual void AfterTests()
+        public void AfterTests()
         {
             Ignition.StopAll(true);
         }
@@ -147,7 +146,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
         /// Dump operations.
         /// </summary>
         /// <param name="dump">Dump.</param>
-        internal static void DumpOperations(ICollection<Operation> dump)
+        private static void DumpOperations(ICollection<Operation> dump)
         {
             _dumps.Add(dump);
         }
@@ -155,6 +154,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
         /// <summary>
         /// Test store implementation.
         /// </summary>
+        // ReSharper disable once UnusedMember.Global
         public class Store : CacheStoreAdapter
         {
             /** Store session. */
@@ -215,7 +215,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
         /// <summary>
         /// Logged operation.
         /// </summary>
-        internal class Operation
+        private class Operation
         {
             /// <summary>
             /// Constructor.
@@ -244,22 +244,22 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
             /// <summary>
             /// Cache name.
             /// </summary>
-            public string CacheName { get; set; }
+            public string CacheName { get; private set; }
             
             /// <summary>
             /// Operation type.
             /// </summary>
-            public OperationType Type { get; set; }
+            public OperationType Type { get; private set; }
 
             /// <summary>
             /// Key.
             /// </summary>
-            public int Key { get; set; }
+            public int Key { get; private set; }
 
             /// <summary>
             /// Value.
             /// </summary>
-            public int Value { get; set; }
+            public int Value { get; private set; }
 
             /// <summary>
             /// Commit flag.
@@ -270,7 +270,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
         /// <summary>
         /// Operation types.
         /// </summary>
-        internal enum OperationType
+        private enum OperationType
         {
             /** Write. */
             Write,

http://git-wip-us.apache.org/repos/asf/ignite/blob/83b5bca6/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs
index d39ccde..869336c 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs
@@ -28,92 +28,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
     using NUnit.Framework;
 
     /// <summary>
-    ///
-    /// </summary>
-    class Key
-    {
-        private readonly int _idx;
-
-        public Key(int idx)
-        {
-            _idx = idx;
-        }
-
-        public int Index()
-        {
-            return _idx;
-        }
-
-        public override bool Equals(object obj)
-        {
-            if (obj == null || obj.GetType() != GetType())
-                return false;
-
-            Key key = (Key)obj;
-
-            return key._idx == _idx;
-        }
-
-        public override int GetHashCode()
-        {
-            return _idx;
-        }
-    }
-
-    /// <summary>
-    ///
-    /// </summary>
-    class Value
-    {
-        private int _idx;
-
-        public Value(int idx)
-        {
-            _idx = idx;
-        }
-
-        public int Index()
-        {
-            return _idx;
-        }
-    }
-
-    /// <summary>
-    /// Cache entry predicate.
-    /// </summary>
-    [Serializable]
-    public class CacheEntryFilter : ICacheEntryFilter<int, string>
-    {
-        /** <inheritdoc /> */
-        public bool Invoke(ICacheEntry<int, string> entry)
-        {
-            return entry.Key >= 105;
-        }
-    }
-
-    /// <summary>
-    /// Cache entry predicate that throws an exception.
-    /// </summary>
-    [Serializable]
-    public class ExceptionalEntryFilter : ICacheEntryFilter<int, string>
-    {
-        /** <inheritdoc /> */
-        public bool Invoke(ICacheEntry<int, string> entry)
-        {
-            throw new Exception("Expected exception in ExceptionalEntryFilter");
-        }
-    }
-
-    /// <summary>
-    /// Filter that can't be serialized.
-    /// </summary>
-    public class InvalidCacheEntryFilter : CacheEntryFilter
-    {
-        // No-op.
-    }
-
-    /// <summary>
-    ///
+    /// Tests cache store functionality.
     /// </summary>
     public class CacheStoreTest
     {
@@ -129,19 +44,12 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
         /** */
         private const string TemplateStoreCacheName = "template_store*";
 
-        /** */
-        private volatile int _storeCount = 3;
-
         /// <summary>
-        ///
+        /// Fixture set up.
         /// </summary>
         [TestFixtureSetUp]
         public virtual void BeforeTests()
         {
-            TestUtils.KillProcesses();
-
-            TestUtils.JvmDebug = true;
-
             var cfg = new IgniteConfiguration
             {
                 GridName = GridName,
@@ -155,7 +63,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
         }
 
         /// <summary>
-        ///
+        /// Fixture tear down.
         /// </summary>
         [TestFixtureTearDown]
         public void AfterTests()
@@ -164,16 +72,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
         }
 
         /// <summary>
-        ///
-        /// </summary>
-        [SetUp]
-        public void BeforeTest()
-        {
-            Console.WriteLine("Test started: " + TestContext.CurrentContext.Test.Name);
-        }
-
-        /// <summary>
-        ///
+        /// Test tear down.
         /// </summary>
         [TearDown]
         public void AfterTest()
@@ -188,11 +87,12 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
                 "Cache is not empty: " +
                 string.Join(", ", cache.Select(x => string.Format("[{0}:{1}]", x.Key, x.Value))));
 
-            TestUtils.AssertHandleRegistryHasItems(300, _storeCount, Ignition.GetIgnite(GridName));
-
-            Console.WriteLine("Test finished: " + TestContext.CurrentContext.Test.Name);
+            TestUtils.AssertHandleRegistryHasItems(300, 3, Ignition.GetIgnite(GridName));
         }
 
+        /// <summary>
+        /// Tests that simple cache loading works and exceptions are propagated properly.
+        /// </summary>
         [Test]
         public void TestLoadCache()
         {
@@ -219,6 +119,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
                 cache.LoadCache(new CacheEntryFilter(), 100, 10)).InnerException);
         }
 
+        /// <summary>
+        /// Tests cache loading in local mode.
+        /// </summary>
         [Test]
         public void TestLocalLoadCache()
         {
@@ -234,6 +137,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
                 Assert.AreEqual("val_" + i, cache.Get(i));
         }
 
+        /// <summary>
+        /// Tests that object metadata propagates properly during cache loading.
+        /// </summary>
         [Test]
         public void TestLoadCacheMetadata()
         {
@@ -254,6 +160,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
             Assert.AreEqual("Value", meta.TypeName);
         }
 
+        /// <summary>
+        /// Tests asynchronous cache load.
+        /// </summary>
         [Test]
         public void TestLoadCacheAsync()
         {
@@ -278,6 +187,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
                     .InnerException);
         }
 
+        /// <summary>
+        /// Tests write-through and read-through behavior.
+        /// </summary>
         [Test]
         public void TestPutLoad()
         {
@@ -285,7 +197,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
 
             cache.Put(1, "val");
 
-            IDictionary map = StoreMap();
+            IDictionary map = GetStoreMap();
 
             Assert.AreEqual(1, map.Count);
 
@@ -305,6 +217,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
             CheckCustomStoreError(Assert.Throws<CacheStoreException>(() => cache.Get(1)).InnerException);
         }
 
+        /// <summary>
+        /// Tests write-through and read-through behavior with binarizable values.
+        /// </summary>
         [Test]
         public void TestPutLoadBinarizable()
         {
@@ -312,7 +227,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
 
             cache.Put(1, new Value(1));
 
-            IDictionary map = StoreMap();
+            IDictionary map = GetStoreMap();
 
             Assert.AreEqual(1, map.Count);
 
@@ -324,11 +239,14 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
 
             Assert.AreEqual(0, cache.GetSize());
 
-            Assert.AreEqual(1, cache.Get(1).Index());
+            Assert.AreEqual(1, cache.Get(1).Index);
 
             Assert.AreEqual(1, cache.GetSize());
         }
 
+        /// <summary>
+        /// Tests write-through and read-through behavior with storeKeepBinary=false.
+        /// </summary>
         [Test]
         public void TestPutLoadObjects()
         {
@@ -336,23 +254,26 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
 
             cache.Put(1, new Value(1));
 
-            IDictionary map = StoreMap();
+            IDictionary map = GetStoreMap();
 
             Assert.AreEqual(1, map.Count);
 
             Value v = (Value)map[1];
 
-            Assert.AreEqual(1, v.Index());
+            Assert.AreEqual(1, v.Index);
 
             cache.LocalEvict(new[] { 1 });
 
             Assert.AreEqual(0, cache.GetSize());
 
-            Assert.AreEqual(1, cache.Get(1).Index());
+            Assert.AreEqual(1, cache.Get(1).Index);
 
             Assert.AreEqual(1, cache.GetSize());
         }
 
+        /// <summary>
+        /// Tests cache store LoadAll functionality.
+        /// </summary>
         [Test]
         public void TestPutLoadAll()
         {
@@ -365,7 +286,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
 
             cache.PutAll(putMap);
 
-            IDictionary map = StoreMap();
+            IDictionary map = GetStoreMap();
 
             Assert.AreEqual(10, map.Count);
 
@@ -391,6 +312,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
             Assert.AreEqual(10, cache.GetSize());
         }
 
+        /// <summary>
+        /// Tests cache store removal.
+        /// </summary>
         [Test]
         public void TestRemove()
         {
@@ -399,7 +323,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
             for (int i = 0; i < 10; i++)
                 cache.Put(i, "val_" + i);
 
-            IDictionary map = StoreMap();
+            IDictionary map = GetStoreMap();
 
             Assert.AreEqual(10, map.Count);
 
@@ -412,6 +336,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
                 Assert.AreEqual("val_" + i, map[i]);
         }
 
+        /// <summary>
+        /// Tests cache store removal.
+        /// </summary>
         [Test]
         public void TestRemoveAll()
         {
@@ -420,7 +347,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
             for (int i = 0; i < 10; i++)
                 cache.Put(i, "val_" + i);
 
-            IDictionary map = StoreMap();
+            IDictionary map = GetStoreMap();
 
             Assert.AreEqual(10, map.Count);
 
@@ -432,6 +359,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
                 Assert.AreEqual("val_" + i, map[i]);
         }
 
+        /// <summary>
+        /// Tests cache store with transactions.
+        /// </summary>
         [Test]
         public void TestTx()
         {
@@ -446,13 +376,16 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
                 tx.Commit();
             }
 
-            IDictionary map = StoreMap();
+            IDictionary map = GetStoreMap();
 
             Assert.AreEqual(1, map.Count);
 
             Assert.AreEqual("val", map[1]);
         }
 
+        /// <summary>
+        /// Tests multithreaded cache loading.
+        /// </summary>
         [Test]
         public void TestLoadCacheMultithreaded()
         {
@@ -470,6 +403,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
                 Assert.AreEqual("val_" + i, cache.Get(i));
         }
 
+        /// <summary>
+        /// Tests that cache store property values are propagated from Spring XML.
+        /// </summary>
         [Test]
         public void TestCustomStoreProperties()
         {
@@ -480,6 +416,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
             Assert.AreEqual("String value", CacheTestStore.stringProperty);
         }
 
+        /// <summary>
+        /// Tests cache store with dynamically started cache.
+        /// </summary>
         [Test]
         public void TestDynamicStoreStart()
         {
@@ -498,6 +437,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
             Assert.AreEqual(handleCount, reg.Count);
         }
 
+        /// <summary>
+        /// Tests the load all.
+        /// </summary>
         [Test]
         public void TestLoadAll([Values(true, false)] bool isAsync)
         {
@@ -529,6 +471,49 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
         }
 
         /// <summary>
+        /// Tests the argument passing to LoadCache method.
+        /// </summary>
+        [Test]
+        public void TestArgumentPassing()
+        {
+            var cache = GetBinaryStoreCache<object, object>();
+
+            Action<object> checkValue = o =>
+            {
+                cache.Clear();
+                Assert.AreEqual(0, cache.GetSize());
+                cache.LoadCache(null, null, 1, o);
+                Assert.AreEqual(o, cache[1]);
+            };
+
+            // Null.
+            cache.LoadCache(null, null);
+            Assert.AreEqual(0, cache.GetSize());
+
+            // Empty args array.
+            cache.LoadCache(null);
+            Assert.AreEqual(0, cache.GetSize());
+
+            // Simple types.
+            checkValue(1);
+            checkValue(new[] {1, 2, 3});
+
+            checkValue("1");
+            checkValue(new[] {"1", "2"});
+
+            checkValue(Guid.NewGuid());
+            checkValue(new[] {Guid.NewGuid(), Guid.NewGuid()});
+
+            checkValue(DateTime.Now);
+            checkValue(new[] {DateTime.Now, DateTime.UtcNow});
+
+            // Collections.
+            checkValue(new ArrayList {1, "2", 3.3});
+            checkValue(new List<int> {1, 2});
+            checkValue(new Dictionary<int, string> {{1, "foo"}});
+        }
+
+        /// <summary>
         /// Get's grid name for this test.
         /// </summary>
         /// <value>Grid name.</value>
@@ -537,31 +522,49 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
             get { return null; }
         }
 
-        private IDictionary StoreMap()
+        /// <summary>
+        /// Gets the store map.
+        /// </summary>
+        private static IDictionary GetStoreMap()
         {
             return CacheTestStore.Map;
         }
 
+        /// <summary>
+        /// Gets the cache.
+        /// </summary>
         private ICache<int, string> GetCache()
         {
             return GetBinaryStoreCache<int, string>();
         }
 
+        /// <summary>
+        /// Gets the binary store cache.
+        /// </summary>
         private ICache<TK, TV> GetBinaryStoreCache<TK, TV>()
         {
             return Ignition.GetIgnite(GridName).GetCache<TK, TV>(BinaryStoreCacheName);
         }
 
+        /// <summary>
+        /// Gets the object store cache.
+        /// </summary>
         private ICache<TK, TV> GetObjectStoreCache<TK, TV>()
         {
             return Ignition.GetIgnite(GridName).GetCache<TK, TV>(ObjectStoreCacheName);
         }
 
+        /// <summary>
+        /// Gets the custom store cache.
+        /// </summary>
         private ICache<int, string> GetCustomStoreCache()
         {
             return Ignition.GetIgnite(GridName).GetCache<int, string>(CustomStoreCacheName);
         }
 
+        /// <summary>
+        /// Gets the template store cache.
+        /// </summary>
         private ICache<int, string> GetTemplateStoreCache()
         {
             var cacheName = TemplateStoreCacheName.Replace("*", Guid.NewGuid().ToString());
@@ -569,6 +572,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
             return Ignition.GetIgnite(GridName).GetOrCreateCache<int, string>(cacheName);
         }
 
+        /// <summary>
+        /// Checks the custom store error.
+        /// </summary>
         private static void CheckCustomStoreError(Exception err)
         {
             var customErr = err as CacheTestStore.CustomStoreException ??
@@ -581,14 +587,93 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
     }
 
     /// <summary>
-    /// 
+    /// Cache key.
     /// </summary>
-    public class NamedNodeCacheStoreTest : CacheStoreTest
+    internal class Key
     {
-        /** <inheritDoc /> */
-        protected override string GridName
+        /** */
+        private readonly int _idx;
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="Key"/> class.
+        /// </summary>
+        public Key(int idx)
+        {
+            _idx = idx;
+        }
+
+        /** <inheritdoc /> */
+        public override bool Equals(object obj)
         {
-            get { return "name"; }
+            if (obj == null || obj.GetType() != GetType())
+                return false;
+
+            return ((Key)obj)._idx == _idx;
         }
+
+        /** <inheritdoc /> */
+        public override int GetHashCode()
+        {
+            return _idx;
+        }
+    }
+
+    /// <summary>
+    /// Cache value.
+    /// </summary>
+    internal class Value
+    {
+        /** */
+        private readonly int _idx;
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="Value"/> class.
+        /// </summary>
+        public Value(int idx)
+        {
+            _idx = idx;
+        }
+
+        /// <summary>
+        /// Gets the index.
+        /// </summary>
+        public int Index
+        {
+            get { return _idx; }
+        }
+    }
+
+    /// <summary>
+    /// Cache entry predicate.
+    /// </summary>
+    [Serializable]
+    public class CacheEntryFilter : ICacheEntryFilter<int, string>
+    {
+        /** <inheritdoc /> */
+        public bool Invoke(ICacheEntry<int, string> entry)
+        {
+            return entry.Key >= 105;
+        }
+    }
+
+    /// <summary>
+    /// Cache entry predicate that throws an exception.
+    /// </summary>
+    [Serializable]
+    public class ExceptionalEntryFilter : ICacheEntryFilter<int, string>
+    {
+        /** <inheritdoc /> */
+        public bool Invoke(ICacheEntry<int, string> entry)
+        {
+            throw new Exception("Expected exception in ExceptionalEntryFilter");
+        }
+    }
+
+    /// <summary>
+    /// Filter that can't be serialized.
+    /// </summary>
+    public class InvalidCacheEntryFilter : CacheEntryFilter
+    {
+        // No-op.
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/83b5bca6/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheTestStore.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheTestStore.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheTestStore.cs
index 4224835..f80f5ce 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheTestStore.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheTestStore.cs
@@ -66,6 +66,20 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
 
             Debug.Assert(_grid != null);
 
+            if (args == null || args.Length == 0)
+                return;
+
+            if (args.Length == 3 && args[0] == null)
+            {
+                // Testing arguments passing.
+                var key = args[1];
+                var val = args[2];
+
+                act(key, val);
+
+                return;
+            }
+
             if (LoadMultithreaded)
             {
                 int cnt = 0;

http://git-wip-us.apache.org/repos/asf/ignite/blob/83b5bca6/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/NamedNodeCacheStoreTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/NamedNodeCacheStoreTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/NamedNodeCacheStoreTest.cs
new file mode 100644
index 0000000..02e257f
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/NamedNodeCacheStoreTest.cs
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Tests.Cache.Store
+{
+    using NUnit.Framework;
+
+    /// <summary>
+    /// Cache store test with named node.
+    /// </summary>
+    [TestFixture]
+    public class NamedNodeCacheStoreTest : CacheStoreTest
+    {
+        /** <inheritDoc /> */
+        protected override string GridName
+        {
+            get { return "name"; }
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/83b5bca6/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs
index 186737c..b8dc6cb 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs
@@ -225,7 +225,7 @@ namespace Apache.Ignite.Core.Impl.Cache
         /// <summary>
         /// Writes the load cache data to the writer.
         /// </summary>
-        private void WriteLoadCacheData(IBinaryRawWriter writer, ICacheEntryFilter<TK, TV> p, object[] args)
+        private void WriteLoadCacheData(BinaryWriter writer, ICacheEntryFilter<TK, TV> p, object[] args)
         {
             if (p != null)
             {
@@ -237,7 +237,17 @@ namespace Apache.Ignite.Core.Impl.Cache
             else
                 writer.WriteObject<CacheEntryFilterHolder>(null);
 
-            writer.WriteArray(args);
+            if (args != null && args.Length > 0)
+            {
+                writer.WriteInt(args.Length);
+
+                foreach (var o in args)
+                    writer.WriteObject(o);
+            }
+            else
+            {
+                writer.WriteInt(0);
+            }
         }
 
         /** <inheritDoc /> */


[4/4] ignite git commit: Merge branch 'master' into ignite-2.0

Posted by pt...@apache.org.
Merge branch 'master' into ignite-2.0


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e8377167
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e8377167
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e8377167

Branch: refs/heads/ignite-2.0
Commit: e8377167b7b8dd020a93d92c743e4541dcd000ed
Parents: 34a9783 83b5bca
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Fri Jan 20 13:00:40 2017 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
Committed: Fri Jan 20 13:00:40 2017 +0300

----------------------------------------------------------------------
 .../store/jdbc/CacheAbstractJdbcStore.java      |  12 +-
 .../store/jdbc/JdbcTypesDefaultTransformer.java |  19 ++
 .../cache/store/jdbc/JdbcTypesTransformer.java  |  17 +
 .../platform/cache/PlatformCache.java           |  11 +-
 .../CacheJdbcPojoStoreAbstractSelfTest.java     |  23 +-
 .../store/jdbc/CacheJdbcPojoStoreTest.java      |   3 +
 ...eJdbcStoreAbstractMultithreadedSelfTest.java |  17 +-
 .../ignite/cache/store/jdbc/model/Gender.java   |  41 +++
 .../ignite/cache/store/jdbc/model/Person.java   |  31 +-
 .../Apache.Ignite.Core.Tests.csproj             |   1 +
 .../Cache/Store/CacheParallelLoadStoreTest.cs   |   9 +-
 .../Cache/Store/CacheStoreSessionTest.cs        |  22 +-
 .../Cache/Store/CacheStoreTest.cs               | 333 ++++++++++++-------
 .../Cache/Store/CacheTestStore.cs               |  14 +
 .../Cache/Store/NamedNodeCacheStoreTest.cs      |  34 ++
 .../Apache.Ignite.Core/Impl/Cache/CacheImpl.cs  |  14 +-
 .../Apache.Ignite.Examples.csproj               |   1 +
 .../Datagrid/QueryDmlExample.cs                 | 159 +++++++++
 .../src/test/config/jdbc-pojo-store-builtin.xml |   8 +
 .../src/test/config/jdbc-pojo-store-obj.xml     |   8 +
 20 files changed, 616 insertions(+), 161 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/e8377167/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
----------------------------------------------------------------------