コード例 #1
0
  public AnnotatedSchema(Class<? extends SormaContentProvider> ormcp) {
    this.contentProviderClass = ormcp;
    this.contentProviderAnnotation = ReflectionUtil.getAnnotation(ormcp, ContentProvider.class);
    version = contentProviderAnnotation.version();

    for (Class<?> cls : contentProviderAnnotation.mappingClasses()) {
      try {
        Table annotation = (Table) ReflectionUtil.getAnnotation(cls, Table.class);
        if (annotation == null) {
          throw new RuntimeException(cls + " class has no @Table annotation");
        }
        Class mappingClass = annotation.mappingClass();
        if (mappingClass == null || Object.class.equals(mappingClass)) {
          mappingClass = cls;
        }
        addTable(new DbTable(mappingClass, annotation));
      } catch (Exception e) {
        throw new SormaException("cannot map " + cls, e);
      }
    }

    for (Table table : contentProviderAnnotation.tables()) {
      try {
        Class cls = table.mappingClass();
        if (cls == null) {
          throw new RuntimeException(
              "@Table annotation inside of @ContentProvider must have mappingClass attribute");
        }
        addTable(new DbTable(cls, table));
      } catch (Exception e) {
        throw new SormaException(e);
      }
    }
  }