0

i have stored the Data for my application in Firebase RealtimeDatabase. Now im facing a big problem by retrieving and writing the data to a csv file. My Database consists of two child nodes: The Model Color with different attributes like yellow, green, red.... and the child Times with different times. Both as String values represented.

For getting the data i have two queries. Everything works fine. But now i discovered that Firebase Queries work asynchron. And the only way to get the data written to the CSV File seems to be inside the onDataChange method from the EventListener.

I tried with interface but this does not solve the problem. (Like described here: Link to stackoverflow

I cant get the values from Firebase to be stored outside of the onDataChange method. I dont know how to split the buffered writer. At the moment its only possible for me to have one buffered writer and all the append.line stuff inside one of the queries. But this is not a solution. i need all data from both queries written to the file.

Does anybody know how to solve such a problem? (Im using java code)

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
steeveKA1
  • 13
  • 6
  • 1
    To understand better, do you want to combine the result of two queries? – Alex Mamo May 16 '23 at 08:16
  • The solution is to nest the second query into the `onDataChange` for the first one, and then nest the writing of the CSV into the `onDataChange` of the first query. If you can't get that work, edit your question to [show us where you got stuck](http://stackoverflow.com/help/mcve). – Frank van Puffelen May 16 '23 at 13:38
  • @FrankvanPuffelen thank you. That did the trick for me. It seems to work now. You saved my day. But one question still remains: Now i have the two queries combined, and maybe in future its possible that the data is growing bigger and bigger. How do i know that performance is still enough that user experience keeps good? Is there a way to test how long it needs to execute the queries and creating and filling the file with the received data? – steeveKA1 May 16 '23 at 14:23
  • Usually you can get pretty far with running the data loading operations in parallel and keeping something like a counter to determine how many of them are still pending. But there's no single idiomatic answer, and it all depends on the exact use-case and the rest of your implementation. – Frank van Puffelen May 16 '23 at 15:35

0 Answers0