ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [30/50] [abbrv] ignite git commit: IGNITE-2963 Fixed special case with Date for Oracle JDBC driver.
Date Tue, 26 Apr 2016 01:07:37 GMT
 IGNITE-2963 Fixed special case with Date for Oracle JDBC driver.


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

Branch: refs/heads/ignite-testing-discovery
Commit: b2c934d7abe6dfe86e1d09ec592875df987f2120
Parents: 8634727
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Wed Apr 6 17:31:21 2016 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Wed Apr 6 17:31:21 2016 +0700

----------------------------------------------------------------------
 .../store/jdbc/CacheAbstractJdbcStore.java      |  4 +++
 .../CacheJdbcPojoStoreAbstractSelfTest.java     | 28 +++++++++++++++-----
 ...eJdbcStoreAbstractMultithreadedSelfTest.java | 25 +++++++++++------
 .../ignite/cache/store/jdbc/model/Person.java   | 25 +++++++++++++++++
 4 files changed, 67 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b2c934d7/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 c5c55e1..c16f2c6 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
@@ -481,6 +481,10 @@ public abstract class CacheAbstractJdbcStore<K, V> implements CacheStore<K,
V>,
                 return UUID.fromString((String)val);
         }
 
+        // Workaround for known issue with Oracle JDBC driver https://community.oracle.com/thread/2355464?tstart=0
+        if (type == java.sql.Date.class && val instanceof java.util.Date)
+            return new java.sql.Date(((java.util.Date)val).getTime());
+
         return val;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b2c934d7/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 0f40bd9..a526b8c 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
@@ -18,12 +18,14 @@
 package org.apache.ignite.cache.store.jdbc;
 
 import java.sql.Connection;
+import java.sql.Date;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.Types;
+import java.util.Random;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.cache.store.jdbc.dialect.H2Dialect;
 import org.apache.ignite.cache.store.jdbc.model.Person;
@@ -96,6 +98,7 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
         stmt.executeUpdate("CREATE TABLE Person (" +
             " id INTEGER PRIMARY KEY," +
             " org_id INTEGER," +
+            " birthday DATE," +
             " name VARCHAR(50))");
 
         conn.commit();
