@Override public void delete(State state) { try { Profiler.Static.startThreadEvent(DELETE_EVENT_NAME, state); super.delete(state); } finally { Profiler.Static.stopThreadEvent(); } }
@Override public void saveUnsafely(State state) { try { Profiler.Static.startThreadEvent(SAVE_UNSAFELY_EVENT_NAME, state); super.saveUnsafely(state); } finally { Profiler.Static.stopThreadEvent(); } }
@Override public void index(State state) { try { Profiler.Static.startThreadEvent(INDEX_EVENT_NAME, state); super.index(state); } finally { Profiler.Static.stopThreadEvent(); } }
@Override public void deleteByQuery(Query<?> query) { try { startQueryEvent(DELETE_BY_QUERY_EVENT_NAME, query); super.deleteByQuery(query); } finally { Profiler.Static.stopThreadEvent(); } }
@Override public <T> List<T> readAll(Query<T> query) { List<T> result = null; try { startQueryEvent(READ_ALL_EVENT_NAME, query); result = super.readAll(query); return result; } finally { Profiler.Static.stopThreadEvent(result); } }
@Override public <T> PaginatedResult<T> readPartial(Query<T> query, long offset, int limit) { PaginatedResult<T> result = null; try { startQueryEvent(READ_PARTIAL_EVENT_NAME, query); result = super.readPartial(query, offset, limit); return result; } finally { Profiler.Static.stopThreadEvent(result); } }
@Override public Date readLastUpdate(Query<?> query) { Date result = null; try { startQueryEvent(READ_LAST_UPDATE_EVENT_NAME, query); result = super.readLastUpdate(query); return result; } finally { Profiler.Static.stopThreadEvent(result); } }
@Override public <T> Iterable<T> readIterable(Query<T> query, int fetchSize) { Iterable<T> result = null; try { startQueryEvent(READ_ITERABLE_EVENT_NAME, query); result = super.readIterable(query, fetchSize); return result; } finally { Profiler.Static.stopThreadEvent(result); } }
@Override public <T> T readFirst(Query<T> query) { T result = null; try { startQueryEvent(READ_FIRST_EVENT_NAME, query); result = super.readFirst(query); return result; } finally { Profiler.Static.stopThreadEvent(result); } }
@Override public long readCount(Query<?> query) { long result = -1; try { startQueryEvent(READ_COUNT_EVENT_NAME, query); result = super.readCount(query); return result; } finally { Profiler.Static.stopThreadEvent(result); } }
@Override public <T> List<Grouping<T>> readAllGrouped(Query<T> query, String... fields) { List<Grouping<T>> result = null; try { startQueryEvent(READ_ALL_GROUPED_EVENT_NAME, query); result = super.readAllGrouped(query, fields); return result; } finally { Profiler.Static.stopThreadEvent(result); } }
@Override public <T> PaginatedResult<Grouping<T>> readPartialGrouped( Query<T> query, long offset, int limit, String... fields) { PaginatedResult<Grouping<T>> result = null; try { startQueryEvent(READ_PARTIAL_GROUPED_EVENT_NAME, query); result = super.readPartialGrouped(query, offset, limit, fields); return result; } finally { Profiler.Static.stopThreadEvent(result); } }
private void startQueryEvent(String event, Query<?> query) { StackTraceElement caller = null; Profiler.Static.pauseThreadEvent(); try { StackTraceElement[] elements = new Throwable().getStackTrace(); for (int i = 2, length = elements.length; i < length; ++i) { StackTraceElement element = elements[i]; String className = element.getClassName(); Class<?> c = ObjectUtils.getClassByName(className); if (c == null || !(Database.class.isAssignableFrom(c) || Query.class.isAssignableFrom(c))) { caller = element; break; } } } finally { Profiler.Static.resumeThreadEvent(); } Object resolving = query.getOptions().get(State.REFERENCE_RESOLVING_QUERY_OPTION); if (resolving != null) { Profiler.Static.startThreadEvent( event + " (Reference Resolving)", resolving, query.getOptions().get(State.REFERENCE_FIELD_QUERY_OPTION), caller); } else { Profiler.Static.startThreadEvent(event, caller, query); } }