GitHub user szczurmys opened a pull request:

    https://github.com/apache/ignite/pull/3192

    Type handler in cassandra module

    I added "type handler" in cassandra module (similar solution is in iBatis 
https://ibatis.apache.org/docs/java/dev/com/ibatis/sqlmap/engine/type/TypeHandler.html),
 that allow use any java type in key|value|pojo and then convert from/to simple 
cassandra type available in cassandra driver.
    
    E.g. you can use java.time.LocalDateTime insead of use java.util.Date 
directly, or even use map<key, value> ( 
https://docs.datastax.com/en/cql/3.1/cql/cql_using/use_map_t.html ), if you 
like.
    
    It should be compatible with previous persistence-settings file.
    
    I would be grateful, if you check and test it :).
    
    
    
    Example of use for LocalDateTime:
    
    Type hander:
    ```java
    public class LocalDateTimeTypeHandler implements 
TypeHandler<java.time.LocalDateTime, java.util.Date> {
        @Override 
        public java.time.LocalDateTime toJavaType(Row row, int index) {
            java.util.Date date = row.getTimestamp(index);
            return date == null ? null : convert(date);
        }
        @Override 
        public java.time.LocalDateTime toJavaType(Row row, String col) {
            java.util.Date date = row.getTimestamp(col);
            return date == null ? null : convert(date);
        }
        @Override 
        public java.util.Date toCassandraPrimitiveType(java.time.LocalDateTime 
javaValue) {
            return javaValue == null ? null : convert(javaValue);
        }
        @Override
        public String getDDLType() {
            return DataType.Name.TIMESTAMP.toString();
        }
        private java.time.LocalDateTime convert(java.util.Date date) {
            return java.time.LocalDateTime.ofInstant(date.toInstant(), 
java.time.ZoneId.systemDefault());
        }
        private java.util.Date convert(java.time.LocalDateTime  date) {
            return 
java.util.Date.from(date.atZone(java.time.ZoneId.systemDefault()).toInstant());
        }
    }
    ```
    
    POJO:
    ```java
    public class TestPojoClass {
        private String name;
        private java.time.LocalDateTime modificationDateTime;
        
        /** getters and setters **/
    }
    
    ```
    
    persistence-settings:
    ```xml
    <persistence keyspace="test1" table="example_of_use_type_handler">
        <keyPersistence class="java.lang.Long" strategy="PRIMITIVE" 
column="key"/>
        <valuePersistence class="TestPojoClass"
                          strategy="POJO"
                          
serializer="org.apache.ignite.cache.store.cassandra.serializer.JavaSerializer">
            <field name="name" column="name" />
            <field name="modificationDateTime" column="modification_date_time" 
handlerClass="LocalDateTimeTypeHandler" />
        </valuePersistence>
    </persistence>
    ```

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/szczurmys/ignite type-handler

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/ignite/pull/3192.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #3192
    
----
commit 206c2ddb02816e114a7eca7686c0d7d881b7ec1b
Author: Jakub Goszczurny <szczur...@o2.pl>
Date:   2017-11-22T23:43:08Z

    Added type handler for cassandra-store.
    
    Signed-off-by: Jakub Goszczurny <szczur...@o2.pl>

commit 0f17e1b25c0ed6f7b043f02311f6a4482bd4eec5
Author: Jakub Goszczurny <szczur...@o2.pl>
Date:   2017-11-23T21:06:23Z

    Fixed some handler bugs. TODO: extend IgnitePersistentStoreTest
    
    Signed-off-by: Jakub Goszczurny <szczur...@o2.pl>

commit 28e12a24832f8548fd77e5b146d96733bc595e2a
Author: Jakub Goszczurny <szczur...@o2.pl>
Date:   2017-11-24T22:00:18Z

    Fixed handler for primitive strategy. Extend IgnitePersistentStoreTest.
    
    Signed-off-by: Jakub Goszczurny <szczur...@o2.pl>

commit 279b98700fe90833de2f7128d8f8dd86ac4ffc54
Author: Jakub Goszczurny <szczur...@o2.pl>
Date:   2017-12-09T13:22:40Z

    Used TypeHandlers instead of DataType.Name in JAVA_TO_CASSANRA_MAPPING. 
Added JavaDoc for TypeHandler. Small refactor.
    
    Signed-off-by: Jakub Goszczurny <szczur...@o2.pl>

commit aec0b17d8d966583bc74d9760c1a674f96654495
Author: Jakub Goszczurny <szczur...@o2.pl>
Date:   2017-12-10T19:07:01Z

    Small refactor.
    
    Signed-off-by: Jakub Goszczurny <szczur...@o2.pl>

----


---

Reply via email to