mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 15:55:54 +01:00
Merge branch 'master' of https://github.com/danieleteti/delphimvcframework
This commit is contained in:
commit
3a0981f207
@ -192,6 +192,11 @@ type
|
||||
/// </summary>
|
||||
procedure OnBeforeInsertOrUpdate; virtual;
|
||||
|
||||
/// <summary>
|
||||
/// Called before execute sql
|
||||
/// </summary>
|
||||
procedure OnBeforeExecuteSQL(var SQL:String); virtual;
|
||||
|
||||
/// <summary>
|
||||
/// Called after insert or update the object to the database
|
||||
/// </summary>
|
||||
@ -633,11 +638,14 @@ var
|
||||
lPar: TFDParam;
|
||||
lPair: TPair<TRttiField, string>;
|
||||
lValue: TValue;
|
||||
lSQL : String;
|
||||
begin
|
||||
lQry := TFDQuery.Create(nil);
|
||||
try
|
||||
lQry.Connection := fConn;
|
||||
lQry.SQL.Text := SQL;
|
||||
lSQL := SQL;
|
||||
OnBeforeExecuteSQL(lSQL);
|
||||
lQry.SQL.Text := lSQL;
|
||||
// lQry.Prepare;
|
||||
for lPair in fMap do
|
||||
begin
|
||||
@ -669,7 +677,7 @@ begin
|
||||
end
|
||||
else
|
||||
begin
|
||||
lQry.ExecSQL(SQL);
|
||||
lQry.ExecSQL(lSQL);
|
||||
end;
|
||||
|
||||
Result := lQry.RowsAffected;
|
||||
@ -1103,6 +1111,10 @@ begin
|
||||
begin
|
||||
aRTTIField.SetValue(Self, BCDtoCurrency(aField.AsBCD));
|
||||
end;
|
||||
ftFloat:
|
||||
begin
|
||||
aRTTIField.SetValue(Self, aField.AsFloat);
|
||||
end;
|
||||
ftBlob:
|
||||
begin
|
||||
lInternalStream := aRTTIField.GetValue(Self).AsObject as TStream;
|
||||
@ -1127,7 +1139,13 @@ end;
|
||||
procedure TMVCActiveRecord.MapTValueToParam(const aValue: TValue; const aParam: TFDParam);
|
||||
var
|
||||
lStream: TStream;
|
||||
lName: String;
|
||||
begin
|
||||
{$IFDEF NEXTGEN}
|
||||
lName := aValue.TypeInfo.NameFld.ToString;
|
||||
{$ELSE}
|
||||
lName := String(aValue.TypeInfo.Name);
|
||||
{$ENDIF}
|
||||
case aValue.TypeInfo.Kind of
|
||||
// tkUnknown:
|
||||
// begin
|
||||
@ -1182,15 +1200,15 @@ begin
|
||||
end;
|
||||
tkFloat:
|
||||
begin
|
||||
if aValue.TypeInfo.Name = 'TDate' then
|
||||
if lName = 'TDate' then
|
||||
begin
|
||||
aParam.AsDate := Trunc(aValue.AsExtended);
|
||||
end
|
||||
else if aValue.TypeInfo.Name = 'TDateTime' then
|
||||
else if lName = 'TDateTime' then
|
||||
begin
|
||||
aParam.AsDateTime := aValue.AsExtended;
|
||||
end
|
||||
else if aValue.TypeInfo.Name = 'Currency' then
|
||||
else if lName = 'Currency' then
|
||||
begin
|
||||
aParam.AsCurrency := aValue.AsCurrency;
|
||||
end
|
||||
@ -1431,6 +1449,11 @@ begin
|
||||
// do nothing
|
||||
end;
|
||||
|
||||
procedure TMVCActiveRecord.OnBeforeExecuteSQL(var SQL:String);
|
||||
begin
|
||||
// do nothing
|
||||
end;
|
||||
|
||||
procedure TMVCActiveRecord.OnBeforeInsert;
|
||||
begin
|
||||
// do nothing
|
||||
@ -1836,7 +1859,7 @@ function TMVCSQLGenerator.GetRQLParser: TRQL2SQL;
|
||||
begin
|
||||
if fRQL2SQL = nil then
|
||||
begin
|
||||
fRQL2SQL := TRQL2SQL.Create(20);
|
||||
fRQL2SQL := TRQL2SQL.Create;//(20);
|
||||
end;
|
||||
Result := fRQL2SQL;
|
||||
end;
|
||||
@ -1862,7 +1885,11 @@ end;
|
||||
destructor TMVCConnectionsRepository.TConnHolder.Destroy;
|
||||
begin
|
||||
if OwnsConnection then
|
||||
Begin
|
||||
if Connection.connected then
|
||||
Connection.connected := False;
|
||||
FreeAndNil(Connection);
|
||||
End;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
|
@ -319,7 +319,19 @@ procedure TMVCActiveRecordController.UpdateEntity(const entityname: string; cons
|
||||
var
|
||||
lAR: TMVCActiveRecord;
|
||||
lARClass: TMVCActiveRecordClass;
|
||||
lProcessor: IMVCEntityProcessor;
|
||||
lHandled: Boolean;
|
||||
begin
|
||||
lProcessor := nil;
|
||||
if ActiveRecordMappingRegistry.FindProcessorByURLSegment(entityname, lProcessor) then
|
||||
begin
|
||||
lHandled := False;
|
||||
lProcessor.UpdateEntity(Context, self, entityname,id ,lHandled);
|
||||
if lHandled then
|
||||
begin
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
// lAR := ActiveRecordMappingRegistry.GetEntityByURLSegment(entityname).Create;
|
||||
if not ActiveRecordMappingRegistry.FindEntityClassByURLSegment(entityname, lARClass) then
|
||||
begin
|
||||
|
@ -70,6 +70,8 @@ type
|
||||
function AsObjectList<T: class, constructor>(CloseAfterScroll: boolean = false;
|
||||
OwnsObjects: boolean = true): TObjectList<T>;
|
||||
function AsObject<T: class, constructor>(CloseAfterScroll: boolean = false): T;
|
||||
procedure LoadFromJSONArrayStringItems(AJSONArrayString: string;
|
||||
AFieldNamePolicy: TFieldNamePolicy = TFieldNamePolicy.fpLowerCase);
|
||||
end;
|
||||
|
||||
TDataSetUtils = class sealed
|
||||
@ -236,6 +238,20 @@ begin
|
||||
AppendFromJSONArrayString(AJSONArrayString, TArray<string>.Create(), AFieldNamePolicy);
|
||||
end;
|
||||
|
||||
procedure TDataSetHelper.LoadFromJSONArrayStringItems(AJSONArrayString: string;
|
||||
AFieldNamePolicy: TFieldNamePolicy);
|
||||
var aJson:TJsonObject;
|
||||
begin
|
||||
aJson := TJsonObject.Create;
|
||||
try
|
||||
aJson.FromJSON(AJSONArrayString);
|
||||
AJSONArrayString := aJson.ExtractArray('items').ToString;
|
||||
AppendFromJSONArrayString(AJSONArrayString, TArray<string>.Create(), AFieldNamePolicy);
|
||||
finally
|
||||
aJson.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDataSetHelper.AppendFromJSONArrayString(AJSONArrayString: string;
|
||||
AIgnoredFields: TArray<string>;
|
||||
AFieldNamePolicy: TFieldNamePolicy);
|
||||
|
@ -41,7 +41,8 @@ uses
|
||||
MVCFramework.Tests.Serializer.Intf,
|
||||
MVCFramework.Tests.Serializer.Entities,
|
||||
MVCFramework.Tests.Serializer.EntitiesModule,
|
||||
JsonDataObjects;
|
||||
JsonDataObjects,
|
||||
MVCFramework.DataSet.Utils;
|
||||
|
||||
type
|
||||
|
||||
@ -108,7 +109,8 @@ type
|
||||
public
|
||||
procedure SerializeRoot(const AObject: TObject;
|
||||
out ASerializerObject: TObject;
|
||||
const AAttributes: System.TArray<System.TCustomAttribute>);
|
||||
const AAttributes: System.TArray<System.TCustomAttribute>;
|
||||
const ASerializationAction: TMVCSerializationAction = nil);
|
||||
procedure SerializeAttribute(const AElementValue: TValue;
|
||||
const APropertyName: string; const ASerializerObject: TObject;
|
||||
const AAttributes: System.TArray<System.TCustomAttribute>);
|
||||
@ -134,7 +136,8 @@ type
|
||||
const AAttributes: System.TArray<System.TCustomAttribute>);
|
||||
procedure SerializeRoot(const AObject: TObject;
|
||||
out ASerializerObject: TObject;
|
||||
const AAttributes: System.TArray<System.TCustomAttribute>);
|
||||
const AAttributes: System.TArray<System.TCustomAttribute>;
|
||||
const ASerializationAction: TMVCSerializationAction = nil);
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -288,6 +291,20 @@ const
|
||||
'"Name_Name":"Ezequiel Juliano Müller"' +
|
||||
'}' +
|
||||
']';
|
||||
|
||||
JSON_ITEMS=
|
||||
'{' +
|
||||
'"items":[' +
|
||||
'{' +
|
||||
'"Id_Id":1,' +
|
||||
'"Name_Name":"Pedro Henrique de Oliveira"' +
|
||||
'},' +
|
||||
'{' +
|
||||
'"Id_Id":2,' +
|
||||
'"Name_Name":"Rogers Abe"' +
|
||||
'}' +
|
||||
'],' +
|
||||
'"meta":{"count":"2"}}';
|
||||
var
|
||||
Dm: TEntitiesModule;
|
||||
begin
|
||||
@ -342,6 +359,16 @@ begin
|
||||
Dm.EntityAsIs.Next;
|
||||
Assert.isTrue(Dm.EntityAsIsId.AsLargeInt = 2);
|
||||
Assert.isTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano Müller');
|
||||
|
||||
Dm.EntityAsIs.EmptyDataSet;
|
||||
Dm.EntityAsIs.LoadFromJSONArrayStringItems(JSON_ITEMS);
|
||||
Dm.EntityAsIs.First;
|
||||
Assert.isTrue(Dm.EntityAsIsId.AsLargeInt = 1);
|
||||
Assert.isTrue(Dm.EntityAsIsName.AsString = 'Pedro Henrique de Oliveira');
|
||||
|
||||
Dm.EntityAsIs.Next;
|
||||
Assert.isTrue(Dm.EntityAsIsId.AsLargeInt = 2);
|
||||
Assert.isTrue(Dm.EntityAsIsName.AsString = 'Rogers Abe');
|
||||
finally
|
||||
Dm.Free;
|
||||
end;
|
||||
@ -701,6 +728,7 @@ const
|
||||
'"Name_Name":"Ezequiel Juliano Müller"' +
|
||||
'}' +
|
||||
']';
|
||||
|
||||
var
|
||||
Dm: TEntitiesModule;
|
||||
S: string;
|
||||
@ -1306,7 +1334,8 @@ end;
|
||||
|
||||
procedure TMVCEntityCustomSerializerJsonDataObjects.SerializeRoot(
|
||||
const AObject: TObject; out ASerializerObject: TObject;
|
||||
const AAttributes: System.TArray<System.TCustomAttribute>);
|
||||
const AAttributes: System.TArray<System.TCustomAttribute>;
|
||||
const ASerializationAction: TMVCSerializationAction);
|
||||
var
|
||||
lEntityCustom: TEntityCustom;
|
||||
begin
|
||||
@ -1348,7 +1377,8 @@ end;
|
||||
|
||||
procedure TMVCNullableIntegerSerializerJsonDataObjects.SerializeRoot(
|
||||
const AObject: TObject; out ASerializerObject: TObject;
|
||||
const AAttributes: System.TArray<System.TCustomAttribute>);
|
||||
const AAttributes: System.TArray<System.TCustomAttribute>;
|
||||
const ASerializationAction: TMVCSerializationAction);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user