@@ -179,6 +182,7 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
         storeTypes[1].setValueFields(
             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"));
 
         return storeTypes;
@@ -218,6 +222,8 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
     protected void fillSampleDatabase(Connection conn) throws SQLException {
         info("Start to fill sample database...");
 
+        Random rnd = new Random();
+
         PreparedStatement orgStmt = conn.prepareStatement("INSERT INTO Organization(id, name,
city) VALUES (?, ?, ?)");
 
         for (int i = 0; i < ORGANIZATION_CNT; i++) {
@@ -234,12 +240,14 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
 
         conn.commit();
 
-        PreparedStatement prnStmt = conn.prepareStatement("INSERT INTO Person(id, org_id,
name) VALUES (?, ?, ?)");
+        PreparedStatement prnStmt = conn.prepareStatement(
+            "INSERT INTO Person(id, org_id, birthday, name) VALUES (?, ?, ?, ?)");
 
         for (int i = 0; i < PERSON_CNT; i++) {
             prnStmt.setInt(1, i);
             prnStmt.setInt(2, i % 100);
-            prnStmt.setString(3, "name" + i);
+            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.addBatch();
         }
@@ -328,7 +336,7 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
 
         Connection conn = getConnection();
         try {
-            PreparedStatement stmt = conn.prepareStatement("SELECT ID, ORG_ID, NAME FROM
PERSON WHERE ID = ?");
+            PreparedStatement stmt = conn.prepareStatement("SELECT ID, ORG_ID, BIRTHDAY,
NAME FROM PERSON WHERE ID = ?");
 
             stmt.setInt(1, -1);
 
@@ -341,7 +349,9 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
             // Test put-insert.
             PersonKey key = new PersonKey(-1);
 
-            c1.put(key, new Person(-1, -2, "Person-to-test-put-insert", 999));
+            Date testDate = Date.valueOf("2001-05-05");
+
+            c1.put(key, new Person(-1, -2, testDate, "Person-to-test-put-insert", 999));
 
             rs = stmt.executeQuery();
 
@@ -349,14 +359,17 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
 
             assertEquals(-1, rs.getInt(1));
             assertEquals(-2, rs.getInt(2));
-            assertEquals("Person-to-test-put-insert", rs.getString(3));
+            assertEquals(testDate, rs.getDate(3));
+            assertEquals("Person-to-test-put-insert", rs.getString(4));
 
             assertFalse("Unexpected more data in result set", rs.next());
 
             U.closeQuiet(rs);
 
             // Test put-update.
-            c1.put(key, new Person(-1, -3, "Person-to-test-put-update", 999));
+            testDate = Date.valueOf("2016-04-04");
+
+            c1.put(key, new Person(-1, -3, testDate, "Person-to-test-put-update", 999));
 
             rs = stmt.executeQuery();
 
@@ -364,7 +377,8 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
 
             assertEquals(-1, rs.getInt(1));
             assertEquals(-3, rs.getInt(2));
-            assertEquals("Person-to-test-put-update", rs.getString(3));
+            assertEquals(testDate, rs.getDate(3));
+            assertEquals("Person-to-test-put-update", rs.getString(4));
 
             assertFalse("Unexpected more data in result set", rs.next());
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b2c934d7/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 592d1cb..e831445 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
@@ -20,6 +20,7 @@ package org.apache.ignite.cache.store.jdbc;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.sql.Connection;
+import java.sql.Date;
 import java.sql.DriverManager;
 import java.sql.Statement;
 import java.util.ArrayList;
@@ -206,7 +207,8 @@ public abstract class CacheJdbcStoreAbstractMultithreadedSelfTest<T
extends Cach
                     if (rnd.nextBoolean())
                         cache.put(new OrganizationKey(id), new Organization(id, "Name" +
id, "City" + id));
                     else
-                        cache.put(new PersonKey(id), new Person(id, rnd.nextInt(), "Name"
+ id, 1));
+                        cache.put(new PersonKey(id), new Person(id, rnd.nextInt(),
+                            new Date(System.currentTimeMillis()), "Name" + id, 1));
                 }
 
                 return null;
@@ -225,7 +227,8 @@ public abstract class CacheJdbcStoreAbstractMultithreadedSelfTest<T
extends Cach
                     if (rnd.nextBoolean())
                         cache.putIfAbsent(new OrganizationKey(id), new Organization(id, "Name"
+ id, "City" + id));
                     else
-                        cache.putIfAbsent(new PersonKey(id), new Person(id, rnd.nextInt(),
"Name" + id, i));
+                        cache.putIfAbsent(new PersonKey(id), new Person(id, rnd.nextInt(),
+                            new Date(System.currentTimeMillis()), "Name" + id, i));
                 }
 
                 return null;
@@ -264,7 +267,8 @@ public abstract class CacheJdbcStoreAbstractMultithreadedSelfTest<T
extends Cach
                         if (rnd.nextBoolean())
                             map.put(new OrganizationKey(id), new Organization(id, "Name"
+ id, "City" + id));
                         else
-                            map.put(new PersonKey(id), new Person(id, rnd.nextInt(), "Name"
+ id, 1));
+                            map.put(new PersonKey(id), new Person(id, rnd.nextInt(),
+                                new Date(System.currentTimeMillis()), "Name" + id, 1));
                     }
 
                     IgniteCache<Object, Object> cache = jcache();
@@ -289,17 +293,22 @@ public abstract class CacheJdbcStoreAbstractMultithreadedSelfTest<T
extends Cach
                     IgniteCache<PersonKey, Person> cache = jcache();
 
                     try (Transaction tx = grid().transactions().txStart()) {
-                        cache.put(new PersonKey(1), new Person(1, rnd.nextInt(), "Name" +
1, 1));
-                        cache.put(new PersonKey(2), new Person(2, rnd.nextInt(), "Name" +
2, 2));
-                        cache.put(new PersonKey(3), new Person(3, rnd.nextInt(), "Name" +
3, 3));
+                        cache.put(new PersonKey(1), new Person(1, rnd.nextInt(),
+                            new Date(System.currentTimeMillis()), "Name" + 1, 1));
+                        cache.put(new PersonKey(2), new Person(2, rnd.nextInt(),
+                            new Date(System.currentTimeMillis()), "Name" + 2, 2));
+                        cache.put(new PersonKey(3), new Person(3, rnd.nextInt(),
+                            new Date(System.currentTimeMillis()), "Name" + 3, 3));
 
                         cache.get(new PersonKey(1));
                         cache.get(new PersonKey(4));
 
                         Map<PersonKey, Person> map =  U.newHashMap(2);
 
-                        map.put(new PersonKey(5), new Person(5, rnd.nextInt(), "Name" + 5,
5));
-                        map.put(new PersonKey(6), new Person(6, rnd.nextInt(), "Name" + 6,
6));
+                        map.put(new PersonKey(5), new Person(5, rnd.nextInt(),
+                            new Date(System.currentTimeMillis()), "Name" + 5, 5));
+                        map.put(new PersonKey(6), new Person(6, rnd.nextInt(),
+                            new Date(System.currentTimeMillis()), "Name" + 6, 6));
 
                         cache.putAll(map);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b2c934d7/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 4d3714e..ddf309b 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
@@ -18,6 +18,7 @@
 package org.apache.ignite.cache.store.jdbc.model;
 
 import java.io.Serializable;
+import java.sql.Date;
 
 /**
  * Person definition.
@@ -34,6 +35,9 @@ public class Person implements Serializable {
     /** Value for orgId. */
     private Integer orgId;
 
+    /** Value for birthday. */
+    private Date birthday;
+
     /** Value for name. */
     private String name;
 
@@ -53,11 +57,13 @@ public class Person implements Serializable {
     public Person(
         Integer id,
         Integer orgId,
+        Date birthday,
         String name,
         Integer salary
     ) {
         this.id = id;
         this.orgId = orgId;
+        this.birthday = birthday;
         this.name = name;
         this.salary = salary;
     }
@@ -99,6 +105,24 @@ public class Person implements Serializable {
     }
 
     /**
+     * Gets birthday.
+     *
+     * @return Value for birthday.
+     */
+    public Date getBirthday() {
+        return birthday;
+    }
+
+    /**
+     * Sets birthday.
+     *
+     * @param birthday New value for birthday.
+     */
+    public void setBirthday(Date birthday) {
+        this.birthday = birthday;
+    }
+
+    /**
      * Gets name.
      *
      * @return Value for name.
@@ -172,6 +196,7 @@ public class Person implements Serializable {
     @Override public String toString() {
         return "Person [id=" + id +
             ", orgId=" + orgId +
+            ", birthday=" + birthday.getTime() +
             ", name=" + name +
             "]";
     }


Mime
View raw message