Пример #1
0
 // adds the child properties to the top most property
 private void addChildProperties(
     EntityMetadata entityMetadata, EMProperty parentProperty, List<String> childPropertyNames) {
   String fullyQualifiedPropertyName = parentProperty.getName();
   for (String childPropertyName : childPropertyNames) {
     fullyQualifiedPropertyName = fullyQualifiedPropertyName + "." + childPropertyName;
     EMProperty childProperty = null;
     if (parentProperty.hasChildProperty(childPropertyName)) {
       // this property already added to the parent property
       childProperty = parentProperty.getChildProperty(childPropertyName);
     } else {
       // this is a new child property so create and add to the parent property
       childProperty = new EMProperty(childPropertyName);
       parentProperty.addChildProperty(childProperty);
       Vocabulary propertyVocabulary =
           entityMetadata.getPropertyVocabulary(fullyQualifiedPropertyName);
       for (Term vocTerm : propertyVocabulary.getTerms()) {
         if (TermComplexGroup.TERM_NAME.equals(vocTerm.getName())) {
           // complex group term not added as the properties are built in tree structure
           continue;
         }
         childProperty.addVocabularyTerm(new EMTerm(vocTerm.getName(), vocTerm.getValue()));
       }
     }
     parentProperty = childProperty;
   }
 }
Пример #2
0
  @Test
  public void testJPAEntityKeyInfo() {
    JPAResponderGen rg = new JPAResponderGen();

    EntityMetadata mdEntity = new EntityMetadata("Flight");
    Vocabulary voc = new Vocabulary();
    voc.setTerm(new TermValueType(TermValueType.INTEGER_NUMBER));
    voc.setTerm(new TermIdField(true));
    mdEntity.setPropertyVocabulary("flightID", voc);
    EntityInfo p = rg.createEntityInfoFromEntityMetadata("AirlineModel", mdEntity);

    assertEquals("flightID", p.getKeyInfo().getName());
    assertEquals("Long", p.getKeyInfo().getType());
    assertEquals(0, p.getFieldInfos().size());
  }
Пример #3
0
  @Test
  public void testEntityInfo() {
    JPAResponderGen rg = new JPAResponderGen();

    EntityMetadata mdEntity = new EntityMetadata("Flight");
    Vocabulary voc = new Vocabulary();
    voc.setTerm(new TermValueType(TermValueType.INTEGER_NUMBER));
    voc.setTerm(new TermIdField(true));
    mdEntity.setPropertyVocabulary("ID", voc);
    EntityInfo p = rg.createEntityInfoFromEntityMetadata("AirlineModel", mdEntity);

    assertEquals("Flight", p.getClazz());
    assertEquals("AirlineModel", p.getPackage());
    assertEquals("AirlineModel.Flight", p.getFQTypeName());
  }
Пример #4
0
  @Test
  public void testJPAEntityFieldInfo() {
    JPAResponderGen rg = new JPAResponderGen();

    EntityMetadata mdEntity = new EntityMetadata("Flight");
    Vocabulary voc = new Vocabulary();
    voc.setTerm(new TermValueType(TermValueType.INTEGER_NUMBER));
    voc.setTerm(new TermIdField(true));
    mdEntity.setPropertyVocabulary("ID", voc);
    voc = new Vocabulary();
    voc.setTerm(new TermValueType(TermValueType.INTEGER_NUMBER));
    mdEntity.setPropertyVocabulary("flightID", voc);
    mdEntity.setPropertyVocabulary("number", new Vocabulary());
    mdEntity.setPropertyVocabulary("runway", new Vocabulary());
    voc = new Vocabulary();
    voc.setTerm(new TermValueType(TermValueType.TIMESTAMP));
    mdEntity.setPropertyVocabulary("departureDT", voc);
    voc = new Vocabulary();
    voc.setTerm(new TermValueType(TermValueType.DATE));
    mdEntity.setPropertyVocabulary("departureDate", voc);
    voc = new Vocabulary();
    voc.setTerm(new TermValueType(TermValueType.TIME));
    mdEntity.setPropertyVocabulary("departureTime", voc);
    EntityInfo p = rg.createEntityInfoFromEntityMetadata("AirlineModel", mdEntity);

    assertEquals(6, p.getFieldInfos().size());
    assertTrue(p.getFieldInfos().contains(new FieldInfo("flightID", "Long", null)));
    assertTrue(p.getFieldInfos().contains(new FieldInfo("number", "String", null)));
    assertTrue(p.getFieldInfos().contains(new FieldInfo("runway", "String", null)));
    assertTrue(p.getFieldInfos().contains(new FieldInfo("departureDT", "java.util.Date", null)));
    assertTrue(p.getFieldInfos().contains(new FieldInfo("departureDate", "java.util.Date", null)));
    assertTrue(p.getFieldInfos().contains(new FieldInfo("departureTime", "java.util.Date", null)));
  }
