/**
   * Generates the table for a specific Entity
   *
   * @param entity The Entity whose table will be generated
   * @throws IllegalArgumentException On Attribute with UNDEFINED type
   */
  private static StringBuilder createEntityTableBuilder(Entity entity)
      throws IllegalArgumentException {
    StringBuilder tableBuilder =
        new StringBuilder(String.format(CREATE_TABLE_FORMAT, entity.getName().toLowerCase()));

    // Build up attribute strings
    for (Attribute attr : entity.getAttributes()) {
      if (attr.getType() == AttributeType.UNDEFINED) {
        throw new IllegalArgumentException(attr.getName() + " does not have a valid type");
      }

      if (attr.isPrimaryKey()) {
        tableBuilder
            .append(String.format(ATTR_COLUMN_DEFN_FORMAT, attr.getName(), PRIMARY_KEY_DEFN))
            .append(",\n");
      } else {
        tableBuilder
            .append(
                String.format(
                    ATTR_COLUMN_DEFN_FORMAT, attr.getName(), attr.getType().toSQLiteString()))
            .append(",\n");
      }
    }

    // Drop last newline and comma, append parenthesis
    tableBuilder.delete(tableBuilder.length() - 2, tableBuilder.length() - 1).append(");");

    return tableBuilder;
  }
  /**
   * Generates the extra columns for Relationships
   *
   * @param entity The Entity whose Relationships will be parsed
   * @param tableBuilders The Map of StringBuilders to edit
   */
  private static void createRelationshipColumns(
      Entity entity, Map<Entity, StringBuilder> tableBuilders) {
    for (Relationship rltn : entity.getRelationships()) {
      StringBuilder rltnBuilder = tableBuilders.get(rltn.getEntity());

      Attribute primaryKey = entity.getPrimaryKey();
      String mergedNameAndKey =
          entity.getName().toLowerCase()
              + primaryKey.getName().substring(0, 1).toUpperCase()
              + primaryKey.getName().substring(1);

      rltnBuilder.insert(
          rltnBuilder.length() - 3,
          ",\n"
              + String.format(
                  ATTR_COLUMN_DEFN_FORMAT,
                  mergedNameAndKey,
                  primaryKey.getType().toSQLiteString()));
    }
  }