Package com.xffffff.wellfed.ingredient
Class IngredientDB
- java.lang.Object
-
- com.xffffff.wellfed.ingredient.IngredientDB
-
public class IngredientDB extends java.lang.Object
The IngredientDB class is used to store and retrieve ingredient data from the database.
-
-
Constructor Summary
Constructors Constructor Description IngredientDB(DBConnection connection)
Constructs an IngredientDB object
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addIngredient(Ingredient ingredient, OnCompleteListener<Ingredient> listener)
Adds an ingredient in storage to the Firebase DB.void
deleteIngredient(Ingredient ingredient, OnCompleteListener<Ingredient> listener)
Deletes an ingredient from the Firebase DB.com.google.firebase.firestore.DocumentReference
getDocumentReference(Ingredient ingredient)
Get document reference of an ingredientvoid
getIngredient(com.google.firebase.firestore.DocumentReference ingredientRef, OnCompleteListener<Ingredient> listener)
Gets an ingredient from Firebase DBvoid
getIngredient(Ingredient ingredient, OnCompleteListener<Ingredient> listener)
Gets an ingredient from Firebase DBvoid
getIngredient(java.lang.String id, OnCompleteListener<Ingredient> listener)
Gets an ingredient from Firebase DBcom.google.firebase.firestore.Query
getQuery()
Gets the CollectionReference that Ingredients are stored incom.google.firebase.firestore.Query
getSearchQuery(java.lang.String field)
com.google.firebase.firestore.Query
getSortQuery(java.lang.String field, boolean ascending)
Ingredient
snapshotToIngredient(com.google.firebase.firestore.DocumentSnapshot document)
Converts a DocumentSnapshot of an ingredient to an Ingredient objectvoid
updateReferenceCount(Ingredient ingredient, int delta, OnCompleteListener<Ingredient> listener)
Updates the reference count of an ingredient in the Firebase DB.
-
-
-
Constructor Detail
-
IngredientDB
public IngredientDB(DBConnection connection)
Constructs an IngredientDB object- Parameters:
connection
- the DBConnection object to use
-
-
Method Detail
-
addIngredient
public void addIngredient(@NonNull Ingredient ingredient, OnCompleteListener<Ingredient> listener)
Adds an ingredient in storage to the Firebase DB.- Parameters:
ingredient
- the ingredient to addlistener
- the listener to call when the ingredient is added
-
getIngredient
public void getIngredient(java.lang.String id, OnCompleteListener<Ingredient> listener)
Gets an ingredient from Firebase DB- Parameters:
id
- the id of the ingredient to be retrievedlistener
- the listener to be called when the ingredient is retrieved
-
getIngredient
public void getIngredient(com.google.firebase.firestore.DocumentReference ingredientRef, OnCompleteListener<Ingredient> listener)
Gets an ingredient from Firebase DB- Parameters:
ingredientRef
- the DocumentReference of the ingredient to be retrievedlistener
- the listener to be called when the ingredient is retrieved
-
getIngredient
public void getIngredient(Ingredient ingredient, OnCompleteListener<Ingredient> listener)
Gets an ingredient from Firebase DB- Parameters:
ingredient
- the ingredient to be retrievedlistener
- the listener to be called when the ingredient is retrieved
-
deleteIngredient
public void deleteIngredient(@NonNull Ingredient ingredient, OnCompleteListener<Ingredient> listener)
Deletes an ingredient from the Firebase DB.- Parameters:
ingredient
- the ingredient to deletelistener
- the listener to call when the ingredient is deleted
-
updateReferenceCount
public void updateReferenceCount(Ingredient ingredient, int delta, OnCompleteListener<Ingredient> listener)
Updates the reference count of an ingredient in the Firebase DB. The reference count keeps track of how many references exist to an object - if the object has 0 references, it is safely deleted.- Parameters:
ingredient
- the ingredient to update the reference count ofdelta
- how much to shift the reference count bylistener
- the listener to be called when the reference count is updated
-
snapshotToIngredient
public Ingredient snapshotToIngredient(com.google.firebase.firestore.DocumentSnapshot document)
Converts a DocumentSnapshot of an ingredient to an Ingredient object- Parameters:
document
- the DocumentSnapshot to convert- Returns:
- the ingredient
-
getDocumentReference
public com.google.firebase.firestore.DocumentReference getDocumentReference(Ingredient ingredient)
Get document reference of an ingredient- Parameters:
ingredient
- the ingredient to get the reference of- Returns:
- the document reference
-
getQuery
public com.google.firebase.firestore.Query getQuery()
Gets the CollectionReference that Ingredients are stored in- Returns:
- the CollectionReference
-
getSortQuery
public com.google.firebase.firestore.Query getSortQuery(java.lang.String field, boolean ascending)
-
getSearchQuery
public com.google.firebase.firestore.Query getSearchQuery(java.lang.String field)
-
-