From: <one...@us...> - 2003-05-02 09:18:15
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/cfg In directory sc8-pr-cvs1:/tmp/cvs-serv19240 Modified Files: Binder.java Log Message: added idbag and made some cleanups to collection fwk Index: Binder.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/cfg/Binder.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Binder.java 26 Apr 2003 06:09:11 -0000 1.16 --- Binder.java 2 May 2003 09:18:11 -0000 1.17 *************** *** 9,12 **** --- 9,13 ---- import net.sf.hibernate.Hibernate; import net.sf.hibernate.MappingException; + import net.sf.hibernate.mapping.IdentifierBag; import net.sf.hibernate.engine.Cascades; import net.sf.hibernate.id.PersistentIdentifierGenerator; *************** *** 20,23 **** --- 21,25 ---- import net.sf.hibernate.mapping.Component; import net.sf.hibernate.mapping.ForeignKey; + import net.sf.hibernate.mapping.IdentifierCollection; import net.sf.hibernate.mapping.IndexedCollection; import net.sf.hibernate.mapping.IntegerValue; *************** *** 445,448 **** --- 447,453 ---- mappings.addSecondPass( new MapSecondPass(node, mappings, (Map) model) ); } + else if (model instanceof IdentifierCollection) { + mappings.addSecondPass( new IdentifierCollectionSecondPass(node, mappings, (IdentifierCollection) model) ); + } else { mappings.addSecondPass( new CollectionSecondPass(node, mappings, model) ); *************** *** 878,881 **** --- 883,899 ---- } + + public static void bindIdentifierCollectionSecondPass(Element node, IdentifierCollection model, java.util.Map persistentClasses, Mappings mappings) throws MappingException { + + bindCollectionSecondPass(node, model, persistentClasses, mappings); + + Element subnode = node.element("collection-id"); + Value id = new Value( model.getTable() ); + bindValue(subnode, id, false, IdentifierCollection.DEFAULT_IDENTIFIER_COLUMN_NAME); + model.setIdentifier(id); + makeIdentifier(subnode, id, mappings); + if ( !model.isOneToMany() ) model.createPrimaryKey(); + + } /** *************** *** 958,962 **** ManyToOne element = new ManyToOne( model.getTable() ); model.setElement(element); ! bindManyToOne(subnode, element, Collection.DEFAULT_ELEMENT_COLUMN_NAME, true); } else if ( "composite-element".equals(name) ) { --- 976,980 ---- ManyToOne element = new ManyToOne( model.getTable() ); model.setElement(element); ! bindManyToOne(subnode, element, Collection.DEFAULT_ELEMENT_COLUMN_NAME, false); } else if ( "composite-element".equals(name) ) { *************** *** 1055,1058 **** --- 1073,1086 ---- } + static class IdentifierCollectionSecondPass extends SecondPass { + IdentifierCollectionSecondPass(Element node, Mappings mappings, IdentifierCollection collection) { + super(node, mappings, collection); + } + void secondPass(java.util.Map persistentClasses) throws MappingException { + Binder.bindIdentifierCollectionSecondPass( node, (IdentifierCollection) collection, persistentClasses, mappings ); + } + + } + static class MapSecondPass extends SecondPass { MapSecondPass(Element node, Mappings mappings, Map collection) { *************** *** 1123,1126 **** --- 1151,1161 ---- } }; + private static final CollectionType IDBAG = new CollectionType("idbag") { + public Collection create(Element node, String prefix, PersistentClass owner, Mappings mappings) throws MappingException { + IdentifierBag bag = new IdentifierBag(owner); + Binder.bindCollection(node, bag, prefix, mappings); + return bag; + } + }; private static final CollectionType ARRAY = new CollectionType("array") { public Collection create(Element node, String prefix, PersistentClass owner, Mappings mappings) throws MappingException { *************** *** 1141,1144 **** --- 1176,1180 ---- INSTANCES.put(MAP.toString(), MAP); INSTANCES.put(BAG.toString(), BAG); + INSTANCES.put(IDBAG.toString(), IDBAG); INSTANCES.put(SET.toString(), SET); INSTANCES.put(LIST.toString(), LIST); |