package com.oreilly.ecomm.reactor;
import java.lang.reflect.Field;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.log4j.Logger;
import org.hibernate.LazyInitializationException;
import org.hibernate.collection.PersistentBag;
import org.hibernate.collection.PersistentList;
import org.hibernate.collection.PersistentMap;
import org.hibernate.collection.PersistentSet;
import org.hibernate.collection.PersistentSortedMap;
import org.hibernate.collection.PersistentSortedSet;
/**
* Completely removes all Hibernate's tentacles from a retreived POJO.
* This is necessary because Hibernate uses CGLib to decorate objects
* with proxy implementations of certain declared fields, particularly collections.
*
* @author haren
*/
@SuppressWarnings({"unchecked", "deprecation"})
public class Dehydrator
{
private static final Logger logger = Logger.getLogger(Dehydrator.class);
private static Map hibernateCollectionsMap = new HashMap();
static
{
hibernateCollectionsMap.put(PersistentBag.class, ArrayList.class);
hibernateCollectionsMap.put(PersistentList.class, ArrayList.class);
hibernateCollectionsMap.put(PersistentMap.class, HashMap.class);
hibernateCollectionsMap.put(PersistentSet.class, HashSet.class);
hibernateCollectionsMap.put(PersistentSortedMap.class, SortedMap.class);
hibernateCollectionsMap.put(PersistentSortedSet.class, SortedSet.class);
}
public static T dehydrate(Object original)
{
return (T) deepCloneAndSanitize(original, new HashMap