0
votes

I am using RDMS and Ignite Integration https://apacheignite-mix.readme.io/v1.7/docs/automatic-persistence to transform each table record into POJO and put the POJO into Ignite Cache.

I want to change the type of a column to anther type for the corresponding field in POJO.

For example, I want to change the BIRTH_DAY column which is string type is db to the corresponding field which is java.sql Date in POJO.

I would ask how to this? Can I do the conversion logic in the CacheConfig code side?

Following is piece of the code that do the mapping between column name and POJO field name,but it looks that I can't add in the conversion logic?

// Value fields for TBL_PERSON
Collection<JdbcTypeField> vals = new ArrayList<>();
vals.add(new JdbcTypeField(Types.INTEGER, "ID", int.class, "id"));
vals.add(new JdbcTypeField(Types.VARCHAR, "NMAE", String.class, "name"));
vals.add(new JdbcTypeField(Types.VARCHAR, "BIRTHDAY", String.class, "birthday"));
1
You should be able to update an Ignite configuration manually once it's automatically prepared for you. Have you tried that? Additionally, I can give a try to the new schema import capabilities provided by Web Console (apacheignite-mix.readme.io/v1.8/docs/web-console) - dmagda
Thanks @drama. I meant to build web console locally but with no luck...perhaps due to network issues. You should be able to update an Ignite configuration manually once it's automatically prepared for you. Have you tried that?---I checked the POJO and CacheConfig,but I didn't find how to add the conversion logic.. - Tom
@Tom, what the problem to start web console locally? Could you post to Apache Ignite user list? See: ignite.apache.org/community/resources.html#ask - kuaw26

1 Answers

1
votes

You may try to create your custom JdbcTypesTransformer and set it via factory (see: CacheJdbcPojoStoreFactory#setTransformer). Also note, that you will need to deploy class with your custom transformer on all nodes. Code could be like this:

public class MyJdbcTypesTransformer extends JdbcTypesDefaultTransformer {
/** */
private static final long serialVersionUID = 0L;

/** {@inheritDoc} */
@Override public Object getColumnValue(ResultSet rs, int colIdx, Class<?> type) throws SQLException {
    Object val = rs.getObject(colIdx);

    if (val instanceOf Strinng && type == Date.class) {
      .... conver from string to date....
    }

    return super.getColumnValue(rs, colIdx, type);
}

Also JdbcTypesDefaultTransformer (default transformer) will try to convert types using underlying JDBC diver (for example, that means if in DB you have Integer, you can try to get it in Java as String). For this you should change mappings manually in config:

vals.add(new JdbcTypeField(Types.INTEGER, "ID", String.class, "id"));

For String -> Date this may not work out of the box, because driver and JdbcTypesTransformer have no idea how date was encoded in string.