All right, so let's get started building this room demo.
Therefore, we're going to first set up the entity, and the entity is basically the data class that
we're going to use here and we could call it employee, for example.
So we have the employee name and employee email ID..
And of course, you could store a bunch more information about your employee, but we're going to simplify
it for now, and you can then easily expand your data class to incorporate all of the properties that
you want to store for a given object.
All right, so let's create an empty activity project for that, and I'm just going to call this one
room demo.
You can, of course, call it different if you want to.
Everything else can stay default.
API 21 is what we're going to use here, and let's click finish.
OK, so once our project is loaded, let's go over to our build that Gradle file.
You need to go to the app file.
Therefore, on the plugins, we need to add another plugin.
The Scotland annotation processor and in order to edit, you just need to add ID and then in parentheses
and single parentheses here, specifically Colin minus K Apetit, which stands for Scotland annotation
processor.
OK, so let's add that and then I also need to make sure that I use the right dependencies here, so
I need to add the room lifecycle dependencies and to Scotland extensions for call routine support with
the room.
And finally, the extensions for co-writing support with activities.
OK.
So let's add all of those.
Therefore, I'm going to go ahead and create a new variable here called room version.
And in my case, I'm going to use the version 2.0 3.0 and then the activity version of one.
Dot 3.1.
And now let's go ahead and use those.
So in order to use the room and lifecycle dependencies, I'm going to add the Android X Room Room runtime
with the version that we have defined up here and adding the Scotland annotation processor here.
With this concept, then we need to add the extensions for quarantine support with the room.
So here room room Katie X Standing for Scotland extensions with the room version that we want to use.
And then we also need to add the Kotlin extensions for quarantine support with activities.
So here Android X activity activity Kati X.
Once we have added all of those, we also need to make sure that we use view binding therefore inside
of this Android tag.
Further down here on their cotton options, I'm going to make sure that I activate the view binding
feature.
So built features.
And here in curly brackets, I had few binding.
True.
OK, so this statement is also going to be required if you want to use view binding throughout your
project, which is best practice and I highly recommend.
OK, once we have added all of those, let's sink our project and this will basically just allow us
to use a bunch of classes that which will help us to store data permanently using room.
OK, so now that all of that is done and are built, that Gradle is ready to go?
Let's go ahead and add an entity.
Therefore, I'm going to create a new class here.
Cuddling class file, and this will be a data class.
Which I'm going to call employee.
Entity.
So this data class employee entity will be using the ET Entity Keyword, which comes from the room library
here, Android X Room, you can see that here and now it added the import for us.
OK, so we can also directly specify the name of the table, but we want to use here.
OK, so I can specify the table name.
By now, giving it a name, I'm going to call this one employee minus table.
OK, so this will now be the table name in your database and you can define it with whatever you want,
but it really makes sense to use something similar to the name that you have here.
So in my case, employee?
OK, now let's define the different properties that we want to have inside of our entity.
And these are going to be the different columns, so to speak, that you will have in your data table.
OK, so you have this table with a bunch of different columns, and every single entry is going to be
a separate row.
So what are going to be the columns that I'm going to require?
Well, first of all, I want to have an ID, so every single employee must have an ID of type integer
and I'm going to set that to zero.
And this, by the way, will also be the primary key.
OK, the primary key should be able to generate it.
So I'm going to also generate that.
I'm going to say that the auto generates that thing should be set to true.
So what is this going to do for us?
Well, it's going to make sure that every single entry that we have in our table is going to be unique.
For example, let's say you have two John Doe's in your table and you have no additional information
about them.
Maybe they even have the same email address, which would be highly unlikely.
But let's say that was the case, then you would need to have a way to distinguish them from each other.
So those two entries, if you have nothing else about them, would be the same entry and this could
screw up your entire system.
So therefore, you have to have something that is uniquely identifiable and that is your ID, and the
ID will be unique for every single user.
And when you have something like that, you use it as your primary key.
OK, so you have only one primary key for your table.
So this will be unique, so every single user will get a new ID.
OK.
And what automatically happens here is when you create a new employee entity object.
So each time you add a new entry to your database into your table and you table, it will auto increment
the value that's finished as employee entity.
And we also want to store the name of a given user.
And by the way, we should use a comma to separate two entries here.
So the name will be empty by default, and we can override that.
And then I'm going to add an email here as well, which will be of type, string and also an empty string.
Now, if you want to give this a different name internally, you can add something called a column info.
OK, and here you just need to say which name you want to use here for.
So I'm going to use the name email ID for my email here.
So this will be the name that we are using when working with the employee entity object and internally
it will be stored as email ID, so the column will have the name of email ID.
So you could have gone ahead and created such a column ID for every single property that you have in
your table and feel free to do so if you feel like it.
Also, you can add more information if you want to, such as such as birthday or the gender size, whatever
information you want to store about your employees, maybe the job position.
If you want to store that, that wouldn't be a bad idea, I guess.
And the phone number, if you want to call them, or maybe even an address, even though with the address,
I would go a little further, I would create an extra entry.
So an extra entity with such an address where the address contains different kinds of information.
So, for example, the country they live in the state, potentially the zip code, the street name.
But we're going to keep it simple for now.
So you see, we basically used the at annotation here in order to define some additional details.
And by the way, if you don't override the name of a column, it will by default get the name that you
gave the property.
So here this property will name will be name this property name, which means this column name will
be ID and this one will not be emailed, but it will be email ID as we have overridden it.
OK, so that is the first step on our way.
So now we have prepared to entity class.
In the next video, we're going to set up the interface and the database class.
So see you there.