<commit_before>package at.barbot.barbot.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import java.io.PipedOutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Martin on 10.10.2016.
 */

public class BarBotDatabaseHelper extends SQLiteOpenHelper {
    //Database Instance
    private static BarBotDatabaseHelper sInstance;

    //Database Info
    private static final String DATABASE_NAME = "barBot";
    private static final int DATABASE_VERSION = 1;

    /**
     * Table Names
     */
    private static final String TABLE_BARBOT = "barbot";
    private static final String TABLE_SLAVEUNIT = "slaveunit";
    private static final String TABLE_INGREDIENT = "ingredient";
    private static final String TABLE_DRINK_HAS_INGREDIENT = "drink_has_ingredient";
    private static final String TABLE_DRINK = "drink";

    /**
     * Table Columns
     */

    //Table BarBot columns
    private static final String COLUMN_BARBOT_PK_ID_BARBOT = "pk_id_barbot";
    private static final String COLUMN_BARBOT_NAME = "name";

    //Table Slaveunit columns
    private static final String COLUMN_SLAVEUNIT_PK_ID_SLAVEUNIT = "pk_id_slaveunit";
    private static final String COLUMN_SLAVEUNIT_NAME = "name";
    private static final String COLUMN_SLAVEUNIT_FILLING_LEVEL_IN_ML = "filling_level_in_ml";
    private static final String COLUMN_SLAVEUNIT_FK_ID_BARBOT = "fk_id_barbot";
    private static final String COLUMN_SLAVEUNIT_FK_ID_INGREDIENT = "fk_id_ingredient";

    //Table Ingredient columns
    private static final String COLUMN_INGREDIENT_PK_ID_INGREDIENT = "pk_id_ingredient";
    private static final String COLUMN_INGREDIENT_NAME = "name";
    private static final String COLUMN_INGREDIENT_VOL_PERCENT = "vol_percent";

    //Table drink_has_ingredient columns
    private static final String COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_DRINK = "pk_fk_id_drink";
    private static final String COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_INGREDIENT = "pk_fk_id_ingredient";
    private static final String COLUMN_DRINK_HAS_INGREDIENT_INGREDIENT_AMOUNT_IN_ML = "ingredient_amount_in_ml";

    //Table drink columns
    private static final String COLUMN_DRINK_PK_ID_DRINK = "pk_id_drink";
    private static final String COLUMN_DRINK_NAME = "name";
    private static final String COLUMN_DRINK_PICTURE = "picture";
    private static final String COLUMN_DRINK_DESCRIPTION = "description";

    private static final String TAG = "BarBotDatabaseHelper";

    private BarBotDatabaseHelper (Context context){
        super(context,DATABASE_NAME, null, DATABASE_VERSION);
    }

    public static synchronized BarBotDatabaseHelper getInstance (Context context){
        if (sInstance == null){
            sInstance = new BarBotDatabaseHelper(context.getApplicationContext());
        }
        return sInstance;
    }

