Class DatabaseQuery<T extends DatabaseInstance<T>>
- Type Parameters:
T- The type of instance being returned
- All Implemented Interfaces:
Database.Dissolvable,Database.Querrier<DatabaseQuery<T>>,Database.UpdateListener
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic classTools to query for documents without loading themNested classes/interfaces inherited from interface com.syzygy.events.database.Database.Querrier
Database.Querrier.DataListener<S extends Database.Querrier<S>,W extends Database.Querrier.QueryResult<?>>, Database.Querrier.Listener<S extends Database.Querrier<S>>, Database.Querrier.QueryInstanceResult<V extends DatabaseInstance<V>>, Database.Querrier.QueryResult<V> Nested classes/interfaces inherited from interface com.syzygy.events.database.Database.UpdateListener
Database.UpdateListener.Type -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Database.CollectionsThe collection which this queriesThe current list of loaded instancesprivate com.google.firebase.firestore.QueryThe current query used to get the pageprivate final DatabaseThe databaseprivate booleanIf an update has occurred since the last refreshprivate final com.google.firebase.firestore.QueryThe query to evaluateprivate final IntegerThe number of results returned per page.private com.google.firebase.firestore.QuerySnapshotThe current document snapshotprivate DatabaseQuery.PageThe pageprivate booleanIf an update has occurred since the last refresh -
Constructor Summary
ConstructorsConstructorDescriptionDatabaseQuery(Database db, com.google.firebase.firestore.Query query, Database.Collections collection, Integer resultsPerPage) Creates a database query which can be refreshed to load the set of instances which are returned by the query -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoiddissolve()Removes references to all instances that have been created and clears the current instanceprivate voidGets the first resultsPerPage of the querystatic DatabaseQuery<EventAssociation>getAttachedUsers(Database db, Event e, String status, boolean returnAll) static com.google.firebase.firestore.QuerygetAttachedUsersQuery(Database db, Event e, String status) static DatabaseQuery<Event>static DatabaseQuery<Event>getFacilityEvents(Database db, Facility facility) static DatabaseQuery<Image>static DatabaseQuery<EventAssociation>getMyEventsFilter(Database db, User u) static DatabaseQuery<Notification>getMyNotifications(Database db, User u) static com.google.firebase.firestore.QuerygetMyNotificationsQuery(Database db, User u) static DatabaseQuery<User>voidgotoFirstPage(Database.Querrier.Listener<DatabaseQuery<T>> listener) Refreshes the query and loads the first page of results Loads all instances of the current snapshot at the page.voidgotoLastPage(Database.Querrier.Listener<DatabaseQuery<T>> listener) Refreshes the query and loads the last page of results Loads all instances of the current snapshot at the page.voidgotoNextPage(Database.Querrier.Listener<DatabaseQuery<T>> listener) Refreshes the query and loads the new instances starting at the instance following the last instance of the current page.voidgotoPage(Database.Querrier.Listener<DatabaseQuery<T>> listener, DatabaseQuery.Page page) Goes to the corresponding pagevoidgotoPreviousPage(Database.Querrier.Listener<DatabaseQuery<T>> listener) Refreshes the query and loads the new instances ending at the instance before the first instance of the current page.booleanbooleanprivate voidGets the last resultsPerPage of the queryprivate voidloadFromSnapshot(Database.Querrier.Listener<DatabaseQuery<T>> listener) Loads all instances of the current snapshot.methods(DatabaseQuery<EventAssociation> query) Returns an object which contains methods that help notify the user or change the status of the associations.(package private) static <T extends Database.Querrier<T>>
EventAssociation.Methods<T>methods(T querrier, DatabaseQuery<EventAssociation> query, List<EventAssociation> eas) Returns an object which contains methods that help notify the user or change the status of the associations.private voidSets the currentPage query to the set of resultsPerPage after the last document in the previous result.<S extends DatabaseInstance<S>>
voidonUpdate(DatabaseInstance<S> instance, Database.UpdateListener.Type type) booleanprivate voidSets the currentPage query to the set of resultsPerPage before the first document in the previous result.voidrefreshData(Database.Querrier.Listener<DatabaseQuery<T>> listener) Refreshes the query and loads the new instances at the current page.private voidsetNewInstances(List<T> newInstances) Sets the new instances.boolean
-
Field Details
-
db
The database -
collection
The collection which this queries -
query
@NonNull private final com.google.firebase.firestore.Query queryThe query to evaluate -
snapshot
@Nullable private com.google.firebase.firestore.QuerySnapshot snapshotThe current document snapshot -
resultsPerPage
The number of results returned per page. If null, all results are returned -
currentInstances
The current list of loaded instances -
currentPage
private com.google.firebase.firestore.Query currentPageThe current query used to get the page -
thisPage
The page -
updates
private boolean updatesIf an update has occurred since the last refresh -
deletes
private boolean deletesIf an update has occurred since the last refresh
-
-
Constructor Details
-
DatabaseQuery
@MustStir public DatabaseQuery(@NonNull Database db, @NonNull com.google.firebase.firestore.Query query, @NonNull Database.Collections collection, @Nullable Integer resultsPerPage) Creates a database query which can be refreshed to load the set of instances which are returned by the query- Parameters:
db- The databasequery- The querycollection- The collection which this queries
-
-
Method Details
-
refreshData
@Titrates(what="Result instances", when="All success") @StirsDeep(what="Previous Instances", when="All success") @Observes public void refreshData(Database.Querrier.Listener<DatabaseQuery<T>> listener) Refreshes the query and loads the new instances at the current page. Loads all instances of the current snapshot at the page. On completion, dissolves all previous instances and sets the current instances to the new instances. Then notifies the listener of success.If any point, and instances errors, dissolves all newly loaded instances and notifies the listener. The current instances remains the same as before the function call.
- Specified by:
refreshDatain interfaceDatabase.Querrier<T extends DatabaseInstance<T>>- Parameters:
listener- The listener. Once the data is loaded, the listener is notified of success. Otherwise the listener is notified of failure.
-
methods
@MustStir public static EventAssociation.Methods<DatabaseQuery<EventAssociation>> methods(@Observes DatabaseQuery<EventAssociation> query) Returns an object which contains methods that help notify the user or change the status of the associations. This object must be called with.dissolveonce complete- Parameters:
query- The query containing the associations- Returns:
- The set of methods for the associations currently in the list (does not match on change)
-
methods
@MustStir static <T extends Database.Querrier<T>> EventAssociation.Methods<T> methods(@Observes T querrier, @Observes DatabaseQuery<EventAssociation> query, @Dilutes List<EventAssociation> eas) Returns an object which contains methods that help notify the user or change the status of the associations. This object must be called with.dissolveonce complete- Parameters:
querrier- The querrier of the resultsquery- The query containing the associationseas- The list of event associations to get methods for- Returns:
- The set of methods for the associations currently in the list (does not match on change)
-
gotoNextPage
@Titrates(what="Result Instances", when="All success") @StirsDeep(what="Previous Instances", when="All success") public void gotoNextPage(Database.Querrier.Listener<DatabaseQuery<T>> listener) Refreshes the query and loads the new instances starting at the instance following the last instance of the current page. If the result is less the the limit, gets the first page. If the current page does not exist or is empty, gets the first page Loads all instances of the current snapshot at the page. On completion, dissolves all previous instances and sets the current instances to the new instances. Then notifies the listener of success.If any point, and instances errors, dissolves all newly loaded instances and notifies the listener. The current instances remains the same as before the function call.
This will refresh data even if the given page is the current page
- Parameters:
listener- The listener. Once the data is loaded, the listener is notified of success. Otherwise the listener is notified of failure.
-
gotoPreviousPage
@Titrates(what="Result Instances", when="All success") @StirsDeep(what="Previous Instances", when="All success") public void gotoPreviousPage(Database.Querrier.Listener<DatabaseQuery<T>> listener) Refreshes the query and loads the new instances ending at the instance before the first instance of the current page. If the results are empty, gets the last page If the current page does not exist or is empty, gets the last page Loads all instances of the current snapshot at the page. On completion, dissolves all previous instances and sets the current instances to the new instances. Then notifies the listener of success.If any point, and instances errors, dissolves all newly loaded instances and notifies the listener. The current instances remains the same as before the function call.
This will refresh data even if the given page is the current page
- Parameters:
listener- The listener. Once the data is loaded, the listener is notified of success. Otherwise the listener is notified of failure.
-
gotoFirstPage
@Titrates(what="Result Instances", when="All success") @StirsDeep(what="Previous Instances", when="All success") public void gotoFirstPage(Database.Querrier.Listener<DatabaseQuery<T>> listener) Refreshes the query and loads the first page of results Loads all instances of the current snapshot at the page. On completion, dissolves all previous instances and sets the current instances to the new instances. Then notifies the listener of success.If any point, and instances errors, dissolves all newly loaded instances and notifies the listener. The current instances remains the same as before the function call.
This will refresh data even if the given page is the current page
- Parameters:
listener- The listener. Once the data is loaded, the listener is notified of success. Otherwise the listener is notified of failure.
-
gotoLastPage
@Titrates(what="Result Instances", when="All success") @StirsDeep(what="Previous Instances", when="All success") public void gotoLastPage(Database.Querrier.Listener<DatabaseQuery<T>> listener) Refreshes the query and loads the last page of results Loads all instances of the current snapshot at the page. On completion, dissolves all previous instances and sets the current instances to the new instances. Then notifies the listener of success.If any point, and instances errors, dissolves all newly loaded instances and notifies the listener. The current instances remains the same as before the function call.
This will refresh data even if the given page is the current page
- Parameters:
listener- The listener. Once the data is loaded, the listener is notified of success. Otherwise the listener is notified of failure.
-
gotoPage
@Titrates(what="Result Instances", when="All success") @StirsDeep(what="Previous Instances", when="All success") public void gotoPage(Database.Querrier.Listener<DatabaseQuery<T>> listener, DatabaseQuery.Page page) Goes to the corresponding page- Parameters:
listener- The listenerpage- The page to goto- See Also:
-
isFirstPage
public boolean isFirstPage()- Returns:
falseif this thinks there is more data before
-
isLastPage
public boolean isLastPage()- Returns:
trueif this thinks there is more data after
-
nextPageQuery
private void nextPageQuery()Sets the currentPage query to the set of resultsPerPage after the last document in the previous result. -
previousPageQuery
private void previousPageQuery()Sets the currentPage query to the set of resultsPerPage before the first document in the previous result. -
firstPageQuery
private void firstPageQuery()Gets the first resultsPerPage of the query -
lastPageQuery
private void lastPageQuery()Gets the last resultsPerPage of the query -
getResultsPerPage
- Returns:
- The number of results per page.
nullif infinite
-
loadFromSnapshot
@Titrates(what="Result Instances", when="All success") @StirsDeep(what="Previous Instances", when="All success") @Observes private void loadFromSnapshot(Database.Querrier.Listener<DatabaseQuery<T>> listener) Loads all instances of the current snapshot. On completion, dissolves all previous instances and sets the current instances to the new instances. Then notifies the listener of success.If any point, and instances errors, dissolves all newly loaded instances and notifies the listener. The current instances remains the same as before the function call.
- Parameters:
listener- The listener for the refresh
-
setNewInstances
@Titrates(what="New Instances") @StirsDeep(what="Previous Instances") private void setNewInstances(@Dilutes List<T> newInstances) Sets the new instances. Dissolves all previous instances and clears updates/deletions- Parameters:
newInstances- the new instances
-
dissolve
Removes references to all instances that have been created and clears the current instance- Specified by:
dissolvein interfaceDatabase.Dissolvable
-
onUpdate
public <S extends DatabaseInstance<S>> void onUpdate(@Observes DatabaseInstance<S> instance, Database.UpdateListener.Type type) - Specified by:
onUpdatein interfaceDatabase.UpdateListener
-
getCurrentInstances
- Returns:
- An unmodifiable list of the current instances loaded
-
getCollection
- Returns:
- The collection to which the instances belong
-
outOfDate
public boolean outOfDate()- Returns:
trueif one of the items in this query has been updated or deleted since the last refresh. Does not account for additions.
-
updateHasOccurred
public boolean updateHasOccurred()- Returns:
trueif one of the items in this query has been updated since the last refresh
-
deletionHasOccurred
public boolean deletionHasOccurred()- Returns:
trueif one of the items in this query has been deleted since the last refresh
-
getMyEventsFilter
@MustStir public static DatabaseQuery<EventAssociation> getMyEventsFilter(Database db, @Observes User u) -
getFacilityEvents
-
getMyNotifications
@MustStir public static DatabaseQuery<Notification> getMyNotifications(Database db, @Observes User u) -
getMyNotificationsQuery
-
getAttachedUsers
@MustStir public static DatabaseQuery<EventAssociation> getAttachedUsers(Database db, @Observes Event e, String status, boolean returnAll) - Parameters:
status- iF null or blank, returns all
-
getAttachedUsersQuery
-
getUsers
-
getEvents
-
getImages
-