/**
   * Return all index file records that match the specified entity name
   *
   * @param indexName
   * @param entityName the name to match
   * @param isPartialName true if the entity name is a partially qualified
   * @return results
   * @throws Exception
   */
  @Override
  protected Collection findChildRecords(
      final MetadataRecord parentRecord, final char childRecordType) throws Exception {
    CoreArgCheck.isNotNull(parentRecord);
    // find the eObject on the parent record
    EObject parentObj = (EObject) parentRecord.getEObject();
    // if not preset look up by uuid
    if (parentObj == null) {
      String uuid = parentRecord.getUUID();
      parentObj = lookupEObject(uuid);
    }
    if (parentObj != null) {
      SqlAspect sqlAspect = AspectManager.getSqlAspect(parentObj);
      if (sqlAspect instanceof SqlTableAspect) {
        SqlTableAspect tableAspect = (SqlTableAspect) sqlAspect;
        switch (childRecordType) {
          case IndexConstants.RECORD_TYPE.COLUMN:
            Collection columns = tableAspect.getColumns(parentObj);
            return findMetadataRecords(childRecordType, columns);
          case IndexConstants.RECORD_TYPE.FOREIGN_KEY:
            Collection foreignKeys = tableAspect.getForeignKeys(parentObj);
            return findMetadataRecords(childRecordType, foreignKeys);
          case IndexConstants.RECORD_TYPE.UNIQUE_KEY:
            Collection uniqueKeys = tableAspect.getUniqueKeys(parentObj);
            return findMetadataRecords(childRecordType, uniqueKeys);
          case IndexConstants.RECORD_TYPE.PRIMARY_KEY:
            EObject primaryKey = (EObject) tableAspect.getPrimaryKey(parentObj);
            MetadataRecord record = createMetadataRecord(childRecordType, primaryKey);
            if (record != null) {
              Collection records = new ArrayList(1);
              records.add(record);
              return records;
            }
            break;
          case IndexConstants.RECORD_TYPE.ACCESS_PATTERN:
            Collection accPtterns = tableAspect.getAccessPatterns(parentObj);
            return findMetadataRecords(childRecordType, accPtterns);
          case IndexConstants.RECORD_TYPE.INDEX:
            Collection indexes = tableAspect.getIndexes(parentObj);
            return findMetadataRecords(childRecordType, indexes);
        }
      } else if (sqlAspect instanceof SqlProcedureAspect) {
        SqlProcedureAspect procAspect = (SqlProcedureAspect) sqlAspect;
        switch (childRecordType) {
          case IndexConstants.RECORD_TYPE.CALLABLE_PARAMETER:
            Collection params = procAspect.getParameters(parentObj);
            return findMetadataRecords(childRecordType, params);
          case IndexConstants.RECORD_TYPE.RESULT_SET:
            EObject result = (EObject) procAspect.getResult(parentObj);
            MetadataRecord record = createMetadataRecord(childRecordType, result);
            if (record != null) {
              Collection records = new ArrayList(1);
              records.add(record);
              return records;
            }
            break;
        }
      } else if (sqlAspect instanceof SqlColumnSetAspect) {
        SqlColumnSetAspect colSetAspect = (SqlColumnSetAspect) sqlAspect;
        switch (childRecordType) {
          case IndexConstants.RECORD_TYPE.COLUMN:
            Collection column = colSetAspect.getColumns(parentObj);
            return findMetadataRecords(childRecordType, column);
          default:
            break;
        }
      }
    }

    return Collections.EMPTY_LIST;
  }
  /**
   * Create the metadataRecord for the given EObject.
   *
   * @param recordType The record type for the expected MetadataRecord
   * @param eObject The EObject whose record is returned
   * @return The metadataRecord for the eObject
   * @throws Exception
   */
  protected MetadataRecord createMetadataRecord(final char recordType, final EObject eObject)
      throws Exception {
    MetadataRecord record = null;
    SqlAspect sqlAspect = AspectManager.getSqlAspect(eObject);
    if (!sqlAspect.isQueryable(eObject)) {
      return null;
    }
    switch (recordType) {
      case IndexConstants.RECORD_TYPE.MODEL:
        if (sqlAspect instanceof SqlModelAspect) {
          record = new ModelRecordImpl((SqlModelAspect) sqlAspect, eObject);
        }
        break;
      case IndexConstants.RECORD_TYPE.TABLE:
        if (sqlAspect instanceof SqlTableAspect) {
          record = new TableRecordImpl((SqlTableAspect) sqlAspect, eObject);
        }
        break;
      case IndexConstants.RECORD_TYPE.CALLABLE:
        if (sqlAspect instanceof SqlProcedureAspect) {
          record = new ProcedureRecordImpl((SqlProcedureAspect) sqlAspect, eObject);
        }
        break;
      case IndexConstants.RECORD_TYPE.CALLABLE_PARAMETER:
        if (sqlAspect instanceof SqlProcedureParameterAspect) {
          record =
              new ProcedureParameterRecordImpl((SqlProcedureParameterAspect) sqlAspect, eObject);
        }
        break;
      case IndexConstants.RECORD_TYPE.COLUMN:
        if (sqlAspect instanceof SqlColumnAspect) {
          record = new ColumnRecordImpl((SqlColumnAspect) sqlAspect, eObject);
        }
        break;
      case IndexConstants.RECORD_TYPE.RESULT_SET:
      case IndexConstants.RECORD_TYPE.INDEX:
      case IndexConstants.RECORD_TYPE.ACCESS_PATTERN:
      case IndexConstants.RECORD_TYPE.PRIMARY_KEY:
      case IndexConstants.RECORD_TYPE.UNIQUE_KEY:
        if (sqlAspect instanceof SqlColumnSetAspect) {
          record = new ColumnSetRecordImpl((SqlColumnSetAspect) sqlAspect, eObject, recordType);
        }
        break;
      case IndexConstants.RECORD_TYPE.FOREIGN_KEY:
        if (sqlAspect instanceof SqlForeignKeyAspect) {
          record = new ForeignKeyRecordImpl((SqlForeignKeyAspect) sqlAspect, eObject);
        }
        break;
      case IndexConstants.RECORD_TYPE.SELECT_TRANSFORM:
      case IndexConstants.RECORD_TYPE.INSERT_TRANSFORM:
      case IndexConstants.RECORD_TYPE.UPDATE_TRANSFORM:
      case IndexConstants.RECORD_TYPE.DELETE_TRANSFORM:
      case IndexConstants.RECORD_TYPE.PROC_TRANSFORM:
      case IndexConstants.RECORD_TYPE.MAPPING_TRANSFORM:
        record = getTransforMationRecord(sqlAspect, eObject, recordType);
        break;
      case IndexConstants.RECORD_TYPE.DATATYPE:
        if (sqlAspect instanceof SqlDatatypeAspect) {
          record = new DatatypeRecordImpl((SqlDatatypeAspect) sqlAspect, eObject);
        }
        break;
      case IndexConstants.RECORD_TYPE.VDB_ARCHIVE:
        if (sqlAspect instanceof SqlVdbAspect) {
          record = new VdbRecordImpl((SqlVdbAspect) sqlAspect, eObject);
        }
        break;
      case IndexConstants.RECORD_TYPE.ANNOTATION:
        if (sqlAspect instanceof SqlAnnotationAspect) {
          record = new AnnotationRecordImpl((SqlAnnotationAspect) sqlAspect, eObject);
        }
        break;
      case IndexConstants.RECORD_TYPE.PROPERTY:
      case IndexConstants.RECORD_TYPE.JOIN_DESCRIPTOR:
        return null;
      default:
        throw new TeiidDesignerException(
            TransformationPlugin.Util.getString(
                "TransformationMetadata.No_known_index_file_type_associated_with_the_recordType_1",
                new Character(recordType))); // $NON-NLS-1$
    }

    return record;
  }