コード例 #1
0
  private void introspectInheritance(Class type, EntityType entityType, EntityType parentType)
      throws SQLException {
    // Inheritance annotation/configuration is specified
    // on the entity class that is the root of the entity
    // class hierarachy.
    InheritanceConfig inheritanceConfig;
    Inheritance inheritanceAnn;

    getInternalInheritanceConfig(type, _annotationCfg);
    inheritanceAnn = (Inheritance) _annotationCfg.getAnnotation();
    inheritanceConfig = _annotationCfg.getInheritanceConfig();

    boolean hasInheritance = !_annotationCfg.isNull();

    if (!hasInheritance && (parentType == null || !parentType.isEntity())) return;

    introspectDiscriminatorValue(type, entityType);

    if (parentType != null) {
      if (hasInheritance)
        throw new ConfigException(
            L.l(
                "'{0}' cannot have @Inheritance. It must be specified on the entity class that is the root of the entity class hierarchy.",
                type));

      EntityType rootType = entityType.getRootType();
      rootType.addSubClass(entityType);

      getInternalPrimaryKeyJoinColumnConfig(type, _annotationCfg);
      PrimaryKeyJoinColumn joinAnn = (PrimaryKeyJoinColumn) _annotationCfg.getAnnotation();
      PrimaryKeyJoinColumnConfig primaryKeyJoinColumnConfig =
          _annotationCfg.getPrimaryKeyJoinColumnConfig();

      if (rootType.isJoinedSubClass()) {
        linkInheritanceTable(
            rootType.getTable(), entityType.getTable(), joinAnn, primaryKeyJoinColumnConfig);

        entityType.setId(new SubId(entityType, rootType));
      }

      return;
    }

    if (!hasInheritance) return;

    if ((inheritanceAnn != null) || (inheritanceConfig != null))
      introspectInheritance(_persistenceUnit, entityType, type, inheritanceAnn, inheritanceConfig);
  }
コード例 #2
0
  private void introspectTable(Class type, EntityType entityType, EntityType parentType) {
    // XXX: need better test
    boolean isEntity = !(entityType instanceof MappedSuperclassType);

    AmberTable table = null;

    getInternalTableConfig(type, _annotationCfg);
    Table tableAnn = (Table) _annotationCfg.getAnnotation();
    TableConfig tableConfig = _annotationCfg.getTableConfig();

    String tableName = null;

    if (tableAnn != null) tableName = tableAnn.name();
    else if (tableConfig != null) tableName = tableConfig.getName();

    // jpa/0gg0, jpa/0gg2
    if (isEntity) { // && ! type.isAbstract()) {

      boolean hasTableConfig = true;

      if (tableName == null || tableName.equals("")) {
        hasTableConfig = false;
        tableName = toSqlName(entityType.getName());
      }

      /*
           InheritanceType strategy = null;

           if (parentType != null)
             strategy = parentType.getInheritanceStrategy();

           if (inheritanceAnn != null)
      strategy = (InheritanceType) inheritanceAnn.get("strategy");
           else if (inheritanceConfig != null)
      strategy = inheritanceConfig.getStrategy();
            */

      // jpa/0gg2
      if (!entityType.isEntity()) return;
      /*
           if (type.isAbstract()
        && strategy != InheritanceType.JOINED
        && ! hasTableConfig) {
      // jpa/0gg0
           }
            */
      else if (parentType == null || parentType.getTable() == null) {
        entityType.setTable(_persistenceUnit.createTable(tableName));
      } else if (parentType.isJoinedSubClass()) {
        entityType.setTable(_persistenceUnit.createTable(tableName));

        EntityType rootType = parentType.getRootType();

        Class rootClass = rootType.getBeanClass();
        getInternalTableConfig(rootClass, _annotationCfg);
        Table rootTableAnn = (Table) _annotationCfg.getAnnotation();
        TableConfig rootTableConfig = _annotationCfg.getTableConfig();

        String rootTableName = null;

        if (rootTableAnn != null) rootTableName = rootTableAnn.name();
        else if (rootTableConfig != null) rootTableName = rootTableConfig.getName();

        if (rootTableName == null || rootTableName.equals("")) {
          String rootEntityName = rootType.getName();

          rootTableName = toSqlName(rootEntityName);
        }

        entityType.setRootTableName(rootTableName);
      } else entityType.setTable(parentType.getTable());
    }
  }