Compare commits
2 Commits
686ae4e724
...
7dc95277c2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7dc95277c2 | ||
|
|
66f3ab66f6 |
@ -2,13 +2,13 @@ package fr.romanet.vj.apps.myrealestateagency;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instrumented test, which will execute on an Android device.
|
* Instrumented test, which will execute on an Android device.
|
||||||
|
|||||||
@ -1,14 +1,48 @@
|
|||||||
package fr.romanet.vj.apps.myrealestateagency;
|
package fr.romanet.vj.apps.myrealestateagency;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.Repository.MyRealEstateAgencyRepository;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.database.RealEstateAgencyDatabase;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.AgencyWithAgents;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private static final String TAG = "MyActivity";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void insertSingleTodo(View view) {
|
||||||
|
Agency test1 = new Agency("AgenceOFParis");
|
||||||
|
|
||||||
|
Agency test2 = new Agency("AgenceOFMarseille");
|
||||||
|
|
||||||
|
Agent test = new Agent("Bader", "Guetari", 1);
|
||||||
|
|
||||||
|
Agent test3 = new Agent("Khalil", "Guetari", 2);
|
||||||
|
|
||||||
|
Agent test10 = new Agent("Achref", "Guetari", 1);
|
||||||
|
|
||||||
|
MyRealEstateAgencyRepository.getInstance(this).addAgency(test1);
|
||||||
|
MyRealEstateAgencyRepository.getInstance(this).addAgency(test2);
|
||||||
|
MyRealEstateAgencyRepository.getInstance(this).addAgent(test);
|
||||||
|
MyRealEstateAgencyRepository.getInstance(this).addAgent(test3);
|
||||||
|
MyRealEstateAgencyRepository.getInstance(this).addAgent(test10);
|
||||||
|
|
||||||
|
String query = "SELECT agency_id FROM agency INNER JOIN agent ON agency.agency_id = agent.agent_id WHERE agency_name =" + "AgenceOFParis" + "GROUP BY agency_name";
|
||||||
|
String query1 = "SELECT agency_id FROM agent INNER JOIN agency ON agency.agency_id = agent.agent_id WHERE agency_name =" + "AgenceOFParis" + "GROUP BY agency_name";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.Repository;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.room.Room;
|
||||||
|
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.database.RealEstateAgencyDatabase;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
private MyRealEstateAgencyRepository(Context context)
|
||||||
|
{
|
||||||
|
realEstateAgencyDatabaseDatabase = Room.databaseBuilder(context, RealEstateAgencyDatabase.class, "real_estate_agency_db").allowMainThreadQueries().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAgency(Agency agency){realEstateAgencyDatabaseDatabase.agencyDao().insertAgency(agency);}
|
||||||
|
public void addAgent(Agent agent){realEstateAgencyDatabaseDatabase.agentDao().insertAgent(agent);}
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.dao;
|
||||||
|
|
||||||
|
import androidx.room.Dao;
|
||||||
|
import androidx.room.Insert;
|
||||||
|
import androidx.room.Query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
public interface AgencyDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM agency")
|
||||||
|
List<Agency> getAgencyList();
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
void insertAgency(Agency agency);
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.dao;
|
||||||
|
|
||||||
|
import androidx.room.Dao;
|
||||||
|
import androidx.room.Query;
|
||||||
|
import androidx.room.Transaction;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.AgencyWithAgents;
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
public interface AgencyWithAgentsDao {
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
@Query("SELECT * FROM agency")
|
||||||
|
List<AgencyWithAgents> getAgenciesAndAgent();
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.dao;
|
||||||
|
|
||||||
|
import androidx.room.Dao;
|
||||||
|
import androidx.room.Query;
|
||||||
|
import androidx.room.Transaction;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.AgencyWithProperties;
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
public interface AgencyWithPropertiesDao {
|
||||||
|
@Transaction
|
||||||
|
@Query("SELECT * FROM agency")
|
||||||
|
List<AgencyWithProperties> getAgenciesAndProperties();
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.dao;
|
||||||
|
|
||||||
|
import androidx.room.Dao;
|
||||||
|
import androidx.room.Insert;
|
||||||
|
import androidx.room.Query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
public interface AgentDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM agent")
|
||||||
|
List<Agent> getAgentList();
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
void insertAgent(Agent agent);
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.dao;
|
||||||
|
|
||||||
|
import androidx.room.Dao;
|
||||||
|
import androidx.room.Insert;
|
||||||
|
import androidx.room.Query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
public interface PropertyDao {
|
||||||
|
@Query("SELECT * FROM property")
|
||||||
|
List<Property> getPropertyList();
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
void insertProperty(Property property);
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.database;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.room.Database;
|
||||||
|
import androidx.room.Room;
|
||||||
|
import androidx.room.RoomDatabase;
|
||||||
|
import androidx.room.TypeConverters;
|
||||||
|
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.dao.AgencyDao;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.dao.AgencyWithAgentsDao;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.dao.AgencyWithPropertiesDao;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.dao.PropertyDao;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.dao.AgentDao;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
||||||
|
|
||||||
|
@Database(entities = {Agency.class, Agent.class, Property.class}, version = 1)
|
||||||
|
@TypeConverters({Property.Converters.class})
|
||||||
|
public abstract class RealEstateAgencyDatabase extends RoomDatabase {
|
||||||
|
|
||||||
|
public abstract AgentDao agentDao();
|
||||||
|
public abstract AgencyDao agencyDao();
|
||||||
|
public abstract PropertyDao propertyDao();
|
||||||
|
public abstract AgencyWithAgentsDao agencyWithAgentsDao();
|
||||||
|
public abstract AgencyWithPropertiesDao agencyWithPropertiesDaoDao();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.entities;
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo;
|
||||||
|
import androidx.room.Entity;
|
||||||
|
import androidx.room.Index;
|
||||||
|
import androidx.room.PrimaryKey;
|
||||||
|
|
||||||
|
//Parent class of agent (indeed, zero or many agents can work in an agency)
|
||||||
|
@Entity(tableName = "agency",
|
||||||
|
indices = {@Index("agency_id"),
|
||||||
|
@Index(value = {"agency_name"}, unique = true)})
|
||||||
|
public class Agency {
|
||||||
|
|
||||||
|
@ColumnInfo(name = "agency_id")
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
public int agencyId;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "agency_name")
|
||||||
|
public String agencyName;
|
||||||
|
|
||||||
|
public Agency(String agencyName)
|
||||||
|
{
|
||||||
|
agencyId = 0;
|
||||||
|
this.agencyName = agencyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAgencyId() {
|
||||||
|
return agencyId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.entities;
|
||||||
|
|
||||||
|
import androidx.room.Embedded;
|
||||||
|
import androidx.room.Relation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AgencyWithAgents {
|
||||||
|
@Embedded public Agency agency;
|
||||||
|
@Relation(
|
||||||
|
parentColumn = "agency_id",
|
||||||
|
entityColumn = "agency_employer_id"
|
||||||
|
)
|
||||||
|
public List<Agent> agents;
|
||||||
|
|
||||||
|
public Agency getAgency() {
|
||||||
|
return agency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Agent> getAgents() {
|
||||||
|
return agents;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.entities;
|
||||||
|
|
||||||
|
import androidx.room.Embedded;
|
||||||
|
import androidx.room.Relation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AgencyWithProperties {
|
||||||
|
public int agency_id;
|
||||||
|
@Relation(
|
||||||
|
parentColumn = "agency_id",
|
||||||
|
entityColumn = "belongs_agency_id"
|
||||||
|
)
|
||||||
|
public List<AgencyWithProperties> agents;
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.entities;
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo;
|
||||||
|
import androidx.room.Entity;
|
||||||
|
import androidx.room.ForeignKey;
|
||||||
|
import androidx.room.Index;
|
||||||
|
import androidx.room.PrimaryKey;
|
||||||
|
|
||||||
|
import static androidx.room.ForeignKey.CASCADE;
|
||||||
|
|
||||||
|
//Child class of Agency (indeed, an agent work only in one agency)
|
||||||
|
@Entity(tableName = "agent",
|
||||||
|
indices = {@Index(value = {"agent_first_name", "agent_last_name"}, unique = true)},
|
||||||
|
foreignKeys = @ForeignKey(entity = Agency.class,
|
||||||
|
parentColumns = "agency_id",
|
||||||
|
childColumns = "agency_employer_id",
|
||||||
|
onDelete = CASCADE))
|
||||||
|
public class Agent {
|
||||||
|
|
||||||
|
@ColumnInfo(name = "agent_id")
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
public int agentId;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "agent_first_name")
|
||||||
|
public String agentFirstName;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "agent_last_name")
|
||||||
|
public String agentLastName;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "agency_employer_id", index = true)
|
||||||
|
public int agencyEmployerId;
|
||||||
|
|
||||||
|
public Agent(String agentFirstName, String agentLastName, int agencyEmployerId)
|
||||||
|
{
|
||||||
|
agentId = 0;
|
||||||
|
this.agentFirstName = agentFirstName;
|
||||||
|
this.agentLastName = agentLastName;
|
||||||
|
this.agencyEmployerId = agencyEmployerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAgentName()
|
||||||
|
{
|
||||||
|
return agentFirstName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,66 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.entities;
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo;
|
||||||
|
import androidx.room.Embedded;
|
||||||
|
import androidx.room.Entity;
|
||||||
|
import androidx.room.ForeignKey;
|
||||||
|
import androidx.room.Index;
|
||||||
|
import androidx.room.PrimaryKey;
|
||||||
|
import androidx.room.TypeConverter;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
|
||||||
|
import static androidx.room.ForeignKey.CASCADE;
|
||||||
|
|
||||||
|
@Entity(tableName = "property",
|
||||||
|
indices = {@Index(value = "property_id") ,@Index(value = {"address","longitude", "latitude"}, unique = true)},
|
||||||
|
foreignKeys = @ForeignKey(entity = Agency.class,
|
||||||
|
parentColumns = "agency_id",
|
||||||
|
childColumns = "belongs_agency_id",
|
||||||
|
onDelete = CASCADE))
|
||||||
|
public class Property {
|
||||||
|
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
@ColumnInfo(name = "property_id")
|
||||||
|
public int propertyId;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "description")
|
||||||
|
public String description;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "address")
|
||||||
|
public String address;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "longitude")
|
||||||
|
public long longitude;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "latitude")
|
||||||
|
public long latitude;
|
||||||
|
|
||||||
|
//@Embedded
|
||||||
|
//public PropertyStatue propertyStatue;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "belongs_agency_id")
|
||||||
|
public int belongsToAgencyId;
|
||||||
|
|
||||||
|
public Property(String description, String address, long longitude, long latitude)
|
||||||
|
{
|
||||||
|
propertyId = 0;
|
||||||
|
this.description = description;
|
||||||
|
this.address = address;
|
||||||
|
this.longitude = longitude;
|
||||||
|
this.latitude = latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Converters {
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
public static Date toDate(Long dateLong){
|
||||||
|
return dateLong == null ? null: new Date(dateLong);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
public static Long fromDate(Date date){
|
||||||
|
return date == null ? null : date.getTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.entities;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.room.ColumnInfo;
|
||||||
|
import androidx.room.Embedded;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
|
||||||
|
public class PropertyStatue{
|
||||||
|
|
||||||
|
@ColumnInfo(name = "statue_sale")
|
||||||
|
public boolean statueSale;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "sold_date")
|
||||||
|
@Nullable
|
||||||
|
public Date soldDate;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "price")
|
||||||
|
public double price;
|
||||||
|
|
||||||
|
@Embedded
|
||||||
|
public PropertyType propertyType;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package fr.romanet.vj.apps.myrealestateagency.entities;
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo;
|
||||||
|
|
||||||
|
public class PropertyType {
|
||||||
|
|
||||||
|
@ColumnInfo(name = "type_description")
|
||||||
|
public String typeDescription;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "number_rooms")
|
||||||
|
public int numberRooms;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "surface_area")
|
||||||
|
public float surfaceArea;
|
||||||
|
|
||||||
|
}
|
||||||
@ -7,6 +7,7 @@
|
|||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/textView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Hello World!"
|
android:text="Hello World!"
|
||||||
@ -15,4 +16,16 @@
|
|||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonZ"
|
||||||
|
android:layout_width="95dp"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:layout_marginBottom="204dp"
|
||||||
|
android:onClick="insertSingleTodo"
|
||||||
|
android:text="Button"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="@+id/textView"
|
||||||
|
app:layout_constraintHorizontal_bias="0.526"
|
||||||
|
app:layout_constraintStart_toStartOf="@+id/textView" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Loading…
Reference in New Issue
Block a user