Пример #5
0
 // adds the property tree to the entity metadata
 private void addProperties(
     EntityMetadata entityMetadata, EMEntity entity, String fyllyQualifiedPropertyName) {
   List<String> propertyNames =
       new ArrayList<String>(Arrays.asList(fyllyQualifiedPropertyName.split("\\.")));
   String rootPropertyName = propertyNames.get(0);
   EMProperty rootProperty = null;
   if (entity.contains(rootPropertyName)) {
     // this property already added to the entity
     rootProperty = entity.getProperty(rootPropertyName);
   } else {
     // new property so create and add to the entity
     rootProperty = new EMProperty(rootPropertyName);
     entity.addProperty(rootProperty);
     Vocabulary vocabulary = entityMetadata.getPropertyVocabulary(rootPropertyName);
     for (Term term : vocabulary.getTerms()) {
       rootProperty.addVocabularyTerm(new EMTerm(term.getName(), term.getValue()));
     }
   }
   propertyNames.remove(0); // removes root property as it's already added to the entity
   addChildProperties(entityMetadata, rootProperty, propertyNames);
 }
Пример #6
0
  @Test
  public void testJPAEntityFieldInfoAnnotations() {
    JPAResponderGen rg = new JPAResponderGen();

    EntityMetadata mdEntity = new EntityMetadata("Flight");
    Vocabulary voc = new Vocabulary();
    voc.setTerm(new TermValueType(TermValueType.INTEGER_NUMBER));
    voc.setTerm(new TermIdField(true));
    mdEntity.setPropertyVocabulary("ID", voc);
    voc = new Vocabulary();
    voc.setTerm(new TermValueType(TermValueType.TIMESTAMP));
    mdEntity.setPropertyVocabulary("departureDT", voc);
    voc = new Vocabulary();
    voc.setTerm(new TermValueType(TermValueType.DATE));
    mdEntity.setPropertyVocabulary("departureDate", voc);
    voc = new Vocabulary();
    voc.setTerm(new TermValueType(TermValueType.TIME));
    mdEntity.setPropertyVocabulary("departureTime", voc);
    EntityInfo p = rg.createEntityInfoFromEntityMetadata("AirlineModel", mdEntity);

    // Annotations
    FieldInfo dateOnlyFI = p.getFieldInfos().get(0);
    assertEquals(1, dateOnlyFI.getAnnotations().size());
    assertEquals("@Temporal(TemporalType.DATE)", dateOnlyFI.getAnnotations().get(0));

    FieldInfo timeFI = p.getFieldInfos().get(1);
    assertEquals(1, timeFI.getAnnotations().size());
    assertEquals("@Temporal(TemporalType.TIME)", timeFI.getAnnotations().get(0));

    FieldInfo dateFI = p.getFieldInfos().get(2);
    assertEquals(1, dateFI.getAnnotations().size());
    assertEquals("@Temporal(TemporalType.TIMESTAMP)", dateFI.getAnnotations().get(0));
  }