// Path: onam/src/main/java/com/basilgregory/onam/android/DbUtil.java
// static String getColumnName(Field field){
//     return getColumnName(getMethod("get", field));
// }
// 
// Path: onam/src/main/java/com/basilgregory/onam/android/DbUtil.java
// static String getMappingForeignColumnNameClass(Class aClass){
//     return aClass.getSimpleName().toLowerCase()+"_id";
// }


import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.basilgregory.onam.annotations.AfterCreate;
import com.basilgregory.onam.annotations.AfterUpdate;
import com.basilgregory.onam.annotations.BeforeCreate;
import com.basilgregory.onam.annotations.BeforeUpdate;
import com.basilgregory.onam.annotations.ManyToMany;
import com.basilgregory.onam.annotations.OneToMany;
import com.basilgregory.onam.annotations.Table;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.basilgregory.onam.android.DbUtil.getColumnName;
import static com.basilgregory.onam.android.DbUtil.getMappingForeignColumnNameClass;
    public static DBExecutor getInstance() {
        return instance;
    }

    public static void init(Context context, Object o) {
        if (o.getClass().getAnnotation(com.basilgregory.onam.annotations.DB.class) == null) return;
        getInstance(context, o.getClass().getAnnotation(com.basilgregory.onam.annotations.DB.class).name(),
                o.getClass().getAnnotation(com.basilgregory.onam.annotations.DB.class).version())
                .createTables(context, o);

    }

    private DBExecutor(Context context, String dbName, int version) {
        super(context, dbName, null, version);
        this.dbName = dbName;
    }

    @Override
    public void onCreate(SQLiteDatabase database) {
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
    //endregion

    //Interface methods used by Entity.java

    Entity findRelatedEntityByMapping(Entity entity, Method method) {
        L.v("executing method "+method.getName()+" in entity "+entity.getClass().getSimpleName());
// Path: onam/src/main/java/com/basilgregory/onam/android/DbUtil.java
// static String getColumnName(Field field){
//     return getColumnName(getMethod("get", field));
// }
// 
// Path: onam/src/main/java/com/basilgregory/onam/android/DbUtil.java
// static String getMappingForeignColumnNameClass(Class aClass){
//     return aClass.getSimpleName().toLowerCase()+"_id";
// }


// Path: onam/src/main/java/com/basilgregory/onam/android/DBExecutor.java
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.basilgregory.onam.annotations.AfterCreate;
import com.basilgregory.onam.annotations.AfterUpdate;
import com.basilgregory.onam.annotations.BeforeCreate;
import com.basilgregory.onam.annotations.BeforeUpdate;
import com.basilgregory.onam.annotations.ManyToMany;
import com.basilgregory.onam.annotations.OneToMany;
import com.basilgregory.onam.annotations.Table;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.basilgregory.onam.android.DbUtil.getColumnName;
import static com.basilgregory.onam.android.DbUtil.getMappingForeignColumnNameClass;

    public static DBExecutor getInstance() {
        return instance;
    }

    public static void init(Context context, Object o) {
        if (o.getClass().getAnnotation(com.basilgregory.onam.annotations.DB.class) == null) return;
        getInstance(context, o.getClass().getAnnotation(com.basilgregory.onam.annotations.DB.class).name(),
                o.getClass().getAnnotation(com.basilgregory.onam.annotations.DB.class).version())
                .createTables(context, o);

    }

    private DBExecutor(Context context, String dbName, int version) {
        super(context, dbName, null, version);
        this.dbName = dbName;
    }

    @Override
    public void onCreate(SQLiteDatabase database) {
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
    //endregion

    //Interface methods used by Entity.java

    Entity findRelatedEntityByMapping(Entity entity, Method method) {
        L.v("executing method "+method.getName()+" in entity "+entity.getClass().getSimpleName());
        String foreignKeyColumn = getColumnName(method);