private void emitContentProviderOperationMethods() throws IOException {
    ArrayList<String> throwing = new ArrayList<String>();
    throwing.add("OperationApplicationException");
    throwing.add("RemoteException");

    ArrayList<String> batchparams = new ArrayList<String>();
    batchparams.add("Context");
    batchparams.add("c");

    writer.emitEmptyLine();
    writer.emitJavadoc("Starts a new batch of operations to run on commit.");
    writer.beginMethod("void", "start", EnumSet.of(Modifier.PUBLIC));
    writer.emitStatement("batchOperations = new ArrayList<ContentProviderOperation>()");
    writer.endMethod();

    writer.emitEmptyLine();
    writer.emitJavadoc(
        "Commits a started batch of operations, this can include any variety of operations.");
    writer.beginMethod(
        "ContentProviderResult[]", "commit", EnumSet.of(Modifier.PUBLIC), batchparams, throwing);
    writer.beginControlFlow("if (batchOperations != null) ");
    writer.emitStatement("ContentResolver cr = c.getContentResolver()");
    writer.emitStatement(
        "ContentProviderResult[] result = cr.applyBatch( "
            + mModel.getContentProviderName()
            + ".AUTHORITY, batchOperations )");
    writer.emitStatement("batchOperations.clear()");
    writer.emitStatement("return result");
    writer.nextControlFlow("else");
    writer.emitStatement(
        "throw new RuntimeException(\""
            + mModel.getCRUDBatchClientName()
            + ".start() needs to be called first!\")");
    writer.endControlFlow();
    writer.endMethod();

    writer.emitEmptyLine();
    writer.emitJavadoc("add an operation to the batch of operations, if this client was started.");
    writer.beginMethod(
        "void", "add", EnumSet.of(Modifier.PUBLIC), "ContentProviderOperation", "operation");
    writer.beginControlFlow("if (batchOperations != null) ");
    writer.emitStatement("batchOperations.add(operation)");
    writer.nextControlFlow("else");
    writer.emitStatement(
        "throw new RuntimeException(\""
            + mModel.getCRUDBatchClientName()
            + ".start() needs to be called first!\")");
    writer.endControlFlow();
    writer.endMethod();
  }
 private void insertAddOpBlock() throws IOException {
   writer.beginControlFlow("if (batchOperations != null)");
   writer.emitStatement("batchOperations.add(operationBuilder.build())");
   writer.nextControlFlow("else");
   writer.emitStatement(
       "throw new RuntimeException(\""
           + mModel.getCRUDBatchClientName()
           + ".start() needs to be called first!\")");
   writer.endControlFlow();
 }
 private void emitClass() throws IOException {
   writer.beginType(
       mModel.getClassPackage() + "." + mModel.getCRUDBatchClientName(),
       "class",
       EnumSet.of(Modifier.PUBLIC, Modifier.FINAL));
 }
 public CRUDBatchClientWriter(String directory, Model model) throws IOException {
   super(directory, model, model.getCRUDBatchClientName());
   this.mModel = model;
 }