package at.c02.tempus.db;

import android.content.Context;
import android.util.Log;

import org.greenrobot.greendao.database.Database;

import javax.inject.Singleton;

import at.c02.tempus.db.entity.DaoMaster;
import at.c02.tempus.db.entity.DaoSession;
import at.c02.tempus.db.repository.BookingRepository;
import at.c02.tempus.db.repository.EmployeeRepository;
import at.c02.tempus.db.repository.ProjectRepository;
import dagger.Module;
import dagger.Provides;

/**
 * Created by Daniel on 09.04.2017.
 */
@Module
public class DatabaseModule {
    private static final String TAG="databaseModule";
    @Provides
    @Singleton
    public DaoSession provideDaoSession(Context context) {
        Log.d(TAG, "initializing DAO Session");
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "tempus-db");
        Database db = helper.getWritableDb();
        return new DaoMaster(db).newSession();
    }

    @Provides
    @Singleton
    public BookingRepository provideBookingRepository(DaoSession daoSession) {
        return new BookingRepository(daoSession.getBookingEntityDao());
    }

    @Provides
    @Singleton
    public EmployeeRepository provideEmployeeRepository(DaoSession daoSession) {
        return new EmployeeRepository(daoSession.getEmployeeEntityDao());
    }

    @Provides
    @Singleton
    public ProjectRepository provideProjectRepository(DaoSession daoSession) {
        return new ProjectRepository(daoSession.getProjectEntityDao());
    }
}

@@ -127,16 +127,67 @@
 atabase;
+%0Aimport org.greenrobot.greendao.query.QueryBuilder;
 %0A%0Aimport
@@ -624,17 +624,19 @@
 ring TAG
-=
+ = 
 %22databas
@@ -645,16 +645,17 @@
 odule%22;%0A
+%0A
     @Pro
@@ -932,45 +932,207 @@
     
-return new DaoMaster(db).newSession()
+DaoMaster daoMaster = new DaoMaster(db);%0A        DaoSession daoSession = daoMaster.newSession();%0A        QueryBuilder.LOG_SQL = true;%0A        QueryBuilder.LOG_VALUES = true;%0A        return daoSession
 ;%0A  

add query logging