The new List comes from an SQLite database.
The oldList, is storing the first and second rows of a JOINED table via the @Embedded interface that android provides.
The query that populates it, is supposed to fetch only those 2 rows, because they comply to a specific WHERE clause.
While doing transactions in the right table, like inserting a 3rd row whose foreign key is not yet "pointing"(?) towards the left table, and while no changes have been made to the first 2 rows (joined rows), the Observer gets called, and gives me my same 2 rows, but the java code tells me they are different.
It is understandable that the Observer is giving me a response as if the data changed, because the joined table HAS indeed changed as a whole, and the the SQL query needs to check if the third row inserted complies with the condition imposed (which it does not), but what is not clear is why the java code fetches the same 2 rows, and tells me that they are different from the same 2 rows stored moments ago.
At first I thought it had something to do with the fact that the list was being .get() from a HashMap<K,V> , it could also be that.
@Override
protected void onFound(List<X> xes, int liveDataId) {
List<X> xOldList = listHashMap.get(liveDataId);
if (xOldList == null) {
Log.d(TAG, "onFound: list not found on HasMap adding response");
listHashMap.put(liveDataId, xes);
if (listHashMap.size() == sources.size()) {
Log.d(TAG, "onFound: HashMap complete, converting HasMap");
ends(listHashMap);
}
} else {
if (!xOldList.equals(xes)) {
Log.d(TAG, "onFound: oldList not the same as new one!");
if (xes.size() > 0) {
Log.d(TAG, "onFound: new list size greater than 0");
synchronizedSubmitList(xes, xOldList, liveDataId);
} else {
Log.d(TAG, "onFound: newList size is zero");
listHashMap.put(liveDataId, xes);
ends(listHashMap);
}
}
}
}
The logs
The @Embedded Pojo
public class PieceQuantityAndPiece implements EntityInterface { private static final String TAG = "PieceQuantityAndPiece";
@Embedded
public PieceQuantity pieceQuantity;
@Relation(
parentColumn = "child_piece_id",
entityColumn = "piece_id"
)
public Piece piece;
public PieceQuantityAndPiece() {
}
}
The Query imposed for left table
@Transaction
@Query("SELECT * FROM piece_quantity_table WHERE folder_id = :folderId")
LiveData<List<PieceQuantityAndPiece>> getPieceQuantityAndPiecesAtFolder(int folderId);
The transactions being performed on the right table that trigger the onChanged():
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(Piece piece);
@Query("UPDATE piece_table SET _total = :total, _date_of_last_edit = :lastEdited WHERE piece_id = :pieceId")
void updatePieceTotalAt(int total, long lastEdited, int pieceId);