Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
removed hc field mappings, rebuild related class
Browse files Browse the repository at this point in the history
  • Loading branch information
zznate committed Feb 3, 2011
1 parent df76925 commit e9a0ef4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
Expand Up @@ -62,25 +62,23 @@ public CassandraStore open() {
return this;
}

public <I> boolean getObject(OpenJPAStateManager stateManager, I idObj) {
// build CFMappingDef
public boolean getObject(OpenJPAStateManager stateManager) {

ClassMetaData metaData = stateManager.getMetaData();
EntityFacade entityFacade = new EntityFacade(metaData);
SliceQuery<byte[], String, byte[]> sliceQuery = mappingUtils.buildSliceQuery(idObj, entityFacade, keyspace);
Object idObj = stateManager.getId();

stateManager.storeObject(0, idObj);
SliceQuery<byte[], String, byte[]> sliceQuery = mappingUtils.buildSliceQuery(idObj, entityFacade, keyspace);

//stateManager.storeObject(0, idObj);

QueryResult<ColumnSlice<String, byte[]>> result = sliceQuery.execute();
// TODO iterate values, loading object
for (Map.Entry<String, ColumnMeta<?>> entry : entityFacade.getColumnMeta().entrySet()) {


for (Map.Entry<String, ColumnMeta<?>> entry : entityFacade.getColumnMeta().entrySet()) {
HColumn<String, byte[]> column = result.get().getColumnByName(entry.getKey());
if ( column != null )
stateManager.storeObject(entry.getValue().fieldId, entry.getValue().serializer.fromBytes(column.getValue()));
}



}
return true;
}

Expand Down
Expand Up @@ -130,7 +130,7 @@ public boolean initialize(OpenJPAStateManager stateManager, PCState pcState,
log.debug("In initialize operation...");
cassandraStore.open();
stateManager.initialize(stateManager.getMetaData().getDescribedType(), pcState);
cassandraStore.getObject(stateManager, stateManager.getId());
cassandraStore.getObject(stateManager);
// TODO need to add the not-found case
return true;
}
Expand All @@ -139,7 +139,7 @@ public boolean initialize(OpenJPAStateManager stateManager, PCState pcState,
public boolean load(OpenJPAStateManager stateManager, BitSet arg1,
FetchConfiguration arg2, int arg3, Object arg4) {
log.debug("In load operation...");
cassandraStore.getObject(stateManager, stateManager.getId());
cassandraStore.getObject(stateManager);
// TODO implement the loading of properties marked as lazy (is this correct?)
// this is a misnomer. load is called to fill in additional information not retrieved from
// initialize call above
Expand Down
@@ -1,5 +1,9 @@
package me.prettyprint.hom.openjpa;

import static org.junit.Assert.*;

import java.util.UUID;

import javax.persistence.EntityManager;

import me.prettyprint.cassandra.utils.TimeUUIDUtils;
Expand All @@ -17,14 +21,21 @@ public void testManyToOneSaveAndLoad() {
em.getTransaction().begin();

SimpleRelationshipBean srb = new SimpleRelationshipBean();
srb.setBaseId(TimeUUIDUtils.getUniqueTimeUUIDinMillis());
UUID uuid = TimeUUIDUtils.getUniqueTimeUUIDinMillis();
srb.setBaseId(uuid);
srb.setMyType("my_type");
srb.addSimpleTestBean(new SimpleTestBean(5L, "my owned bean"));

em.persist(srb);

//em.persist(new SimpleTestBean(1, "foo"));
em.getTransaction().commit();
em.close();

EntityManager em2 = entityManagerFactory.createEntityManager();
SimpleRelationshipBean srb2 = em2.find(SimpleRelationshipBean.class, uuid);
assertEquals(1,srb.getSimpleTestBeans().size());
assertEquals("my owned bean", srb.getSimpleTestBeans().iterator().next().getName());
assertEquals(uuid,srb.getBaseId());

}
}

0 comments on commit e9a0ef4

Please sign in to comment.