mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
MVCAREntitiesGenerator can optionally register all the generated entities also in the ActiveRecordMappingRegistry
(Thanks to [Fabrizio Bitti](https://twitter.com/fabriziobitti) from [bit Time Software](http://www.bittime.it))
This commit is contained in:
parent
9b57586dd4
commit
57da1259d8
@ -78,6 +78,7 @@ Congratulations to Daniele Teti and all the staff for the excellent work!" -- Ma
|
||||
- New! Added SQLGenerator and RQL compiler for PostgreSQL, SQLite and MSSQLServer (in addition to MySQL, MariaDB, Firebird and Interbase)
|
||||
- New! Added support for interfaces serialization - now it is possible to serialize Spring4D collections (thanks to [João Antônio Duarte](https://github.com/joaoduarte19))
|
||||
- New! Added support for Spring4D Nullable Types - check (thanks to [João Antônio Duarte](https://github.com/joaoduarte19))
|
||||
- Added `TMVCJSONRPCExecutor.ConfigHTTPClient` to fully customize the inner `THTTPClient` (e.g. `ConnectionTimeout`, `ResponseTimeout` and so on)
|
||||
- Improved! Greatly improved support for [HATEOAS](https://en.wikipedia.org/wiki/HATEOAS) in renders. Check `TRenderSampleController.GetPeople_AsObjectList_HATEOS` and all the others actions end with `HATEOS` in `renders.dproj` sample)
|
||||
|
||||
```delphi
|
||||
@ -232,6 +233,8 @@ end;
|
||||
|
||||
Before it was not possible because you should add the `MVCListOf` attribute to the `TObjectList` type property.
|
||||
|
||||
- New! The **MVCAREntitiesGenerator** can optionally register all the generated entities also in the `ActiveRecordMappingRegistry` (Thanks to [Fabrizio Bitti](https://twitter.com/fabriziobitti) from [bit Time Software](http://www.bittime.it))
|
||||
|
||||
- Fixed! [issue184](https://github.com/danieleteti/delphimvcframework/issues/184)
|
||||
|
||||
- Fixed! [issue278](https://github.com/danieleteti/delphimvcframework/issues/278)
|
||||
@ -240,7 +243,7 @@ end;
|
||||
|
||||
- Fixed! [issue182](https://github.com/danieleteti/delphimvcframework/issues/182)
|
||||
|
||||
- Fixed! [issue232](https://github.com/danieleteti/delphimvcframework/issues/232) (Thanks to Thank you to [João Antônio Duarte](https://github.com/joaoduarte19))
|
||||
- Fixed! [issue232](https://github.com/danieleteti/delphimvcframework/issues/232) (Thanks to [João Antônio Duarte](https://github.com/joaoduarte19))
|
||||
|
||||
- New Installation procedure!
|
||||
|
||||
|
@ -1397,7 +1397,9 @@ begin
|
||||
FError.ErrMessage := JSON.O[JSONRPC_ERROR].S[JSONRPC_MESSAGE];
|
||||
end
|
||||
else
|
||||
begin
|
||||
raise EMVCJSONRPCException.Create('Response message must have ''result'' or ''error''');
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -215,6 +215,18 @@ object MainForm: TMainForm
|
||||
TabOrder = 1
|
||||
OnClick = btnGetTablesClick
|
||||
end
|
||||
object chGenerateMapping: TCheckBox
|
||||
Left = 255
|
||||
Top = 12
|
||||
Width = 514
|
||||
Height = 17
|
||||
Caption =
|
||||
'Register entities in ActiveRecordMappingRegistry (needed by TMVC' +
|
||||
'ActiveRecordController)'
|
||||
Checked = True
|
||||
State = cbChecked
|
||||
TabOrder = 2
|
||||
end
|
||||
end
|
||||
object PageControl1: TPageControl
|
||||
AlignWithMargins = True
|
||||
@ -292,7 +304,7 @@ object MainForm: TMainForm
|
||||
end
|
||||
object FDConnection1: TFDConnection
|
||||
Params.Strings = (
|
||||
'ConnectionDef=EMPLOYEE_FB')
|
||||
'DriverID=MSSQL')
|
||||
ConnectedStoredUsage = []
|
||||
LoginPrompt = False
|
||||
Left = 256
|
||||
@ -309,8 +321,8 @@ object MainForm: TMainForm
|
||||
UpdateOptions.EnableDelete = False
|
||||
UpdateOptions.EnableInsert = False
|
||||
UpdateOptions.EnableUpdate = False
|
||||
Left = 328
|
||||
Top = 200
|
||||
Left = 304
|
||||
Top = 152
|
||||
end
|
||||
object FDPhysFBDriverLink1: TFDPhysFBDriverLink
|
||||
Left = 616
|
||||
@ -389,80 +401,4 @@ object MainForm: TMainForm
|
||||
Left = 48
|
||||
Top = 368
|
||||
end
|
||||
object FDQuery1: TFDQuery
|
||||
Connection = FDConnection1
|
||||
FetchOptions.AssignedValues = [evRecsMax, evRowsetSize, evAutoFetchAll]
|
||||
FetchOptions.RowsetSize = 1
|
||||
FetchOptions.RecsMax = 1
|
||||
FetchOptions.AutoFetchAll = afDisable
|
||||
UpdateOptions.AssignedValues = [uvEDelete, uvEInsert, uvEUpdate]
|
||||
UpdateOptions.EnableDelete = False
|
||||
UpdateOptions.EnableInsert = False
|
||||
UpdateOptions.EnableUpdate = False
|
||||
SQL.Strings = (
|
||||
'select * from customer')
|
||||
Left = 336
|
||||
Top = 208
|
||||
object FDQuery1CUST_NO: TIntegerField
|
||||
FieldName = 'CUST_NO'
|
||||
Origin = 'CUST_NO'
|
||||
ProviderFlags = [pfInUpdate, pfInWhere, pfInKey]
|
||||
Required = True
|
||||
end
|
||||
object FDQuery1CUSTOMER: TStringField
|
||||
FieldName = 'CUSTOMER'
|
||||
Origin = 'CUSTOMER'
|
||||
Required = True
|
||||
Size = 25
|
||||
end
|
||||
object FDQuery1CONTACT_FIRST: TStringField
|
||||
FieldName = 'CONTACT_FIRST'
|
||||
Origin = 'CONTACT_FIRST'
|
||||
Size = 15
|
||||
end
|
||||
object FDQuery1CONTACT_LAST: TStringField
|
||||
FieldName = 'CONTACT_LAST'
|
||||
Origin = 'CONTACT_LAST'
|
||||
end
|
||||
object FDQuery1PHONE_NO: TStringField
|
||||
FieldName = 'PHONE_NO'
|
||||
Origin = 'PHONE_NO'
|
||||
end
|
||||
object FDQuery1ADDRESS_LINE1: TStringField
|
||||
FieldName = 'ADDRESS_LINE1'
|
||||
Origin = 'ADDRESS_LINE1'
|
||||
Size = 30
|
||||
end
|
||||
object FDQuery1ADDRESS_LINE2: TStringField
|
||||
FieldName = 'ADDRESS_LINE2'
|
||||
Origin = 'ADDRESS_LINE2'
|
||||
Size = 30
|
||||
end
|
||||
object FDQuery1CITY: TStringField
|
||||
FieldName = 'CITY'
|
||||
Origin = 'CITY'
|
||||
Size = 25
|
||||
end
|
||||
object FDQuery1STATE_PROVINCE: TStringField
|
||||
FieldName = 'STATE_PROVINCE'
|
||||
Origin = 'STATE_PROVINCE'
|
||||
Size = 15
|
||||
end
|
||||
object FDQuery1COUNTRY: TStringField
|
||||
FieldName = 'COUNTRY'
|
||||
Origin = 'COUNTRY'
|
||||
Size = 15
|
||||
end
|
||||
object FDQuery1POSTAL_CODE: TStringField
|
||||
FieldName = 'POSTAL_CODE'
|
||||
Origin = 'POSTAL_CODE'
|
||||
Size = 12
|
||||
end
|
||||
object FDQuery1ON_HOLD: TStringField
|
||||
FieldName = 'ON_HOLD'
|
||||
Origin = 'ON_HOLD'
|
||||
FixedChar = True
|
||||
Size = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -92,6 +92,7 @@ type
|
||||
lstCatalog: TListBox;
|
||||
btnRefreshCatalog: TButton;
|
||||
Label1: TLabel;
|
||||
chGenerateMapping: TCheckBox;
|
||||
procedure btnGenEntitiesClick(Sender: TObject);
|
||||
procedure btnGetTablesClick(Sender: TObject);
|
||||
procedure btnSaveCodeClick(Sender: TObject);
|
||||
@ -105,7 +106,7 @@ type
|
||||
private
|
||||
fCatalog: string;
|
||||
fSchema: string;
|
||||
fIntfBuff, fImplBuff: TStringStream;
|
||||
fIntfBuff, fImplBuff, fInitializationBuff: TStringStream;
|
||||
FHistoryFileName: string;
|
||||
lTypesName: TArray<string>;
|
||||
procedure EmitHeaderComments;
|
||||
@ -132,6 +133,7 @@ uses
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
|
||||
const
|
||||
INDENT = ' ';
|
||||
|
||||
@ -146,6 +148,7 @@ var
|
||||
begin
|
||||
fIntfBuff.Clear;
|
||||
fImplBuff.Clear;
|
||||
fInitializationBuff.Clear;
|
||||
lKeyFields := TStringList.Create;
|
||||
try
|
||||
EmitHeaderComments;
|
||||
@ -164,7 +167,7 @@ begin
|
||||
fIntfBuff.WriteString(INDENT + 'private' + sLineBreak);
|
||||
for F := 0 to qry.Fields.Count - 1 do
|
||||
begin
|
||||
EmitField(qry.Fields[F], LKeyFields.IndexOf(qry.Fields[F].FieldName) > -1);
|
||||
EmitField(qry.Fields[F], lKeyFields.IndexOf(qry.Fields[F].FieldName) > -1);
|
||||
|
||||
if GetDelphiType(qry.Fields[F].DataType) = 'TStream' then
|
||||
begin
|
||||
@ -205,7 +208,7 @@ begin
|
||||
dsTablesMapping.Next;
|
||||
end;
|
||||
EmitUnitEnd;
|
||||
mmOutput.Lines.Text := fIntfBuff.DataString + fImplBuff.DataString;
|
||||
mmOutput.Lines.Text := fIntfBuff.DataString + fImplBuff.DataString + fInitializationBuff.DataString;
|
||||
|
||||
finally
|
||||
lKeyFields.Free;
|
||||
@ -277,8 +280,9 @@ begin
|
||||
FDConnection1.Close;
|
||||
FDManager.GetConnectionDefParams(cboConnectionDefs.Text, mmConnectionParams.Lines);
|
||||
lstCatalog.Items.Clear;
|
||||
// FDConnection1.GetCatalogNames('', lstCatalog.Items);
|
||||
lstSchema.Items.Clear;
|
||||
FDConnection1.Params.Clear;
|
||||
FDConnection1.Params.Text := mmConnectionParams.Text;
|
||||
end;
|
||||
|
||||
procedure TMainForm.EmitClass(const aTableName, aClassName: string);
|
||||
@ -288,6 +292,9 @@ begin
|
||||
if trim(aClassName) = '' then
|
||||
raise Exception.Create('Invalid class name');
|
||||
fIntfBuff.WriteString(INDENT + aClassName + ' = class(TMVCActiveRecord)' + sLineBreak);
|
||||
if chGenerateMapping.Checked then
|
||||
fInitializationBuff.WriteString(INDENT + Format('ActiveRecordMappingRegistry.AddEntity(''%s'',%s);',
|
||||
[aTableName.ToLower, aClassName]) + sLineBreak);
|
||||
end;
|
||||
|
||||
procedure TMainForm.EmitClassEnd;
|
||||
@ -298,15 +305,10 @@ end;
|
||||
procedure TMainForm.EmitField(F: TField; const IsPK: Boolean);
|
||||
var
|
||||
lAttrib, lField: String;
|
||||
lOptions: TArray<String>;
|
||||
begin
|
||||
if IsPK then
|
||||
begin
|
||||
if F.AutoGenerateValue = arAutoInc then
|
||||
Insert('foAutoGenerated', lOptions, 0);
|
||||
if pfInKey in F.ProviderFlags then
|
||||
Insert('foPrimaryKey', lOptions, 0);
|
||||
lAttrib := Format('[MVCTableField(''%s'', [' + String.Join(', ', lOptions) + '])]', [F.FieldName]);
|
||||
lAttrib := Format('[MVCTableField(''%s'', [foPrimaryKey, foAutoGenerated])]', [F.FieldName]);
|
||||
end
|
||||
else
|
||||
begin
|
||||
@ -389,23 +391,27 @@ begin
|
||||
fIntfBuff.WriteString('' + sLineBreak);
|
||||
|
||||
fImplBuff.WriteString('implementation' + sLineBreak + sLineBreak);
|
||||
|
||||
fInitializationBuff.WriteString('initialization' + sLineBreak + sLineBreak);
|
||||
end;
|
||||
|
||||
procedure TMainForm.EmitUnitEnd;
|
||||
begin
|
||||
fImplBuff.WriteString(sLineBreak + 'end.');
|
||||
fInitializationBuff.WriteString(sLineBreak + 'end.');
|
||||
end;
|
||||
|
||||
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
|
||||
begin
|
||||
fIntfBuff.Free;
|
||||
fImplBuff.Free;
|
||||
fInitializationBuff.Free;
|
||||
end;
|
||||
|
||||
procedure TMainForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
fIntfBuff := TStringStream.Create;
|
||||
fImplBuff := TStringStream.Create;
|
||||
fInitializationBuff := TStringStream.Create;
|
||||
FHistoryFileName := TPath.Combine(TPath.GetDocumentsPath, TPath.GetFileNameWithoutExtension(ParamStr(0)) +
|
||||
'.history');
|
||||
try
|
||||
@ -427,7 +433,7 @@ var
|
||||
lNextLetter: Integer;
|
||||
lNextLetterChar: string;
|
||||
begin
|
||||
lTableName := aTableName.ToLower.DeQuotedString('"').Replace(' ','_',[rfReplaceAll]);
|
||||
lTableName := aTableName.ToLower.DeQuotedString('"').Replace(' ', '_', [rfReplaceAll]);
|
||||
Result := 'T' + lTableName.Substring(0, 1).ToUpper + lTableName.Substring(1).ToLower;
|
||||
|
||||
while Result.IndexOf('_') > -1 do
|
||||
|
Loading…
Reference in New Issue
Block a user