Skip to content

Commit

Permalink
Refatoração
Browse files Browse the repository at this point in the history
  • Loading branch information
isaquepinheiro committed Oct 18, 2023
1 parent 94eccc8 commit 8f88d90
Show file tree
Hide file tree
Showing 61 changed files with 1,070 additions and 1,062 deletions.
41 changes: 20 additions & 21 deletions Source/Core/cqlbr.ast.pas
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ TCQLAST = class(TInterfacedObject, ICQLAST)
FJoins: ICQLJoins;
FOrderBy: ICQLOrderBy;
FWhere: ICQLWhere;
function GetASTColumns: ICQLNames;
procedure SetASTColumns(const Value: ICQLNames);
function GetASTSection: ICQLSection;
procedure SetASTSection(const Value: ICQLSection);
function GetASTName: ICQLName;
procedure SetASTName(const Value: ICQLName);
function GetASTTableNames: ICQLNames;
procedure SetASTTableNames(const Value: ICQLNames);
protected
function _GetASTColumns: ICQLNames;
procedure _SetASTColumns(const Value: ICQLNames);
function _GetASTSection: ICQLSection;
procedure _SetASTSection(const Value: ICQLSection);
function _GetASTName: ICQLName;
procedure _SetASTName(const Value: ICQLName);
function _GetASTTableNames: ICQLNames;
procedure _SetASTTableNames(const Value: ICQLNames);
public
constructor Create(const ADatabase: TDBName);
destructor Destroy; override;
Expand All @@ -77,10 +76,10 @@ TCQLAST = class(TInterfacedObject, ICQLAST)
function GroupBy: ICQLGroupBy;
function Having: ICQLHaving;
function OrderBy: ICQLOrderBy;
property ASTColumns: ICQLNames read GetASTColumns write SetASTColumns;
property ASTSection: ICQLSection read GetASTSection write SetASTSection;
property ASTName: ICQLName read GetASTName write SetASTName;
property ASTTableNames: ICQLNames read GetASTTableNames write SetASTTableNames;
property ASTColumns: ICQLNames read _GetASTColumns write _SetASTColumns;
property ASTSection: ICQLSection read _GetASTSection write _SetASTSection;
property ASTName: ICQLName read _GetASTName write _SetASTName;
property ASTTableNames: ICQLNames read _GetASTTableNames write _SetASTTableNames;
end;

implementation
Expand Down Expand Up @@ -137,22 +136,22 @@ destructor TCQLAST.Destroy;
inherited;
end;

function TCQLAST.GetASTColumns: ICQLNames;
function TCQLAST._GetASTColumns: ICQLNames;
begin
Result := FASTColumns;
end;

function TCQLAST.GetASTName: ICQLName;
function TCQLAST._GetASTName: ICQLName;
begin
Result := FASTName;
end;

function TCQLAST.GetASTSection: ICQLSection;
function TCQLAST._GetASTSection: ICQLSection;
begin
Result := FASTSection;
end;

function TCQLAST.GetASTTableNames: ICQLNames;
function TCQLAST._GetASTTableNames: ICQLNames;
begin
Result := FASTTableNames;
end;
Expand Down Expand Up @@ -202,22 +201,22 @@ function TCQLAST.Select: ICQLSelect;
Result := FSelect;
end;

procedure TCQLAST.SetASTColumns(const Value: ICQLNames);
procedure TCQLAST._SetASTColumns(const Value: ICQLNames);
begin
FASTColumns := Value;
end;

procedure TCQLAST.SetASTName(const Value: ICQLName);
procedure TCQLAST._SetASTName(const Value: ICQLName);
begin
FASTName := Value;
end;

procedure TCQLAST.SetASTSection(const Value: ICQLSection);
procedure TCQLAST._SetASTSection(const Value: ICQLSection);
begin
FASTSection := Value;
end;

procedure TCQLAST.SetASTTableNames(const Value: ICQLNames);
procedure TCQLAST._SetASTTableNames(const Value: ICQLNames);
begin
FASTTableNames := Value;
end;
Expand Down
23 changes: 11 additions & 12 deletions Source/Core/cqlbr.cases.pas
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TCQLCase = class(TInterfacedObject, ICQLCase)
constructor Create;
public
class function New: ICQLCase;
function Serialize: String; virtual;
function Serialize: string; virtual;
property CaseExpression: ICQLExpression read GetCaseExpression write SetCaseExpression;
property WhenList: ICQLCaseWhenList read GetWhenList write SetWhenList;
property ElseExpression: ICQLExpression read GetElseExpression write SetElseExpression;
Expand All @@ -98,25 +98,24 @@ TCQLCriteriaCase = class(TInterfacedObject, ICQLCriteriaCase)
FOwner: ICQL;
FCase: ICQLCase;
FLastExpression: ICQLCriteriaExpression;
protected
function GetCase: ICQLCase;
function _GetCase: ICQLCase;
public
constructor Create(const AOwner: ICQL; const AExpression: String);
constructor Create(const AOwner: ICQL; const AExpression: string);
function &And(const AExpression: array of const): ICQLCriteriaCase; overload;
function &And(const AExpression: String): ICQLCriteriaCase; overload;
function &And(const AExpression: string): ICQLCriteriaCase; overload;
function &And(const AExpression: ICQLCriteriaExpression): ICQLCriteriaCase; overload;
function &Else(const AValue: String): ICQLCriteriaCase; overload;
function &Else(const AValue: string): ICQLCriteriaCase; overload;
function &Else(const AValue: Int64): ICQLCriteriaCase; overload;
function &End: ICQL;
function &Or(const AExpression: array of const): ICQLCriteriaCase; overload;
function &Or(const AExpression: String): ICQLCriteriaCase; overload;
function &Or(const AExpression: string): ICQLCriteriaCase; overload;
function &Or(const AExpression: ICQLCriteriaExpression): ICQLCriteriaCase; overload;
function &Then(const AValue: String): ICQLCriteriaCase; overload;
function &Then(const AValue: string): ICQLCriteriaCase; overload;
function &Then(const AValue: Int64): ICQLCriteriaCase; overload;
function When(const ACondition: String): ICQLCriteriaCase; overload;
function When(const ACondition: string): ICQLCriteriaCase; overload;
function When(const ACondition: array of const): ICQLCriteriaCase; overload;
function When(const ACondition: ICQLCriteriaExpression): ICQLCriteriaCase; overload;
property &Case: ICQLCase read GetCase;
property &Case: ICQLCase read _GetCase;
end;

implementation
Expand Down Expand Up @@ -153,7 +152,7 @@ class function TCQLCase.New: ICQLCase;
Result := Self.Create;
end;

function TCQLCase.Serialize: String;
function TCQLCase.Serialize: string;
var
LFor: Integer;
LWhenThen: ICQLCaseWhenThen;
Expand Down Expand Up @@ -305,7 +304,7 @@ function TCQLCriteriaCase.&End: ICQL;
Result := FOwner;
end;

function TCQLCriteriaCase.GetCase: ICQLCase;
function TCQLCriteriaCase._GetCase: ICQLCase;
begin
Result := FCase;
end;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/cqlbr.delete.pas
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ TCQLDelete = class(TCQLSection, ICQLDelete)
procedure Clear; override;
function IsEmpty: boolean; override;
function TableNames: ICQLNames;
function Serialize: String;
function Serialize: string;
end;

implementation
Expand All @@ -74,7 +74,7 @@ function TCQLDelete.IsEmpty: boolean;
Result := FTableNames.IsEmpty;
end;

