Skip to content

Commit

Permalink
https://github.com/danieleteti/delphimvcframework/issues/682
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Aug 30, 2023
1 parent f5f9220 commit f21bb11
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 24 deletions.
63 changes: 51 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,52 @@ Congratulations to Daniele Teti and all the staff for the excellent work!" -- Ma

- 🐞 FIX [Issue 680](https://github.com/danieleteti/delphimvcframework/issues/680)

- 🐞 FIX [Issue 682](https://github.com/danieleteti/delphimvcframework/issues/682) (Thanks to [wuhao13](https://github.com/wuhao13))

- 🐞 FIX Wrong comparison in checks for ro/RW/PK fields in `TMVCActiveRecord`

- 🐞 FIX wrong default initialization for JWT (thanks to Flavio Basile)

- ⚡ Wizard updated to be dotEnv aware

- ⚡ Added "Load Style" methods to `TMVCActiveRecord` as suggested by https://github.com/danieleteti/delphimvcframework/issues/675
- ⚡ Added "Load Style" methods to `TMVCActiveRecord` (more info https://github.com/danieleteti/delphimvcframework/issues/675)

- `TMVCActiveRecord` support "Factory Style" and "Load Style" methods when loads data from database.

Using "Factory Style" methods (available from the first version) the result list is returned by the loader method (as shown in this piece of code from the `activerecord_showcase` sample).

```delphi
Log('>> RQL Query (2) - ' + cRQL2);
lCustList := TMVCActiveRecord.SelectRQL<TCustomer>(cRQL2, 20);
try
Log(lCustList.Count.ToString + ' record/s found');
for lCustomer in lCustList do
begin
Log(Format('%5s - %s (%s)', [lCustomer.Code.ValueOrDefault,
lCustomer.CompanyName.ValueOrDefault, lCustomer.City]));
end;
finally
lCustList.Free;
end;
```
For some scenarios would be useful to have also "Load Style" methods where the list is filled by the loader method (not instantiated internally).
```delphi
Log('>> RQL Query (2) - ' + cRQL2);
lCustList := TObjectList<TCustomer>.Create;
try
lRecCount := TMVCActiveRecord.SelectRQL<TCustomer>(cRQL2, 20, lCustList); //new in 3.4.0-neon
Log(lRecCount.ToString + ' record/s found');
for lCustomer in lCustList do
begin
Log(Format('%5s - %s (%s)', [lCustomer.Code.ValueOrDefault,
lCustomer.CompanyName.ValueOrDefault, lCustomer.City]));
end;
finally
lCustList.Free;
end;
```
- ⚡ Better error message in case of serialization of `TArray<TObject>`
Expand Down Expand Up @@ -344,20 +383,20 @@ Congratulations to Daniele Teti and all the staff for the excellent work!" -- Ma
"message":"My Message"
}
```



**Data based response with single object**

```pascal
function TMyController.GetMVCResponse2: TMVCResponse;
begin
Result := MVCResponse(HTTP_STATUS.OK, TPerson.Create('Daniele','Teti', 99));
end;
```

Produces

```json
{
"data": {
Expand All @@ -367,9 +406,9 @@ Congratulations to Daniele Teti and all the staff for the excellent work!" -- Ma
}
}
```

**Data based response with list of objects**

```pascal
function TMyController.GetMVCResponse3: TMVCResponse;
begin
Expand All @@ -382,9 +421,9 @@ Congratulations to Daniele Teti and all the staff for the excellent work!" -- Ma
);
end;
```

Produces

```json
{
"data": [
Expand All @@ -408,7 +447,7 @@ Congratulations to Daniele Teti and all the staff for the excellent work!" -- Ma
```

**Data dictionary based response with `IMVCObjectDictionary` **

```pascal
function TMyController.GetMVCResponseWithObjectDictionary: IMVCResponse;
begin
Expand All @@ -430,9 +469,9 @@ Congratulations to Daniele Teti and all the staff for the excellent work!" -- Ma
);
end;
```

Produces

```json
{
"employees": [
Expand Down
2 changes: 0 additions & 2 deletions sources/MVCFramework.ActiveRecord.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,6 @@ constructor TMVCActiveRecord.Create(aLazyLoadConnection: Boolean);
begin
inherited Create;
fConn := nil;
{ TODO -oDanieleT -cGeneral : Consider lazyconnection }
if not aLazyLoadConnection then
begin
GetConnection;
Expand Down Expand Up @@ -3366,7 +3365,6 @@ procedure TMVCActiveRecord.Assign(ActiveRecord: TMVCActiveRecord);

class function TMVCActiveRecordHelper.All(const aQualifiedClassName: String): TObjectList<TMVCActiveRecord>;
var
lTmp: TObject;
lAR: TMVCActiveRecord;
begin
lAR := TMVCActiveRecord.CreateMVCActiveRecord<TMVCActiveRecord>(aQualifiedClassName, []);
Expand Down
6 changes: 1 addition & 5 deletions sources/MVCFramework.ObjectPool.pas
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ TPoolFactory = class

implementation

uses
WinAPI.Windows;


{ TObjectPool<T> }

constructor TObjectPool<T>.Create(MaxSize: Integer; ShrinkTriggerSize, ShrinkTargetSize: Integer; const Factory: TFunc<T>);
Expand Down Expand Up @@ -243,7 +239,7 @@ procedure TCleanupThread<T>.Execute;
fObjectPool.Lock;
try
fObjectPool.ShrinkPoolTo(fObjectPool.fShrinkTargetSize);
ZeroMemory(@lAvgSize, SizeOf(lAvgSize));
FillChar(lAvgSize, SizeOf(lAvgSize), 0);
finally
fObjectPool.UnLock;
end;
Expand Down
10 changes: 5 additions & 5 deletions sources/MVCFramework.Rtti.Utils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -757,14 +757,14 @@ class procedure TRttiUtils.CopyObjectAS<T>(ASourceObject, ATargetObject: TObject

class function TRttiUtils.CreateObject(AQualifiedClassName: string; const AParams: TArray<TValue> = nil): TObject;
var
rttitype: TRttiType;
lRTTIType: TRttiType;
begin
rttitype := GlContext.FindType(AQualifiedClassName);
if Assigned(rttitype) then
Result := CreateObject(rttitype, AParams)
lRTTIType := GlContext.FindType(AQualifiedClassName);
if Assigned(lRTTIType) then
Result := CreateObject(lRTTIType, AParams)
else
raise Exception.Create('Cannot find RTTI for ' + AQualifiedClassName +
'. Hint: Is the specified classtype linked in the module?');
'. HINT: Is the specified "QualifiedClassName" linked in the module?');
end;

class function TRttiUtils.CreateObject(ARttiType: TRttiType; const AParams: TArray<TValue> = nil): TObject;
Expand Down

0 comments on commit f21bb11

Please sign in to comment.