cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Atul Saroha <atul.sar...@snapdeal.com>
Subject Re: ORM layer for cassandra-java?
Date Fri, 12 Feb 2016 12:50:01 GMT
sorry I was  my understanding issue of solution 2. Thanks for the solution

---------------------------------------------------------------------------------------------------------------------
Atul Saroha
*Sr. Software Engineer*
*M*: +91 8447784271 *T*: +91 124-415-6069 *EXT*: 12369
Plot # 362, ASF Centre - Tower A, Udyog Vihar,
 Phase -4, Sector 18, Gurgaon, Haryana 122016, INDIA

On Fri, Feb 12, 2016 at 3:39 PM, Atul Saroha <atul.saroha@snapdeal.com>
wrote:

> Thanks for the reply. We would go with solution 1.
>
> One more thing, which might be a bug. We are using 4.0.1 version. And
> query of solution 2  is not possible. c3 is cluster key. No option is
> visible for this cluster key:
>
>    1. we cannot use it in set (manager.dsl().update().fromBaseTable().<no
>    option for c3>)
>    2. even after where clause (only available option is based on id "
>    :manager.dsl().update().fromBaseTable().c4_Set("1").where().id_Eq(id)")
>    in DSL.
>
>
> @Entity(keyspace = "ks" , table="PrimeUser")
>
>> public class PrimeUser {
>>
>>     @PartitionKey
>>
>>> @Column("id")
>>>
>>     private int id;
>>
>>     @Column("c1")
>>     @Static
>>     private String c1;
>>
>>     @Column("c2")
>>     @Static
>>     private Boolean c2;
>>
>>
>>     @Column("c3")
>>     @ClusteringColumn(1)
>>     private String c3;
>>
>>     @Column("c4")
>>     private String c4;
>>
>> }
>>
>> Regards,
>
>
>
> ---------------------------------------------------------------------------------------------------------------------
> Atul Saroha
> *Sr. Software Engineer*
> *M*: +91 8447784271 *T*: +91 124-415-6069 *EXT*: 12369
> Plot # 362, ASF Centre - Tower A, Udyog Vihar,
>  Phase -4, Sector 18, Gurgaon, Haryana 122016, INDIA
>
> On Fri, Feb 12, 2016 at 3:01 PM, DuyHai Doan <doanduyhai@gmail.com> wrote:
>
>> "How could I achieve Delta Update through this ORM  where I want to
>> inserting one row for id,c3,c4 columns only"
>>
>> 2 ways:
>>
>> 1. Create an empty PrimeUser entity with only id, c3 and c4 values. Use
>>       manager
>>            .crud()
>>            .insert(entity)
>>            .withInsertStrategy(InsertStrategy.NOT_NULL_FIELDS)
>>            .execute()
>>
>>     This way, Achilles will only extract the 3 columns (id, c3, c4) and
>> generates only INSERT INTO primeuser(id,c3,c4) VALUES(...) and skip
>> inserting null values
>>
>>
>> 2. Use the Update DSL
>>
>>     manager
>>            .dsl()
>>            .update()
>>            .fromBaseTable()
>>            .c3_Set("....")
>>            .c4_Set("....")
>>            .where()
>>            .id_Eq(partitionKey)
>>            .execute()
>>
>>
>> "Since Achilies does not have persistence context like hibernate does,
>> to track what has beed updated in my java entity and update the change only
>> though DynamicUpdate anotation."
>>
>>  This is made on-purpose. Having a proxy to intercept calls to setters
>> and to track what has been updated would require a "read-before-write" e.g.
>> load existing data first from Cassandra into the proxy. And
>> read-before-write is an anti-pattern.
>>
>>  Optionally, one could create an empty proxy without read-before-write
>> and intercept only data that have been added to the entity. And this is
>> exactly what solution 1. does: create a new empty instance of PrimeUser,
>> populate some values and user insert() with NOT_NULL_FIELDS insert
>> strategy. The only difference is that Achilles creates INSERT statement
>> instead of UPDATE.
>>
>>
>>
>>
>>
>> On Fri, Feb 12, 2016 at 9:02 AM, Atul Saroha <atul.saroha@snapdeal.com>
>> wrote:
>>
>>> Thanks Doan,
>>>
>>> We are now evaluating or nearly finalized to use Achilles.
>>>
>>> We are looking for one use case.
>>> As I mentioned in above for static columns.
>>>
>>>> CREATE TABLE IF NOT EXISTS  ks.PrimeUser(
>>>>   id int,
>>>>   c1 text STATIC,
>>>>   c2 boolean STATIC,
>>>>   c3 text,
>>>>   c4 text,
>>>>   PRIMARY KEY (id, c3)
>>>>
>>> );
>>>>
>>> How could I achieve Delta Update through this ORM  where I want to
>>> inserting one row for id,c3,c4 columns only or updating one row for c4
>>> column only against ( id,c3). If I use my entity PrimeUser.java and crud
>>> insert method then it will insert all columns including static.
>>> I think that there is only one way which is to use update method of
>>> dsl/Query API. Since Achilies does not have persistence context like
>>> hibernate does, to track what has beed updated in my java entity and update
>>> the change only though DynamicUpdate anotation.
>>> Or there is something I am missing here?.
>>>
>>> Thanks , reply will be highly appreciated
>>>
>>>
>>>
>>> ---------------------------------------------------------------------------------------------------------------------
>>> Atul Saroha
>>> *Sr. Software Engineer*
>>> *M*: +91 8447784271 *T*: +91 124-415-6069 *EXT*: 12369
>>> Plot # 362, ASF Centre - Tower A, Udyog Vihar,
>>>  Phase -4, Sector 18, Gurgaon, Haryana 122016, INDIA
>>>
>>> On Tue, Feb 9, 2016 at 8:32 PM, DuyHai Doan <doanduyhai@gmail.com>
>>> wrote:
>>>
>>>> Look at Achilles and how it models Partition key & clustering columns:
>>>>
>>>>
>>>> https://github.com/doanduyhai/Achilles/wiki/5-minutes-Tutorial#clustered-entities
>>>>
>>>>
>>>>
>>>> On Tue, Feb 9, 2016 at 12:48 PM, Atul Saroha <atul.saroha@snapdeal.com>
>>>> wrote:
>>>>
>>>>> I know the most popular ORM api
>>>>>
>>>>>    1. Kundera :
>>>>>    https://github.com/impetus-opensource/Kundera/wiki/Using-Compound-keys-with-Kundera
>>>>>    2. Hector (outdated- no longer in development)
>>>>>
>>>>> I am bit confuse to model this table into java domain entity structure
>>>>>
>>>>> CREATE TABLE IF NOT EXISTS  ks.PrimeUser(
>>>>>   id int,
>>>>>   c1 text STATIC,
>>>>>   c2 boolean STATIC,
>>>>>   c3 text,
>>>>>   c4 text,
>>>>>   PRIMARY KEY (id, c3)
>>>>> );
>>>>>
>>>>>
>>>>> One way is to create compound key based on id and c3 column as shown
>>>>> below.
>>>>>
>>>>>> @Entity
>>>>>> @Table(name="PrimeUser", schema="ks")
>>>>>> public class PrimeUser
>>>>>> {
>>>>>>
>>>>>>     @EmbeddedId
>>>>>>     private CompoundKey key;
>>>>>>
>>>>>>    @Column
>>>>>>    private String c1;
>>>>>>    @Column
>>>>>>    private String c2;
>>>>>>    @Column
>>>>>>    private String c4;
>>>>>> }
>>>>>>
>>>>>> Here key has to be an Embeddable entity:
>>>>>>
>>>>>> @Embeddable
>>>>>> public class CompoundKey
>>>>>> {
>>>>>>     @Column private int id;
>>>>>>     @Column private String c1;
>>>>>> }
>>>>>>
>>>>>> Then again when we fetch the data based on id only then c1 and c2
>>>>> will be duplicated multiple times object, even though they are stored
per
>>>>> "id" basis. c3 column is cluster key and its corresponding value is mapped
>>>>> to column c4. We avoid using map<c3,c4> here as it will cause performance
>>>>> hit. Also he have use cases to fetch the data based on (b1,c3) both also.
>>>>>
>>>>> Is there any other ORM API which handle such scenario.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------------------------------------------------------
>>>>> Atul Saroha
>>>>> *Sr. Software Engineer*
>>>>> *M*: +91 8447784271 *T*: +91 124-415-6069 *EXT*: 12369
>>>>> Plot # 362, ASF Centre - Tower A, Udyog Vihar,
>>>>>  Phase -4, Sector 18, Gurgaon, Haryana 122016, INDIA
>>>>>
>>>>
>>>>
>>>
>>
>

Mime
View raw message