function TCQLDelete.Serialize: String;
function TCQLDelete.Serialize: string;
begin
if IsEmpty then
Result := ''
Expand Down
64 changes: 32 additions & 32 deletions Source/Core/cqlbr.expression.pas
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ TCQLExpression = class(TInterfacedObject, ICQLExpression)
FOperation: TExpressionOperation;
FLeft: ICQLExpression;
FRight: ICQLExpression;
FTerm: String;
function SerializeWhere(AAddParens: Boolean): String;
function SerializeAND: String;
function SerializeOR: String;
function SerializeOperator: String;
function SerializeFunction: String;
FTerm: string;
function _SerializeWhere(AAddParens: Boolean): string;
function _SerializeAND: string;
function _SerializeOR: string;
function _SerializeOperator: string;
function _SerializeFunction: string;
protected
function GetLeft: ICQLExpression;
function GetOperation: TExpressionOperation;
Expand All @@ -58,13 +58,13 @@ TCQLExpression = class(TInterfacedObject, ICQLExpression)
procedure SetLeft(const AValue: ICQLExpression);
procedure SetOperation(const AValue: TExpressionOperation);
procedure SetRight(const AValue: ICQLExpression);
procedure SetTerm(const AValue: String);
procedure SetTerm(const AValue: string);
public
class function New: ICQLExpression;
procedure Assign(const ANode: ICQLExpression);
procedure Clear;
function IsEmpty: Boolean;
function Serialize(AAddParens: Boolean = False): String;
function Serialize(AAddParens: Boolean = False): string;
property Term: string read GetTerm write SetTerm;
property Operation: TExpressionOperation read GetOperation write SetOperation;
property Left: ICQLExpression read GetLeft write SetLeft;
Expand All @@ -78,21 +78,21 @@ TCQLCriteriaExpression = class(TInterfacedObject, ICQLCriteriaExpression)
protected
function FindRightmostAnd(const AExpression: ICQLExpression): ICQLExpression;
public
constructor Create(const AExpression: String = ''); overload;
constructor Create(const AExpression: string = ''); overload;
constructor Create(const AExpression: ICQLExpression); overload;
function &And(const AExpression: array of const): ICQLCriteriaExpression; overload;
function &And(const AExpression: String): ICQLCriteriaExpression; overload;
function &And(const AExpression: string): ICQLCriteriaExpression; overload;
function &And(const AExpression: ICQLExpression): ICQLCriteriaExpression; overload;
function &Or(const AExpression: array of const): ICQLCriteriaExpression; overload;
function &Or(const AExpression: String): ICQLCriteriaExpression; overload;
function &Or(const AExpression: string): ICQLCriteriaExpression; overload;
function &Or(const AExpression: ICQLExpression): ICQLCriteriaExpression; overload;
function &Ope(const AExpression: array of const): ICQLCriteriaExpression; overload;
function &Ope(const AExpression: String): ICQLCriteriaExpression; overload;
function &Ope(const AExpression: string): ICQLCriteriaExpression; overload;
function &Ope(const AExpression: ICQLExpression): ICQLCriteriaExpression; overload;
function &Fun(const AExpression: array of const): ICQLCriteriaExpression; overload;
function &Fun(const AExpression: String): ICQLCriteriaExpression; overload;
function &Fun(const AExpression: string): ICQLCriteriaExpression; overload;
function &Fun(const AExpression: ICQLExpression): ICQLCriteriaExpression; overload;
function AsString: String;
function AsString: string;
function Expression: ICQLExpression;
end;

Expand Down Expand Up @@ -150,54 +150,54 @@ class function TCQLExpression.New: ICQLExpression;
Result := Self.Create;
end;

function TCQLExpression.Serialize(AAddParens: Boolean): String;
function TCQLExpression.Serialize(AAddParens: Boolean): string;
begin
if IsEmpty then
Result := ''
else
case FOperation of
opNone:
Result := SerializeWhere(AAddParens);
Result := _SerializeWhere(AAddParens);
opAND:
Result := SerializeAND;
Result := _SerializeAND;
opOR:
Result := SerializeOR;
Result := _SerializeOR;
opOperation:
Result := SerializeOperator;
Result := _SerializeOperator;
opFunction:
Result := SerializeFunction;
Result := _SerializeFunction;
else
raise Exception.Create('TCQLExpression.Serialize: Unknown operation');
end;
end;

