package com.justeat.mickeydb.generator;

import com.justeat.mickeydb.Strings;
import com.justeat.mickeydb.mickeyLang.ColumnSource;
import com.justeat.mickeydb.mickeyLang.CreateTableStatement;
import com.justeat.mickeydb.mickeyLang.CreateViewStatement;
import com.justeat.mickeydb.mickeyLang.TableDefinition;
import java.util.Arrays;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;

@SuppressWarnings("all")
public class ActiveRecordGenerator {
  public CharSequence generate(final String packageName, final String databaseName, final TableDefinition stmt) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/*");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* Generated by Mickey DB");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("package ");
    _builder.append(packageName, "");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("import android.content.ContentResolver;");
    _builder.newLine();
    _builder.append("import android.database.Cursor;");
    _builder.newLine();
    _builder.append("import android.os.Bundle;");
    _builder.newLine();
    _builder.append("import android.os.Parcel;");
    _builder.newLine();
    _builder.append("import android.os.Parcelable;");
    _builder.newLine();
    _builder.append("import android.net.Uri;");
    _builder.newLine();
    _builder.append("import ");
    _builder.append(packageName, "");
    _builder.append(".");
    String _pascalize = Strings.pascalize(databaseName);
    _builder.append(_pascalize, "");
    _builder.append("Contract.");
    String _name = stmt.getName();
    String _pascalize_1 = Strings.pascalize(_name);
    _builder.append(_pascalize_1, "");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.append("import ");
    _builder.append(packageName, "");
    _builder.append(".");
    String _pascalize_2 = Strings.pascalize(databaseName);
    _builder.append(_pascalize_2, "");
    _builder.append("Contract.");
    String _name_1 = stmt.getName();
    String _pascalize_3 = Strings.pascalize(_name_1);
    _builder.append(_pascalize_3, "");
    _builder.append(".Builder;");
    _builder.newLineIfNotEmpty();
    _builder.append("import com.justeat.mickeydb.util.Closeables;");
    _builder.newLine();
    _builder.append("import com.justeat.mickeydb.ActiveRecord;");
    _builder.newLine();
    _builder.append("import com.justeat.mickeydb.ActiveRecordFactory;");
    _builder.newLine();
    _builder.append("import com.justeat.mickeydb.Mickey;");
    _builder.newLine();
    _builder.append("import com.justeat.mickeydb.AbstractValuesBuilder;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("public class ");
    String _name_2 = stmt.getName();
    String _pascalize_4 = Strings.pascalize(_name_2);
    _builder.append(_pascalize_4, "");
    _builder.append("Record extends ActiveRecord implements Parcelable {");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private static ActiveRecordFactory<");
    String _name_3 = stmt.getName();
    String _pascalize_5 = Strings.pascalize(_name_3);
    _builder.append(_pascalize_5, "\t");
    _builder.append("Record> sFactory = new ActiveRecordFactory<");
    String _name_4 = stmt.getName();
    String _pascalize_6 = Strings.pascalize(_name_4);
    _builder.append(_pascalize_6, "\t");
    _builder.append("Record>() {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("public ");
    String _name_5 = stmt.getName();
    String _pascalize_7 = Strings.pascalize(_name_5);
    _builder.append(_pascalize_7, "\t\t");
    _builder.append("Record create(Cursor c) {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("return fromCursor(c);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("public String[] getProjection() {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return PROJECTION;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("        ");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("public Uri getContentUri() {");
    _builder.newLine();
    _builder.append("\t\t    ");
    _builder.append("return ");
    String _name_6 = stmt.getName();
    String _pascalize_8 = Strings.pascalize(_name_6);
    _builder.append(_pascalize_8, "\t\t    ");
    _builder.append(".CONTENT_URI;");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("};");
    _builder.newLine();
    _builder.newLine();
    _builder.append("public static ActiveRecordFactory<");
    String _name_7 = stmt.getName();
    String _pascalize_9 = Strings.pascalize(_name_7);
    _builder.append(_pascalize_9, "");
    _builder.append("Record> getFactory() {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("return sFactory;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("    ");
    _builder.append("public static final Parcelable.Creator<");
    String _name_8 = stmt.getName();
    String _pascalize_10 = Strings.pascalize(_name_8);
    _builder.append(_pascalize_10, "    ");
    _builder.append("Record> CREATOR ");
    _builder.newLineIfNotEmpty();
    _builder.append("    \t");
    _builder.append("= new Parcelable.Creator<");
    String _name_9 = stmt.getName();
    String _pascalize_11 = Strings.pascalize(_name_9);
    _builder.append(_pascalize_11, "    \t");
    _builder.append("Record>() {");
    _builder.newLineIfNotEmpty();
    _builder.append("        ");
    _builder.append("public ");
    String _name_10 = stmt.getName();
    String _pascalize_12 = Strings.pascalize(_name_10);
    _builder.append(_pascalize_12, "        ");
    _builder.append("Record createFromParcel(Parcel in) {");
    _builder.newLineIfNotEmpty();
    _builder.append("            ");
    _builder.append("return new ");
    String _name_11 = stmt.getName();
    String _pascalize_13 = Strings.pascalize(_name_11);
    _builder.append(_pascalize_13, "            ");
    _builder.append("Record(in);");
    _builder.newLineIfNotEmpty();
    _builder.append("        ");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("        ");
    _builder.append("public ");
    String _name_12 = stmt.getName();
    String _pascalize_14 = Strings.pascalize(_name_12);
    _builder.append(_pascalize_14, "        ");
    _builder.append("Record[] newArray(int size) {");
    _builder.newLineIfNotEmpty();
    _builder.append("            ");
    _builder.append("return new ");
    String _name_13 = stmt.getName();
    String _pascalize_15 = Strings.pascalize(_name_13);
    _builder.append(_pascalize_15, "            ");
    _builder.append("Record[size];");
    _builder.newLineIfNotEmpty();
    _builder.append("        ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("};");
    _builder.newLine();
    _builder.append("    ");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("public static String[] PROJECTION = {");
    _builder.newLine();
    _builder.append("    \t");
    CharSequence _generateProjectionArrayMembers = this.generateProjectionArrayMembers(stmt);
    _builder.append(_generateProjectionArrayMembers, "    \t");
    _builder.newLineIfNotEmpty();
    _builder.append("    ");
    _builder.append("};");
    _builder.newLine();
    _builder.append("    ");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("public interface Indices {");
    _builder.newLine();
    _builder.append("    \t");
    CharSequence _generateProjectionIndicesMembers = this.generateProjectionIndicesMembers(stmt);
    _builder.append(_generateProjectionIndicesMembers, "    \t");
    _builder.newLineIfNotEmpty();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("    ");
    _builder.newLine();
    _builder.append("    ");
    CharSequence _generateFields = this.generateFields(stmt);
    _builder.append(_generateFields, "    ");
    _builder.newLineIfNotEmpty();
    _builder.append("    ");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("protected String[] _getProjection() {");
    _builder.newLine();
    _builder.append("    \t");
    _builder.append("return PROJECTION;");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("    ");
    _builder.newLine();
    _builder.append("    ");
    CharSequence _generateAccessors = this.generateAccessors(stmt);
    _builder.append(_generateAccessors, "    ");
    _builder.newLineIfNotEmpty();
    _builder.append("    ");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("public ");
    String _name_14 = stmt.getName();
    String _pascalize_16 = Strings.pascalize(_name_14);
    _builder.append(_pascalize_16, "    ");
    _builder.append("Record() {");
    _builder.newLineIfNotEmpty();
    _builder.append("    \t");
    _builder.append("super(");
    String _name_15 = stmt.getName();
    String _pascalize_17 = Strings.pascalize(_name_15);
    _builder.append(_pascalize_17, "    \t");
    _builder.append(".CONTENT_URI);");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private ");
    String _name_16 = stmt.getName();
    String _pascalize_18 = Strings.pascalize(_name_16);
    _builder.append(_pascalize_18, "\t");
    _builder.append("Record(Parcel in) {");
    _builder.newLineIfNotEmpty();
    _builder.append("    \t");
    _builder.append("super(");
    String _name_17 = stmt.getName();
    String _pascalize_19 = Strings.pascalize(_name_17);
    _builder.append(_pascalize_19, "    \t");
    _builder.append(".CONTENT_URI);");
    _builder.newLineIfNotEmpty();
    _builder.append("    \t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("setId(in.readLong());");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    CharSequence _generateParcelDeserializationStatements = this.generateParcelDeserializationStatements(stmt);
    _builder.append(_generateParcelDeserializationStatements, "\t\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public int describeContents() {");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("return 0;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public void writeToParcel(Parcel dest, int flags) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("dest.writeLong(getId());");
    _builder.newLine();
    _builder.append("\t\t");
    CharSequence _generateParcelSerializationStatements = this.generateParcelSerializationStatements(stmt);
    _builder.append(_generateParcelSerializationStatements, "\t\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("protected AbstractValuesBuilder createBuilder() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("Builder builder = ");
    String _name_18 = stmt.getName();
    String _pascalize_20 = Strings.pascalize(_name_18);
    _builder.append(_pascalize_20, "\t\t");
    _builder.append(".newBuilder();");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t\t");
    CharSequence _generateBuilderStatements = this.generateBuilderStatements(stmt);
    _builder.append(_generateBuilderStatements, "\t\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return builder;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public void makeDirty(boolean dirty){");
    _builder.newLine();
    _builder.append("\t\t");
    CharSequence _generateMakeDirtyStatements = this.generateMakeDirtyStatements(stmt);
    _builder.append(_generateMakeDirtyStatements, "\t\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("protected void setPropertiesFromCursor(Cursor c) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("setId(c.getLong(Indices._ID));");
    _builder.newLine();
    _builder.append("\t\t");
    CharSequence _generateSetFromCursorStatements = this.generateSetFromCursorStatements(stmt);
    _builder.append(_generateSetFromCursorStatements, "\t\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static ");
    String _name_19 = stmt.getName();
    String _pascalize_21 = Strings.pascalize(_name_19);
    _builder.append(_pascalize_21, "\t");
    _builder.append("Record fromCursor(Cursor c) {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t    ");
    String _name_20 = stmt.getName();
    String _pascalize_22 = Strings.pascalize(_name_20);
    _builder.append(_pascalize_22, "\t    ");
    _builder.append("Record item = new ");
    String _name_21 = stmt.getName();
    String _pascalize_23 = Strings.pascalize(_name_21);
    _builder.append(_pascalize_23, "\t    ");
    _builder.append("Record();");
    _builder.newLineIfNotEmpty();
    _builder.append("\t    ");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("item.setPropertiesFromCursor(c);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("item.makeDirty(false);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("return item;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static ");
    String _name_22 = stmt.getName();
    String _pascalize_24 = Strings.pascalize(_name_22);
    _builder.append(_pascalize_24, "\t");
    _builder.append("Record fromBundle(Bundle bundle, String key) {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("bundle.setClassLoader(");
    String _name_23 = stmt.getName();
    String _pascalize_25 = Strings.pascalize(_name_23);
    _builder.append(_pascalize_25, "\t\t");
    _builder.append("Record.class.getClassLoader());");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("return bundle.getParcelable(key);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static ");
    String _name_24 = stmt.getName();
    String _pascalize_26 = Strings.pascalize(_name_24);
    _builder.append(_pascalize_26, "\t");
    _builder.append("Record get(long id) {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t    ");
    _builder.append("Cursor c = null;");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("ContentResolver resolver = Mickey.getContentResolver();");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("try {");
    _builder.newLine();
    _builder.append("\t        ");
    _builder.append("c = resolver.query(");
    String _name_25 = stmt.getName();
    String _pascalize_27 = Strings.pascalize(_name_25);
    _builder.append(_pascalize_27, "\t        ");
    _builder.append(".CONTENT_URI.buildUpon()");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append(".appendPath(String.valueOf(id)).build(), PROJECTION, null, null, null);");
    _builder.newLine();
    _builder.append("\t        ");
    _builder.newLine();
    _builder.append("\t        ");
    _builder.append("if(!c.moveToFirst()) {");
    _builder.newLine();
    _builder.append("\t            ");
    _builder.append("return null;");
    _builder.newLine();
    _builder.append("\t        ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t        ");
    _builder.newLine();
    _builder.append("\t        ");
    _builder.append("return fromCursor(c);");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("} finally {");
    _builder.newLine();
    _builder.append("\t        ");
    _builder.append("Closeables.closeSilently(c);");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
  
  protected CharSequence _generateSetFromCursorStatements(final CreateTableStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field toJavaTypeName is undefined for the type ColumnType"
      + "\npascalize cannot be resolved");
  }
  
  protected CharSequence _generateSetFromCursorStatements(final CreateViewStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field viewResultColumns is undefined for the type CreateViewStatement"
      + "\nThe method or field inferredColumnType is undefined for the type ResultColumn"
      + "\nfilter cannot be resolved"
      + "\n== cannot be resolved"
      + "\n== cannot be resolved"
      + "\ntoJavaTypeName cannot be resolved"
      + "\npascalize cannot be resolved");
  }
  
  protected CharSequence _generateMakeDirtyStatements(final CreateTableStatement stmt) {
    StringConcatenation _builder = new StringConcatenation();
    {
      EList<ColumnSource> _columnDefs = stmt.getColumnDefs();
      final Function1<ColumnSource, Boolean> _function = (ColumnSource it) -> {
        String _name = it.getName();
        boolean _equals = _name.equals("_id");
        return Boolean.valueOf((!_equals));
      };
      Iterable<ColumnSource> _filter = IterableExtensions.<ColumnSource>filter(_columnDefs, _function);
      for(final ColumnSource col : _filter) {
        _builder.append("m");
        String _name = col.getName();
        String _pascalize = Strings.pascalize(_name);
        _builder.append(_pascalize, "");
        _builder.append("Dirty = dirty;");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  protected CharSequence _generateMakeDirtyStatements(final CreateViewStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field viewResultColumns is undefined for the type CreateViewStatement"
      + "\nfilter cannot be resolved"
      + "\nname cannot be resolved"
      + "\npascalize cannot be resolved");
  }
  
  protected CharSequence _generateBuilderStatements(final CreateTableStatement stmt) {
    StringConcatenation _builder = new StringConcatenation();
    {
      EList<ColumnSource> _columnDefs = stmt.getColumnDefs();
      final Function1<ColumnSource, Boolean> _function = (ColumnSource it) -> {
        String _name = it.getName();
        boolean _equals = _name.equals("_id");
        return Boolean.valueOf((!_equals));
      };
      Iterable<ColumnSource> _filter = IterableExtensions.<ColumnSource>filter(_columnDefs, _function);
      for(final ColumnSource col : _filter) {
        _builder.append("if(m");
        String _name = col.getName();
        String _pascalize = Strings.pascalize(_name);
        _builder.append(_pascalize, "");
        _builder.append("Dirty) {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("builder.set");
        String _name_1 = col.getName();
        String _pascalize_1 = Strings.pascalize(_name_1);
        _builder.append(_pascalize_1, "\t");
        _builder.append("(m");
        String _name_2 = col.getName();
        String _pascalize_2 = Strings.pascalize(_name_2);
        _builder.append(_pascalize_2, "\t");
        _builder.append(");");
        _builder.newLineIfNotEmpty();
        _builder.append("}");
        _builder.newLine();
      }
    }
    return _builder;
  }
  
  protected CharSequence _generateBuilderStatements(final CreateViewStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field viewResultColumns is undefined for the type CreateViewStatement"
      + "\nfilter cannot be resolved"
      + "\nname cannot be resolved"
      + "\npascalize cannot be resolved"
      + "\nname cannot be resolved"
      + "\npascalize cannot be resolved"
      + "\nname cannot be resolved"
      + "\npascalize cannot be resolved");
  }
  
  protected CharSequence _generateParcelSerializationStatements(final CreateTableStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field toJavaTypeName is undefined for the type ColumnType"
      + "\npascalize cannot be resolved");
  }
  
  protected CharSequence _generateParcelSerializationStatements(final CreateViewStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field viewResultColumns is undefined for the type CreateViewStatement"
      + "\nThe method or field inferredColumnType is undefined for the type ResultColumn"
      + "\nfilter cannot be resolved"
      + "\n== cannot be resolved"
      + "\n== cannot be resolved"
      + "\ntoJavaTypeName cannot be resolved"
      + "\npascalize cannot be resolved"
      + "\nfilter cannot be resolved"
      + "\nname cannot be resolved"
      + "\npascalize cannot be resolved");
  }
  
  protected CharSequence _generateParcelDeserializationStatements(final CreateTableStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field toJavaTypeName is undefined for the type ColumnType"
      + "\npascalize cannot be resolved");
  }
  
  protected CharSequence _generateParcelDeserializationStatements(final CreateViewStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field viewResultColumns is undefined for the type CreateViewStatement"
      + "\nThe method or field inferredColumnType is undefined for the type ResultColumn"
      + "\nfilter cannot be resolved"
      + "\n== cannot be resolved"
      + "\n== cannot be resolved"
      + "\ntoJavaTypeName cannot be resolved"
      + "\npascalize cannot be resolved"
      + "\nsize cannot be resolved"
      + "\n- cannot be resolved"
      + "\nfilter cannot be resolved"
      + "\nname cannot be resolved"
      + "\npascalize cannot be resolved");
  }
  
  protected String _getName(final CreateTableStatement statement) {
    return statement.getName();
  }
  
  protected String _getName(final CreateViewStatement statement) {
    return statement.getName();
  }
  
  protected CharSequence _generateProjectionArrayMembers(final CreateTableStatement stmt) {
    StringConcatenation _builder = new StringConcatenation();
    {
      EList<ColumnSource> _columnDefs = stmt.getColumnDefs();
      boolean _hasElements = false;
      for(final ColumnSource col : _columnDefs) {
        if (!_hasElements) {
          _hasElements = true;
        } else {
          _builder.appendImmediate(",", "");
        }
        String _name = stmt.getName();
        String _pascalize = Strings.pascalize(_name);
        _builder.append(_pascalize, "");
        _builder.append(".");
        String _name_1 = col.getName();
        String _underscore = Strings.underscore(_name_1);
        String _upperCase = _underscore.toUpperCase();
        _builder.append(_upperCase, "");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  protected CharSequence _generateProjectionArrayMembers(final CreateViewStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field viewResultColumns is undefined for the type CreateViewStatement"
      + "\nname cannot be resolved"
      + "\nunderscore cannot be resolved"
      + "\ntoUpperCase cannot be resolved");
  }
  
  protected CharSequence _generateProjectionIndicesMembers(final CreateTableStatement stmt) {
    StringConcatenation _builder = new StringConcatenation();
    int counter = (-1);
    _builder.newLineIfNotEmpty();
    {
      EList<ColumnSource> _columnDefs = stmt.getColumnDefs();
      for(final ColumnSource col : _columnDefs) {
        _builder.append("int ");
        String _name = col.getName();
        String _underscore = Strings.underscore(_name);
        String _upperCase = _underscore.toUpperCase();
        _builder.append(_upperCase, "");
        _builder.append(" = ");
        _builder.append(counter = (counter + 1), "");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  protected CharSequence _generateProjectionIndicesMembers(final CreateViewStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field viewResultColumns is undefined for the type CreateViewStatement"
      + "\nname cannot be resolved"
      + "\nunderscore cannot be resolved"
      + "\ntoUpperCase cannot be resolved");
  }
  
  protected CharSequence _generateFields(final CreateTableStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field toJavaTypeName is undefined for the type ColumnType");
  }
  
  protected CharSequence _generateFields(final CreateViewStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field viewResultColumns is undefined for the type CreateViewStatement"
      + "\nThe method or field inferredColumnType is undefined for the type ResultColumn"
      + "\nfilter cannot be resolved"
      + "\ntoJavaTypeName cannot be resolved");
  }
  
  protected CharSequence _generateAccessors(final CreateTableStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field toJavaTypeName is undefined for the type ColumnType"
      + "\nThe method or field toJavaTypeName is undefined for the type ColumnType");
  }
  
  protected CharSequence _generateAccessors(final CreateViewStatement stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field viewResultColumns is undefined for the type CreateViewStatement"
      + "\nThe method or field inferredColumnType is undefined for the type ResultColumn"
      + "\nfilter cannot be resolved"
      + "\ntoJavaTypeName cannot be resolved"
      + "\ntoJavaTypeName cannot be resolved");
  }
  
  public CharSequence generateSetFromCursorStatements(final TableDefinition stmt) {
    if (stmt instanceof CreateTableStatement) {
      return _generateSetFromCursorStatements((CreateTableStatement)stmt);
    } else if (stmt instanceof CreateViewStatement) {
      return _generateSetFromCursorStatements((CreateViewStatement)stmt);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(stmt).toString());
    }
  }
  
  public CharSequence generateMakeDirtyStatements(final TableDefinition stmt) {
    if (stmt instanceof CreateTableStatement) {
      return _generateMakeDirtyStatements((CreateTableStatement)stmt);
    } else if (stmt instanceof CreateViewStatement) {
      return _generateMakeDirtyStatements((CreateViewStatement)stmt);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(stmt).toString());
    }
  }
  
  public CharSequence generateBuilderStatements(final TableDefinition stmt) {
    if (stmt instanceof CreateTableStatement) {
      return _generateBuilderStatements((CreateTableStatement)stmt);
    } else if (stmt instanceof CreateViewStatement) {
      return _generateBuilderStatements((CreateViewStatement)stmt);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(stmt).toString());
    }
  }
  
  public CharSequence generateParcelSerializationStatements(final TableDefinition stmt) {
    if (stmt instanceof CreateTableStatement) {
      return _generateParcelSerializationStatements((CreateTableStatement)stmt);
    } else if (stmt instanceof CreateViewStatement) {
      return _generateParcelSerializationStatements((CreateViewStatement)stmt);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(stmt).toString());
    }
  }
  
  public CharSequence generateParcelDeserializationStatements(final TableDefinition stmt) {
    if (stmt instanceof CreateTableStatement) {
      return _generateParcelDeserializationStatements((CreateTableStatement)stmt);
    } else if (stmt instanceof CreateViewStatement) {
      return _generateParcelDeserializationStatements((CreateViewStatement)stmt);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(stmt).toString());
    }
  }
  
  public String getName(final TableDefinition statement) {
    if (statement instanceof CreateTableStatement) {
      return _getName((CreateTableStatement)statement);
    } else if (statement instanceof CreateViewStatement) {
      return _getName((CreateViewStatement)statement);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(statement).toString());
    }
  }
  
  public CharSequence generateProjectionArrayMembers(final TableDefinition stmt) {
    if (stmt instanceof CreateTableStatement) {
      return _generateProjectionArrayMembers((CreateTableStatement)stmt);
    } else if (stmt instanceof CreateViewStatement) {
      return _generateProjectionArrayMembers((CreateViewStatement)stmt);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(stmt).toString());
    }
  }
  
  public CharSequence generateProjectionIndicesMembers(final TableDefinition stmt) {
    if (stmt instanceof CreateTableStatement) {
      return _generateProjectionIndicesMembers((CreateTableStatement)stmt);
    } else if (stmt instanceof CreateViewStatement) {
      return _generateProjectionIndicesMembers((CreateViewStatement)stmt);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(stmt).toString());
    }
  }
  
  public CharSequence generateFields(final TableDefinition stmt) {
    if (stmt instanceof CreateTableStatement) {
      return _generateFields((CreateTableStatement)stmt);
    } else if (stmt instanceof CreateViewStatement) {
      return _generateFields((CreateViewStatement)stmt);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(stmt).toString());
    }
  }
  
  public CharSequence generateAccessors(final TableDefinition stmt) {
    if (stmt instanceof CreateTableStatement) {
      return _generateAccessors((CreateTableStatement)stmt);
    } else if (stmt instanceof CreateViewStatement) {
      return _generateAccessors((CreateViewStatement)stmt);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(stmt).toString());
    }
  }
}
