// Path: core/src/main/java/com/contentful/vault/BaseFields.java
// public static final String REMOTE_ID = "remote_id";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static final String TABLE_ENTRY_TYPES = "entry_types";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static final String TABLE_LINKS = "links";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static String escape(String name) {
//   return String.format("`%s`", name);
// }
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static String localizeName(String name, String locale) {
//   return String.format("%s$%s", name, locale);
// }


import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static com.contentful.java.cda.CDAType.ASSET;
import static com.contentful.vault.BaseFields.REMOTE_ID;
import static com.contentful.vault.Sql.TABLE_ENTRY_TYPES;
import static com.contentful.vault.Sql.TABLE_LINKS;
import static com.contentful.vault.Sql.escape;
import static com.contentful.vault.Sql.localizeName;
        linksToAssets ? "1" : "0",
        field.id()
    };

    Cursor cursor = query.vault().getReadableDatabase().rawQuery(sql, args);
    try {
      result = new ArrayList<>();
      if (cursor.moveToFirst()) {
        do {
          String childId = cursor.getString(0);
          String childContentType = cursor.getString(1);
          result.add(new Link(parentId, childId, field.id(), childContentType));
        } while (cursor.moveToNext());
      }
    } finally {
      cursor.close();
    }

    return result;
  }

  private String queryAssetLinks(String locale) {
    return String.format("SELECT l.child, null FROM %s l WHERE %s ORDER BY l.position",
        escape(localizeName(TABLE_LINKS, locale)),
        LINKS_WHERE_CLAUSE);
  }

  private String queryEntryLinks(String locale) {
    return String.format(
        "SELECT l.child, t.type_id FROM %s l INNER JOIN %s t ON l.child = t.%s WHERE %s ORDER BY l.position",
// Path: core/src/main/java/com/contentful/vault/BaseFields.java
// public static final String REMOTE_ID = "remote_id";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static final String TABLE_ENTRY_TYPES = "entry_types";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static final String TABLE_LINKS = "links";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static String escape(String name) {
//   return String.format("`%s`", name);
// }
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static String localizeName(String name, String locale) {
//   return String.format("%s$%s", name, locale);
// }


// Path: core/src/main/java/com/contentful/vault/LinkResolver.java
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static com.contentful.java.cda.CDAType.ASSET;
import static com.contentful.vault.BaseFields.REMOTE_ID;
import static com.contentful.vault.Sql.TABLE_ENTRY_TYPES;
import static com.contentful.vault.Sql.TABLE_LINKS;
import static com.contentful.vault.Sql.escape;
import static com.contentful.vault.Sql.localizeName;

        linksToAssets ? "1" : "0",
        field.id()
    };

    Cursor cursor = query.vault().getReadableDatabase().rawQuery(sql, args);
    try {
      result = new ArrayList<>();
      if (cursor.moveToFirst()) {
        do {
          String childId = cursor.getString(0);
          String childContentType = cursor.getString(1);
          result.add(new Link(parentId, childId, field.id(), childContentType));
        } while (cursor.moveToNext());
      }
    } finally {
      cursor.close();
    }

    return result;
  }

  private String queryAssetLinks(String locale) {
    return String.format("SELECT l.child, null FROM %s l WHERE %s ORDER BY l.position",
        escape(localizeName(TABLE_LINKS, locale)),
        LINKS_WHERE_CLAUSE);
  }

  private String queryEntryLinks(String locale) {
    return String.format(
        "SELECT l.child, t.type_id FROM %s l INNER JOIN %s t ON l.child = t.%s WHERE %s ORDER BY l.position",
        escape(localizeName(TABLE_LINKS, locale)),