You need to have a composite index with plate and date of repair and then a function to query your Repair entity for a given plate and date of repair values. If you get a response for the query , use getkey() for the query result and pass it to a function to create a corresponding linerepair entity.
Google App Engine Java and searches on Entities
-
02-06-2022 - |
Question
I'm developing a web application with GAE Java. I created the entity Repair and LineRepair in this way:
public static void createOrUpdateRiparazione(Key key, String plate,
String mechanicname, String type, String km, String description,
String date, String price, String qta) {
Transaction txn = Util.getDatastoreServiceInstance().beginTransaction();
try {
Entity repair = new Entity("Repair", key);
repair.setProperty("plate", plate);
repair.setProperty("date", date);
repair.setProperty("status", "Created");
repair.setProperty("km", km);
repair.setProperty("mechanic", mechanicname);
Util.getDatastoreServiceInstance().put(repair);
Entity lineRepair = new Entity("LineRepair", repair.getKey());
lineRepair.setProperty("type", type);
lineRepair.setProperty("description", description);
lineRepair.setProperty("price", price);
lineRepair.setProperty("qta", qta);
lineRepair.setProperty("repairID",
String.valueOf(repair.getKey().getId()));
Util.getDatastoreServiceInstance().put(lineRepair);
txn.commit();
} finally {
if (txn.isActive()) {
txn.rollback();
}
}
}
Now i won't to search the repairs of the car given the plate and the date of the reparation. this is because I would like to add a condition that if there is already a repair on that date then add a LineRepair. I m using the class util of Code Lab Project. Here there are Entities Car and User. Thanks for any help
Edit: They key passed is the key of Car
No correct solution
OTHER TIPS
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow