How do i understand firebase query in android? [duplicate] - java

I have a list of numbers inside that have certain data, in which I am adding a value "Sí" or "No", as in this image:
The last "Sí" that I added was the one that is in number 4, but if I do a filter in Firebase with
.equalTo("Sí").limitToLast(1)
I return the value of "Sí" positioned in the number 5 and not in the 4 that was the last "Sí" that I added to the database. There is some way to recognize the last "Sí", without the need of that is in the last position of the list?
I still can not find the solution to this, I hope you can help me.
Thank you.

There is some way to recognize the last "Sí", without the need of that is in the last position of the list?
Yes there is. The most common approach would be to add under each object a new property of type Timestamp named lastUpdate and then query descending according to it. Everytime you update a value, change the value also to lastUpdate with the current timestamp. This is how your schema might look like:
Firebase-root
|
--- Users
|
--- 1
| |
| --- Activo: "Si"
| |
| --- lastUpdate: 1561202277
|
--- 2
|
--- Activo: "No"
|
--- lastUpdate: 1561202299
This is how to save the timestamp:
How to save the current date/time when I add new value to Firebase Realtime Database
And this is how to order descending:
Firebase Data Desc Sorting in Android
How to arrange firebase database data in ascending or descending order?

Related

How to create category containing products in firestore firebase

I am using Cloud Firestore to make my own E-commerce App. I want my category collection to contain many categories like shoes, clothes, watches, etc and in each of those categories there are different products so I can click on that category and show all the related products on my app, please guide me or if you have another way to do this, please show me.
Category and Products
According to your comment:
just tens, this is just my personal project.
Since you only have tens of category names, then the best option that you have is to store them in a single document, in an array type field. Then each product document should contain a field where you have to specify the category. Your schema should look like this:
Firestore-root
|
--- shop (collection)
| |
| --- category (document)
| |
| --- names: ["shoes", "clothes", "watches"]
|
--- products (collection)
|
--- $productId (document)
|
--- name: "Nike Air Jordan"
|
--- category: "shoes"
To be able to display the category names, you should simply read the array that exists in the document, and display the content into a ListView, or even better, in a RecyclerView.
Furthermore, if you need to click on a particular category, and go forward to display only the products that correspond to a specific category, then you should use the following query:
FirebaseFirestore db = FirebaseFirestore.getInstance();
Query queryByCategory = db.collection("products").whereEqualTo("category", "shoes");
For displaying the products you might consider reading my answer from the following post:
How to display data from Firestore in a RecyclerView with Android?
The following article might also help you read the data with the use of the Firebase-UI library:
How to read data from Cloud Firestore using get()?

FirebaseRecyclerView - make onBindViewHolder method create severals elements

I am creating a FirebaseRecyclerView.
I give to my FirebaseRecyclerView a Query that refers to objects from my FirestoreDatabase.
But instead of having 1 element for each object, I want to create severals elements.
Example of 1 object structure :
Firestore-root
|
--- collection (collection)
|
--- document1 (document)
| |
| --- documentField (List<Object>): "Data1"
| : "Data2"
| : "Data3"
What I can do :
View_I_Can_Do
What I want to do :
View_I_Want_To_Have
NB : The number of ''Data'' is changing, so I can't design an itemView to match with an undefined number of variables.
I suppose the solution is in the onBindViewHolder method, but I don't know how to make it works.
Don't hesitate to ask for more details if needed.
Any help or suggestion would be appreciated, thanks in advance !
Edit 01/21/2022 :
I'm still stuck on this ...
I tried to give more detail in this question : Display one item for each object in a single Firebase document field - FirebaseRecyclerView
Maybe this is more explicit.

How to sum inserted rows in tjavaflex component when iterating between inputs?

In Talend (open studio for data integration) 7.0.1 (and earlier versions). I use tJavaFlex to log how many rows have been inserted into a database.
Talend Job In detail:
1. Split large file into multiple smaller
2. Iterate between smaller files, insert them into database
3. Log how many rows have been inserted
The logging part logs every iteration, to look like this:
2019-01-31 09:39:20 |Stage_SalesInvoiceLine | Rows inserted 5000
2019-01-31 09:39:25 |Stage_SalesInvoiceLine | Rows inserted 5000
2019-01-31 09:39:32 |Stage_SalesInvoiceLine | Rows inserted 5000
I need help figuring out how to get it to look like this:
2019-01-31 09:39:32 |Stage_SalesInvoiceLine | Rows inserted 15000
tJavaFlex behaviour when changing loop position I've tried to look here for an answer, but did not manage to solve my problem
Current code in tJavaFlex Main code part (start and end parts are empty)
Integer Inserted = ((Integer)globalMap.get("tJDBCOutput_6_NB_LINE"));
String InsertedS = "Rows inserted " + Integer.toString(Inserted);
row19.TimeStamp = TalendDate.getDate("yyyy-MM-dd HH:mm:ss ");
row19.LogRow = "Stage_SalesInvoiceLine | " + InsertedS;
If you use local variables in tJavaFlex they will get reset at each iteration. Instead, you could define a global variable before the start of your subjob, increment it inside tJavaFlex, and retrieve its value after you've done all your inserts.
tSetGlobalVar (NB_INSERTS set to 0)
|
OnSubjobOK
|
database inserts -- OnComponentOK -- tJavaFlex
|
tFixedFlowInput -- tFileOutputDelimited
In the above tJavaFlex, you can increment your variable in the main part:
globalMap.put("NB_INSERTS", (Integer)globalMap.get("NB_INSERTS") + (Integer)globalMap.get("tJDBCOutput_1_NB_LINE_INSERTED"))
in tFixedFlowInput: "Rows inserted " + (Integer)globalMap.get("NB_INSERTS")

Context variable is null in tMysqlInput query

I have a problem with my job when I want to make a query with 2 context variables. I attached photos with my job and my components and when I run the job, it's giving me this error:
Exception in component tMysqlInput_1 (facebook_amazon_us)
java.lang.NullPointerException
at mava.facebook_amazon_us_0_1.facebook_amazon_us.tWaitForFile_1Process(facebook_amazon_us.java:2058)
at mava.facebook_amazon_us_0_1.facebook_amazon_us.tMysqlConnection_1Process(facebook_amazon_us.java:798)
at mava.facebook_amazon_us_0_1.facebook_amazon_us.runJobInTOS(facebook_amazon_us.java:5363)
at mava.facebook_amazon_us_0_1.facebook_amazon_us.main(facebook_amazon_us.java:5085)
What I want to do in this job: I have a csv file with multiple columns. The first one is called Reporting_Starts. I want to get the first registration from that column and put it in the query for a select like:
SELECT * FROM my_table WHERE MONTH(my_table.Reporting_Starts)='"+context.month+"'.
I cannot get why my tJava_4 sees the variables and tMysqlInput don't.
In my tJava_4 I have the following code:
System.out.println(context.month);[My job][1][after running the job][1][tJava_3][1][tJavaRow_1][1][tMysqlInput_1 query][1]
Please let me know if you need any additional information about the job.
Thanks!
With all the iterate links you have, I'm guessing the code isn't executing in the order you expect. Could you please make the following changes:
Remove all the iterate links from tFileList_1
Reorganize your jobs as :
tMysqlConnection_1
|
OnSubjobOk
|
tWaitForFile_1
|
Iterate
|
tFileList_1 -- Iterate -- tJava_3
|
OnSubjobOk
|
tFileInputDelimited_1 -- Main -- tJavaRow_1
|
OnSubjobOk
|
tMysqlInput -- tMap -- tMysqlOutput (delete mode, set a column as delete key)
|
tFileInputDelimited -- tMap -- tMysqlOutput (insert csv)
|
OnSubjobOk
|
tFileCopy
First test with just this part. Then if it works, you can add the rest of your job.

How can i rename a branch/node in firebase

I have attached a picture, wherein i wish to rename the node during the run time for an application.
Short Answer:
Currently, Firebase doesn't allow you to rename a node/branch. So you might delete that node and create a new node again.
There is no api within Firebase for doing that. What can you do instead is to copy the information to another node and then simply delete the old one.
This is not a good practice to have the name of the product as a Firebase key. You need instead of using the product name, to use a unique identifier, an id. The best option is to use the unique key generated by the push() method. The name of the product will be then a child of your productId. Your database should look like this:
Firebase-root
|
--- prducts_details
|
--- -Ki-k6fM5GTRpQhGBRFRa
| |
| --- productName: "product1"
|
--- -Ki-oAAtTG1bWzLvKD5L
|
--- productName: "product2"
You have an option to Export the data. Once exported open and edit the exported.json. Here you can edit the node you want then save it and have Import to firebase db.

Categories