Skip to content

Commit

Permalink
OPE Tree commands update (#70)
Browse files Browse the repository at this point in the history
* Add InsertOpetreeCommand, remove values from RebalanceOpetreeCommand

* Removed discretionary cloning of more objects (missed in previous PR)

* Refactoring of commands, add OPE tree status command

* Add OpetreeRebuildCommand, stop types for OpetreeRebalanceCommand
  • Loading branch information
cheziyi authored Apr 26, 2020
1 parent 1632b27 commit 43dbe9e
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 72 deletions.
58 changes: 39 additions & 19 deletions src/PrismaDB.QueryAST/DCL/AsyncCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ public abstract class AsyncCommand : Command
public bool StatusCheck;
}

public class UpdateKeysCommand : AsyncCommand
public class KeysUpdateCommand : AsyncCommand
{
public UpdateKeysCommand(bool statusCheck = false) { StatusCheck = statusCheck; }
public KeysUpdateCommand(bool statusCheck = false) { StatusCheck = statusCheck; }

public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

public override string ToString() => DialectResolver.Dialect.UpdateKeysCommandToString(this);
public override string ToString() => DialectResolver.Dialect.KeysUpdateCommandToString(this);

public override object Clone() => new UpdateKeysCommand(StatusCheck);
public override object Clone() => new KeysUpdateCommand(StatusCheck);
}

public class EncryptColumnCommand : AsyncCommand
Expand Down Expand Up @@ -74,33 +74,53 @@ public DecryptColumnCommand(ColumnRef column, bool statusCheck = false)
public override object Clone() => new DecryptColumnCommand((ColumnRef)Column.Clone(), StatusCheck);
}

public class RebalanceOpetreeCommand : AsyncCommand
public class OpetreeRebuildCommand : AsyncCommand
{
public List<ConstantContainer> WithValues;
public OpetreeRebuildCommand(bool statusCheck = false) { StatusCheck = statusCheck; }

public RebalanceOpetreeCommand(bool statusCheck = false)
public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

public override string ToString() => DialectResolver.Dialect.OpetreeRebuildCommandToString(this);

public override object Clone() => new OpetreeRebuildCommand(StatusCheck);
}

public class OpetreeRebalanceCommand : AsyncCommand
{
public RebalanceStopType StopType;
public DecimalConstant StopAfter;

public OpetreeRebalanceCommand(bool statusCheck = false)
{
WithValues = new List<ConstantContainer>();
StopType = RebalanceStopType.FULL;
StopAfter = new DecimalConstant(1);
StatusCheck = statusCheck;
}
public RebalanceOpetreeCommand(List<ConstantContainer> withValues, bool statusCheck = false)

public OpetreeRebalanceCommand(RebalanceStopType stopType = RebalanceStopType.FULL, decimal stopAfter = 1, bool statusCheck = false)
{
WithValues = withValues;
StopType = stopType;
StopAfter = new DecimalConstant(stopAfter);
StatusCheck = statusCheck;
}

public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => WithValues;
public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

public override string ToString() => DialectResolver.Dialect.RebalanceOpetreeCommandToString(this);
public override string ToString() => DialectResolver.Dialect.OpetreeRebalanceCommandToString(this);

public override object Clone()
{
var res = new RebalanceOpetreeCommand(StatusCheck);
foreach (var value in WithValues)
res.WithValues.Add((ConstantContainer)value.Clone());
return res;
}
public override object Clone() => new OpetreeRebalanceCommand(StopType, StopAfter.decimalvalue, StatusCheck);
}

public enum RebalanceStopType
{
FULL,
IMMEDIATE,
ITERATIONS,
HOURS,
MINUTES
}
}
117 changes: 79 additions & 38 deletions src/PrismaDB.QueryAST/DCL/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,86 +5,114 @@ namespace PrismaDB.QueryAST.DCL
{
public abstract class Command : Query { }

public class SaveSettingsCommand : Command
public class SettingsSaveCommand : Command
{
public SaveSettingsCommand() { }
public SettingsSaveCommand() { }

public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

public override string ToString() => DialectResolver.Dialect.SaveSettingsCommandToString(this);
public override string ToString() => DialectResolver.Dialect.SettingsSaveCommandToString(this);

public override object Clone() => new SaveSettingsCommand();
public override object Clone() => new SettingsSaveCommand();
}

public class LoadSettingsCommand : Command
public class SettingsLoadCommand : Command
{
public LoadSettingsCommand() { }
public SettingsLoadCommand() { }

public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

public override string ToString() => DialectResolver.Dialect.LoadSettingsCommandToString(this);
public override string ToString() => DialectResolver.Dialect.SettingsLoadCommandToString(this);

public override object Clone() => new LoadSettingsCommand();
public override object Clone() => new SettingsLoadCommand();
}

public class SaveOpetreeCommand : Command
public class OpetreeSaveCommand : Command
{
public SaveOpetreeCommand() { }
public OpetreeSaveCommand() { }

public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

public override string ToString() => DialectResolver.Dialect.SaveOpetreeCommandToString(this);
public override string ToString() => DialectResolver.Dialect.OpetreeSaveCommandToString(this);

public override object Clone() => new SaveOpetreeCommand();
public override object Clone() => new OpetreeSaveCommand();
}

public class LoadOpetreeCommand : Command
public class OpetreeLoadCommand : Command
{
public LoadOpetreeCommand() { }
public OpetreeLoadCommand() { }

public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

public override string ToString() => DialectResolver.Dialect.LoadOpetreeCommandToString(this);
public override string ToString() => DialectResolver.Dialect.OpetreeLoadCommandToString(this);

public override object Clone() => new LoadOpetreeCommand();
public override object Clone() => new OpetreeLoadCommand();
}

public class LoadSchemaCommand : Command
public class OpetreeInsertCommand : Command
{
public LoadSchemaCommand() { }
public List<ConstantContainer> Values;

public OpetreeInsertCommand()
{
Values = new List<ConstantContainer>();
}
public OpetreeInsertCommand(List<ConstantContainer> values)
{
Values = values;
}

public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => Values;

public override string ToString() => DialectResolver.Dialect.OpetreeInsertCommandToString(this);

public override object Clone()
{
var res = new OpetreeInsertCommand();
foreach (var value in Values)
res.Values.Add((ConstantContainer)value.Clone());
return res;
}
}

public class SchemaLoadCommand : Command
{
public SchemaLoadCommand() { }

public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

public override string ToString() => DialectResolver.Dialect.LoadSchemaCommandToString(this);
public override string ToString() => DialectResolver.Dialect.SchemaLoadCommandToString(this);

public override object Clone() => new LoadSchemaCommand();
public override object Clone() => new SchemaLoadCommand();
}

public class ExportKeysCommand : Command
public class KeysExportCommand : Command
{
public StringConstant FileUri;

public ExportKeysCommand() { FileUri = new StringConstant(""); }
public KeysExportCommand() { FileUri = new StringConstant(""); }

public ExportKeysCommand(string fileUri) { FileUri = new StringConstant(fileUri); }
public KeysExportCommand(string fileUri) { FileUri = new StringConstant(fileUri); }

public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

public override string ToString() => DialectResolver.Dialect.ExportKeysCommandToString(this);
public override string ToString() => DialectResolver.Dialect.KeysExportCommandToString(this);

public override object Clone() => new ExportKeysCommand(FileUri.strvalue);
public override object Clone() => new KeysExportCommand(FileUri.strvalue);
}

public class RegisterUserCommand : Command
Expand Down Expand Up @@ -130,46 +158,59 @@ public BypassCommand() { }
public override object Clone() => new BypassCommand((Query)Query.Clone());
}

public class RefreshLicenseCommand : Command
public class LicenseRefreshCommand : Command
{
public RefreshLicenseCommand() { }
public LicenseRefreshCommand() { }

public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

public override string ToString() => DialectResolver.Dialect.RefreshLicenseCommandToString(this);
public override string ToString() => DialectResolver.Dialect.LicenseRefreshCommandToString(this);

public override object Clone() => new RefreshLicenseCommand();
public override object Clone() => new LicenseRefreshCommand();
}

public class SetLicenseKeyCommand : Command
public class LicenseSetKeyCommand : Command
{
public StringConstant LicenseKey;

public SetLicenseKeyCommand() { LicenseKey = new StringConstant(""); }
public LicenseSetKeyCommand() { LicenseKey = new StringConstant(""); }

public LicenseSetKeyCommand(string licenseKey) { LicenseKey = new StringConstant(licenseKey); }

public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

public override string ToString() => DialectResolver.Dialect.LicenseSetKeyCommandToString(this);

public SetLicenseKeyCommand(string licenseKey) { LicenseKey = new StringConstant(licenseKey); }
public override object Clone() => new LicenseSetKeyCommand(LicenseKey.strvalue);
}

public class LicenseStatusCommand : Command
{
public LicenseStatusCommand() { }

public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

public override string ToString() => DialectResolver.Dialect.SetLicenseKeyCommandToString(this);
public override string ToString() => DialectResolver.Dialect.LicenseStatusCommandToString(this);

public override object Clone() => new SetLicenseKeyCommand(LicenseKey.strvalue);
public override object Clone() => new LicenseStatusCommand();
}

