示例#1
0
  @Test
  public void testSchemaInPersistenceMetadata() {
    Index index = getMockedIndex("default-schema.xml");
    index.printAnnotations();
    // Global Configuration should be accessed like this, not from ClassInfo
    List<AnnotationInstance> annotationInstanceList =
        index.getAnnotations(JPADotNames.TABLE_GENERATOR);
    assertNotNull(annotationInstanceList);
    assertEquals(1, annotationInstanceList.size());
    AnnotationInstance generator = annotationInstanceList.get(0);
    assertEquals("TABLE_GEN", generator.value("name").asString());
    assertEquals("ANNOTATION_CATALOG", generator.value("catalog").asString());
    assertEquals("ANNOTATION_SCHEMA", generator.value("schema").asString());

    annotationInstanceList = index.getAnnotations(JPADotNames.SEQUENCE_GENERATOR);
    assertNotNull(annotationInstanceList);
    assertEquals(1, annotationInstanceList.size());
    generator = annotationInstanceList.get(0);
    assertEquals("SEQ_GEN", generator.value("name").asString());
    assertEquals("XML_CATALOG", generator.value("catalog").asString());
    assertEquals("XML_SCHEMA", generator.value("schema").asString());
    assertEquals(123, generator.value("initialValue").asInt());
    // Book and Author and Topic are all not defined @Table
    // but orm xml defines default schema and catalog in persistence-unit-metadata
    // so, we have to mock @Table for entities, Book and Author but not Topic which is a Embeddable
    annotationInstanceList = index.getAnnotations(JPADotNames.TABLE);
    assertNotNull(annotationInstanceList);
    assertEquals(2, annotationInstanceList.size());
    for (AnnotationInstance table : annotationInstanceList) {
      assertEquals("XML_CATALOG", table.value("catalog").asString());
      assertEquals("XML_SCHEMA", table.value("schema").asString());
    }
  }
示例#2
0
  @Test
  public void testSchemaInEntityMapping() {
    Index index = getMockedIndex("default-schema2.xml");
    index.printAnnotations();
    // Global Configuration should be accessed like this, not from ClassInfo
    List<AnnotationInstance> annotationInstanceList =
        index.getAnnotations(JPADotNames.TABLE_GENERATOR);
    assertNotNull(annotationInstanceList);
    assertEquals(1, annotationInstanceList.size());
    AnnotationInstance generator = annotationInstanceList.get(0);
    assertEquals("TABLE_GEN", generator.value("name").asString());
    assertEquals("ANNOTATION_CATALOG", generator.value("catalog").asString());
    assertEquals("ANNOTATION_SCHEMA", generator.value("schema").asString());

    annotationInstanceList = index.getAnnotations(JPADotNames.SEQUENCE_GENERATOR);
    assertNotNull(annotationInstanceList);
    assertEquals(1, annotationInstanceList.size());
    generator = annotationInstanceList.get(0);
    assertEquals("SEQ_GEN", generator.value("name").asString());
    assertNull(generator.value("catalog"));
    assertNull(generator.value("schema"));
    assertEquals(123, generator.value("initialValue").asInt());

    annotationInstanceList = index.getAnnotations(JPADotNames.TABLE);
    assertNotNull(annotationInstanceList);
    assertEquals(0, annotationInstanceList.size());
  }
示例#3
0
  /**
   * Entity has a @AttributeOverride on property topic and this property also has a
   * <attribute-override> in orm.xml but with different name by jpa override rules, this two
   * attribute-override should be merged into one @AttributeOverrides
   */
  @Test
  public void testAttributeOverride() {
    Index index = getMockedIndex("AttributeOverride.xml");
    DotName className = DotName.createSimple(Book.class.getName());
    index.printAnnotations();
    assertHasNoAnnotation(index, className, JPADotNames.ATTRIBUTE_OVERRIDE);
    assertAnnotationValue(
        index,
        className,
        JPADotNames.ATTRIBUTE_OVERRIDES,
        new AnnotationValueChecker() {
          @Override
          public void check(AnnotationInstance annotationInstance) {
            AnnotationValue value = annotationInstance.value();
            assertNotNull(value);
            AnnotationInstance[] annotationInstances = value.asNestedArray();
            assertEquals(2, annotationInstances.length);
            AnnotationInstance ai = annotationInstances[0];
            String name = ai.value("name").asString();
            AnnotationValue columnValue = ai.value("column").asNested().value("name");
            if (name.equals("title")) {
              assertEquals("TOC_TITLE", columnValue.asString());

            } else if (name.equals("summary")) {
              assertEquals("TOPIC_SUMMARY", columnValue.asString());
            } else {
              fail(
                  "AttributeOverride's name is "
                      + name
                      + ", should be either 'title' or 'summary'");
            }
          }
        });
  }
示例#4
0
 @Test
 public void testOverrideToMappedSuperClass() {
   Index index = getMockedIndex("override-to-mappedsuperclass.xml");
   index.printAnnotations();
   DotName authorName = DotName.createSimple(Author.class.getName());
   assertHasAnnotation(index, authorName, JPADotNames.ENTITY);
   assertHasNoAnnotation(index, authorName, JPADotNames.TABLE);
   DotName bookName = DotName.createSimple(Book.class.getName());
   assertHasAnnotation(index, bookName, JPADotNames.MAPPED_SUPERCLASS);
   assertHasNoAnnotation(index, bookName, JPADotNames.TABLE);
 }
示例#5
0
文件: Main.java 项目: maozturk/jandex
  private void dumpIndex(File source) throws IOException {
    FileInputStream input = new FileInputStream(source);
    IndexReader reader = new IndexReader(input);

    long start = System.currentTimeMillis();
    Index index = reader.read();
    long end = System.currentTimeMillis() - start;
    index.printAnnotations();
    index.printSubclasses();

    System.out.printf("\nRead %s in %.04f seconds\n", source.getName(), end / 1000.0);
  }