Skip to content

Instantly share code, notes, and snippets.

@kombadzomba
Created September 16, 2016 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kombadzomba/d60d8c2d76c828cd1c060e80d3ff6a05 to your computer and use it in GitHub Desktop.
Save kombadzomba/d60d8c2d76c828cd1c060e80d3ff6a05 to your computer and use it in GitHub Desktop.
public LinkedList<TerminEntity> getTerminByDateAndClientName(StaffEntity staff, Date startDate, Date endDate, String clientName) {
if (couchDbOrg == null) {
EventBus.getDefault().post(new DbNotInitializedEvent());
return new LinkedList<>();
}
synchronized (viewFactory.terminByClientNameView) {
TerminByClientNameView view = viewFactory.terminByClientNameView;
view.setDescending(true);
LinkedList<TerminEntity> results = (LinkedList<TerminEntity>) view.getData();
return new LinkedList(results);
}
}
public LinkedList<StaffEntity> getStaffAll() {
try {
if (couchDbOrg == null) {
EventBus.getDefault().post(new DbNotInitializedEvent());
return new LinkedList<>();
}
synchronized (viewFactory.staffByIdView) {
StaffByIdView view = viewFactory.staffByIdView;
view.setStartKey(null);
view.setEndKey(null);
LinkedList<StaffEntity> results = (LinkedList<StaffEntity>) view.getData();
Log.d(TAG, "Staff fetched - count = " + (results != null ? results.size() : 0));
return new LinkedList(results);
}
} catch (Exception ex) {
LogUtil.reportToDevelopers(ex);
return new LinkedList<>();
}
}
public ServiceEntity getServiceById(String id) {
try {
if (couchDbOrg == null) {
EventBus.getDefault().post(new DbNotInitializedEvent());
return null;
}
if (id == null) return null;
synchronized (viewFactory.serviceByIdView) {
ServiceByIdView view = viewFactory.serviceByIdView;
view.setStartKey(id);
view.setEndKey(id);
LinkedList<ServiceEntity> results = (LinkedList<ServiceEntity>) view.getData();
return results.isEmpty() ? null : results.get(0);
}
} catch (Exception ex) {
LogUtil.reportToDevelopers(ex);
return null;
}
}
public LinkedList<ServiceEntity> getServicesActiveAll() {
try {
if (couchDbOrg == null) {
EventBus.getDefault().post(new DbNotInitializedEvent());
return null;
}
synchronized (viewFactory.serviceActiveByNameView) {
ServiceActiveByNameView view = viewFactory.serviceActiveByNameView;
view.setStartKey(null);
view.setEndKey(null);
view.setDescending(false);
LinkedList<ServiceEntity> results = (LinkedList<ServiceEntity>) view.getData();
return new LinkedList(results);
}
} catch (Exception ex) {
LogUtil.reportToDevelopers(ex);
return new LinkedList<>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment