You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by michal23849 <mi...@gmail.com> on 2018/08/10 12:35:02 UTC

Re: apache ignite cassandra persistentStore for enum fields

Hi,

I have the same issue with CacheJdbcPojoStore with writeBehind persistency
in SQL DB. 

Is it only possible to store ENUMs as BLOBs or is there any other way to map
them as strings, or anything else?
I got the ENUMs both in the Key and Value fields.

Regards
Michal



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: apache ignite cassandra persistentStore for enum fields

Posted by michal23849 <mi...@gmail.com>.
Ilya, 

Thank you for all clarifications!

Best regards
Michal



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: apache ignite cassandra persistentStore for enum fields

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

I think that VARCHAR option is only available when object is passed to
cache store in deserialized (POJO) form. If it is passed in serialized
(BinaryObject) form then it will always store ordinal.
And, for some reason, after
https://issues.apache.org/jira/browse/IGNITE-4949 for CacheJdbcPojoStore
serialized form is always used.

+ Dmitriy

Why was this change made? Is

if (fieldVal instanceof Enum) {
    Enum val = (Enum)fieldVal;

    fieldVal = NUMERIC_TYPES.contains(field.getDatabaseFieldType()) ?
val.ordinal() : val.name();
}
block from CacheAbstractJdbcStore still useful after this change?

Regards,
-- 

Ilya Kasnacheev


вт, 28 авг. 2018 г. в 11:57, michal23849 <mi...@gmail.com>:

> Hi Ilya,
>
> Thank you for your advice. It does work now when I put my class as the
> javaFieldType. However one thing still does bother me.
>
> Previously you advised that Ignite will determine itself if the enum is
> ORDINAL or a STRING and store accordingly - either Ordinal or the Name.
>
> So I have accordingly mapped 2 fields - one as Integer and one as String.
>
> <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
>   <property name="databaseFieldType" >
>           <util:constant static-field="java.sql.Types.INTEGER"/>
>   </property>
>   <property name="databaseFieldName" value="state" />
>   <property name="javaFieldType" value="com.myModel.CState" />
>   <property name="javaFieldName" value="state" />
> </bean>
>
>
> <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
>   <property name="databaseFieldType" >
>           <util:constant static-field="java.sql.Types.VARCHAR"/>
>   </property>
>   <property name="databaseFieldName" value="type" />
>   <property name="javaFieldType" value="com.myModel.CType" />
>   <property name="javaFieldName" value="type" />
> </bean>
>
> Here is my SQLServer Table:
>
> CREATE TABLE [dbo].[CCache1](
>         [ric] [varchar](255) NOT NULL,
>         [state] [int] null,
>         [type] [varchar](255) null
> )
>
> The problem is that no matter if I map the ENUM to Integer or String - it
> always stores it as Integer, even in Varchar column. Please advise.
>
> Please see the SQLServer results after storing data in Ignite:
> select top 100 ric, state, type from [CCache1]
> ric     state   type
> .CSUS0457       1       20
>
>
>
> Thanks,
> Michal
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: apache ignite cassandra persistentStore for enum fields

Posted by michal23849 <mi...@gmail.com>.
Hi Ilya,

Thank you for your advice. It does work now when I put my class as the
javaFieldType. However one thing still does bother me. 

Previously you advised that Ignite will determine itself if the enum is
ORDINAL or a STRING and store accordingly - either Ordinal or the Name.

So I have accordingly mapped 2 fields - one as Integer and one as String.

<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
  <property name="databaseFieldType" >
	  <util:constant static-field="java.sql.Types.INTEGER"/>
  </property>
  <property name="databaseFieldName" value="state" />
  <property name="javaFieldType" value="com.myModel.CState" />
  <property name="javaFieldName" value="state" />
</bean>		


<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
  <property name="databaseFieldType" >
	  <util:constant static-field="java.sql.Types.VARCHAR"/>
  </property>
  <property name="databaseFieldName" value="type" />
  <property name="javaFieldType" value="com.myModel.CType" />
  <property name="javaFieldName" value="type" />
</bean>		

Here is my SQLServer Table:

CREATE TABLE [dbo].[CCache1](
	[ric] [varchar](255) NOT NULL,
	[state] [int] null,
	[type] [varchar](255) null
)

The problem is that no matter if I map the ENUM to Integer or String - it
always stores it as Integer, even in Varchar column. Please advise.

Please see the SQLServer results after storing data in Ignite:
select top 100 ric, state, type from [CCache1]
ric	state	type
.CSUS0457	1	20



Thanks,
Michal



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: apache ignite cassandra persistentStore for enum fields

Posted by Ilya Kasnacheev <il...@gmail.com>.
Have you tried specifying the actual enum type? e.g. com.corp.my.Enum

Regards,
-- 
Ilya Kasnacheev


пн, 27 авг. 2018 г. в 17:41, michal23849 <mi...@gmail.com>:

> Hi Ilya,
>
> Following up to ENUMs - what should I put then as the JavaFieldType?
>
> I tried java.lang.Enum, java.lang.Integer and it is failing. What value
> should be specified for PojoStore to correctly map the Enum to
> DatabaseFieldName and Type?
>
> Thank You,
> Michal
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: apache ignite cassandra persistentStore for enum fields

Posted by michal23849 <mi...@gmail.com>.
Hi Ilya,

Following up to ENUMs - what should I put then as the JavaFieldType? 

I tried java.lang.Enum, java.lang.Integer and it is failing. What value
should be specified for PojoStore to correctly map the Enum to
DatabaseFieldName and Type?

Thank You,
Michal



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: apache ignite cassandra persistentStore for enum fields

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

I can see the following in code:

fieldVal = NUMERIC_TYPES.contains(field.getDatabaseFieldType()) ?
val.ordinal() : val.name();

As you can see here, if the column is numeric then ordinal is stored,
otherwise it's name. Which is the one that you want. Just specify the
appropriate databaseFieldType.

Regards,

-- 
Ilya Kasnacheev

2018-08-10 15:35 GMT+03:00 michal23849 <mi...@gmail.com>:

> Hi,
>
> I have the same issue with CacheJdbcPojoStore with writeBehind persistency
> in SQL DB.
>
> Is it only possible to store ENUMs as BLOBs or is there any other way to
> map
> them as strings, or anything else?
> I got the ENUMs both in the Key and Value fields.
>
> Regards
> Michal
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>