Impetus / kundera

A JPA 2.1 compliant Polyglot Object-Datastore Mapping Library for NoSQL Datastores.Please subscribe to:
http://groups.google.com/group/kundera-discuss/subscribe
Apache License 2.0
903 stars 233 forks source link

Kundera-Cassandra, batch #804

Open pavanraotk opened 8 years ago

pavanraotk commented 8 years ago

Hi Everybody,,

I am trying to run a cassandra batch, but by using Kundera and not using the actual batch code.

Essentially, I am doing this:

private boolean redeemOnlyTermPoints(ActivePoint activePoint, int points) throws Exception { boolean executeStatus = true; try { em = getEntityManager(); int term_current_balance = activePoint.getTerm_current_balance(); activePoint.setTerm_current_balance(activePoint.getTerm_current_balance() - points); em.merge(activePoint); activePoint = getInsertRowRedeemTermPointsOnly(activePoint, points, term_current_balance); em.persist(activePoint); List activeTermPoints = getActivePointByUserInternalIdAndType( activePoint.getId().getUser_internal_id(), "Term"); for (ActivePoint activeTermPoint : activeTermPoints) { if (points >= 0) { activeTermPoint.setRedeemed_term_points(activeTermPoint.getTerm_point_amount()); points = points - activeTermPoint.getTerm_point_amount(); em.merge(activeTermPoint); } else { break; } } em.flush(); } finally { closeEntityManager(); } return executeStatus; }

public EntityManager getEntityManager() { if (em == null) { emf = Persistence.createEntityManagerFactory("PMS_CORE"); em = emf.createEntityManager(); } else { em = emf.createEntityManager(); } return em; }

Essentially, this is doing this:

10:23:49.151 [main] INFO c.i.c.cassandra.CassandraClientBase - Returning cql query INSERT INTO "active_points"("term_point_balance","term_point_amount","std_point_amount","redeemed_term_points","std_point_balance","term_current_balance","transaction_id","expiry","redeemed_std_points","std_current_balance","user_internal_id","type","ts") VALUES(200,200,0,200,0,700,1186a84b-21ac-4bee-a985-437b5fe31e89,'1454635429111',0,1000,8c24d55f-a9ad-49ff-86f2-59158d0dea87,'Term','1446686629111') . 10:23:49.151 [main] INFO c.i.c.cassandra.CassandraClientBase - Returning cql query INSERT

INTO "active_points"("term_point_balance","term_point_amount","std_point_amount","redeemed_term_points","std_point_balance","term_current_balance","transaction_id","expiry","redeemed_std_points","std_current_balance","user_internal_id","type","ts") VALUES(500,500,0,500,0,700,aa48dd62-418e-44d7-918d-75703c4d42ce,'1454635429121',0,1000,8c24d55f-a9ad-49ff-86f2-59158d0dea87,'Term','1446686629121') .

But, the problem is, it just returns me the CQL query and is not executing it(that is, I don't see the changes in the Cassandra database). How do I make it execute? I checked the code in https://github.com/impetus-opensource/Kundera/blob/0e858ba9236318fdddef56bb547ed1b27a4a1c88/src/kundera-cassandra/cassandra-core/src/test/java/com/impetus/client/crud/batch/CassandraBatchProcessorTest.java

But this didn't help me.

My persistence xml looks like this:

com.impetus.kundera.KunderaPersistence com.rakuten.cassandra.jpa.entity.ActivePoint com.rakuten.cassandra.jpa.entity.ActivePointPK true

My understanding was, if I have multiple merge/persist/remove and do em.flush(), that essentially runs all the merge/persist/remove queries.

Could you please help?

pavanraotk commented 8 years ago

kundera.batch.size = "5000"

Not sure why I could not attach my persistence xml code.

pavanraotk commented 8 years ago

I kind of solved the issue, removed the kundera.batch.size = "5000" from my persistence.xml and it resolved.

But, why is it used for?