Coverage Report - org.trails.component.HibernateEditCollection
 
Classes in this File Line Coverage Branch Coverage Complexity
HibernateEditCollection
0% 
0% 
0
 
 1  0
 package org.trails.component;
 2  
 
 3  
 import org.apache.commons.logging.Log;
 4  
 import org.apache.commons.logging.LogFactory;
 5  
 import org.apache.tapestry.IAsset;
 6  
 import org.apache.tapestry.annotations.Asset;
 7  
 import org.apache.tapestry.annotations.ComponentClass;
 8  
 import org.apache.tapestry.annotations.InjectObject;
 9  
 import org.apache.tapestry.annotations.Parameter;
 10  
 import org.apache.tapestry.form.IPropertySelectionModel;
 11  
 import org.hibernate.criterion.DetachedCriteria;
 12  
 import org.hibernate.criterion.Restrictions;
 13  
 import org.trails.descriptor.IClassDescriptor;
 14  
 import org.trails.persistence.HibernatePersistenceService;
 15  
 
 16  
 
 17  
 /**
 18  
  * This component produces a editor for a ManyToOne or ManyToMany collection
 19  
  */
 20  
 @ComponentClass(allowBody = true, allowInformalParameters = true)
 21  0
 public abstract class HibernateEditCollection extends EditCollection
 22  
 {
 23  
 
 24  
         @Asset(value = "/org/trails/component/EditCollection.html")
 25  
         public abstract IAsset get$template();
 26  
 
 27  0
         protected static final Log LOG = LogFactory.getLog(HibernateEditCollection.class);
 28  
 
 29  
         /**
 30  
          * @todo: remove when the components reuse issue goes away
 31  
          */
 32  
         @InjectObject("service:trails.hibernate.PersistenceService")
 33  
         public abstract HibernatePersistenceService getHibernatePersistenceService();
 34  
 
 35  
         /**
 36  
          * @todo: remove when the components reuse issue goes away
 37  
          */
 38  
         @Override
 39  
         public HibernatePersistenceService getPersistenceService()
 40  
         {
 41  0
                 return getHibernatePersistenceService();
 42  
         }
 43  
 
 44  
         @Parameter(required = false)
 45  
         public abstract DetachedCriteria getCriteria();
 46  
 
 47  
         /**
 48  
          * @return
 49  
          */
 50  
         public IPropertySelectionModel getSelectionModel()
 51  
         {
 52  0
                 IClassDescriptor elementDescriptor = getDescriptorService().getClassDescriptor(getCollectionDescriptor().getElementType());
 53  
 
 54  0
                 if (getCriteria() == null)
 55  
                 {
 56  
                         // don't allow use to select from all here
 57  0
                         if (getCollectionDescriptor().isChildRelationship())
 58  
                         {
 59  0
                                 return new IdentifierSelectionModel(getSelectedList(), elementDescriptor.getIdentifierDescriptor().getName());
 60  
                         }
 61  
                         // but do here
 62  0
                         else if (getCollectionDescriptor().getInverseProperty() != null && getCollectionDescriptor().isOneToMany())
 63  
                         {
 64  0
                                 DetachedCriteria criteria = DetachedCriteria.forClass(getCollectionDescriptor().getElementType());
 65  0
                                 String identifier = elementDescriptor.getIdentifierDescriptor().getName();
 66  0
                                 if (getModel() != null)
 67  
                                 {
 68  0
                                         criteria.add(
 69  0
                                                         Restrictions.disjunction()
 70  0
                                                                         .add(Restrictions.isNull(getCollectionDescriptor().getInverseProperty()))
 71  0
                                                                         .add(Restrictions.eq(
 72  0
                                                                         getCollectionDescriptor().getInverseProperty() + "." + identifier,
 73  0
                                                                         getPersistenceService().getIdentifier(getModel(), elementDescriptor))));
 74  
                                 } else
 75  
                                 {
 76  0
                                         criteria.add(Restrictions.isNull(getCollectionDescriptor().getInverseProperty()));
 77  
                                 }
 78  
 
 79  0
                                 return new IdentifierSelectionModel(getPersistenceService().getInstances(getCollectionDescriptor().getElementType(), criteria), elementDescriptor.getIdentifierDescriptor().getName());
 80  
                         } else
 81  
                         {
 82  0
                                 return new IdentifierSelectionModel(getPersistenceService().getAllInstances(getCollectionDescriptor().getElementType()),
 83  0
                                         elementDescriptor.getIdentifierDescriptor().getName());
 84  
                         }
 85  
                 } else
 86  
                 {
 87  0
                         return new IdentifierSelectionModel(
 88  0
                                         getPersistenceService().getInstances(getCollectionDescriptor().getElementType(), getCriteria()),
 89  0
                                         elementDescriptor.getIdentifierDescriptor().getName());
 90  
                 }
 91  
         }
 92  
 }