    @Override
    public void onConfigure(SQLiteDatabase db) {
        super.onConfigure(db);
        db.setForeignKeyConstraintsEnabled(true);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String create_table_barbot = "CREATE TABLE IF NOT EXISTS" + TABLE_BARBOT +
                "(" +   COLUMN_BARBOT_PK_ID_BARBOT + " INTEGER PRIMARY KEY," +
                        COLUMN_BARBOT_NAME + " VARCHAR(45)" +
                ")";
        String create_table_slaveunit = "CREATE TABLE IF NOT EXISTS" + TABLE_SLAVEUNIT +
                "(" +   COLUMN_SLAVEUNIT_PK_ID_SLAVEUNIT + " INTEGER PRIMARY KEY," +
                        COLUMN_SLAVEUNIT_NAME + " VARCHAR(45)," +
                        COLUMN_SLAVEUNIT_FILLING_LEVEL_IN_ML + " INTEGER," +
                        COLUMN_SLAVEUNIT_FK_ID_BARBOT + " INTEGER," +
                        COLUMN_SLAVEUNIT_FK_ID_INGREDIENT + " INTEGER," +
                        "FOREIGN KEY(" + COLUMN_SLAVEUNIT_FK_ID_BARBOT + ") REFERENCES " + TABLE_BARBOT + "(" + COLUMN_BARBOT_PK_ID_BARBOT + ")" +
                ")";
        String create_table_ingredient = "CREATE TABLE" + TABLE_INGREDIENT +
                "(" +   COLUMN_INGREDIENT_PK_ID_INGREDIENT + " INTEGER PRIMARY KEY," +
                        COLUMN_INGREDIENT_NAME + " VARCHAR(100)," +
                        COLUMN_INGREDIENT_VOL_PERCENT + " INTEGER" +
                ")";
        String create_table_drink_has_ingredient = "CREATE TABLE" + TABLE_DRINK_HAS_INGREDIENT +
                "(" +   COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_INGREDIENT + " INTEGER," +
                        COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_DRINK + " INTEGER," +
                        COLUMN_DRINK_HAS_INGREDIENT_INGREDIENT_AMOUNT_IN_ML + " INTEGER" +
                        "PRIMARY KEY (" + COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_INGREDIENT + "," + COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_DRINK + ")" +
                        "FOREIGN KEY(" + COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_INGREDIENT + ") REFERENCES " + TABLE_INGREDIENT + "(" + COLUMN_INGREDIENT_PK_ID_INGREDIENT + ")" +
                        "FOREIGN KEY(" + COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_DRINK + ") REFERENCES " + TABLE_DRINK + "(" + COLUMN_DRINK_PK_ID_DRINK + ")" +
                ")";
        String create_table_drink = "CREATE TABLE" + TABLE_DRINK +
                "(" +   COLUMN_DRINK_PK_ID_DRINK + " INTEGER," +
                        COLUMN_DRINK_NAME + " VARCHAR(100)," +
                        COLUMN_DRINK_DESCRIPTION + " MEDIUMTEXT," +
                        COLUMN_DRINK_PICTURE + "VARCHAR(200)" +
                ")";

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldV, int newV) {
        if (oldV != newV) {
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_BARBOT);
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_SLAVEUNIT);
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_INGREDIENT);
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_DRINK_HAS_INGREDIENT);
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_DRINK);
            onCreate(db);
        }
    }

    /*
        ----------------------- Create Actions -----------------------
     */

    /**
     * Einen neuen BarBot hinzufuegen
     * @param barBot: Ein Model, welches den BarBot repraesentiert
     */
    public void addBarBot (BarBot barBot){
        // create and/or open database
        SQLiteDatabase db = getWritableDatabase();

        db.beginTransaction();
        try {<commit_msg>added execution for tables<commit_after>package at.barbot.barbot.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import java.io.PipedOutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Martin on 10.10.2016.
 */

public class BarBotDatabaseHelper extends SQLiteOpenHelper {
    //Database Instance
    private static BarBotDatabaseHelper sInstance;

    //Database Info
    private static final String DATABASE_NAME = "barBot";
    private static final int DATABASE_VERSION = 1;

    /**
     * Table Names
     */
    private static final String TABLE_BARBOT = "barbot";
    private static final String TABLE_SLAVEUNIT = "slaveunit";
    private static final String TABLE_INGREDIENT = "ingredient";
    private static final String TABLE_DRINK_HAS_INGREDIENT = "drink_has_ingredient";
    private static final String TABLE_DRINK = "drink";

    /**
     * Table Columns
     */

    //Table BarBot columns
    private static final String COLUMN_BARBOT_PK_ID_BARBOT = "pk_id_barbot";
    private static final String COLUMN_BARBOT_NAME = "name";

    //Table Slaveunit columns
    private static final String COLUMN_SLAVEUNIT_PK_ID_SLAVEUNIT = "pk_id_slaveunit";
    private static final String COLUMN_SLAVEUNIT_NAME = "name";
    private static final String COLUMN_SLAVEUNIT_FILLING_LEVEL_IN_ML = "filling_level_in_ml";
    private static final String COLUMN_SLAVEUNIT_FK_ID_BARBOT = "fk_id_barbot";
    private static final String COLUMN_SLAVEUNIT_FK_ID_INGREDIENT = "fk_id_ingredient";

    //Table Ingredient columns
    private static final String COLUMN_INGREDIENT_PK_ID_INGREDIENT = "pk_id_ingredient";
    private static final String COLUMN_INGREDIENT_NAME = "name";
    private static final String COLUMN_INGREDIENT_VOL_PERCENT = "vol_percent";

    //Table drink_has_ingredient columns
    private static final String COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_DRINK = "pk_fk_id_drink";
    private static final String COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_INGREDIENT = "pk_fk_id_ingredient";
    private static final String COLUMN_DRINK_HAS_INGREDIENT_INGREDIENT_AMOUNT_IN_ML = "ingredient_amount_in_ml";

    //Table drink columns
    private static final String COLUMN_DRINK_PK_ID_DRINK = "pk_id_drink";
    private static final String COLUMN_DRINK_NAME = "name";
    private static final String COLUMN_DRINK_PICTURE = "picture";
    private static final String COLUMN_DRINK_DESCRIPTION = "description";

    private static final String TAG = "BarBotDatabaseHelper";

    private BarBotDatabaseHelper (Context context){
        super(context,DATABASE_NAME, null, DATABASE_VERSION);
    }

    public static synchronized BarBotDatabaseHelper getInstance (Context context){
        if (sInstance == null){
            sInstance = new BarBotDatabaseHelper(context.getApplicationContext());
        }
        return sInstance;
    }

    @Override
    public void onConfigure(SQLiteDatabase db) {
        super.onConfigure(db);
        db.setForeignKeyConstraintsEnabled(true);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String create_table_barbot = "CREATE TABLE IF NOT EXISTS" + TABLE_BARBOT +
                "(" +   COLUMN_BARBOT_PK_ID_BARBOT + " INTEGER PRIMARY KEY," +
                        COLUMN_BARBOT_NAME + " VARCHAR(45)" +
                ")";
        String create_table_slaveunit = "CREATE TABLE IF NOT EXISTS" + TABLE_SLAVEUNIT +
                "(" +   COLUMN_SLAVEUNIT_PK_ID_SLAVEUNIT + " INTEGER PRIMARY KEY," +
                        COLUMN_SLAVEUNIT_NAME + " VARCHAR(45)," +
                        COLUMN_SLAVEUNIT_FILLING_LEVEL_IN_ML + " INTEGER," +
                        COLUMN_SLAVEUNIT_FK_ID_BARBOT + " INTEGER," +
                        COLUMN_SLAVEUNIT_FK_ID_INGREDIENT + " INTEGER," +
                        "FOREIGN KEY(" + COLUMN_SLAVEUNIT_FK_ID_BARBOT + ") REFERENCES " + TABLE_BARBOT + "(" + COLUMN_BARBOT_PK_ID_BARBOT + ")," +
                        "FOREIGN KEY(" + COLUMN_SLAVEUNIT_FK_ID_INGREDIENT + ") REFERENCES " + TABLE_INGREDIENT + "(" + COLUMN_INGREDIENT_PK_ID_INGREDIENT + ")" +
                ")";
        String create_table_ingredient = "CREATE TABLE IF NOT EXISTS" + TABLE_INGREDIENT +
                "(" +   COLUMN_INGREDIENT_PK_ID_INGREDIENT + " INTEGER PRIMARY KEY," +
                        COLUMN_INGREDIENT_NAME + " VARCHAR(100)," +
                        COLUMN_INGREDIENT_VOL_PERCENT + " INTEGER" +
                ")";
        String create_table_drink_has_ingredient = "CREATE TABLE IF NOT EXISTS" + TABLE_DRINK_HAS_INGREDIENT +
                "(" +   COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_INGREDIENT + " INTEGER," +
                        COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_DRINK + " INTEGER," +
                        COLUMN_DRINK_HAS_INGREDIENT_INGREDIENT_AMOUNT_IN_ML + " INTEGER," +
                        "PRIMARY KEY(" + COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_INGREDIENT + "," + COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_DRINK + ")," +
                        "FOREIGN KEY(" + COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_INGREDIENT + ") REFERENCES " + TABLE_INGREDIENT + "(" + COLUMN_INGREDIENT_PK_ID_INGREDIENT + ")," +
                        "FOREIGN KEY(" + COLUMN_DRINK_HAS_INGREDIENT_PK_FK_ID_DRINK + ") REFERENCES " + TABLE_DRINK + "(" + COLUMN_DRINK_PK_ID_DRINK + ")" +
                ")";
        String create_table_drink = "CREATE TABLE IF NOT EXISTS" + TABLE_DRINK +
                "(" +   COLUMN_DRINK_PK_ID_DRINK + " INTEGER," +
                        COLUMN_DRINK_NAME + " VARCHAR(100)," +
                        COLUMN_DRINK_DESCRIPTION + " MEDIUMTEXT," +
                        COLUMN_DRINK_PICTURE + "VARCHAR(200)" +
                ")";

        db.execSQL(create_table_barbot);
        db.execSQL(create_table_ingredient);
        db.execSQL(create_table_slaveunit);
        db.execSQL(create_table_drink);
        db.execSQL(create_table_drink_has_ingredient);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldV, int newV) {
        if (oldV != newV) {
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_BARBOT);
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_SLAVEUNIT);
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_INGREDIENT);
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_DRINK_HAS_INGREDIENT);
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_DRINK);
            onCreate(db);
        }
    }

    /*
        ----------------------- Create Actions -----------------------
     */

    /**
     * Einen neuen BarBot hinzufuegen
     * @param barBot: Ein Model, welches den BarBot repraesentiert
     */
    public void addBarBot (BarBot barBot){
        // create and/or open database
        SQLiteDatabase db = getWritableDatabase();

        db.beginTransaction();
        try {
{'fraction_non_alphanumeric': 0.08741594620557157, 'fraction_numerical': 0.003251311608660312, 'mean_word_length': 2.7594444444444446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2144258', 'n_tokens_mistral': 4482, 'n_tokens_neox': 4253, 'n_words': 823}