public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister, Serializable key) { if ( session.getEntityMode()==EntityMode.DOM4J ) { return new PersistentMapElementHolder(session, persister, key); } else { return new PersistentMap(session); } }
public PersistentCollection wrap(SessionImplementor session, Object collection) { if ( session.getEntityMode()==EntityMode.DOM4J ) { return new PersistentMapElementHolder( session, (Element) collection ); } else { return new PersistentMap( session, (java.util.Map) collection ); } }
public void init() { collectionMap.put(PersistentBag.class, ArrayList.class); collectionMap.put(PersistentList.class, ArrayList.class); collectionMap.put(PersistentMap.class, HashMap.class); collectionMap.put(PersistentSet.class, HashSet.class); collectionMap.put(PersistentSortedMap.class, TreeMap.class); collectionMap.put(PersistentSortedSet.class, TreeSet.class); }
public void testWriteMethodDirtying() { Parent parent = new Parent( "p1" ); Child child = new Child( "c1" ); parent.getChildren().put( child.getName(), child ); child.setParent( parent ); Child otherChild = new Child( "c2" ); Session session = openSession(); session.beginTransaction(); session.save( parent ); session.flush(); // at this point, the set on parent has now been replaced with a PersistentSet... PersistentMap children = ( PersistentMap ) parent.getChildren(); Object old = children.put( child.getName(), child ); assertTrue( old == child ); assertFalse( children.isDirty() ); old = children.remove( otherChild.getName() ); assertNull( old ); assertFalse( children.isDirty() ); HashMap otherMap = new HashMap(); otherMap.put( child.getName(), child ); children.putAll( otherMap ); assertFalse( children.isDirty() ); otherMap = new HashMap(); otherMap.put( otherChild.getName(), otherChild ); children.putAll( otherMap ); assertTrue( children.isDirty() ); children.clearDirty(); session.delete( child ); children.clear(); assertTrue( children.isDirty() ); session.flush(); children.clear(); assertFalse( children.isDirty() ); session.delete( parent ); session.getTransaction().commit(); session.close(); }