Skip to content

Commit

Permalink
refactor: removed some duplicated implementations in the query engine
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Dec 30, 2024
1 parent 2f78c09 commit d6e5c04
Show file tree
Hide file tree
Showing 77 changed files with 135 additions and 922 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -176,7 +177,7 @@ public Object executeFunction(
} else if (result.hasArrayElements()) {
final List<Object> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public OResultSet toResultSet(Object value) {
else if (v.hasArrayElements()) {
final List<Object> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, ? extends Object>) v);
Object result = pred.execute(doc, iContext);
Object result =
pred.execute(new OResultInternal((Map<String, Object>) v), iContext);
if (Boolean.TRUE.equals(result)) {
values.add(v);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public OResultInternal() {
content = new LinkedHashMap<>();
}

public OResultInternal(Map<String, Object> c) {
content = c;
}

public OResultInternal(OIdentifiable ident) {
setElement(ident);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,7 +74,7 @@ public OExecutionStream executeDDL(OCommandContext ctx) {
List<OResult> result = new ArrayList<>();
List<Integer> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit d6e5c04

Please sign in to comment.