Office Hours — Today, June 26

Saturday, June 23

Jun 26
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:30 PM
Ahmad M.
has entered the room
Mark M.
hello, Ahmad!
how can I help you today?
Ahmad M.
hello MR.Mark
Mark M.
do you have a question?
Ahmad M.
in the @Embedded section can i embedded a Location object in the database ?
in Room database
the Location from android.location.Location
Mark M.
probably not
that is not your class
and you do not know what its fields are
you do not know if those fields will change in an Android OS version update
you are welcome to create your own class that captures the relevant bits of data (latitude, longitude, etc.) and use that with @Embedded
7:35 PM
Mark M.
but I would not try to embed a class that is not yours, unless it is specifically documented to be supported that way
Ahmad M.
ok it's clear
in @Transaction what we mean about that and what we use it for ?
i can't uderstand what it's do for Room
Mark M.
I cover that in "Android's Architecture Components"
see page 42 of Version 0.9
View paste
"Whatever a @Transaction -annotated method does is wrapped in a SQLite
transaction. The transaction will be committed if the @Transaction -annotated
method does not throw an exception. If it does, the transaction will be rolled back."
Ahmad M.
yes you rghit but the genral idea i can't understand it
Mark M.
you can put it on a custom method on your DAO that makes multiple other DAO calls, such as inserting a parent and several children in one transaction
7:40 PM
Ahmad M.
ok
Mark M.
View paste
@Dao
public abstract class InvoiceStore {
  @Insert
  public abstract void _insert(Invoice invoice);

  @Insert
  public abstract void insert(List<InvoiceLineItem> lineItems);

  @Transaction
  public void insert(Invoice invoice) {
    _insert(invoice);
    insert(invoice.getLineItems());
  }
}
here, insert() not only inserts an Invoice entity, but also the InvoiceLineItem entities that are children of the Invoice (1:N relationship)
this way, the Invoice and all of the InvoiceLineItem objects will be stored in a transaction, so either it all gets stored, or none of it gets stored
you do not wind up in a case where part of the data is stored successfully and the rest is not
there are some other scenarios in the book (pages 42-44 of Version 0.9)
Ahmad M.
ok i thenk it's clear now
*think
7:45 PM
Ahmad M.
what is Instrumentation Tests?
Mark M.
those are the tests that you put in androidTest/, that run on the Android device
they are covered in "The Busy Coder's Guide to Android Development", starting in the chapter on JUnit4
see page 1011 of Version 8.12
Ahmad M.
yes, forgave me i'm confuse about it
7:50 PM
Mark M.
if you have specific questions, I can try to answer them, but I recommend that you read the chapters first, if you have not done so already
7:50 PM
Ahmad M.
thank you very much Mr.Mark i don't have a question.
8:05 PM
Ahmad M.
hello Mark
Mark M.
hello!
Ahmad M.
are you there ?
Mark M.
yes
you have not asked a question
the last entry in the chat that I see from you is "i don't have a question"
if you asked something after that, the chat room lost it -- could you ask again?
Ahmad M.
View paste
public class ExtracteLocation {

    public double lat;

    public double lon;

    public double alt;

    public ExtracteLocation(Location location) {
        this.lat = location.getLatitude();
        this.lon = location.getLongitude();
        this.lat = location.getAltitude();
    }
}
Mark M.
ExtracteLocation should work with @Embedded, if that is what you are asking
Ahmad M.
yse can i Embedded this in the Entity calss
Mark M.
that should work fine
Ahmad M.
ok thank you very much i realy don't have any more questions.
Mark M.
OK
8:30 PM
Mark M.
that is a wrap for today's chat
the transcript will be posted to https://commonsware.com/office-hours/ shortly
the next chat is Thursday at 9am US Eastern
have a pleasant day!
Ahmad M.
has left the room
Mark M.
turned off guest access

Saturday, June 23

 

Office Hours

People in this transcript

  • Ahmad Mustafa
  • Mark Murphy