* @return The pojo that corresponds to the provided entity.
*/
public static Object entityToPojo(final Entity entity, final AbstractClassMetaData acmd,
final ClassLoaderResolver clr, ObjectManager om,
boolean ignoreCache, final FetchPlan fetchPlan) {
final DatastoreManager storeMgr = (DatastoreManager) om.getStoreManager();
storeMgr.validateMetaDataForClass(acmd, clr);
FieldValues fv = new FieldValues() {
public void fetchFields(StateManager sm) {
sm.replaceFields(
acmd.getPKMemberPositions(),
new DatastoreFieldManager(sm, storeMgr, entity, DatastoreFieldManager.Operation.READ));
}
public void fetchNonLoadedFields(StateManager sm) {
sm.replaceNonLoadedFields(
acmd.getPKMemberPositions(),
new DatastoreFieldManager(sm, storeMgr, entity, DatastoreFieldManager.Operation.READ));
}
public FetchPlan getFetchPlanForLoading() {
return fetchPlan;
}
};
Object pojo = om.findObjectUsingAID(clr.classForName(acmd.getFullClassName()), fv, ignoreCache, true);
StateManager stateMgr = om.findStateManager(pojo);
DatastorePersistenceHandler handler = storeMgr.getPersistenceHandler();
// TODO(maxr): Seems like we should be able to refactor the handler
// so that we can do a fetch without having to hide the entity in the
// state manager.
handler.setAssociatedEntity(stateMgr, EntityUtils.getCurrentTransaction(om), entity);
int[] fieldsToFetch =
fetchPlan != null ?
fetchPlan.getFetchPlanForClass(acmd).getFieldsInActualFetchPlan() : acmd.getAllMemberPositions();
storeMgr.getPersistenceHandler().fetchObject(
stateMgr, fieldsToFetch);
return pojo;
}