public FormScan getTable(ResourceId formId) { FormScan scan = tableMap.get(formId); if(scan == null) { scan = new FormScan(columnFactory, formClassProvider.getFormClass(formId), formVersionProvider.getCurrentFormVersion(formId)); tableMap.put(formId, scan); } return scan; }
public Slot<ForeignKey> addForeignKey(FormulaNode referenceField, ResourceId rightFormId) { if(referenceField instanceof SymbolNode) { return addForeignKey(((SymbolNode) referenceField).getName(), rightFormId); } else { throw new UnsupportedOperationException("TODO: " + referenceField); } }
public boolean isEmpty() { return allQueriesResolved(); } }
/** * * Attempts to retrieve as many of the required columns and ForeignKeyMaps as needed from * Memcache * * @return true if everything could be retrieved from the cache, or false if there remain columns to * retrieve. */ public Set<String> getCacheKeys() { // If the collection cannot provide a cache version, then it is not safe to cache columns // from this collection if (cacheVersion == 0) { LOGGER.severe(() -> this.formId + " has zero-valued version."); return Collections.emptySet(); } // Otherwise, try to retrieve all of the ColumnView and ForeignKeyMaps we need // from the Memcache service Set<String> toFetch = new HashSet<>(); for (FieldComponent fieldId : columnMap.keySet()) { toFetch.add(fieldCacheKey(fieldId)); } for (ForeignKeyId fk : foreignKeyMap.keySet()) { toFetch.add(fkCacheKey(fk)); } if (rowCount != null) { toFetch.add(rowCountKey()); } return toFetch; }
public Map<String, Object> getValuesToCache() { Map<String, Object> toPut = new HashMap<>(); for (Map.Entry<FieldComponent, PendingSlot<ColumnView>> column : columnMap.entrySet()) { ColumnView value; try { value = column.getValue().get(); } catch (IllegalStateException e) { throw new IllegalStateException(column.getKey().toString(), e); } toPut.put(fieldCacheKey(column.getKey()), value); } for (Map.Entry<ForeignKeyId, PendingSlot<ForeignKey>> fk : foreignKeyMap.entrySet()) { toPut.put(fkCacheKey(fk.getKey()), fk.getValue().get()); } if(!columnMap.isEmpty()) { toPut.put(rowCountKey(), rowCountFromColumn(columnMap)); } else if(rowCount != null) { toPut.put(rowCountKey(), rowCount.get()); } return toPut; }
private void resolveFromCache(FormScanBatch batch) { Set<String> toFetch = new HashSet<>(); // Collect the keys we need from all enqueued tables for (FormScan formScan : batch.getScans()) { toFetch.addAll(formScan.getCacheKeys()); } if (!toFetch.isEmpty()) { Map<String, Object> cached = cache.getAll(toFetch); // Now populate the individual collection scans with what we got back from memcache // with a little luck nothing will be left to query directly from the database for (FormScan formScan : batch.getScans()) { formScan.updateFromCache(cached); } } }
if(allQueriesResolved()) { return; CursorObserver<FieldValue> fieldObserver = buildObserver(column.getKey(), column.getValue());
/** * Adds a ResourceId to the batch */ public Slot<ColumnView> addRecordIdColumn(FilterLevel filterLevel, ResourceId formId) { return filter(filterLevel, formId, getTable(formId).addResourceId()); }
public Slot<ColumnView> getDataColumn(FilterLevel filterLevel, ResourceId formId, FieldComponent match) { return filter(filterLevel, formId, getTable(formId).addField(match)); }
public Slot<Integer> addRowCount(FilterLevel filterLevel, ResourceId formId) { Slot<TableFilter> filter = getFilter(filterLevel, formId); Slot<Integer> countSlot = getTable(formId).addCount(); return new FilteredRowCountSlot(countSlot, filter); }
ColumnView view = (ColumnView) cached.get(fieldCacheKey(fieldId)); if (view != null) { ForeignKey map = (ForeignKey) cached.get(fkCacheKey(keyId)); if (map != null) { foreignKeyMap.get(keyId).set(map); Integer count = (Integer)cached.get(rowCountKey()); if(count != null) { rowCount.set(count);
private Slot<ForeignKey> addForeignKey(FilterLevel filterLevel, JoinNode node) { Slot<ForeignKey> foreignKey = getTable(node.getLeftFormId()).addForeignKey(node.getReferenceField(), node.getRightFormId()); Slot<TableFilter> filter = getFilter(filterLevel, node.getLeftFormId()); return new MemoizedSlot2<>(foreignKey, filter, new BiFunction<ForeignKey, TableFilter, ForeignKey>() { @Override public ForeignKey apply(ForeignKey foreignKey, TableFilter filter) { return filter.apply(foreignKey); } }); }
public void prepare(ColumnQueryBuilderV2 columnQueryBuilder) { if(allQueriesResolved()) { return;