/** * Unregister a {@link DataChangedNotifier} previously registered by * {@link #registerDataChangedNotifier(DataChangedNotifier)} * * @param notifier the DataChangedNotifier to unregister */ public void unregisterDataChangedNotifier(DataChangedNotifier<?> notifier) { if (notifier == null) { return; } synchronized (notifiersLock) { Collection<SqlTable<?>> tables = notifier.whichTables(); if (tables == null || tables.isEmpty()) { globalNotifiers.remove(notifier); } else { for (SqlTable<?> table : tables) { List<DataChangedNotifier<?>> notifiersForTable = tableNotifiers.get(table); if (notifiersForTable != null) { notifiersForTable.remove(notifier); } } } } }
final boolean onDataChanged(SqlTable<?> table, SquidDatabase database, DBOperation operation, AbstractModel modelValues, long rowId) { return enabled && accumulateNotificationObjects(notifyObjectAccumulator.get(), table, database, operation, modelValues, rowId); }
private void flushAccumulatedNotifications(boolean transactionSuccess) { Set<DataChangedNotifier<?>> accumulatedNotifiers = notifierAccumulator.get(); if (!accumulatedNotifiers.isEmpty()) { for (DataChangedNotifier<?> notifier : accumulatedNotifiers) { notifier.flushAccumulatedNotifications(this, transactionSuccess && dataChangedNotificationsEnabled); } accumulatedNotifiers.clear(); } }
final void flushAccumulatedNotifications(SquidDatabase database, boolean shouldSendNotifications) { Set<T> accumulatedNotifications = notifyObjectAccumulator.get(); if (enabled && shouldSendNotifications) { sendNotificationsToAll(database, accumulatedNotifications); } accumulatedNotifications.clear(); }
/** * The default implementation of this method iterates over the notifyObjects set and calls * {@link #sendNotification(SquidDatabase, Object)} for each of them. Subclasses may override if they want to * handle notifying the entire set differently. * * @param database the SquidDatabase the change occurred in * @param notifyObjects the objects to be used for sending a notification */ protected void sendNotificationsToAll(SquidDatabase database, Set<T> notifyObjects) { for (T notifyObject : notifyObjects) { sendNotification(database, notifyObject); } }
private void onDataChanged(List<DataChangedNotifier<?>> notifiers, DataChangedNotifier.DBOperation op, AbstractModel modelValues, SqlTable<?> table, long rowId) { if (notifiers != null) { for (DataChangedNotifier<?> notifier : notifiers) { if (notifier.onDataChanged(table, this, op, modelValues, rowId)) { notifierAccumulator.get().add(notifier); } } } }
final void flushAccumulatedNotifications(SquidDatabase database, boolean shouldSendNotifications) { Set<T> accumulatedNotifications = notifyObjectAccumulator.get(); if (enabled && shouldSendNotifications) { sendNotificationsToAll(database, accumulatedNotifications); } accumulatedNotifications.clear(); }
/** * The default implementation of this method iterates over the notifyObjects set and calls * {@link #sendNotification(SquidDatabase, Object)} for each of them. Subclasses may override if they want to * handle notifying the entire set differently. * * @param database the SquidDatabase the change occurred in * @param notifyObjects the objects to be used for sending a notification */ protected void sendNotificationsToAll(SquidDatabase database, Set<T> notifyObjects) { for (T notifyObject : notifyObjects) { sendNotification(database, notifyObject); } }
private void onDataChanged(List<DataChangedNotifier<?>> notifiers, DataChangedNotifier.DBOperation op, AbstractModel modelValues, SqlTable<?> table, long rowId) { if (notifiers != null) { for (DataChangedNotifier<?> notifier : notifiers) { if (notifier.onDataChanged(table, this, op, modelValues, rowId)) { notifierAccumulator.get().add(notifier); } } } }
/** * Register a {@link DataChangedNotifier} to listen for database changes. The DataChangedNotifier object will be * notified whenever a table it is interested is modified, and can accumulate a set of notifications to send when * the current transaction or statement completes successfully. * * @param notifier the DataChangedNotifier to register */ public void registerDataChangedNotifier(DataChangedNotifier<?> notifier) { if (notifier == null) { return; } synchronized (notifiersLock) { Collection<SqlTable<?>> tables = notifier.whichTables(); if (tables == null || tables.isEmpty()) { globalNotifiers.add(notifier); } else { for (SqlTable<?> table : tables) { List<DataChangedNotifier<?>> notifiersForTable = tableNotifiers.get(table); if (notifiersForTable == null) { notifiersForTable = new ArrayList<>(); tableNotifiers.put(table, notifiersForTable); } notifiersForTable.add(notifier); } } } }
private void flushAccumulatedNotifications(boolean transactionSuccess) { Set<DataChangedNotifier<?>> accumulatedNotifiers = notifierAccumulator.get(); if (!accumulatedNotifiers.isEmpty()) { for (DataChangedNotifier<?> notifier : accumulatedNotifiers) { notifier.flushAccumulatedNotifications(this, transactionSuccess && dataChangedNotificationsEnabled); } accumulatedNotifiers.clear(); } }
final boolean onDataChanged(SqlTable<?> table, SquidDatabase database, DBOperation operation, AbstractModel modelValues, long rowId) { return enabled && accumulateNotificationObjects(notifyObjectAccumulator.get(), table, database, operation, modelValues, rowId); }
private void testNotifierConstructorsInternal(DataChangedNotifier<?> notifier, SqlTable<?>... tables) { Set<SqlTable<?>> whichTables = notifier.whichTables(); assertEquals(tables.length, whichTables.size()); assertTrue(whichTables.containsAll(Arrays.asList(tables))); }
/** * Unregister a {@link DataChangedNotifier} previously registered by * {@link #registerDataChangedNotifier(DataChangedNotifier)} * * @param notifier the DataChangedNotifier to unregister */ public void unregisterDataChangedNotifier(DataChangedNotifier<?> notifier) { if (notifier == null) { return; } synchronized (notifiersLock) { Collection<SqlTable<?>> tables = notifier.whichTables(); if (tables == null || tables.isEmpty()) { globalNotifiers.remove(notifier); } else { for (SqlTable<?> table : tables) { List<DataChangedNotifier<?>> notifiersForTable = tableNotifiers.get(table); if (notifiersForTable != null) { notifiersForTable.remove(notifier); } } } } }
/** * Register a {@link DataChangedNotifier} to listen for database changes. The DataChangedNotifier object will be * notified whenever a table it is interested is modified, and can accumulate a set of notifications to send when * the current transaction or statement completes successfully. * * @param notifier the DataChangedNotifier to register */ public void registerDataChangedNotifier(DataChangedNotifier<?> notifier) { if (notifier == null) { return; } synchronized (notifiersLock) { Collection<SqlTable<?>> tables = notifier.whichTables(); if (tables == null || tables.isEmpty()) { globalNotifiers.add(notifier); } else { for (SqlTable<?> table : tables) { List<DataChangedNotifier<?>> notifiersForTable = tableNotifiers.get(table); if (notifiersForTable == null) { notifiersForTable = new ArrayList<>(); tableNotifiers.put(table, notifiersForTable); } notifiersForTable.add(notifier); } } } }