public OSQLTarget parseTarget(final String iText, final OCommandContext iContext) { return new OSQLTarget(iText, iContext); }
public OSQLTarget(final String iText, final OCommandContext iContext) { super(); context = iContext; parserText = iText; parserTextUpperCase = upperCase(iText); try { empty = !extractTargets(); } catch (OQueryParsingException e) { if (e.getText() == null) // QUERY EXCEPTION BUT WITHOUT TEXT: NEST IT throw OException.wrapException( new OQueryParsingException("Error on parsing query", parserText, parserGetCurrentPosition()), e); throw e; } catch(OCommandExecutionException ex){ throw ex; }catch (Exception e) { throw OException.wrapException(new OQueryParsingException("Error on parsing query", parserText, parserGetCurrentPosition()), e); } }
@Override protected void throwSyntaxErrorException(String iText) { throw new OCommandSQLParsingException(iText + ". Use " + getSyntax(), parserText, parserGetPreviousPosition()); }
final ODatabaseDocument db = getDatabase(); if (parsedTarget.getTargetQuery() != null && parsedTarget .getTargetRecords() instanceof OCommandExecutorSQLResultsetDelegate) { final Set<String> clIds = ((OCommandExecutorSQLResultsetDelegate) parsedTarget.getTargetRecords()).getInvolvedClusters(); for (String c : clIds) { } else if (parsedTarget.getTargetRecords() != null) { for (OIdentifiable identifiable : parsedTarget.getTargetRecords()) { final String c = db.getClusterNameById(identifiable.getIdentity().getClusterId()).toLowerCase(Locale.ENGLISH); if (parsedTarget.getTargetClasses() != null) { return getInvolvedClustersOfClasses(parsedTarget.getTargetClasses().values()); if (parsedTarget.getTargetClusters() != null) { return getInvolvedClustersOfClusters(parsedTarget.getTargetClusters().keySet()); if (parsedTarget.getTargetIndex() != null) { return getInvolvedClustersOfIndex(parsedTarget.getTargetIndex());
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) { 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();
if (this.parsedTarget.getTargetClasses() != null) { for (String clazz : parsedTarget.getTargetClasses().keySet()) { if (docClass.isSubClassOf(clazz)) { return true; if (this.parsedTarget.getTargetRecords() != null) { for (OIdentifiable r : parsedTarget.getTargetRecords()) { if (r.getIdentity().equals(value.getIdentity())) { return true; if (this.parsedTarget.getTargetClusters() != null) { final String clusterName = execDb.getClusterNameById(value.getIdentity().getClusterId()); if (clusterName != null) { for (String cluster : parsedTarget.getTargetClusters().keySet()) { if (clusterName.equalsIgnoreCase(cluster)) {//make it case insensitive in 3.0? return true;
private boolean isRidOnlySort() { if (parsedTarget.getTargetClasses() != null && this.orderedFields.size() == 1 && this.orderedFields.get(0).getKey() .toLowerCase(Locale.ENGLISH).equals("@rid")) { if (this.target != null && target instanceof ORecordIteratorClass) { return true; } } return false; }
OSQLTarget target = new OSQLTarget(text, ctx); Iterable targetResult = (Iterable) target.getTargetRecords(); if (targetResult == null) { return null;
@Override protected boolean assignTarget(Map<Object, Object> iArgs) { if (!super.assignTarget(iArgs)) { if (parsedTarget.getTargetIndex() != null) { searchInIndex(); } else { throw new OQueryParsingException( "No source found in query: specify class, cluster(s), index or single record(s). Use " + getSyntax()); } } return true; }
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(Locale.ENGLISH)); 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(Locale.ENGLISH)); 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, clIds).setRange(range[0], range[1]); }
long count = 0; if (parsedTarget.getTargetClasses() != null) { final String className = parsedTarget.getTargetClasses().keySet().iterator().next(); final OClass cls = getDatabase().getMetadata().getImmutableSchemaSnapshot().getClass(className); count = cls.count(); } else if (parsedTarget.getTargetClusters() != null) { for (String cluster : parsedTarget.getTargetClusters().keySet()) { count += getDatabase().countClusterElements(cluster); } else if (parsedTarget.getTargetIndex() != null) { count += getDatabase().getMetadata().getIndexManager().getIndex(parsedTarget.getTargetIndex()).getSize(); } else { final Iterable<? extends OIdentifiable> recs = parsedTarget.getTargetRecords(); if (recs != null) { if (recs instanceof Collection<?>)
protected void searchInClasses(final boolean iAscendentOrder) { final String cls = parsedTarget.getTargetClasses().keySet().iterator().next(); target = searchInClasses(getDatabase().getMetadata().getSchema().getClass(cls), true, iAscendentOrder); }
private void searchInIndex() { final OIndex<Object> index = (OIndex<Object>) getDatabase().getMetadata().getIndexManager() .getIndex(parsedTarget.getTargetIndex()); throw new OCommandExecutionException("Target index '" + parsedTarget.getTargetIndex() + "' not found");
@Override protected void searchInClasses() { final String className = parsedTarget.getTargetClasses().keySet().iterator().next(); final OClass cls = getDatabase().getMetadata().getImmutableSchemaSnapshot().getClass(className); if (!searchForIndexes(cls) && !searchForSubclassIndexes(cls)) { // CHECK FOR INVERSE ORDER final boolean browsingOrderAsc = isBrowsingAscendingOrder(); super.searchInClasses(browsingOrderAsc); } }
private boolean isUsingRestrictedClasses() { boolean restrictedClasses = false; final OSecurityUser user = getDatabase().getUser(); if (parsedTarget.getTargetClasses() != null && user != null && user.checkIfAllowed(ORule.ResourceGeneric.BYPASS_RESTRICTED, null, ORole.PERMISSION_READ) == null) { for (String className : parsedTarget.getTargetClasses().keySet()) { final OClass cls = getDatabase().getMetadata().getImmutableSchemaSnapshot().getClass(className); if (cls.isSubClassOf(OSecurityShared.RESTRICTED_CLASSNAME)) { restrictedClasses = true; break; } } } return restrictedClasses; }
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); }