function TCQLExpression.SerializeAND: String;
function TCQLExpression._SerializeAND: string;
begin
Result := TUtils.Concat([FLeft.Serialize(True),
'AND',
FRight.Serialize(True)]);
end;

function TCQLExpression.SerializeFunction: String;
function TCQLExpression._SerializeFunction: string;
begin
Result := TUtils.Concat([FLeft.Serialize(False),
FRight.Serialize(False)]);
end;

function TCQLExpression.SerializeOperator: String;
function TCQLExpression._SerializeOperator: string;
begin
Result := '(' + TUtils.Concat([FLeft.Serialize(False),
FRight.Serialize(False)]) + ')';
end;

function TCQLExpression.SerializeOR: String;
function TCQLExpression._SerializeOR: string;
begin
Result := '(' + TUtils.Concat([FLeft.Serialize(True),
'OR',
FRight.Serialize(True)]) + ')';
end;

function TCQLExpression.SerializeWhere(AAddParens: Boolean): String;
function TCQLExpression._SerializeWhere(AAddParens: Boolean): string;
begin
if AAddParens then
Result := TUtils.concat(['(', FTerm, ')'], '')
Expand All @@ -220,7 +220,7 @@ procedure TCQLExpression.SetRight(const AValue: ICQLExpression);
FRight := AValue;
end;

procedure TCQLExpression.SetTerm(const AValue: String);
procedure TCQLExpression.SetTerm(const AValue: string);
begin
FTerm := AValue;
end;
Expand Down Expand Up @@ -250,7 +250,7 @@ function TCQLCriteriaExpression.&And(const AExpression: ICQLExpression): ICQLCri
Result := Self;
end;

function TCQLCriteriaExpression.&And(const AExpression: String): ICQLCriteriaExpression;
function TCQLCriteriaExpression.&And(const AExpression: string): ICQLCriteriaExpression;
var
LNode: ICQLExpression;
begin
Expand All @@ -264,7 +264,7 @@ function TCQLCriteriaExpression.&And(const AExpression: array of const): ICQLCri
Result := &And(TUtils.SqlParamsToStr(AExpression));
end;

function TCQLCriteriaExpression.AsString: String;
function TCQLCriteriaExpression.AsString: string;
begin
Result := FExpression.Serialize;
end;
Expand All @@ -280,7 +280,7 @@ function TCQLCriteriaExpression.Expression: ICQLExpression;
Result := FExpression;
end;

constructor TCQLCriteriaExpression.Create(const AExpression: String);
constructor TCQLCriteriaExpression.Create(const AExpression: string);
begin
FExpression := TCQLExpression.New;
if AExpression <> '' then
Expand All @@ -303,7 +303,7 @@ function TCQLCriteriaExpression.Fun(const AExpression: array of const): ICQLCrit
Result := &Fun(TUtils.SqlParamsToStr(AExpression));
end;

function TCQLCriteriaExpression.Fun(const AExpression: String): ICQLCriteriaExpression;
function TCQLCriteriaExpression.Fun(const AExpression: string): ICQLCriteriaExpression;
var
LNode: ICQLExpression;
begin
Expand All @@ -329,7 +329,7 @@ function TCQLCriteriaExpression.&Or(const AExpression: array of const): ICQLCrit
Result := &Or(TUtils.SqlParamsToStr(AExpression));
end;

function TCQLCriteriaExpression.&Or(const AExpression: String): ICQLCriteriaExpression;
function TCQLCriteriaExpression.&Or(const AExpression: string): ICQLCriteriaExpression;
var
LNode: ICQLExpression;
begin
Expand All @@ -343,7 +343,7 @@ function TCQLCriteriaExpression.&Ope(const AExpression: array of const): ICQLCri
Result := &Ope(TUtils.SqlParamsToStr(AExpression));
end;

function TCQLCriteriaExpression.&Ope(const AExpression: String): ICQLCriteriaExpression;
function TCQLCriteriaExpression.&Ope(const AExpression: string): ICQLCriteriaExpression;
var
LNode: ICQLExpression;
begin
Expand Down
Loading

0 comments on commit 8f88d90

Please sign in to comment.