protected boolean filter(final ORecord iRecord, final OCommandContext iContext) { if (iRecord instanceof ODocument) { // CHECK THE TARGET CLASS final ODocument recordSchemaAware = (ODocument) iRecord; Map<String, String> targetClasses = parsedTarget.getTargetClasses(); // check only classes that specified in query will go to result set if ((targetClasses != null) && (!targetClasses.isEmpty())) { for (String targetClass : targetClasses.keySet()) { if (!((OMetadataDefault) getDatabase().getMetadata()) .getImmutableSchemaSnapshot() .getClass(targetClass) .isSuperClassOf(ODocumentInternal.getImmutableSchemaClass(recordSchemaAware))) return false; } iContext.updateMetric("documentAnalyzedCompatibleClass", +1); } } return evaluateRecord(iRecord, iContext); }
protected void searchInClusters() { final ODatabaseDocumentInternal database = getDatabase(); final Set<Integer> clusterIds = new HashSet<Integer>(); for (String clusterName : parsedTarget.getTargetClusters().keySet()) { if (clusterName == null || clusterName.length() == 0) throw new OCommandExecutionException("No cluster or schema class selected in query"); database.checkSecurity( ORule.ResourceGeneric.CLUSTER, ORole.PERMISSION_READ, clusterName.toLowerCase()); if (Character.isDigit(clusterName.charAt(0))) { // GET THE CLUSTER NUMBER for (int clusterId : OStringSerializerHelper.splitIntArray(clusterName)) { if (clusterId == -1) throw new OCommandExecutionException("Cluster '" + clusterName + "' not found"); clusterIds.add(clusterId); } } else { // GET THE CLUSTER NUMBER BY THE CLASS NAME final int clusterId = database.getClusterIdByName(clusterName.toLowerCase()); if (clusterId == -1) throw new OCommandExecutionException("Cluster '" + clusterName + "' not found"); clusterIds.add(clusterId); } } // CREATE CLUSTER AS ARRAY OF INT final int[] clIds = new int[clusterIds.size()]; int i = 0; for (int c : clusterIds) clIds[i++] = c; final ORID[] range = getRange(); target = new ORecordIteratorClusters<ORecord>(database, database, clIds) .setRange(range[0], range[1]); }
protected void searchInClasses(final boolean iAscendentOrder) { final String cls = parsedTarget.getTargetClasses().keySet().iterator().next(); target = searchInClasses( getDatabase().getMetadata().getSchema().getClass(cls), true, iAscendentOrder); }
/** * Assign the right TARGET if found. * * @param iArgs Parameters to bind * @return true if the target has been recognized, otherwise false */ protected boolean assignTarget(final Map<Object, Object> iArgs) { parameters = iArgs; if (parsedTarget == null) return true; if (iArgs != null && iArgs.size() > 0 && compiledFilter != null) compiledFilter.bindParameters(iArgs); if (target == null) { if (parsedTarget.getTargetClasses() != null) searchInClasses(); else if (parsedTarget.getTargetIndexValues() != null) { target = new IndexValuesIterator( parsedTarget.getTargetIndexValues(), parsedTarget.isTargetIndexValuesAsc()); } else if (parsedTarget.getTargetClusters() != null) searchInClusters(); else if (parsedTarget.getTargetRecords() != null) { if (!lazyIteration && parsedTarget.getTargetQuery() != null) { // EXECUTE THE QUERY TO ALLOW DISTRIB EXECUTION target = ((Iterable<? extends OIdentifiable>) getDatabase() .command(new OCommandSQL(parsedTarget.getTargetQuery())) .execute(iArgs)) .iterator(); } else if (parsedTarget.getTargetRecords() instanceof OIterableRecordSource) { target = ((OIterableRecordSource) parsedTarget.getTargetRecords()).iterator(iArgs); } else { target = parsedTarget.getTargetRecords().iterator(); } } else if (parsedTarget.getTargetVariable() != null) { final Object var = getContext().getVariable(parsedTarget.getTargetVariable()); if (var == null) { target = Collections.EMPTY_LIST.iterator(); return true; } else if (var instanceof OIdentifiable) { final ArrayList<OIdentifiable> list = new ArrayList<OIdentifiable>(); list.add((OIdentifiable) var); target = list.iterator(); } else if (var instanceof Iterable<?>) target = ((Iterable<? extends OIdentifiable>) var).iterator(); } else return false; } return true; }