/** Deletes record with id 1000 from the Country resource. */
  private static void doDeleteWithPk() throws SqlResourceException {
    System.out.println("Delete with PK");

    // Get the resource object
    final SqlResource sqlResource = Factory.getSqlResource("Country");

    // Create the delete request
    final List<NameValuePair> resIds = new ArrayList<NameValuePair>(1);

    final List<NameValuePair> params = null;
    resIds.add(new NameValuePair("country_id", "1000", Operator.Equals));
    final List<List<NameValuePair>> childrenParams = null;
    final RequestLogger requestLogger = Factory.getRequestLogger();
    final Request request =
        Factory.getRequest(
            Request.Type.DELETE,
            sqlResource.getName(),
            resIds,
            params,
            childrenParams,
            requestLogger);

    // Execute the delete request
    final int rowsAffected = sqlResource.write(request);

    System.out.println("\t" + requestLogger.getSql());
    System.out.println("\tdeleted " + rowsAffected + " row(s)\n");
  }
  /** Updates record with country name Wohoo! in the Country resource. */
  private static void doUpdateWithParam() throws SqlResourceException {
    System.out.println("Update with Param");

    // Get the resource object
    final SqlResource sqlResource = Factory.getSqlResource("Country");

    // Create the record
    final List<NameValuePair> params = new ArrayList<NameValuePair>(3);

    // Create the delete request
    final List<NameValuePair> resIds = new ArrayList<NameValuePair>(1);
    resIds.add(new NameValuePair("country", "Test2"));
    params.add(new NameValuePair("country", "Test1"));
    params.add(new NameValuePair("last_update", "2012-02-18 10:00:10"));
    final List<List<NameValuePair>> childrenParams = null;
    final RequestLogger requestLogger = Factory.getRequestLogger();
    final Request request =
        Factory.getRequest(
            Request.Type.UPDATE,
            sqlResource.getName(),
            resIds,
            params,
            childrenParams,
            requestLogger);

    // Execute the update request
    final int rowsAffected = sqlResource.write(request);

    System.out.println("\t" + requestLogger.getSql());
    System.out.println("\tupdated " + rowsAffected + " row(s)\n");
  }
  /** Creates record in the Country resource. */
  private static void doInsert(final List<NameValuePair> params) throws SqlResourceException {
    // Get the resource object
    final SqlResource sqlResource = Factory.getSqlResource("Country");

    // Create the request
    final List<NameValuePair> resIds = null;
    final List<List<NameValuePair>> childrenParams = null;
    final RequestLogger requestLogger = Factory.getRequestLogger();
    final Request request =
        Factory.getRequest(
            Request.Type.INSERT,
            sqlResource.getName(),
            resIds,
            params,
            childrenParams,
            requestLogger);

    // Execute the insert request
    final int rowsAffected = sqlResource.write(request);

    System.out.println("\t" + requestLogger.getSql());
    System.out.println("\tinserted " + rowsAffected + " row(s)");
  }
  /** Deletes records with country name like W% from the Country resource. */
  private static void doDeleteWithWildcard() throws SqlResourceException {
    System.out.println("Delete with wildcard");

    // Get the resource object
    final SqlResource sqlResource = Factory.getSqlResource("Country");

    // Create the record
    final List<NameValuePair> params = new ArrayList<NameValuePair>(3);
    params.add(new NameValuePair("country_id", "1000"));
    params.add(new NameValuePair("country", "Test1"));
    doInsert(params);
    params.clear();
    params.add(new NameValuePair("country_id", "1001"));
    params.add(new NameValuePair("country", "Test2"));
    doInsert(params);

    // Create the delete request
    final List<NameValuePair> resIds = null;
    params.clear();
    params.add(new NameValuePair("country", "Test%"));
    final List<List<NameValuePair>> childrenParams = null;
    final RequestLogger requestLogger = Factory.getRequestLogger();
    final Request request =
        Factory.getRequest(
            Request.Type.DELETE,
            sqlResource.getName(),
            resIds,
            params,
            childrenParams,
            requestLogger);

    // Execute the delete request
    final int rowsAffected = sqlResource.write(request);

    System.out.println("\t" + requestLogger.getSql());
    System.out.println("\tdeleted " + rowsAffected + " row(s)\n");
  }