diff --git a/agent/src/main/java/com/orientechnologies/agent/services/backup/OBackupConfig.java b/agent/src/main/java/com/orientechnologies/agent/services/backup/OBackupConfig.java index 90364e92df4..81a04064651 100755 --- a/agent/src/main/java/com/orientechnologies/agent/services/backup/OBackupConfig.java +++ b/agent/src/main/java/com/orientechnologies/agent/services/backup/OBackupConfig.java @@ -29,13 +29,19 @@ import com.orientechnologies.common.log.OLogger; import com.orientechnologies.common.parser.OSystemVariableResolver; import com.orientechnologies.orient.core.exception.OConfigurationException; +import com.orientechnologies.orient.core.record.OElement; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.schedule.OCronExpression; +import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.server.handler.OAutomaticBackup; import java.io.File; import java.io.IOException; import java.text.ParseException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; /** Created by Enrico Risa on 22/03/16. */ public class OBackupConfig { @@ -200,10 +206,14 @@ public ODocument removeBackup(final String uuid) { } public OBackupStrategy strategy(final ODocument cfg, final OBackupLogger logger) { - final ODocument full = - (ODocument) cfg.eval(OBackupConfig.MODES + "." + OAutomaticBackup.MODE.FULL_BACKUP); - final ODocument incremental = - (ODocument) cfg.eval(OBackupConfig.MODES + "." + OAutomaticBackup.MODE.INCREMENTAL_BACKUP); + OResult fullRess = + ((OResult) cfg.eval(OBackupConfig.MODES + "." + OAutomaticBackup.MODE.FULL_BACKUP)); + final OElement full = fullRess != null ? fullRess.toElement() : null; + + OResult incrementRess = + ((OResult) cfg.eval(OBackupConfig.MODES + "." + OAutomaticBackup.MODE.INCREMENTAL_BACKUP)); + final OElement incremental = incrementRess != null ? incrementRess.toElement() : null; + OBackupStrategy strategy; if (full != null && incremental != null) { strategy = new OBackupStrategyMixBackup(cfg, logger); diff --git a/agent/src/main/java/com/orientechnologies/agent/services/backup/strategy/OBackupStrategyMixBackup.java b/agent/src/main/java/com/orientechnologies/agent/services/backup/strategy/OBackupStrategyMixBackup.java index 566947f9ddd..708a92a8977 100755 --- a/agent/src/main/java/com/orientechnologies/agent/services/backup/strategy/OBackupStrategyMixBackup.java +++ b/agent/src/main/java/com/orientechnologies/agent/services/backup/strategy/OBackupStrategyMixBackup.java @@ -20,13 +20,19 @@ import com.orientechnologies.agent.services.backup.OBackupConfig; import com.orientechnologies.agent.services.backup.OBackupListener; -import com.orientechnologies.agent.services.backup.log.*; +import com.orientechnologies.agent.services.backup.log.OBackupFinishedLog; +import com.orientechnologies.agent.services.backup.log.OBackupLog; +import com.orientechnologies.agent.services.backup.log.OBackupLogType; +import com.orientechnologies.agent.services.backup.log.OBackupLogger; +import com.orientechnologies.agent.services.backup.log.OBackupScheduledLog; import com.orientechnologies.common.log.OLogManager; import com.orientechnologies.common.log.OLogger; import com.orientechnologies.orient.core.db.ODatabaseInternal; import com.orientechnologies.orient.core.db.document.ODatabaseDocument; +import com.orientechnologies.orient.core.record.OElement; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.schedule.OCronExpression; +import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.storage.impl.local.paginated.OEnterpriseLocalPaginatedStorage; import com.orientechnologies.orient.server.handler.OAutomaticBackup; import java.io.File; @@ -97,13 +103,14 @@ protected String defaultPath() { public Date scheduleNextExecution(final OBackupListener listener) { final OBackupScheduledLog lastBackupSchedule = lastUnfiredSchedule(); if (lastBackupSchedule == null) { - final ODocument full = - (ODocument) cfg.eval(OBackupConfig.MODES + "." + OAutomaticBackup.MODE.FULL_BACKUP); - final String whenFull = full.field(OBackupConfig.WHEN); - final ODocument incremental = - (ODocument) - cfg.eval(OBackupConfig.MODES + "." + OAutomaticBackup.MODE.INCREMENTAL_BACKUP); - final String whenIncremental = incremental.field(OBackupConfig.WHEN); + final OElement full = + ((OResult) cfg.eval(OBackupConfig.MODES + "." + OAutomaticBackup.MODE.FULL_BACKUP)) + .toElement(); + final String whenFull = full.getProperty(OBackupConfig.WHEN); + final OElement incremental = + ((OResult) cfg.eval(OBackupConfig.MODES + "." + OAutomaticBackup.MODE.INCREMENTAL_BACKUP)) + .toElement(); + final String whenIncremental = incremental.getProperty(OBackupConfig.WHEN); try { final OCronExpression eFull = new OCronExpression(whenFull); final OCronExpression eIncremental = new OCronExpression(whenIncremental); diff --git a/core/src/main/java/com/orientechnologies/orient/core/command/script/OPolyglotScriptExecutor.java b/core/src/main/java/com/orientechnologies/orient/core/command/script/OPolyglotScriptExecutor.java index b7004a1fe29..46e1b6aa8d9 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/command/script/OPolyglotScriptExecutor.java +++ b/core/src/main/java/com/orientechnologies/orient/core/command/script/OPolyglotScriptExecutor.java @@ -9,6 +9,7 @@ import com.orientechnologies.orient.core.config.OGlobalConfiguration; import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal; +import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.metadata.function.OFunction; import com.orientechnologies.orient.core.metadata.security.ORole; import com.orientechnologies.orient.core.metadata.security.ORule; @@ -176,7 +177,7 @@ public Object executeFunction( } else if (result.hasArrayElements()) { final List array = new ArrayList<>((int) result.getArraySize()); for (int i = 0; i < result.getArraySize(); ++i) - array.add(new OResultInternal(result.getArrayElement(i).asHostObject())); + array.add(new OResultInternal((OIdentifiable) result.getArrayElement(i).asHostObject())); finalResult = array; } else if (result.isHostObject()) { finalResult = result.asHostObject(); diff --git a/core/src/main/java/com/orientechnologies/orient/core/command/script/transformer/OScriptTransformerImpl.java b/core/src/main/java/com/orientechnologies/orient/core/command/script/transformer/OScriptTransformerImpl.java index cfb63b827ec..263fadf3c8a 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/command/script/transformer/OScriptTransformerImpl.java +++ b/core/src/main/java/com/orientechnologies/orient/core/command/script/transformer/OScriptTransformerImpl.java @@ -55,7 +55,7 @@ public OResultSet toResultSet(Object value) { else if (v.hasArrayElements()) { final List array = new ArrayList<>((int) v.getArraySize()); for (int i = 0; i < v.getArraySize(); ++i) - array.add(new OResultInternal(v.getArrayElement(i).asHostObject())); + array.add(new OResultInternal((OIdentifiable) v.getArrayElement(i).asHostObject())); value = array; } else if (v.isHostObject()) value = v.asHostObject(); else if (v.isString()) value = v.asString(); diff --git a/core/src/main/java/com/orientechnologies/orient/core/metadata/schema/OClassImpl.java b/core/src/main/java/com/orientechnologies/orient/core/metadata/schema/OClassImpl.java index 68b6471ab46..57f3620a5bc 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/metadata/schema/OClassImpl.java +++ b/core/src/main/java/com/orientechnologies/orient/core/metadata/schema/OClassImpl.java @@ -1463,7 +1463,7 @@ protected void renameCluster(String oldName, String newName) { if (!hasClusterId(clusterId)) return; - database.command("alter cluster `" + oldName + "` NAME \"" + newName + "\"").close(); + database.command("alter cluster `" + oldName + "` NAME " + newName + "").close(); } protected void onlyAddPolymorphicClusterId(int clusterId) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/metadata/security/OSecurityEngine.java b/core/src/main/java/com/orientechnologies/orient/core/metadata/security/OSecurityEngine.java index 4b841fa4586..8d7ca829f67 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/metadata/security/OSecurityEngine.java +++ b/core/src/main/java/com/orientechnologies/orient/core/metadata/security/OSecurityEngine.java @@ -11,6 +11,7 @@ import com.orientechnologies.orient.core.record.ORecord; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.executor.OResult; +import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.parser.OAndBlock; import com.orientechnologies.orient.core.sql.parser.OBooleanExpression; import com.orientechnologies.orient.core.sql.parser.OOrBlock; @@ -430,7 +431,7 @@ static boolean evaluateSecuirtyPolicyPredicate( (inContext) -> { return user; }); - return predicate.evaluate(record, ctx); + return predicate.evaluate(new OResultInternal(record), ctx); })) .get(); } catch (Exception e) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/record/impl/ODocumentHelper.java b/core/src/main/java/com/orientechnologies/orient/core/record/impl/ODocumentHelper.java index a10612b77ac..9398d92676d 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/record/impl/ODocumentHelper.java +++ b/core/src/main/java/com/orientechnologies/orient/core/record/impl/ODocumentHelper.java @@ -48,6 +48,7 @@ import com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerStringAbstract; import com.orientechnologies.orient.core.sql.OSQLEngine; import com.orientechnologies.orient.core.sql.executor.OResult; +import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.parser.OExpression; import java.lang.reflect.Array; import java.text.DateFormat; @@ -519,13 +520,13 @@ else if (Character.isDigit(indexAsString.charAt(0))) for (Object v : OMultiValue.getMultiValueIterable(value)) { if (v instanceof OIdentifiable) { - Object result = pred.execute((OIdentifiable) v, iContext); + Object result = pred.execute(new OResultInternal((OIdentifiable) v), iContext); if (Boolean.TRUE.equals(result)) { values.add(v); } } else if (v instanceof Map) { - ODocument doc = new ODocument().fromMap((Map) v); - Object result = pred.execute(doc, iContext); + Object result = + pred.execute(new OResultInternal((Map) v), iContext); if (Boolean.TRUE.equals(result)) { values.add(v); } diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/OSQLEngine.java b/core/src/main/java/com/orientechnologies/orient/core/sql/OSQLEngine.java index 731827f3442..d9b4ef4174e 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/OSQLEngine.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/OSQLEngine.java @@ -36,7 +36,9 @@ import com.orientechnologies.orient.core.db.OrientDBInternal; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandInterruptedException; +import com.orientechnologies.orient.core.record.OElement; import com.orientechnologies.orient.core.sql.executor.OResult; +import com.orientechnologies.orient.core.sql.executor.OUpdatableResult; import com.orientechnologies.orient.core.sql.functions.OSQLFunction; import com.orientechnologies.orient.core.sql.functions.OSQLFunctionFactory; import com.orientechnologies.orient.core.sql.method.OSQLMethod; @@ -121,7 +123,7 @@ public static Object eval(String expression, Object target, OCommandContext ctx) if (predicate.isPresent()) { return predicate.get().evaluate(target, ctx); } else { - return parseExpression(expression).execute((OIdentifiable) target, ctx); + return parseExpression(expression).execute(new OUpdatableResult((OElement) target), ctx); } } diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/FetchFromVariableStep.java b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/FetchFromVariableStep.java index fb5f6cab010..70b67560cb0 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/FetchFromVariableStep.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/FetchFromVariableStep.java @@ -3,6 +3,7 @@ import com.orientechnologies.common.concur.OTimeoutException; import com.orientechnologies.common.exception.OException; import com.orientechnologies.orient.core.command.OCommandContext; +import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.id.ORID; import com.orientechnologies.orient.core.record.OElement; @@ -40,7 +41,9 @@ public OExecutionStream internalStart(OCommandContext ctx) throws OTimeoutExcept OExecutionStream.resultIterator(((OResultSet) src).stream().iterator()) .onClose((context) -> ((OResultSet) src).close()); } else if (src instanceof ORID) { - source = OExecutionStream.singleton(new OResultInternal(ctx.getDatabase().load((ORID) src))); + source = + OExecutionStream.singleton( + new OResultInternal((OIdentifiable) ctx.getDatabase().load((ORID) src))); } else if (src instanceof OElement) { source = OExecutionStream.singleton(new OResultInternal((OElement) src)); } else if (src instanceof OResult) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/MatchFieldTraverser.java b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/MatchFieldTraverser.java index 7438a75fcd1..aed89c719bb 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/MatchFieldTraverser.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/MatchFieldTraverser.java @@ -23,7 +23,10 @@ protected OExecutionStream traversePatternEdge( Object qR; try { // TODO check possible results! - qR = ((OFieldMatchPathItem) this.item).getExp().execute(startingPoint, iCommandContext); + qR = + ((OFieldMatchPathItem) this.item) + .getExp() + .execute(new OResultInternal(startingPoint), iCommandContext); } finally { iCommandContext.setCurrent(prevCurrent); } diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/OResultInternal.java b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/OResultInternal.java index 87cec64b1c2..bd3fe985e47 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/OResultInternal.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/OResultInternal.java @@ -39,6 +39,10 @@ public OResultInternal() { content = new LinkedHashMap<>(); } + public OResultInternal(Map c) { + content = c; + } + public OResultInternal(OIdentifiable ident) { setElement(ident); } diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/functions/math/OSQLFunctionEval.java b/core/src/main/java/com/orientechnologies/orient/core/sql/functions/math/OSQLFunctionEval.java index 8d86aa0f47a..87ff56fddea 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/functions/math/OSQLFunctionEval.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/functions/math/OSQLFunctionEval.java @@ -24,8 +24,8 @@ import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; -import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.OSQLEngine; +import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.parser.OExpression; import com.orientechnologies.orient.core.sql.parser.OOrBlock; import java.util.List; @@ -67,12 +67,11 @@ public Object execute( } } - final ODocument currentResult = iRecord instanceof ODocument ? (ODocument) iRecord : null; try { if (predicate != null) { - return predicate.evaluate(currentResult, iContext); + return predicate.evaluate(new OResultInternal(iRecord), iContext); } else { - return expression.execute(currentResult, iContext); + return expression.execute(new OResultInternal(iRecord), iContext); } } catch (ArithmeticException e) { logger.error("Division by 0", e); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterClassStatement.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterClassStatement.java index fc4ddacfcd9..6eb8567d50f 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterClassStatement.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterClassStatement.java @@ -4,10 +4,10 @@ import com.orientechnologies.common.exception.OException; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.index.OIndex; import com.orientechnologies.orient.core.metadata.schema.OClass; +import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.executor.resultset.OExecutionStream; import java.util.ArrayList; @@ -404,7 +404,7 @@ public OExecutionStream executeDDL(OCommandContext ctx) { case CUSTOM: Object value = null; if (customValue != null) { - value = customValue.execute((OIdentifiable) null, ctx); + value = customValue.execute((OResult) null, ctx); } if (value != null) { value = "" + value; diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterClusterStatement.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterClusterStatement.java index 7458b8a5909..2c2f1aa6d8c 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterClusterStatement.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterClusterStatement.java @@ -4,7 +4,6 @@ import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.OResultInternal; @@ -75,7 +74,7 @@ public OExecutionStream executeDDL(OCommandContext ctx) { List result = new ArrayList<>(); List clustersToUpdate = getClusters(ctx); - Object finalValue = attributeValue.execute((OIdentifiable) null, ctx); + Object finalValue = attributeValue.getDefaultAlias().getValue(); final com.orientechnologies.orient.core.storage.OCluster.ATTRIBUTES attribute = Arrays.stream(OCluster.ATTRIBUTES.values()) diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterDatabaseStatement.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterDatabaseStatement.java index 29e327ee523..0b2826cf84a 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterDatabaseStatement.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterDatabaseStatement.java @@ -6,7 +6,6 @@ import com.orientechnologies.orient.core.config.OStorageEntryConfiguration; import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; import com.orientechnologies.orient.core.db.ODatabaseSession; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.metadata.security.ORole; import com.orientechnologies.orient.core.metadata.security.ORule; import com.orientechnologies.orient.core.sql.executor.OResult; @@ -57,7 +56,7 @@ private OResult executeCustomAlter( } } } - Object finalValue = customPropertyValue.execute((OIdentifiable) null, ctx); + Object finalValue = customPropertyValue.execute((OResult) null, ctx); db.setCustom(customPropertyName.getStringValue(), finalValue); OResultInternal result = new OResultInternal(); @@ -76,7 +75,7 @@ private OResult executeSimpleAlter( ODatabaseDocumentInternal db = (ODatabaseDocumentInternal) ctx.getDatabase(); db.checkSecurity(ORule.ResourceGeneric.DATABASE, ORole.PERMISSION_UPDATE); Object oldValue = db.get(attribute); - Object finalValue = settingValue.execute((OIdentifiable) null, ctx); + Object finalValue = settingValue.execute((OResult) null, ctx); db.setInternal(attribute, finalValue); OResultInternal result = new OResultInternal(); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterPropertyStatement.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterPropertyStatement.java index ce00699c20b..96b2b75b84c 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterPropertyStatement.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterPropertyStatement.java @@ -5,11 +5,11 @@ import com.orientechnologies.common.exception.OException; import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.ODatabaseSession; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.metadata.schema.OProperty; import com.orientechnologies.orient.core.sql.OCommandSQLParsingException; +import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.executor.resultset.OExecutionStream; import java.util.Arrays; @@ -57,7 +57,7 @@ public OExecutionStream executeDDL(OCommandContext ctx) { if (customPropertyName != null) { String customName = customPropertyName.getStringValue(); Object oldValue = property.getCustom(customName); - Object finalValue = customPropertyValue.execute((OIdentifiable) null, ctx); + Object finalValue = customPropertyValue.execute((OResult) null, ctx); property.setCustom(customName, finalValue == null ? null : "" + finalValue); result.setProperty("operation", "alter property custom"); @@ -67,7 +67,7 @@ public OExecutionStream executeDDL(OCommandContext ctx) { } else { String setting = settingName.getStringValue(); boolean isCollate = setting.equalsIgnoreCase("collate"); - Object finalValue = settingValue.execute((OIdentifiable) null, ctx); + Object finalValue = settingValue.execute((OResult) null, ctx); if (finalValue == null && (setting.equalsIgnoreCase("name") || setting.equalsIgnoreCase("shortname") diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterSequenceStatement.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterSequenceStatement.java index e08cdadb09a..157dd17f85d 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterSequenceStatement.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAlterSequenceStatement.java @@ -6,11 +6,11 @@ import com.orientechnologies.common.log.OLogger; import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.exception.ODatabaseException; import com.orientechnologies.orient.core.metadata.sequence.OSequence; import com.orientechnologies.orient.core.metadata.sequence.SequenceOrderType; +import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.executor.resultset.OExecutionStream; import java.util.Map; @@ -55,21 +55,21 @@ public OExecutionStream executeDDL(OCommandContext ctx) { params.resetNull(); if (start != null) { - Object val = start.execute((OIdentifiable) null, ctx); + Object val = start.execute((OResult) null, ctx); if (!(val instanceof Number)) { throw new OCommandExecutionException("invalid start value for a sequence: " + val); } params.setStart(((Number) val).longValue()); } if (increment != null) { - Object val = increment.execute((OIdentifiable) null, ctx); + Object val = increment.execute((OResult) null, ctx); if (!(val instanceof Number)) { throw new OCommandExecutionException("invalid increment value for a sequence: " + val); } params.setIncrement(((Number) val).intValue()); } if (cache != null) { - Object val = cache.execute((OIdentifiable) null, ctx); + Object val = cache.execute((OResult) null, ctx); if (!(val instanceof Number)) { throw new OCommandExecutionException("invalid cache value for a sequence: " + val); } @@ -83,7 +83,7 @@ public OExecutionStream executeDDL(OCommandContext ctx) { params.setRecyclable(cyclic); } if (limitValue != null) { - Object val = limitValue.execute((OIdentifiable) null, ctx); + Object val = limitValue.execute((OResult) null, ctx); if (!(val instanceof Number)) { throw new OCommandExecutionException("invalid cache value for a sequence: " + val); } diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAndBlock.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAndBlock.java index efc6152f87d..facebf00d93 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAndBlock.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OAndBlock.java @@ -4,7 +4,6 @@ import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.metadata.OIndexCandidate; @@ -27,20 +26,6 @@ public OAndBlock(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - if (getSubBlocks() == null) { - return true; - } - - for (OBooleanExpression block : subBlocks) { - if (!block.evaluate(currentRecord, ctx)) { - return false; - } - } - return true; - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (getSubBlocks() == null) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArrayConcatExpression.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArrayConcatExpression.java index e7311310901..ce585a0414e 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArrayConcatExpression.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArrayConcatExpression.java @@ -4,7 +4,6 @@ import com.orientechnologies.common.collection.OMultiValue; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.sql.executor.AggregationContext; import com.orientechnologies.orient.core.sql.executor.OResult; @@ -85,14 +84,6 @@ public Object apply(Object left, Object right) { return result; } - public Object execute(OIdentifiable iCurrentRecord, OCommandContext ctx) { - Object result = childExpressions.get(0).execute(iCurrentRecord, ctx); - for (int i = 1; i < childExpressions.size(); i++) { - result = apply(result, childExpressions.get(i).execute(iCurrentRecord, ctx)); - } - return result; - } - public Object execute(OResult iCurrentRecord, OCommandContext ctx) { Object result = childExpressions.get(0).execute(iCurrentRecord, ctx); for (int i = 1; i < childExpressions.size(); i++) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArrayNumberSelector.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArrayNumberSelector.java index 811f14dad82..8373e5f16df 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArrayNumberSelector.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArrayNumberSelector.java @@ -3,7 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.OResultInternal; import java.util.Map; @@ -44,25 +43,6 @@ public void toGenericStatement(StringBuilder builder) { } } - public Integer getValue(OIdentifiable iCurrentRecord, Object iResult, OCommandContext ctx) { - Object result = null; - if (inputValue != null) { - result = inputValue.getValue(ctx.getInputParameters()); - } else if (expressionValue != null) { - result = expressionValue.execute(iCurrentRecord, ctx); - } else if (integer != null) { - result = integer; - } - - if (result == null) { - return null; - } - if (result instanceof Number) { - return ((Number) result).intValue(); - } - return null; - } - public Integer getValue(OResult iCurrentRecord, Object iResult, OCommandContext ctx) { Object result = null; if (inputValue != null) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArrayRangeSelector.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArrayRangeSelector.java index 8c7f9f0c7ab..8d381d7b876 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArrayRangeSelector.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArrayRangeSelector.java @@ -4,7 +4,6 @@ import com.orientechnologies.common.collection.OMultiValue; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.OResultInternal; @@ -76,46 +75,6 @@ public void toGenericStatement(StringBuilder builder) { } } - public Object execute(OIdentifiable iCurrentRecord, Object result, OCommandContext ctx) { - if (result == null) { - return null; - } - if (!OMultiValue.isMultiValue(result)) { - return null; - } - Integer lFrom = from; - if (fromSelector != null) { - lFrom = fromSelector.getValue(iCurrentRecord, result, ctx); - } - if (lFrom == null) { - lFrom = 0; - } - Integer lTo = to; - if (toSelector != null) { - lTo = toSelector.getValue(iCurrentRecord, result, ctx); - } - if (included) { - lTo++; - } - if (lFrom > lTo) { - return null; - } - Object[] arrayResult = OMultiValue.array(result); - - if (arrayResult == null || arrayResult.length == 0) { - return arrayResult; - } - lFrom = Math.max(lFrom, 0); - if (arrayResult.length < lFrom) { - return null; - } - lFrom = Math.min(lFrom, arrayResult.length - 1); - - lTo = Math.min(lTo, arrayResult.length); - - return Arrays.asList(Arrays.copyOfRange(arrayResult, lFrom, lTo)); - } - public Object execute(OResult iCurrentRecord, Object result, OCommandContext ctx) { if (result == null) { return null; diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArraySelector.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArraySelector.java index 04b335fc988..3698af4e0b2 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArraySelector.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArraySelector.java @@ -3,7 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.OResultInternal; import java.lang.reflect.Array; @@ -53,25 +52,6 @@ public void toGenericStatement(StringBuilder builder) { } } - public Object getValue(OIdentifiable iCurrentRecord, Object iResult, OCommandContext ctx) { - Object result = null; - if (inputParam != null) { - result = inputParam.getValue(ctx.getInputParameters()); - } else if (expression != null) { - result = expression.execute(iCurrentRecord, ctx); - } else if (integer != null) { - result = integer; - } - - if (result == null) { - return null; - } - if (result instanceof Number) { - return ((Number) result).intValue(); - } - return result; - } - public Object getValue(OResult iCurrentRecord, Object iResult, OCommandContext ctx) { Object result = null; if (inputParam != null) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArraySingleValuesSelector.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArraySingleValuesSelector.java index 78ccaab54db..9db71346733 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArraySingleValuesSelector.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OArraySingleValuesSelector.java @@ -4,7 +4,6 @@ import com.orientechnologies.common.collection.OMultiValue; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.record.OElement; import com.orientechnologies.orient.core.sql.executor.OResult; @@ -52,38 +51,6 @@ public void toGenericStatement(StringBuilder builder) { } } - public Object execute(OIdentifiable iCurrentRecord, Object iResult, OCommandContext ctx) { - List result = new ArrayList(); - for (OArraySelector item : items) { - Object index = item.getValue(iCurrentRecord, iResult, ctx); - if (index == null) { - return null; - } - - if (index instanceof Integer) { - result.add(OMultiValue.getValue(iResult, ((Integer) index).intValue())); - } else { - if (iResult instanceof Map) { - result.add(((Map) iResult).get(index)); - } else if (iResult instanceof OElement && index instanceof String) { - result.add(((OElement) iResult).getProperty((String) index)); - } else if (OMultiValue.isMultiValue(iResult)) { - Iterator iter = OMultiValue.getMultiValueIterator(iResult); - while (iter.hasNext()) { - result.add(calculateValue(iter.next(), index)); - } - } else { - result.add(null); - } - } - if (this.items.size() == 1 && result.size() == 1) { - // if (this.items.size() == 1) { - return result.get(0); - } - } - return result; - } - public Object execute(OResult iCurrentRecord, Object iResult, OCommandContext ctx) { List result = new ArrayList(); for (OArraySelector item : items) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBaseExpression.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBaseExpression.java index aa8ed23c080..90cc3cba21f 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBaseExpression.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBaseExpression.java @@ -101,25 +101,6 @@ public void toGenericStatement(StringBuilder builder) { } } - public Object execute(OIdentifiable iCurrentRecord, OCommandContext ctx) { - Object result = null; - if (number != null) { - result = number.getValue(); - } else if (identifier != null) { - result = identifier.execute(iCurrentRecord, ctx); - } else if (string != null && string.length() > 1) { - result = OStringSerializerHelper.decode(string.substring(1, string.length() - 1)); - } else if (inputParam != null) { - result = inputParam.getValue(ctx.getInputParameters()); - } - - if (modifier != null) { - result = modifier.execute(iCurrentRecord, result, ctx); - } - - return result; - } - public Object execute(OResult iCurrentRecord, OCommandContext ctx) { Object result = null; if (number != null) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBaseIdentifier.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBaseIdentifier.java index 677cc1a5da0..a8094e3adff 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBaseIdentifier.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBaseIdentifier.java @@ -55,16 +55,6 @@ public void toGenericStatement(StringBuilder builder) { } } - public Object execute(OIdentifiable iCurrentRecord, OCommandContext ctx) { - if (levelZero != null) { - return levelZero.execute(iCurrentRecord, ctx); - } - if (suffix != null) { - return suffix.execute(iCurrentRecord, ctx); - } - return null; - } - public Object execute(OResult iCurrentRecord, OCommandContext ctx) { if (levelZero != null) { return levelZero.execute(iCurrentRecord, ctx); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBetweenCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBetweenCondition.java index d84dab815ed..f0609873f54 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBetweenCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBetweenCondition.java @@ -3,7 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.metadata.schema.OType; import com.orientechnologies.orient.core.sql.executor.OIndexSearchInfo; @@ -28,32 +27,6 @@ public OBetweenCondition(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - Object firstValue = first.execute(currentRecord, ctx); - if (firstValue == null) { - return false; - } - - Object secondValue = second.execute(currentRecord, ctx); - if (secondValue == null) { - return false; - } - - secondValue = OType.convert(secondValue, firstValue.getClass()); - - Object thirdValue = third.execute(currentRecord, ctx); - if (thirdValue == null) { - return false; - } - thirdValue = OType.convert(thirdValue, firstValue.getClass()); - - final int leftResult = ((Comparable) firstValue).compareTo(secondValue); - final int rightResult = ((Comparable) firstValue).compareTo(thirdValue); - - return leftResult >= 0 && rightResult <= 0; - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBinaryCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBinaryCondition.java index 40dbba9733b..6f32924b7eb 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBinaryCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBinaryCondition.java @@ -36,12 +36,6 @@ public OBinaryCondition(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - return operator.execute( - left.execute(currentRecord, ctx), right.execute(currentRecord, ctx), ctx); - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (left.isFunctionAny()) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBooleanExpression.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBooleanExpression.java index d4c5f754b9d..ec94e18f0d4 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBooleanExpression.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OBooleanExpression.java @@ -3,7 +3,6 @@ import com.orientechnologies.common.exception.OException; import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.sql.executor.OIndexSearchInfo; @@ -22,10 +21,6 @@ public abstract class OBooleanExpression extends SimpleNode { public static final OBooleanExpression TRUE = new OBooleanExpression(0) { - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - return true; - } @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { @@ -105,10 +100,6 @@ public boolean isAlwaysTrue() { public static final OBooleanExpression FALSE = new OBooleanExpression(0) { - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - return false; - } @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { @@ -189,8 +180,6 @@ public OBooleanExpression(OrientSql p, int id) { super(p, id); } - public abstract boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx); - public abstract boolean evaluate(OResult currentRecord, OCommandContext ctx); /** diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OCollection.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OCollection.java index a071e867103..80beebcc2df 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OCollection.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OCollection.java @@ -3,7 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.OResultInternal; @@ -55,14 +54,6 @@ public void add(OExpression exp) { this.expressions.add(exp); } - public Object execute(OIdentifiable iCurrentRecord, OCommandContext ctx) { - List result = new ArrayList(); - for (OExpression exp : expressions) { - result.add(exp.execute(iCurrentRecord, ctx)); - } - return result; - } - public Object execute(OResult iCurrentRecord, OCommandContext ctx) { List result = new ArrayList(); for (OExpression exp : expressions) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OConsoleStatement.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OConsoleStatement.java index df253e59ff3..e9e4cd5a270 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OConsoleStatement.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OConsoleStatement.java @@ -5,8 +5,8 @@ import com.orientechnologies.common.log.OLogManager; import com.orientechnologies.common.log.OLogger; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; +import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.executor.resultset.OExecutionStream; import java.util.Map; @@ -27,7 +27,7 @@ public OConsoleStatement(OrientSql p, int id) { @Override public OExecutionStream executeSimple(OCommandContext ctx) { OResultInternal item = new OResultInternal(); - Object msg = "" + message.execute((OIdentifiable) null, ctx); + Object msg = "" + message.execute((OResult) null, ctx); if (logLevel.getStringValue().equalsIgnoreCase("log")) { logger.info("%s", msg); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsAllCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsAllCondition.java index 29faf74b9fd..0c267172ac2 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsAllCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsAllCondition.java @@ -6,6 +6,7 @@ import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.sql.executor.OResult; +import com.orientechnologies.orient.core.sql.executor.OResultInternal; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -90,35 +91,6 @@ public boolean execute(Object left, Object right) { return false; } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - Object leftValue = left.execute(currentRecord, ctx); - if (right != null) { - Object rightValue = right.execute(currentRecord, ctx); - return execute(leftValue, rightValue); - } else { - if (!OMultiValue.isMultiValue(leftValue)) { - return false; - } - Iterator iter = OMultiValue.getMultiValueIterator(leftValue); - while (iter.hasNext()) { - Object item = iter.next(); - if (item instanceof OIdentifiable) { - if (!rightBlock.evaluate((OIdentifiable) item, ctx)) { - return false; - } - } else if (item instanceof OResult) { - if (!rightBlock.evaluate((OResult) item, ctx)) { - return false; - } - } else { - return false; - } - } - return true; - } - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (left.isFunctionAny()) { @@ -165,7 +137,7 @@ private boolean evaluateSingle(Object leftValue, OResult currentRecord, OCommand while (iter.hasNext()) { Object item = iter.next(); if (item instanceof OIdentifiable) { - if (!rightBlock.evaluate((OIdentifiable) item, ctx)) { + if (!rightBlock.evaluate(new OResultInternal((OIdentifiable) item), ctx)) { return false; } } else if (item instanceof OResult) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsAnyCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsAnyCondition.java index f3455e255f2..f9c2a26b256 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsAnyCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsAnyCondition.java @@ -8,6 +8,7 @@ import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.sql.executor.OIndexSearchInfo; import com.orientechnologies.orient.core.sql.executor.OResult; +import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.executor.metadata.OIndexCandidate; import com.orientechnologies.orient.core.sql.executor.metadata.OIndexFinder; import com.orientechnologies.orient.core.sql.executor.metadata.OPath; @@ -92,35 +93,6 @@ public boolean execute(Object left, Object right) { return false; } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - Object leftValue = left.execute(currentRecord, ctx); - if (right != null) { - Object rightValue = right.execute(currentRecord, ctx); - return execute(leftValue, rightValue); - } else { - if (!OMultiValue.isMultiValue(leftValue)) { - return false; - } - Iterator iter = OMultiValue.getMultiValueIterator(leftValue); - while (iter.hasNext()) { - Object item = iter.next(); - if (item instanceof OIdentifiable) { - if (!rightBlock.evaluate((OIdentifiable) item, ctx)) { - return false; - } - } else if (item instanceof OResult) { - if (!rightBlock.evaluate((OResult) item, ctx)) { - return false; - } - } else { - return false; - } - } - return true; - } - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { Object leftValue = left.execute(currentRecord, ctx); @@ -135,7 +107,7 @@ public boolean evaluate(OResult currentRecord, OCommandContext ctx) { while (iter.hasNext()) { Object item = iter.next(); if (item instanceof OIdentifiable) { - if (!rightBlock.evaluate((OIdentifiable) item, ctx)) { + if (!rightBlock.evaluate(new OResultInternal((OIdentifiable) item), ctx)) { return false; } } else if (item instanceof OResult) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsCondition.java index 1813f00c1af..b41d128c0dd 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsCondition.java @@ -132,29 +132,6 @@ private boolean equalsInContainsSpace(Object left, Object right) { } } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - Object leftValue = left.execute(currentRecord, ctx); - if (right != null) { - Object rightValue = right.execute(currentRecord, ctx); - return execute(leftValue, rightValue); - } else { - if (!OMultiValue.isMultiValue(leftValue)) { - return false; - } - Iterator iter = OMultiValue.getMultiValueIterator(leftValue); - while (iter.hasNext()) { - Object item = iter.next(); - if (item instanceof OIdentifiable && condition.evaluate((OIdentifiable) item, ctx)) { - return true; - } else if (item instanceof OResult && condition.evaluate((OResult) item, ctx)) { - return true; - } - } - return false; - } - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (left.isFunctionAny()) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsTextCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsTextCondition.java index cd3afb40120..91e6ecc3cd7 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsTextCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsTextCondition.java @@ -3,7 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.metadata.OIndexCandidate; import com.orientechnologies.orient.core.sql.executor.metadata.OIndexFinder; @@ -27,20 +26,6 @@ public OContainsTextCondition(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - Object leftValue = left.execute(currentRecord, ctx); - if (leftValue == null || !(leftValue instanceof String)) { - return false; - } - Object rightValue = right.execute(currentRecord, ctx); - if (rightValue == null || !(rightValue instanceof String)) { - return false; - } - - return ((String) leftValue).indexOf((String) rightValue) > -1; - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (left.isFunctionAny()) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsValueCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsValueCondition.java index 92851f5c00f..1f29dc1fc61 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsValueCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OContainsValueCondition.java @@ -3,7 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.sql.executor.OIndexSearchInfo; import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.metadata.OIndexCandidate; @@ -30,26 +29,6 @@ public OContainsValueCondition(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - Object leftValue = left.execute(currentRecord, ctx); - if (leftValue instanceof Map) { - Map map = (Map) leftValue; - if (condition != null) { - for (Object o : map.values()) { - if (condition.evaluate(o, ctx)) { - return true; - } - } - return false; - } else { - Object rightValue = expression.execute(currentRecord, ctx); - return map.values().contains(rightValue); // TODO type conversions...? - } - } - return false; - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (left.isFunctionAny()) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OCreatePropertyAttributeStatement.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OCreatePropertyAttributeStatement.java index dda982dad81..a4b9744a9be 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OCreatePropertyAttributeStatement.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OCreatePropertyAttributeStatement.java @@ -4,9 +4,9 @@ import com.orientechnologies.common.exception.OException; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.metadata.schema.OPropertyImpl; +import com.orientechnologies.orient.core.sql.executor.OResult; import java.util.Map; public class OCreatePropertyAttributeStatement extends SimpleNode { @@ -71,7 +71,7 @@ public int hashCode() { public Object setOnProperty(OPropertyImpl internalProp, OCommandContext ctx) { String attrName = settingName.getStringValue(); Object attrValue = - this.settingValue == null ? true : this.settingValue.execute((OIdentifiable) null, ctx); + this.settingValue == null ? true : this.settingValue.execute((OResult) null, ctx); try { if (attrName.equalsIgnoreCase("readonly")) { internalProp.setReadonly((boolean) attrValue); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OCreateSequenceStatement.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OCreateSequenceStatement.java index c4ad84dfb50..83c92d2b7be 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OCreateSequenceStatement.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OCreateSequenceStatement.java @@ -5,10 +5,10 @@ import com.orientechnologies.common.log.OLogManager; import com.orientechnologies.common.log.OLogger; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.metadata.sequence.OSequence; import com.orientechnologies.orient.core.metadata.sequence.SequenceOrderType; +import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.executor.resultset.OExecutionStream; import java.util.Map; @@ -85,7 +85,7 @@ private void executeInternal(OCommandContext ctx, OResultInternal result) private OSequence.CreateParams createParams(OCommandContext ctx, OResultInternal result) { OSequence.CreateParams params = new OSequence.CreateParams(); if (start != null) { - Object o = start.execute((OIdentifiable) null, ctx); + Object o = start.execute((OResult) null, ctx); if (o instanceof Number) { params.setStart(((Number) o).longValue()); result.setProperty("start", o); @@ -94,7 +94,7 @@ private OSequence.CreateParams createParams(OCommandContext ctx, OResultInternal } } if (increment != null) { - Object o = increment.execute((OIdentifiable) null, ctx); + Object o = increment.execute((OResult) null, ctx); if (o instanceof Number) { params.setIncrement(((Number) o).intValue()); result.setProperty("increment", o); @@ -103,7 +103,7 @@ private OSequence.CreateParams createParams(OCommandContext ctx, OResultInternal } } if (cache != null) { - Object o = cache.execute((OIdentifiable) null, ctx); + Object o = cache.execute((OResult) null, ctx); if (o instanceof Number) { params.setCacheSize(((Number) o).intValue()); result.setProperty("cacheSize", o); @@ -113,7 +113,7 @@ private OSequence.CreateParams createParams(OCommandContext ctx, OResultInternal } if (limitValue != null) { - Object o = limitValue.execute((OIdentifiable) null, ctx); + Object o = limitValue.execute((OResult) null, ctx); if (o instanceof Number) { params.setLimitValue(((Number) o).longValue()); result.setProperty("limitValue", o); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OExpression.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OExpression.java index 10ee2d3218a..274d4bbbe1c 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OExpression.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OExpression.java @@ -51,48 +51,6 @@ public OExpression(ORecordAttribute attr, OModifier modifier) { mathExpression = new OBaseExpression(attr, modifier); } - public Object execute(OIdentifiable iCurrentRecord, OCommandContext ctx) { - if (isNull) { - return null; - } - if (rid != null) { - return rid.toRecordId(iCurrentRecord, ctx); - } - if (mathExpression != null) { - return mathExpression.execute(iCurrentRecord, ctx); - } - if (arrayConcatExpression != null) { - return arrayConcatExpression.execute(iCurrentRecord, ctx); - } - if (json != null) { - return json.toObjectDetermineType(iCurrentRecord, ctx); - } - if (booleanValue != null) { - return booleanValue; - } - if (value instanceof ONumber) { - return ((ONumber) value).getValue(); // only for old executor (manually replaced params) - } - - // from here it's old stuff, only for the old executor - if (value instanceof ORid) { - ORid v = (ORid) value; - return new ORecordId(v.cluster.getValue().intValue(), v.position.getValue().longValue()); - } else if (value instanceof OMathExpression) { - return ((OMathExpression) value).execute(iCurrentRecord, ctx); - } else if (value instanceof OArrayConcatExpression) { - return ((OArrayConcatExpression) value).execute(iCurrentRecord, ctx); - } else if (value instanceof OJson) { - return ((OJson) value).toMap(iCurrentRecord, ctx); - } else if (value instanceof String) { - return value; - } else if (value instanceof Number) { - return value; - } - - return value; - } - public Object execute(OResult iCurrentRecord, OCommandContext ctx) { if (isNull) { return null; diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OFieldMatchPathItem.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OFieldMatchPathItem.java index d49c75bb830..5e17ffb91c2 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OFieldMatchPathItem.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OFieldMatchPathItem.java @@ -5,6 +5,7 @@ import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.record.impl.ODocument; +import com.orientechnologies.orient.core.sql.executor.OResultInternal; import java.util.Collections; import java.util.Map; import java.util.Objects; @@ -67,7 +68,7 @@ protected Iterable traversePatternEdge( exp = new OSuffixIdentifier(field); } // TODO check possible results! - Object qR = this.exp.execute(startingPoint, iCommandContext); + Object qR = this.exp.execute(new OResultInternal(startingPoint), iCommandContext); return (qR instanceof Iterable && !(qR instanceof ODocument)) ? (Iterable) qR : Collections.singleton((OIdentifiable) qR); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OFunctionCall.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OFunctionCall.java index 0513ce6deea..d1a893b45b2 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OFunctionCall.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OFunctionCall.java @@ -90,22 +90,18 @@ public void toGenericStatement(StringBuilder builder) { builder.append(")"); } - public Object execute(Object targetObjects, OCommandContext ctx) { + public Object execute(OResult targetObjects, OCommandContext ctx) { return execute(targetObjects, ctx, name.getStringValue()); } - private Object execute(Object targetObjects, OCommandContext ctx, String name) { + private Object execute(OResult targetObjects, OCommandContext ctx, String name) { List paramValues = new ArrayList(); Object record = null; if (record == null) { - if (targetObjects instanceof OIdentifiable) { - record = (OIdentifiable) targetObjects; - } else if (targetObjects instanceof OResult) { + if (targetObjects != null) { record = ((OResult) targetObjects).toElement(); - } else { - record = targetObjects; } } if (record == null) { @@ -118,7 +114,7 @@ record = ((OResult) current).toElement(); if (targetObjects instanceof OResult) { paramValues.add(expr.execute((OResult) targetObjects, ctx)); } else if (record instanceof OIdentifiable) { - paramValues.add(expr.execute((OIdentifiable) record, ctx)); + paramValues.add(expr.execute(new OResultInternal((OIdentifiable) record), ctx)); } else if (record instanceof OResult) { paramValues.add(expr.execute((OResult) record, ctx)); } else if (record == null) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OInCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OInCondition.java index c4d46385065..774d8e7ed3c 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OInCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OInCondition.java @@ -5,7 +5,6 @@ import com.orientechnologies.common.collection.OMultiValue; import com.orientechnologies.orient.core.command.OBasicCommandContext; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.sql.executor.OIndexSearchInfo; import com.orientechnologies.orient.core.sql.executor.OResult; @@ -39,32 +38,6 @@ public OInCondition(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - Object leftVal = evaluateLeft(currentRecord, ctx); - Object rightVal = evaluateRight(currentRecord, ctx); - if (rightVal == null) { - return false; - } - return evaluateExpression(leftVal, rightVal); - } - - public Object evaluateRight(OIdentifiable currentRecord, OCommandContext ctx) { - Object rightVal = null; - if (rightStatement != null) { - rightVal = executeQuery(rightStatement, ctx); - } else if (rightParam != null) { - rightVal = rightParam.getValue(ctx.getInputParameters()); - } else if (rightMathExpression != null) { - rightVal = rightMathExpression.execute(currentRecord, ctx); - } - return rightVal; - } - - public Object evaluateLeft(OIdentifiable currentRecord, OCommandContext ctx) { - return left.execute(currentRecord, ctx); - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { Object rightVal = evaluateRight(currentRecord, ctx); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OInstanceofCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OInstanceofCondition.java index 42cca513886..e72607f1dc0 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OInstanceofCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OInstanceofCondition.java @@ -3,7 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.record.ORecord; import com.orientechnologies.orient.core.record.impl.ODocument; @@ -29,31 +28,6 @@ public OInstanceofCondition(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - if (currentRecord == null) { - return false; - } - ORecord record = currentRecord.getRecord(); - if (record == null) { - return false; - } - if (!(record instanceof ODocument)) { - return false; - } - ODocument doc = (ODocument) record; - OClass clazz = ODocumentInternal.getImmutableSchemaClass(doc); - if (clazz == null) { - return false; - } - if (right != null) { - return clazz.isSubClassOf(right.getStringValue()); - } else if (rightString != null) { - return clazz.isSubClassOf(decode(rightString)); - } - return false; - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (currentRecord == null) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsDefinedCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsDefinedCondition.java index 666ab416f83..b8972abe613 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsDefinedCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsDefinedCondition.java @@ -3,8 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; -import com.orientechnologies.orient.core.record.OElement; import com.orientechnologies.orient.core.sql.executor.OResult; import java.util.Collections; import java.util.List; @@ -23,15 +21,6 @@ public OIsDefinedCondition(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - Object elem = currentRecord.getRecord(); - if (elem instanceof OElement) { - return expression.isDefinedFor((OElement) elem); - } - return false; - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (expression.isFunctionAny()) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsNotDefinedCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsNotDefinedCondition.java index b4f09ffb604..e20519f8817 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsNotDefinedCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsNotDefinedCondition.java @@ -3,8 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; -import com.orientechnologies.orient.core.record.OElement; import com.orientechnologies.orient.core.sql.executor.OResult; import java.util.Collections; import java.util.List; @@ -23,15 +21,6 @@ public OIsNotDefinedCondition(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - Object elem = currentRecord.getRecord(); - if (elem instanceof OElement) { - return !expression.isDefinedFor((OElement) elem); - } - return true; - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (expression.isFunctionAny() || expression.isFunctionAll()) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsNotNullCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsNotNullCondition.java index 51b837607d8..9303ab56a3d 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsNotNullCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsNotNullCondition.java @@ -3,7 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.sql.executor.OResult; import java.util.Collections; import java.util.List; @@ -22,11 +21,6 @@ public OIsNotNullCondition(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - return expression.execute(currentRecord, ctx) != null; - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (expression.isFunctionAny()) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsNullCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsNullCondition.java index 44e8b4150e9..e211bac7f1d 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsNullCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OIsNullCondition.java @@ -3,7 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.sql.executor.OIndexSearchInfo; import com.orientechnologies.orient.core.sql.executor.OResult; import java.util.Collections; @@ -23,11 +22,6 @@ public OIsNullCondition(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - return expression.execute(currentRecord, ctx) == null; - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (expression.isFunctionAny()) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OJson.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OJson.java index f7d934b7343..8869d9437e7 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OJson.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OJson.java @@ -5,13 +5,11 @@ import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.metadata.schema.OType; -import com.orientechnologies.orient.core.record.OElement; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.record.impl.ODocumentHelper; import com.orientechnologies.orient.core.serialization.serializer.record.string.OFieldTypesString; import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.OResultInternal; -import com.orientechnologies.orient.core.sql.executor.OUpdatableResult; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -77,7 +75,7 @@ public ODocument toDocument(OIdentifiable source, OCommandContext ctx) { if (item.right.value instanceof OJson) { value = ((OJson) item.right.value).toDocument(source, ctx); } else { - value = item.right.execute(source, ctx); + value = item.right.execute(new OResultInternal(source), ctx); } doc.field(name, value); } @@ -136,34 +134,6 @@ public Object toObjectDetermineType(OResult source, OCommandContext ctx) { } } - public Object toObjectDetermineType(OIdentifiable source, OCommandContext ctx) { - String className = getClassNameForDocument(ctx); - String type = getTypeForDocument(ctx); - if (className != null || (type != null && "d".equalsIgnoreCase(type))) { - OUpdatableResult element = null; - if (source != null) { - element = new OUpdatableResult((OElement) ctx.getDatabase().load(source.getIdentity())); - } - return toDocument(element, ctx, className); - } else { - return toMap(source, ctx); - } - } - - public Map toMap(OIdentifiable source, OCommandContext ctx) { - Map doc = new LinkedHashMap(); - for (OJsonItem item : items) { - String name = item.getLeftValue(); - if (name == null) { - continue; - } - Object value = item.right.execute(source, ctx); - doc.put(name, value); - } - - return doc; - } - public Map toMap(OResult source, OCommandContext ctx) { Map doc = new LinkedHashMap(); for (OJsonItem item : items) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OLevelZeroIdentifier.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OLevelZeroIdentifier.java index f6e110b74c2..731ad65b3b1 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OLevelZeroIdentifier.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OLevelZeroIdentifier.java @@ -44,19 +44,6 @@ public void toGenericStatement(StringBuilder builder) { } } - public Object execute(OIdentifiable iCurrentRecord, OCommandContext ctx) { - if (functionCall != null) { - return functionCall.execute(iCurrentRecord, ctx); - } - if (collection != null) { - return collection.execute(iCurrentRecord, ctx); - } - if (Boolean.TRUE.equals(self)) { - return iCurrentRecord; - } - throw new UnsupportedOperationException(); - } - public Object execute(OResult iCurrentRecord, OCommandContext ctx) { if (functionCall != null) { return functionCall.execute(iCurrentRecord, ctx); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMatchPathItemFirst.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMatchPathItemFirst.java index f8bd59abf1c..0d772643a33 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMatchPathItemFirst.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMatchPathItemFirst.java @@ -2,6 +2,7 @@ import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.record.OIdentifiable; +import com.orientechnologies.orient.core.sql.executor.OResultInternal; import java.util.Collections; import java.util.Map; @@ -41,7 +42,7 @@ protected Iterable traversePatternEdge( OMatchStatement.MatchContext matchContext, OIdentifiable startingPoint, OCommandContext iCommandContext) { - Object qR = this.function.execute(startingPoint, iCommandContext); + Object qR = this.function.execute(new OResultInternal(startingPoint), iCommandContext); return (qR instanceof Iterable) ? (Iterable) qR : Collections.singleton((OIdentifiable) qR); } diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMatchesCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMatchesCondition.java index a3b91e99b60..8b1362ec59b 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMatchesCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMatchesCondition.java @@ -3,7 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.sql.executor.OResult; import java.util.ArrayList; import java.util.List; @@ -25,31 +24,6 @@ public OMatchesCondition(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - String regex = right; - if (regex != null) { - regex = regex.substring(1, regex.length() - 1); - } else if (rightExpression != null) { - Object val = rightExpression.execute(currentRecord, ctx); - if (val instanceof String) { - regex = (String) val; - } else { - return false; - } - } else { - Object paramVal = rightParam.getValue(ctx.getInputParameters()); - if (paramVal instanceof String) { - regex = (String) paramVal; - } else { - return false; - } - } - Object value = expression.execute(currentRecord, ctx); - - return matches(value, regex, ctx); - } - private boolean matches(Object value, String regex, OCommandContext ctx) { final String key = "MATCHES_" + regex.hashCode(); java.util.regex.Pattern p = (java.util.regex.Pattern) ctx.getVariable(key); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMathExpression.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMathExpression.java index 4580ce87edb..3eed619d79a 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMathExpression.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMathExpression.java @@ -641,27 +641,6 @@ public boolean isCacheable() { return true; } - public Object execute(OIdentifiable iCurrentRecord, OCommandContext ctx) { - if (childExpressions == null || operators == null) { - return null; - } - - if (childExpressions.size() == 0) { - return null; - } - if (childExpressions.size() == 1) { - return childExpressions.get(0).execute(iCurrentRecord, ctx); - } - - if (childExpressions.size() == 2) { - Object leftValue = childExpressions.get(0).execute(iCurrentRecord, ctx); - Object rightValue = childExpressions.get(1).execute(iCurrentRecord, ctx); - return operators.get(0).apply(leftValue, rightValue); - } - - return calculateWithOpPriority(iCurrentRecord, ctx); - } - public Object execute(OResult iCurrentRecord, OCommandContext ctx) { if (childExpressions == null || operators == null) { return null; @@ -712,35 +691,6 @@ private Object calculateWithOpPriority(OResult iCurrentRecord, OCommandContext c return iterateOnPriorities(valuesStack, operatorsStack); } - private Object calculateWithOpPriority(OIdentifiable iCurrentRecord, OCommandContext ctx) { - Deque valuesStack = new ArrayDeque<>(); - Deque operatorsStack = new ArrayDeque(); - if (childExpressions != null && operators != null) { - OMathExpression nextExpression = childExpressions.get(0); - Object val = nextExpression.execute(iCurrentRecord, ctx); - valuesStack.push(val == null ? NULL_VALUE : val); - - for (int i = 0; i < operators.size() && i + 1 < childExpressions.size(); i++) { - Operator nextOperator = operators.get(i); - Object rightValue = childExpressions.get(i + 1).execute(iCurrentRecord, ctx); - - if (!operatorsStack.isEmpty() - && operatorsStack.peek().getPriority() <= nextOperator.getPriority()) { - Object right = valuesStack.poll(); - right = right == NULL_VALUE ? null : right; - Object left = valuesStack.poll(); - left = left == NULL_VALUE ? null : left; - Object calculatedValue = operatorsStack.poll().apply(left, right); - valuesStack.push(calculatedValue == null ? NULL_VALUE : calculatedValue); - } - operatorsStack.push(nextOperator); - - valuesStack.push(rightValue == null ? NULL_VALUE : rightValue); - } - } - return iterateOnPriorities(valuesStack, operatorsStack); - } - private Object iterateOnPriorities(Deque values, Deque operators) { while (true) { if (values.size() == 0) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMethodCall.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMethodCall.java index 1e843dd0b72..48e72701f40 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMethodCall.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OMethodCall.java @@ -197,11 +197,11 @@ private static List resolveParams( List paramValues = new ArrayList(); for (OExpression expr : iParams) { if (val instanceof OIdentifiable) { - paramValues.add(expr.execute((OIdentifiable) val, ctx)); + paramValues.add(expr.execute(new OResultInternal((OIdentifiable) val), ctx)); } else if (val instanceof OResult) { paramValues.add(expr.execute((OResult) val, ctx)); } else if (targetObjects instanceof OIdentifiable) { - paramValues.add(expr.execute((OIdentifiable) targetObjects, ctx)); + paramValues.add(expr.execute(new OResultInternal((OIdentifiable) targetObjects), ctx)); } else if (targetObjects instanceof OResult) { paramValues.add(expr.execute((OResult) targetObjects, ctx)); } else if (val == null) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OModifier.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OModifier.java index 705497a4642..c65d72d58f1 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OModifier.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OModifier.java @@ -102,10 +102,6 @@ public void toGenericStatement(StringBuilder builder) { } } - public Object execute(OIdentifiable iCurrentRecord, Object result, OCommandContext ctx) { - return execute(new OResultInternal(iCurrentRecord), result, ctx); - } - public Object execute(OResult iCurrentRecord, Object result, OCommandContext ctx) { ctx.setCurrentIfMissing(iCurrentRecord); if (methodCall != null) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ONestedProjection.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ONestedProjection.java index deb3a4fe6e6..4f6259c31ab 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ONestedProjection.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ONestedProjection.java @@ -5,8 +5,6 @@ import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.db.record.ridbag.ORidBag; -import com.orientechnologies.orient.core.record.OElement; -import com.orientechnologies.orient.core.record.ORecord; import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.OResultInternal; import java.util.ArrayList; @@ -46,7 +44,7 @@ public Object apply(OExpression expression, Object input, OCommandContext ctx) { if (input instanceof OIdentifiable) { return apply( expression, - (OIdentifiable) input, + new OResultInternal((OIdentifiable) input), ctx, recursion == null ? 0 : recursion.getValue().intValue()); } @@ -126,47 +124,6 @@ private Object tryExpand( return propValue; } - private Object apply( - OExpression expression, OIdentifiable input, OCommandContext ctx, int recursion) { - OElement elem; - if (input instanceof OElement) { - elem = (OElement) input; - } else { - ORecord e = input.getRecord(); - if (e instanceof OElement) { - elem = (OElement) e; - } else { - return input; - } - } - OResultInternal result = new OResultInternal(); - if (starItem != null || includeItems.size() == 0) { - for (String property : elem.getPropertyNames()) { - if (isExclude(property)) { - continue; - } - result.setProperty( - property, - convert(tryExpand(expression, property, elem.getProperty(property), ctx, recursion))); - } - } - if (includeItems.size() > 0) { - // TODO manage wildcards! - for (ONestedProjectionItem item : includeItems) { - String alias = - item.alias != null - ? item.alias.getStringValue() - : item.expression.getDefaultAlias().getStringValue(); - Object value = item.expression.execute(elem, ctx); - if (item.expansion != null) { - value = item.expand(expression, alias, value, ctx, recursion - 1); - } - result.setProperty(alias, convert(value)); - } - } - return result; - } - private Object apply( OExpression expression, Map input, OCommandContext ctx, int recursion) { OResultInternal result = new OResultInternal(); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ONotBlock.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ONotBlock.java index a8f21ef23f4..eb204cb7b6f 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ONotBlock.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ONotBlock.java @@ -4,7 +4,6 @@ import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.metadata.OIndexCandidate; @@ -27,18 +26,6 @@ public ONotBlock(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - if (sub == null) { - return true; - } - boolean result = sub.evaluate(currentRecord, ctx); - if (negate) { - return !result; - } - return result; - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (sub == null) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ONotInCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ONotInCondition.java index ec756835eee..eca4a944730 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ONotInCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ONotInCondition.java @@ -3,7 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.sql.executor.OResult; import java.util.ArrayList; import java.util.List; @@ -31,23 +30,6 @@ public ONotInCondition(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - Object leftVal = left.execute(currentRecord, ctx); - Object rightVal = null; - if (rightStatement != null) { - rightVal = OInCondition.executeQuery(rightStatement, ctx); - } else if (rightParam != null) { - rightVal = rightParam.getValue(ctx.getInputParameters()); - } else if (rightMathExpression != null) { - rightVal = rightMathExpression.execute(currentRecord, ctx); - } - if (rightVal == null) { - return true; - } - return !OInCondition.evaluateExpression(leftVal, rightVal); - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { Object leftVal = left.execute(currentRecord, ctx); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OOrBlock.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OOrBlock.java index 8576fed358e..a5166de2948 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OOrBlock.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OOrBlock.java @@ -6,8 +6,8 @@ import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.metadata.schema.OClass; -import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.executor.OResult; +import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.executor.metadata.OIndexCandidate; import com.orientechnologies.orient.core.sql.executor.metadata.OIndexFinder; import com.orientechnologies.orient.core.sql.executor.metadata.ORequiredIndexCanditate; @@ -29,20 +29,6 @@ public OOrBlock(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - if (getSubBlocks() == null) { - return true; - } - - for (OBooleanExpression block : subBlocks) { - if (block.evaluate(currentRecord, ctx)) { - return true; - } - } - return false; - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (getSubBlocks() == null) { @@ -61,11 +47,9 @@ public boolean evaluate(Object currentRecord, OCommandContext ctx) { if (currentRecord instanceof OResult) { return evaluate((OResult) currentRecord, ctx); } else if (currentRecord instanceof OIdentifiable) { - return evaluate((OIdentifiable) currentRecord, ctx); + return evaluate(new OResultInternal((OIdentifiable) currentRecord), ctx); } else if (currentRecord instanceof Map) { - ODocument doc = new ODocument(); - doc.fromMap((Map) currentRecord); - return evaluate(doc, ctx); + return evaluate(new OResultInternal((Map) currentRecord), ctx); } return false; } diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OParenthesisBlock.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OParenthesisBlock.java index 62c3bf0c7a7..df039700887 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OParenthesisBlock.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OParenthesisBlock.java @@ -3,7 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.metadata.OIndexCandidate; import com.orientechnologies.orient.core.sql.executor.metadata.OIndexFinder; @@ -24,11 +23,6 @@ public OParenthesisBlock(OrientSql p, int id) { super(p, id); } - @Override - public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { - return subElement.evaluate(currentRecord, ctx); - } - @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { return subElement.evaluate(currentRecord, ctx); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OParenthesisExpression.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OParenthesisExpression.java index ebec3d90a0a..bbba43835a8 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OParenthesisExpression.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OParenthesisExpression.java @@ -3,7 +3,6 @@ package com.orientechnologies.orient.core.sql.parser; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.sql.executor.OInsertExecutionPlan; import com.orientechnologies.orient.core.sql.executor.OInternalExecutionPlan; @@ -36,18 +35,6 @@ public boolean isParentesis() { return true; } - @Override - public Object execute(OIdentifiable iCurrentRecord, OCommandContext ctx) { - if (expression != null) { - return expression.execute(iCurrentRecord, ctx); - } - if (statement != null) { - throw new UnsupportedOperationException( - "Execution of select in parentheses is not supported"); - } - return super.execute(iCurrentRecord, ctx); - } - @Override public Object execute(OResult iCurrentRecord, OCommandContext ctx) { if (expression != null) { diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OProjectionItem.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OProjectionItem.java index f1cc065fbbe..64008247a72 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OProjectionItem.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OProjectionItem.java @@ -131,19 +131,6 @@ public void toGenericStatement(StringBuilder builder) { } } - public Object execute(OIdentifiable iCurrentRecord, OCommandContext ctx) { - Object result; - if (all) { - result = iCurrentRecord; - } else { - result = expression.execute(iCurrentRecord, ctx); - } - if (nestedProjection != null) { - result = nestedProjection.apply(expression, result, ctx); - } - return convert(result, ctx); - } - public static Object convert(Object value, OCommandContext context) { if (value instanceof ORidBag) { List result = new ArrayList(); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ORid.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ORid.java index 051f44d76ab..173bb09383a 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ORid.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ORid.java @@ -68,24 +68,6 @@ public ORecordId toRecordId(OResult target, OCommandContext ctx) { } } - public ORecordId toRecordId(OIdentifiable target, OCommandContext ctx) { - if (legacy || (expression == null && cluster != null && position != null)) { - return new ORecordId(cluster.value.intValue(), position.value.longValue()); - } else { - Object result = expression.execute(target, ctx); - if (result == null) { - return null; - } - if (result instanceof OIdentifiable) { - return (ORecordId) ((OIdentifiable) result).getIdentity(); - } - if (result instanceof String) { - return new ORecordId((String) result); - } - return null; - } - } - public ORid copy() { ORid result = new ORid(-1); result.cluster = cluster == null ? null : cluster.copy(); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ORightBinaryCondition.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ORightBinaryCondition.java index c48189a479d..f9f77dc56a5 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ORightBinaryCondition.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/ORightBinaryCondition.java @@ -101,50 +101,6 @@ public Object execute(OResult iCurrentRecord, Object elementToFilter, OCommandCo return result; } - public Object execute(OIdentifiable iCurrentRecord, Object elementToFilter, OCommandContext ctx) { - if (elementToFilter == null) { - return null; - } - Iterator iterator; - if (elementToFilter instanceof OIdentifiable) { - iterator = Collections.singleton(elementToFilter).iterator(); - } else if (elementToFilter instanceof Iterable) { - iterator = ((Iterable) elementToFilter).iterator(); - } else if (elementToFilter instanceof Iterator) { - iterator = (Iterator) elementToFilter; - } else { - iterator = Collections.singleton(elementToFilter).iterator(); - } - - List result = new ArrayList(); - while (iterator.hasNext()) { - Object element = iterator.next(); - if (matchesFilters(iCurrentRecord, element, ctx)) { - result.add(element); - } - } - return result; - } - - private boolean matchesFilters( - OIdentifiable iCurrentRecord, Object element, OCommandContext ctx) { - if (operator != null) { - operator.execute(element, right.execute(iCurrentRecord, ctx), ctx); - } else if (inOperator != null) { - - Object rightVal = evaluateRight(iCurrentRecord, ctx); - if (rightVal == null) { - return false; - } - boolean result = OInCondition.evaluateExpression(element, rightVal); - if (not) { - result = !result; - } - return result; - } - return false; - } - private boolean matchesFilters(OResult iCurrentRecord, Object element, OCommandContext ctx) { if (operator != null) { return operator.execute(element, right.execute(iCurrentRecord, ctx), ctx); @@ -163,10 +119,6 @@ private boolean matchesFilters(OResult iCurrentRecord, Object element, OCommandC return false; } - public Object evaluateRight(OIdentifiable currentRecord, OCommandContext ctx) { - return right.execute(currentRecord, ctx); - } - public Object evaluateRight(OResult currentRecord, OCommandContext ctx) { return right.execute(currentRecord, ctx); } diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OSuffixIdentifier.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OSuffixIdentifier.java index d3c916a84d5..08127675ba9 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OSuffixIdentifier.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OSuffixIdentifier.java @@ -7,7 +7,6 @@ import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; -import com.orientechnologies.orient.core.id.OContextualRecordId; import com.orientechnologies.orient.core.record.OElement; import com.orientechnologies.orient.core.record.ORecord; import com.orientechnologies.orient.core.record.impl.ODocument; @@ -15,6 +14,7 @@ import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.executor.OResultSet; +import com.orientechnologies.orient.core.sql.executor.OUpdatableResult; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -63,51 +63,6 @@ public void toGenericStatement(StringBuilder builder) { } } - public Object execute(OIdentifiable iCurrentRecord, OCommandContext ctx) { - if (star) { - return iCurrentRecord; - } - if (identifier != null) { - String varName = identifier.getStringValue(); - if (ctx != null && varName.equalsIgnoreCase("$parent")) { - return ctx.getParent(); - } - if (varName.startsWith("$") && ctx != null) { - return ctx.getVariable(varName); - } - - if (iCurrentRecord != null) { - if (iCurrentRecord instanceof OContextualRecordId) { - Map meta = ((OContextualRecordId) iCurrentRecord).getContext(); - if (meta != null && meta.containsKey(varName)) { - return meta.get(varName); - } - } - OElement rec = iCurrentRecord.getRecord(); - if (rec == null) { - return null; - } - Object result = rec.getProperty(varName); - if (result == null && ctx != null) { - result = ctx.getVariable(varName); - } - return result; - } - return varName; - } - if (recordAttribute != null && iCurrentRecord != null) { - OElement rec = - iCurrentRecord instanceof OElement - ? (OElement) iCurrentRecord - : iCurrentRecord.getRecord(); - if (rec != null) { - return recordAttribute.evaluate(rec, ctx); - } - } - - return null; - } - public Object execute(OResult iCurrentRecord, OCommandContext ctx) { if (star) { return iCurrentRecord; @@ -135,8 +90,10 @@ public Object execute(OResult iCurrentRecord, OCommandContext ctx) { && ((OResultInternal) iCurrentRecord).getTemporaryProperties().contains(varName)) { return ((OResultInternal) iCurrentRecord).getTemporaryProperty(varName); } + return null; + } else { + return null; } - return null; } if (iCurrentRecord != null && recordAttribute != null) { @@ -226,7 +183,7 @@ public Object execute(Object currentValue, OCommandContext ctx) { return execute((OResult) currentValue, ctx); } if (currentValue instanceof OIdentifiable) { - return execute((OIdentifiable) currentValue, ctx); + return execute(new OResultInternal((OIdentifiable) currentValue), ctx); } if (currentValue instanceof Map) { return execute((Map) currentValue, ctx); @@ -341,7 +298,12 @@ public void setValue(Object target, Object value, OCommandContext ctx) { if (target instanceof OResult) { setValue((OResult) target, value, ctx); } else if (target instanceof OIdentifiable) { - setValue((OIdentifiable) target, value, ctx); + if (target instanceof OElement) { + setValue(new OUpdatableResult((OElement) target), value, ctx); + } else { + OElement element = ctx.getDatabase().load(((OIdentifiable) target).getIdentity()); + setValue(new OUpdatableResult(element), value, ctx); + } } else if (target instanceof Map) { setValue((Map) target, value, ctx); } diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OValueExpression.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OValueExpression.java index f4c93c2790d..bfdf002775b 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OValueExpression.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OValueExpression.java @@ -4,7 +4,6 @@ import com.orientechnologies.orient.core.collate.OCollate; import com.orientechnologies.orient.core.command.OCommandContext; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.record.OElement; import com.orientechnologies.orient.core.sql.executor.AggregationContext; @@ -25,10 +24,6 @@ public OValueExpression(Object val) { this.value = val; } - public Object execute(OIdentifiable iCurrentRecord, OCommandContext ctx) { - return value; - } - public Object execute(OResult iCurrentRecord, OCommandContext ctx) { return value; } diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OWhereClause.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OWhereClause.java index 5cb84bea932..792697f4d80 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OWhereClause.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OWhereClause.java @@ -45,10 +45,7 @@ public OWhereClause(OrientSql p, int id) { } public boolean matchesFilters(OIdentifiable currentRecord, OCommandContext ctx) { - if (baseExpression == null) { - return true; - } - return baseExpression.evaluate(currentRecord, ctx); + return matchesFilters(new OResultInternal(currentRecord), ctx); } public boolean matchesFilters(OResult currentRecord, OCommandContext ctx) { diff --git a/etl/src/main/java/com/orientechnologies/orient/etl/OETLAbstractComponent.java b/etl/src/main/java/com/orientechnologies/orient/etl/OETLAbstractComponent.java index 492a8542c96..4a9f92dc9e4 100755 --- a/etl/src/main/java/com/orientechnologies/orient/etl/OETLAbstractComponent.java +++ b/etl/src/main/java/com/orientechnologies/orient/etl/OETLAbstractComponent.java @@ -30,6 +30,8 @@ import com.orientechnologies.orient.core.exception.OConfigurationException; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.OSQLEngine; +import com.orientechnologies.orient.core.sql.executor.OResult; +import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.parser.OOrBlock; import com.orientechnologies.orient.etl.context.OETLContext; @@ -94,8 +96,8 @@ public String toString() { protected boolean skip(final Object input) { final OOrBlock ifFilter = getIfFilter(); if (ifFilter != null) { - final ODocument doc = - input instanceof OIdentifiable ? (ODocument) ((OIdentifiable) input).getRecord() : null; + final OResult doc = + input instanceof OIdentifiable ? new OResultInternal(((OIdentifiable) input)) : null; debug("Evaluating conditional expression if=%s...", ifFilter); @@ -187,7 +189,7 @@ protected Object resolve(final Object content) { "={", "}", variable -> { - return OSQLEngine.parseExpression(variable).execute((OIdentifiable) null, context); + return OSQLEngine.parseExpression(variable).execute((OResult) null, context); }); } return value; diff --git a/etl/src/main/java/com/orientechnologies/orient/etl/transformer/OETLFieldTransformer.java b/etl/src/main/java/com/orientechnologies/orient/etl/transformer/OETLFieldTransformer.java index 06643d6a161..22986b4872a 100644 --- a/etl/src/main/java/com/orientechnologies/orient/etl/transformer/OETLFieldTransformer.java +++ b/etl/src/main/java/com/orientechnologies/orient/etl/transformer/OETLFieldTransformer.java @@ -24,6 +24,7 @@ import com.orientechnologies.orient.core.record.ORecord; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.OSQLEngine; +import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.parser.OExpression; import java.util.List; @@ -96,7 +97,7 @@ public Object executeTransform(ODatabaseDocument db, final Object input) { // ONLY THE FIRST TIME sqlFilter = OSQLEngine.parseExpression(expression); - newValue = sqlFilter.execute(doc, context); + newValue = sqlFilter.execute(new OResultInternal(doc), context); } else newValue = value; // SET THE TRANSFORMED FIELD BACK diff --git a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneCrossClassSearchFunction.java b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneCrossClassSearchFunction.java index e80a6398f2f..d8b08332929 100644 --- a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneCrossClassSearchFunction.java +++ b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneCrossClassSearchFunction.java @@ -15,6 +15,7 @@ import com.orientechnologies.orient.core.id.ORID; import com.orientechnologies.orient.core.index.OIndex; import com.orientechnologies.orient.core.record.impl.ODocument; +import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.functions.OIndexableSQLFunction; import com.orientechnologies.orient.core.sql.functions.OSQLFunctionAbstract; import com.orientechnologies.orient.core.sql.parser.OBinaryCompareOperator; @@ -55,7 +56,7 @@ public Iterable searchFromTarget( OLuceneFullTextIndex fullTextIndex = searchForIndex(); OExpression expression = args[0]; - String query = (String) expression.execute((OIdentifiable) null, ctx); + String query = (String) expression.execute((OResult) null, ctx); if (fullTextIndex != null) { diff --git a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneFunctionsUtils.java b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneFunctionsUtils.java index 425cdee1f74..817b520f456 100755 --- a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneFunctionsUtils.java +++ b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneFunctionsUtils.java @@ -3,8 +3,8 @@ import com.orientechnologies.lucene.index.OLuceneFullTextIndex; import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; -import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.metadata.OMetadataInternal; +import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.parser.OExpression; import org.apache.lucene.index.memory.MemoryIndex; @@ -13,7 +13,7 @@ public class OLuceneFunctionsUtils { public static final String MEMORY_INDEX = "_memoryIndex"; protected static OLuceneFullTextIndex searchForIndex(OExpression[] args, OCommandContext ctx) { - final String indexName = (String) args[0].execute((OIdentifiable) null, ctx); + final String indexName = (String) args[0].execute((OResult) null, ctx); return getLuceneFullTextIndex(ctx, indexName); } diff --git a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchFunctionTemplate.java b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchFunctionTemplate.java index 5c159773975..e018cb20ec0 100644 --- a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchFunctionTemplate.java +++ b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchFunctionTemplate.java @@ -5,6 +5,7 @@ import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.record.impl.ODocument; +import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.functions.OIndexableSQLFunction; import com.orientechnologies.orient.core.sql.functions.OSQLFunctionAbstract; import com.orientechnologies.orient.core.sql.parser.OBinaryCompareOperator; @@ -72,7 +73,7 @@ public long estimate( } protected ODocument getMetadata(OExpression metadata, OCommandContext ctx) { - final Object md = metadata.execute((OIdentifiable) null, ctx); + final Object md = metadata.execute((OResult) null, ctx); if (md instanceof ODocument) { return (ODocument) md; } else if (md instanceof Map) { diff --git a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchMoreLikeThisFunction.java b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchMoreLikeThisFunction.java index a473c866358..8a232acf7c8 100755 --- a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchMoreLikeThisFunction.java +++ b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchMoreLikeThisFunction.java @@ -135,7 +135,7 @@ public Iterable searchFromTarget( private List parseRids(OCommandContext ctx, OExpression expression) { - Object expResult = expression.execute((OIdentifiable) null, ctx); + Object expResult = expression.execute((OResult) null, ctx); // single rind if (expResult instanceof OIdentifiable) { diff --git a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchOnClassFunction.java b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchOnClassFunction.java index 5b6256a51bb..a8a67b1fd1a 100644 --- a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchOnClassFunction.java +++ b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchOnClassFunction.java @@ -127,7 +127,7 @@ public Iterable searchFromTarget( OLuceneFullTextIndex index = searchForIndex(target, ctx); OExpression expression = args[0]; - String query = (String) expression.execute((OIdentifiable) null, ctx); + String query = (String) expression.execute((OResult) null, ctx); if (index != null) { diff --git a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchOnFieldsFunction.java b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchOnFieldsFunction.java index bf101851320..22686ad310f 100644 --- a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchOnFieldsFunction.java +++ b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchOnFieldsFunction.java @@ -114,7 +114,7 @@ public Iterable searchFromTarget( OLuceneFullTextIndex index = searchForIndex(target, ctx, args); OExpression expression = args[1]; - Object query = expression.execute((OIdentifiable) null, ctx); + Object query = expression.execute((OResult) null, ctx); if (index != null) { ODocument meta = getMetadata(args, ctx); @@ -143,7 +143,7 @@ private ODocument getMetadata(OExpression[] args, OCommandContext ctx) { @Override protected OLuceneFullTextIndex searchForIndex( OFromClause target, OCommandContext ctx, OExpression... args) { - List fieldNames = (List) args[0].execute((OIdentifiable) null, ctx); + List fieldNames = (List) args[0].execute((OResult) null, ctx); OFromItem item = target.getItem(); String className = item.getIdentifier().getStringValue(); diff --git a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchOnIndexFunction.java b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchOnIndexFunction.java index 25933d29668..60c4012db69 100644 --- a/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchOnIndexFunction.java +++ b/lucene/src/main/java/com/orientechnologies/lucene/functions/OLuceneSearchOnIndexFunction.java @@ -125,7 +125,7 @@ public Iterable searchFromTarget( OLuceneFullTextIndex index = searchForIndex(target, ctx, args); OExpression expression = args[1]; - String query = (String) expression.execute((OIdentifiable) null, ctx); + String query = (String) expression.execute((OResult) null, ctx); if (index != null && query != null) { ODocument meta = getMetadata(args, ctx); @@ -164,7 +164,7 @@ protected OLuceneFullTextIndex searchForIndex( private OLuceneFullTextIndex searchForIndex( String className, OCommandContext ctx, OExpression... args) { - String indexName = (String) args[0].execute((OIdentifiable) null, ctx); + String indexName = (String) args[0].execute((OResult) null, ctx); final ODatabaseDocumentInternal database = (ODatabaseDocumentInternal) ctx.getDatabase(); OIndex index = diff --git a/lucene/src/main/java/com/orientechnologies/spatial/functions/OSTDWithinFunction.java b/lucene/src/main/java/com/orientechnologies/spatial/functions/OSTDWithinFunction.java index 225900910bc..8baf740671c 100644 --- a/lucene/src/main/java/com/orientechnologies/spatial/functions/OSTDWithinFunction.java +++ b/lucene/src/main/java/com/orientechnologies/spatial/functions/OSTDWithinFunction.java @@ -17,6 +17,7 @@ import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.db.record.OIdentifiable; +import com.orientechnologies.orient.core.sql.executor.OResult; import com.orientechnologies.orient.core.sql.parser.OBinaryCompareOperator; import com.orientechnologies.orient.core.sql.parser.OExpression; import com.orientechnologies.orient.core.sql.parser.OFromClause; @@ -74,7 +75,7 @@ protected void onAfterParsing( OExpression number = args[2]; - Number parsedNumber = (Number) number.execute((OIdentifiable) null, ctx); + Number parsedNumber = (Number) number.execute((OResult) null, ctx); params.put("distance", parsedNumber.doubleValue()); } diff --git a/lucene/src/main/java/com/orientechnologies/spatial/functions/OSpatialFunctionAbstractIndexable.java b/lucene/src/main/java/com/orientechnologies/spatial/functions/OSpatialFunctionAbstractIndexable.java index 80dcd733126..ca1909ccd4b 100755 --- a/lucene/src/main/java/com/orientechnologies/spatial/functions/OSpatialFunctionAbstractIndexable.java +++ b/lucene/src/main/java/com/orientechnologies/spatial/functions/OSpatialFunctionAbstractIndexable.java @@ -97,7 +97,7 @@ protected Iterable results( ODocument doc = new ODocument().fromJSON(json.toString()); shape = doc.toMap(); } else { - shape = args[1].execute((OIdentifiable) null, ctx); + shape = args[1].execute((OResult) null, ctx); } if (shape instanceof Collection) { diff --git a/tools/src/main/java/com/orientechnologies/orient/console/OConsoleDatabaseApp.java b/tools/src/main/java/com/orientechnologies/orient/console/OConsoleDatabaseApp.java index f604440bb3b..899c536b4ef 100755 --- a/tools/src/main/java/com/orientechnologies/orient/console/OConsoleDatabaseApp.java +++ b/tools/src/main/java/com/orientechnologies/orient/console/OConsoleDatabaseApp.java @@ -86,6 +86,7 @@ import com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerStringAbstract; import com.orientechnologies.orient.core.sql.OSQLEngine; import com.orientechnologies.orient.core.sql.executor.OResult; +import com.orientechnologies.orient.core.sql.executor.OResultInternal; import com.orientechnologies.orient.core.sql.executor.OResultSet; import com.orientechnologies.orient.core.storage.OStorage; import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage; @@ -1274,7 +1275,7 @@ public void move( final Object result = OSQLEngine.parseExpression(iText) - .execute(currentRecord, new OBasicCommandContext(currentDatabase)); + .execute(new OResultInternal(currentRecord), new OBasicCommandContext(currentDatabase)); if (result != null) { if (result instanceof OIdentifiable) {