private void processDefaultHolder(
      Entity entity, AnnotationMetadata<DefaultHolder> defaultHolder) {

    Query query = ContextUtil.getEntityFactory().buildQuery(entity.getEntityType());
    for (String filter : defaultHolder.getAnnotation().filters()) {
      query.addCriterion(
          new Path(filter),
          Condition.EQ,
          ContextUtil.getMRS()
              .getPropertyMetadata(entity.getEntityType(), filter)
              .getValue(entity));
    }
    List<Entity> existingEntities = ContextUtil.getDRS().findByQuery(query);
    PropertyMetadata propertyMetadata =
        ContextUtil.getMRS()
            .getPropertyMetadata(entity.getEntityType(), defaultHolder.getField().getName());
    boolean currentValue = (Boolean) propertyMetadata.getValue(entity);

    if (existingEntities.size() > 1 && currentValue) {
      for (Entity existingEntity : existingEntities) {
        if (!existingEntity.equals(entity) && (Boolean) propertyMetadata.getValue(existingEntity)) {
          propertyMetadata.setValue(existingEntity, false);
          sessionFactory.getCurrentSession().saveOrUpdate(existingEntity);
        }
      }
    } else if (existingEntities.size() == 1 && !currentValue) {
      propertyMetadata.setValue(entity, true);
      sessionFactory.getCurrentSession().saveOrUpdate(entity);
    }
  }
  public void testMaster() throws Exception {
    PropertyMetadata meta =
        DolphinHelper.lookupPropertyMetadataByName(Snoopy.class.getName(), "parentName", true);
    System.out.println(XMLUtil.toString(XMLUtil.toXMLElement(meta, "property")));

    String sMaster = meta.getMaster();
    assertEquals("parentId.name", sMaster);
  }
  /*
   * Class under test for org.jdom.Element toXMLElement(String)
   */
  public void testToXMLElementString() {
    this.log("to test toXMLElement() ...");
    try {
      PropertyMetadata property = new PropertyMetadata("Name", "ObjName", DataTypes.STRING, 200);
      property.setMultiple(true);
      property.setValidator4Java("[1-9]");
      property.setValidatorDesc("number");

      PropertyRef ref = new PropertyRef();
      ref.setType(Snoopy.class.getName());
      ref.setKey("id");
      ref.setLocator("DolphinRefLocator");
      property.setRef(ref);

      System.out.println(property.toString());

      // test toXMLElement
      Element element = XMLUtil.toXMLElement(property, "property");
      System.out.println(XMLUtil.toString(element, null));

      // test fromXML
      property.fromXML(element);
      System.out.println(property.toString());
    } catch (Exception ex) {
      ex.printStackTrace(System.out);
    }
  }
 @Deprecated // since 2.3
 protected SettableBeanProperty(
     String propName,
     JavaType type,
     PropertyName wrapper,
     TypeDeserializer typeDeser,
     Annotations contextAnnotations,
     boolean isRequired) {
   this(
       new PropertyName(propName),
       type,
       wrapper,
       typeDeser,
       contextAnnotations,
       PropertyMetadata.construct(isRequired, null));
 }
 @Override
 public boolean isRequired() {
   return _metadata.isRequired();
 }
 private void _verifyProperty(BeanDescription beanDesc, boolean verifyDesc, boolean verifyIndex) {
   assertNotNull(beanDesc);
   List<BeanPropertyDefinition> props = beanDesc.findProperties();
   assertEquals(2, props.size());
   for (BeanPropertyDefinition prop : props) {
     String name = prop.getName();
     final PropertyMetadata md = prop.getMetadata();
     if ("a".equals(name)) {
       assertFalse(md.isRequired());
       assertNull(md.getRequired());
       if (verifyDesc) {
         assertEquals(PropDescBean.A_DESC, md.getDescription());
       }
       if (verifyIndex) {
         assertNull(md.getIndex());
       }
     } else if ("b".equals(name)) {
       assertTrue(md.isRequired());
       assertEquals(Boolean.TRUE, md.getRequired());
       if (verifyDesc) {
         assertNull(md.getDescription());
       }
       if (verifyIndex) {
         assertEquals(Integer.valueOf(PropDescBean.B_INDEX), md.getIndex());
       }
     } else {
       fail("Unrecognized property '" + name + "'");
     }
   }
 }