Deleting the older repository and creating a new one (for each table)
This commit is contained in:
parent
00830fb0d1
commit
7b1b326425
@ -0,0 +1,27 @@
|
||||
package fr.romanet.vj.apps.myrealestateagency.repository;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.dao.AgentDao;
|
||||
import fr.romanet.vj.apps.myrealestateagency.database.RealEstateAgencyDatabase;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||
|
||||
public class AgentRepository {
|
||||
|
||||
private AgentDao agentDao;
|
||||
private LiveData<List<Agent>> allAgents;
|
||||
|
||||
public AgentRepository(Application application) {
|
||||
RealEstateAgencyDatabase realEstateAgencyDatabase = RealEstateAgencyDatabase.getInstance(application);
|
||||
agentDao = realEstateAgencyDatabase.agentDao();
|
||||
allAgents = agentDao.getAgentList();
|
||||
}
|
||||
|
||||
public LiveData<List<Agent>> getAllAgents() {
|
||||
return allAgents;
|
||||
}
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
package fr.romanet.vj.apps.myrealestateagency.repository;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
|
||||
import java.util.List;
|
||||
import fr.romanet.vj.apps.myrealestateagency.database.RealEstateAgencyDatabase;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
||||
|
||||
public final class MyRealEstateAgencyRepository {
|
||||
private static volatile MyRealEstateAgencyRepository instance;
|
||||
|
||||
public static MyRealEstateAgencyRepository getInstance(Context context)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
synchronized (MyRealEstateAgencyRepository.class)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new MyRealEstateAgencyRepository(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final RealEstateAgencyDatabase realEstateAgencyDatabaseDatabase;
|
||||
|
||||
public MyRealEstateAgencyRepository(Context context)
|
||||
{
|
||||
realEstateAgencyDatabaseDatabase = Room.databaseBuilder(context, RealEstateAgencyDatabase.class, "real_estate_agency_db").allowMainThreadQueries().build();
|
||||
}
|
||||
|
||||
public List<Agent> getAgents(){return realEstateAgencyDatabaseDatabase.agentDao().getAgentList();}
|
||||
public void addAgency(Agency agency){realEstateAgencyDatabaseDatabase.agencyDao().insertAgency(agency);}
|
||||
public void addAgent(Agent agent){realEstateAgencyDatabaseDatabase.agentDao().insertAgent(agent);}
|
||||
public void addProperty(Property property){realEstateAgencyDatabaseDatabase.propertyDao().insertProperty(property);}
|
||||
public String getAgencyName(Agent agent){return realEstateAgencyDatabaseDatabase.agentDao().getAgencyName(agent.agencyEmployerId);}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user