public Object mergeResults(Map<String, Object> results) throws Exception { if (results.isEmpty()) return null; // TODO: DELEGATE MERGE AT EVERY COMMAND final ArrayList<Object> mergedResult = new ArrayList<Object>(); final Object firstResult = results.values().iterator().next(); for (Map.Entry<String, Object> entry : results.entrySet()) { final String nodeName = entry.getKey(); final Object nodeResult = entry.getValue(); if (nodeResult instanceof Collection) mergedResult.addAll((Collection<?>) nodeResult); else if (nodeResult instanceof Exception) // RECEIVED EXCEPTION throw (Exception) nodeResult; else mergedResult.add(nodeResult); } Object result = null; if (firstResult instanceof OResultSet) { // REUSE THE SAME RESULTSET TO AVOID DUPLICATES ((OResultSet) firstResult).clear(); ((OResultSet) firstResult).addAll(mergedResult); result = firstResult; } else result = new ArrayList<Object>(mergedResult); return result; }
public NugetApiKeyEntity findByPrimaryPrincipal( final ODatabaseDocumentTx db, final String principal) { final OResultSet<ODocument> resultSet = db.command(new OSQLSynchQuery<ODocument>(SELECT_BY_PRIMARY_PRINCIPAL)) .execute(checkNotNull(principal)); if (resultSet.isEmpty()) { return null; } return readEntity(resultSet.iterator().next()); }
@Nullable public NugetApiKeyEntity findByApiKey(final ODatabaseDocumentTx db, final char[] apiKey) { final OResultSet<ODocument> resultSet = db.command(new OSQLSynchQuery<ODocument>(SELECT_BY_API_KEY)) .execute(String.valueOf(checkNotNull(apiKey))); if (resultSet.isEmpty()) { return null; } return readEntity(resultSet.iterator().next()); }