public class CheckLicenseStatusCommand : Command
public class OpetreeStatusCommand : Command
{
public CheckLicenseStatusCommand() { }
public OpetreeStatusCommand() { }

public override List<TableRef> GetTables() => new List<TableRef>();

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

public override string ToString() => DialectResolver.Dialect.CheckLicenseStatusCommandToString(this);
public override string ToString() => DialectResolver.Dialect.OpetreeStatusCommandToString(this);

public override object Clone() => new CheckLicenseStatusCommand();
public override object Clone() => new OpetreeStatusCommand();
}
}
2 changes: 1 addition & 1 deletion src/PrismaDB.QueryAST/DDL/CreateIndexQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public CreateIndexQuery(CreateIndexQuery other)
: this(other.Name.id, other.OnTable, other.Type, other.Modifier, other.MsSqlFullTextKeyIndex?.id, other.OnColumns.ToArray())
{ }

public override List<TableRef> GetTables() => new List<TableRef> { OnTable.Clone() };
public override List<TableRef> GetTables() => new List<TableRef> { OnTable };

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

Expand Down
2 changes: 1 addition & 1 deletion src/PrismaDB.QueryAST/DDL/DropTableQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public DropTableQuery(DropTableQuery other)
TableName = other.TableName.Clone();
}

public override List<TableRef> GetTables() => new List<TableRef> { TableName.Clone() };
public override List<TableRef> GetTables() => new List<TableRef> { TableName };

public override List<ConstantContainer> GetConstants() => new List<ConstantContainer>();

Expand Down
2 changes: 1 addition & 1 deletion src/PrismaDB.QueryAST/DML/UpdateQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public UpdateQuery(UpdateQuery other)
Where = other.Where;
}

public override List<TableRef> GetTables() => new List<TableRef> { UpdateTable.Clone() };
public override List<TableRef> GetTables() => new List<TableRef> { UpdateTable };

public override List<ConstantContainer> GetConstants()
{
Expand Down
25 changes: 14 additions & 11 deletions src/PrismaDB.QueryAST/Dialect/IDialect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,24 @@ public interface IDialect
string LinRegAggregationFunctionToString(LinRegAggregationFunction q);
string UseStatementToString(UseStatement q);

string ExportKeysCommandToString(ExportKeysCommand c);
string KeysExportCommandToString(KeysExportCommand c);
string RegisterUserCommandToString(RegisterUserCommand c);
string UpdateKeysCommandToString(UpdateKeysCommand c);
string KeysUpdateCommandToString(KeysUpdateCommand c);
string DecryptColumnCommandToString(DecryptColumnCommand c);
string EncryptColumnCommandToString(EncryptColumnCommand c);
string RebalanceOpetreeCommandToString(RebalanceOpetreeCommand c);
string SaveOpetreeCommandToString(SaveOpetreeCommand c);
string LoadOpetreeCommandToString(LoadOpetreeCommand c);
string LoadSchemaCommandToString(LoadSchemaCommand c);
string SaveSettingsCommandToString(SaveSettingsCommand c);
string LoadSettingsCommandToString(LoadSettingsCommand c);
string OpetreeRebalanceCommandToString(OpetreeRebalanceCommand c);
string OpetreeSaveCommandToString(OpetreeSaveCommand c);
string OpetreeLoadCommandToString(OpetreeLoadCommand c);
string OpetreeInsertCommandToString(OpetreeInsertCommand c);
string OpetreeRebuildCommandToString(OpetreeRebuildCommand c);
string OpetreeStatusCommandToString(OpetreeStatusCommand c);
string SchemaLoadCommandToString(SchemaLoadCommand c);
string SettingsSaveCommandToString(SettingsSaveCommand c);
string SettingsLoadCommandToString(SettingsLoadCommand c);
string BypassCommandToString(BypassCommand c);
string RefreshLicenseCommandToString(RefreshLicenseCommand c);
string SetLicenseKeyCommandToString(SetLicenseKeyCommand c);
string CheckLicenseStatusCommandToString(CheckLicenseStatusCommand c);
string LicenseRefreshCommandToString(LicenseRefreshCommand c);
string LicenseSetKeyCommandToString(LicenseSetKeyCommand c);
string LicenseStatusCommandToString(LicenseStatusCommand c);

string SqlDataTypeToString(SqlDataType q);
string ColumnEncryptionFlagsToString(ColumnEncryptionFlags q);
Expand Down
2 changes: 1 addition & 1 deletion test/QueryTests/QueryTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
Expand Down

0 comments on commit 43dbe9e

Please sign in to comment.