Browse Source

* Rework zodat domeinen aangemaakt kunnen worden

git-svn-id: trunk@11606 -
michael 17 years ago
parent
commit
8aa9dc6d0e
1 changed files with 120 additions and 21 deletions
  1. 120 21
      packages/fcl-db/src/datadict/fpdatadict.pp

+ 120 - 21
packages/fcl-db/src/datadict/fpdatadict.pp

@@ -30,6 +30,10 @@ Type
 
 
   TFPDDFieldList = Class;
   TFPDDFieldList = Class;
   TFPDDIndexList = Class;
   TFPDDIndexList = Class;
+  TDDTableDef = Class;
+  TDDTableDefs = Class;
+  TDDFieldDefs = Class;
+  TFPDataDictionary = Class;
 
 
   { TDDFieldDef }
   { TDDFieldDef }
 
 
@@ -43,6 +47,7 @@ Type
     FDefaultExpression: string;
     FDefaultExpression: string;
     FDisplayLabel: string;
     FDisplayLabel: string;
     FDisplayWidth: Longint;
     FDisplayWidth: Longint;
+    FDomainName: string;
     FFieldName: string;
     FFieldName: string;
     FFieldType: TFieldType;
     FFieldType: TFieldType;
     FHint: String;
     FHint: String;
@@ -59,6 +64,7 @@ Type
     procedure SetSectionName(const Value: String); override;
     procedure SetSectionName(const Value: String); override;
   Public
   Public
     Constructor Create(ACollection : TCollection); override;
     Constructor Create(ACollection : TCollection); override;
+    Function FieldDefs : TDDFieldDefs;
     Procedure ImportFromField(F: TField; Existing : Boolean = True);
     Procedure ImportFromField(F: TField; Existing : Boolean = True);
     Procedure ApplyToField(F : TField);
     Procedure ApplyToField(F : TField);
     Procedure Assign(Source : TPersistent);  override;
     Procedure Assign(Source : TPersistent);  override;
@@ -74,6 +80,7 @@ Type
     property DisplayLabel : string read FDisplayLabel write FDisplayLabel;
     property DisplayLabel : string read FDisplayLabel write FDisplayLabel;
     property DisplayWidth: Longint read FDisplayWidth write FDisplayWidth;
     property DisplayWidth: Longint read FDisplayWidth write FDisplayWidth;
     property FieldName: string read FFieldName write FFieldName;
     property FieldName: string read FFieldName write FFieldName;
+    property DomainName: string read FDomainName write FDomainName;
     property Constraint: string read FConstraint write FConstraint;
     property Constraint: string read FConstraint write FConstraint;
     property ReadOnly: Boolean read FReadOnly write FReadOnly;
     property ReadOnly: Boolean read FReadOnly write FReadOnly;
     property Required: Boolean read FRequired write FRequired;
     property Required: Boolean read FRequired write FRequired;
@@ -83,24 +90,41 @@ Type
     Property Hint : String Read FHint Write FHint;
     Property Hint : String Read FHint Write FHint;
     Property ProviderFlags : TProviderFlags Read FProviderFlags Write FProviderFlags;
     Property ProviderFlags : TProviderFlags Read FProviderFlags Write FProviderFlags;
   end;
   end;
-  
-  { TDDFieldDefs }
 
 
-  TDDFieldDefs = Class(TIniCollection)
+  { TDDTableCollection }
+  TDDTableCollection = Class(TIniCollection)
   private
   private
+    FTableDef : TDDTableDef;
     FTableName: String;
     FTableName: String;
+    function GetTableName: String;
+  Protected
+    Procedure SetTableDef(ATableDef : TDDTableDef);
+    procedure SetTableName(const AValue: String); virtual;
+  Public
+    Function DataDictionary : TFPDataDictionary;
+    Property TableDef : TDDTableDef Read FTableDef;
+    Property TableName : String Read GetTableName Write SetTableName;
+  end;
+
+  { TDDFieldDefs }
+
+  TDDFieldDefs = Class(TDDTableCollection)
+  private
     function GetField(Index : Integer): TDDFieldDef;
     function GetField(Index : Integer): TDDFieldDef;
     procedure SetField(Index : Integer; const AValue: TDDFieldDef);
     procedure SetField(Index : Integer; const AValue: TDDFieldDef);
-    procedure SetTableName(const AValue: String);
+  Protected
+    procedure SetTableName(const AValue: String); override;
   Public
   Public
-    Constructor Create(ATableName : String);
+    Constructor Create(ATableDef : TDDTableDef);
+    Constructor Create(ATableName : string);
+    Property TableDef : TDDTableDef Read FTableDef;
+    Property TableName : String Read GetTableName Write SetTableName;
     Function AddField(AFieldName: String = '') : TDDFieldDef;
     Function AddField(AFieldName: String = '') : TDDFieldDef;
     Function IndexOfField(AFieldName : String) : Integer;
     Function IndexOfField(AFieldName : String) : Integer;
     Function FindField(AFieldName : String) : TDDFieldDef;
     Function FindField(AFieldName : String) : TDDFieldDef;
     Function FieldByName(AFieldName : String) : TDDFieldDef;
     Function FieldByName(AFieldName : String) : TDDFieldDef;
     Procedure FillFieldList(Const AFieldNames: String; List : TFPDDFieldList);
     Procedure FillFieldList(Const AFieldNames: String; List : TFPDDFieldList);
     Property Fields[Index : Integer] : TDDFieldDef Read GetField Write SetField; default;
     Property Fields[Index : Integer] : TDDFieldDef Read GetField Write SetField; default;
-    Property TableName : String Read FTableName Write SetTableName;
   end;
   end;
   
   
   { TDDIndexDef }
   { TDDIndexDef }
@@ -131,21 +155,20 @@ Type
   end;
   end;
   
   
   { TDDIndexDefs }
   { TDDIndexDefs }
-
-  TDDIndexDefs = Class(TIniCollection)
+  TDDIndexDefs = Class(TDDTableCollection)
   private
   private
-    FTableName : String;
     function GetIndex(Index : Integer): TDDIndexDef;
     function GetIndex(Index : Integer): TDDIndexDef;
     procedure SetIndex(Index : Integer; const AValue: TDDIndexDef);
     procedure SetIndex(Index : Integer; const AValue: TDDIndexDef);
-    procedure SetTableName(const AValue: String);
+  Protected
+    procedure SetTableName(const AValue: String); override;
   Public
   Public
+    Constructor Create(ATableDef : TDDTableDef);
     Constructor Create(ATableName : String);
     Constructor Create(ATableName : String);
     Function AddDDIndexDef(AName : String) : TDDIndexDef;
     Function AddDDIndexDef(AName : String) : TDDIndexDef;
     function AddIndex (AName: String) : TDDIndexDef;
     function AddIndex (AName: String) : TDDIndexDef;
     function IndexByName(AIndexName: String): TDDIndexDef;
     function IndexByName(AIndexName: String): TDDIndexDef;
     function FindIndex(AIndexName: String): TDDIndexDef;
     function FindIndex(AIndexName: String): TDDIndexDef;
     function IndexOfIndex(AIndexName: String): Integer;
     function IndexOfIndex(AIndexName: String): Integer;
-    Property TableName : String Read FTableName Write SetTableName;
     Property Indexes[Index : Integer] : TDDIndexDef Read GetIndex Write SetIndex; default;
     Property Indexes[Index : Integer] : TDDIndexDef Read GetIndex Write SetIndex; default;
   end;
   end;
   
   
@@ -205,6 +228,8 @@ Type
   Public
   Public
     Constructor Create(ACollection : TCollection); override;
     Constructor Create(ACollection : TCollection); override;
     Destructor Destroy; override;
     Destructor Destroy; override;
+    Function DataDictionary : TFPDataDictionary;
+    Function TableDefs : TDDTableDefs;
     Function ImportFromDataset(Dataset : TDataSet; DoClear : Boolean = False; UpdateExisting : Boolean = True) : Integer;
     Function ImportFromDataset(Dataset : TDataSet; DoClear : Boolean = False; UpdateExisting : Boolean = True) : Integer;
     Procedure ApplyToDataset(Dataset : TDataset);
     Procedure ApplyToDataset(Dataset : TDataset);
     Function AddField(AFieldName : String = '') : TDDFieldDef;
     Function AddField(AFieldName : String = '') : TDDFieldDef;
@@ -223,10 +248,12 @@ Type
 
 
   TDDTableDefs = Class(TIniCollection)
   TDDTableDefs = Class(TIniCollection)
   private
   private
+    FDataDictionary: TFPDataDictionary;
     FOnProgress: TDDProgressEvent;
     FOnProgress: TDDProgressEvent;
     function GetTable(Index : Integer): TDDTableDef;
     function GetTable(Index : Integer): TDDTableDef;
     procedure SetTable(Index : Integer; const AValue: TDDTableDef);
     procedure SetTable(Index : Integer; const AValue: TDDTableDef);
   Public
   Public
+    Property DataDictionary: TFPDataDictionary Read FDataDictionary;
     Function AddTable(ATableName : String = '') : TDDTableDef;
     Function AddTable(ATableName : String = '') : TDDTableDef;
     Function IndexOfTable(ATableName : String) : Integer;
     Function IndexOfTable(ATableName : String) : Integer;
     Function FindTable(ATableName : String) : TDDTableDef;
     Function FindTable(ATableName : String) : TDDTableDef;
@@ -585,6 +612,7 @@ Const
   KeyDisplayLabel           = 'DisplayLabel';
   KeyDisplayLabel           = 'DisplayLabel';
   KeyDisplayWidth           = 'DisplayWidth';
   KeyDisplayWidth           = 'DisplayWidth';
   KeyFieldName              = 'FieldName';
   KeyFieldName              = 'FieldName';
+  KeyDomainName             = 'DomainName';
   KeyConstraint             = 'Constraint';
   KeyConstraint             = 'Constraint';
   KeyReadOnly               = 'ReadOnly';
   KeyReadOnly               = 'ReadOnly';
   KeyRequired               = 'Required';
   KeyRequired               = 'Required';
@@ -923,6 +951,11 @@ begin
   FAlignMent:=taLeftJustify;
   FAlignMent:=taLeftJustify;
 end;
 end;
 
 
+function TDDFieldDef.FieldDefs: TDDFieldDefs;
+begin
+  Result:=(Collection as TDDFieldDefs)
+end;
+
 procedure TDDFieldDef.ImportFromField(F: TField; Existing : Boolean = True);
 procedure TDDFieldDef.ImportFromField(F: TField; Existing : Boolean = True);
 begin
 begin
   FieldName:=F.FieldName;
   FieldName:=F.FieldName;
@@ -993,6 +1026,7 @@ begin
     DBDefault:=DF.DBDefault;
     DBDefault:=DF.DBDefault;
     DisplayLabel:=DisplayLabel;
     DisplayLabel:=DisplayLabel;
     FieldName:=DF.FieldName;
     FieldName:=DF.FieldName;
+    DomainName:=DF.DomainName;
     Constraint:=DF.Constraint;
     Constraint:=DF.Constraint;
     Hint:=DF.Hint;
     Hint:=DF.Hint;
     ReadOnly:=DF.ReadOnly;
     ReadOnly:=DF.ReadOnly;
@@ -1026,6 +1060,7 @@ begin
     WriteString(ASection,KeyDBDefault,DBDefault);
     WriteString(ASection,KeyDBDefault,DBDefault);
     WriteString(ASection,KeyDisplayLabel,DisplayLabel);
     WriteString(ASection,KeyDisplayLabel,DisplayLabel);
     WriteString(ASection,KeyFieldName,FieldName);
     WriteString(ASection,KeyFieldName,FieldName);
+    WriteString(ASection,KeyDomainName,DomainName);
     WriteString(ASection,KeyConstraint,Constraint);
     WriteString(ASection,KeyConstraint,Constraint);
     WriteString(ASection,KeyHint,Hint);
     WriteString(ASection,KeyHint,Hint);
     O:=Integer(ProviderFlags);
     O:=Integer(ProviderFlags);
@@ -1061,6 +1096,7 @@ begin
     DBDefault:=ReadString(ASection,KeyDBDefault,DBDefault);
     DBDefault:=ReadString(ASection,KeyDBDefault,DBDefault);
     DisplayLabel:=ReadString(ASection,KeyDisplayLabel,DisplayLabel);
     DisplayLabel:=ReadString(ASection,KeyDisplayLabel,DisplayLabel);
     FieldName:=ReadString(ASection,KeyFieldName,FieldName);
     FieldName:=ReadString(ASection,KeyFieldName,FieldName);
+    DomainName:=ReadString(ASection,KeyDomainName,DomainName);
     Constraint:=ReadString(ASection,KeyConstraint,Constraint);
     Constraint:=ReadString(ASection,KeyConstraint,Constraint);
     Hint:=ReadString(ASection,KeyHint,Hint);
     Hint:=ReadString(ASection,KeyHint,Hint);
     S:=ReadString(ASection,KeyProviderFlags,'');
     S:=ReadString(ASection,KeyProviderFlags,'');
@@ -1080,27 +1116,36 @@ end;
 
 
 procedure TDDFieldDefs.SetTableName(const AValue: String);
 procedure TDDFieldDefs.SetTableName(const AValue: String);
 begin
 begin
-  FTableName:=AValue;
+  Inherited;
   FSectionPrefix:=AValue;
   FSectionPrefix:=AValue;
   GlobalSection:=AValue+SFieldSuffix;
   GlobalSection:=AValue+SFieldSuffix;
 end;
 end;
 
 
+constructor TDDFieldDefs.Create(ATableDef: TDDTableDef);
+begin
+  Inherited Create(TDDFieldDef);
+  FPrefix:='Field';
+  SetTableDef(ATableDef);
+end;
+
+constructor TDDFieldDefs.Create(ATableName: String);
+begin
+  Inherited Create(TDDFieldDef);
+  FPrefix:='Field';
+  TableName:=ATableName;
+end;
+
 function TDDFieldDefs.GetField(Index : Integer): TDDFieldDef;
 function TDDFieldDefs.GetField(Index : Integer): TDDFieldDef;
 begin
 begin
   Result:=TDDFieldDef(Items[Index]);
   Result:=TDDFieldDef(Items[Index]);
 end;
 end;
 
 
+
 procedure TDDFieldDefs.SetField(Index : Integer; const AValue: TDDFieldDef);
 procedure TDDFieldDefs.SetField(Index : Integer; const AValue: TDDFieldDef);
 begin
 begin
   Items[Index]:=AValue;
   Items[Index]:=AValue;
 end;
 end;
 
 
-constructor TDDFieldDefs.Create(ATableName: String);
-begin
-  Inherited Create(TDDFieldDef);
-  FPrefix:='Field';
-  TableName:=ATableName;
-end;
 
 
 function TDDFieldDefs.AddField(AFieldName: String): TDDFieldDef;
 function TDDFieldDefs.AddField(AFieldName: String): TDDFieldDef;
 
 
@@ -1206,8 +1251,8 @@ end;
 constructor TDDTableDef.Create(ACollection: TCollection);
 constructor TDDTableDef.Create(ACollection: TCollection);
 begin
 begin
   inherited Create(ACollection);
   inherited Create(ACollection);
-  FFieldDefs:=TDDFieldDefs.Create('NewTable');
-  FIndexDefs:=TDDIndexDefs.Create('NewTable');
+  FFieldDefs:=TDDFieldDefs.Create(Self);
+  FIndexDefs:=TDDIndexDefs.Create(Self);
   FKeyDefs:=TDDForeignkeyDefs.Create('NewTable');
   FKeyDefs:=TDDForeignkeyDefs.Create('NewTable');
 end;
 end;
 
 
@@ -1220,6 +1265,19 @@ begin
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
+function TDDTableDef.DataDictionary: TFPDataDictionary;
+begin
+  If Assigned(TableDefs) then
+    Result:=TableDefs.DataDictionary
+  else
+    Result:=Nil;
+end;
+
+function TDDTableDef.TableDefs: TDDTableDefs;
+begin
+  Result:=TDDTableDefs(Collection);
+end;
+
 Function TDDTableDef.ImportFromDataset(Dataset: TDataSet; DoClear : Boolean = False; UpdateExisting : Boolean = True) : Integer;
 Function TDDTableDef.ImportFromDataset(Dataset: TDataSet; DoClear : Boolean = False; UpdateExisting : Boolean = True) : Integer;
 
 
 Var
 Var
@@ -1316,6 +1374,7 @@ begin
   Items[Index]:=AValue;
   Items[Index]:=AValue;
 end;
 end;
 
 
+
 function TDDTableDefs.AddTable(ATableName: String): TDDTableDef;
 function TDDTableDefs.AddTable(ATableName: String): TDDTableDef;
 
 
 Var
 Var
@@ -2480,11 +2539,20 @@ end;
 
 
 procedure TDDIndexDefs.SetTableName(const AValue: String);
 procedure TDDIndexDefs.SetTableName(const AValue: String);
 begin
 begin
-  FTableName:=AValue;
+  Inherited;
   FSectionPrefix:=AValue;
   FSectionPrefix:=AValue;
   GlobalSection:=AValue+SIndexSuffix;
   GlobalSection:=AValue+SIndexSuffix;
 end;
 end;
 
 
+constructor TDDIndexDefs.Create(ATableDef: TDDTableDef);
+begin
+  FTableDef:=ATableDef;
+  If Assigned(FTableDef) then
+    Create(FTableDef.TableName)
+  else
+    Create('')
+end;
+
 constructor TDDIndexDefs.Create(ATableName: String);
 constructor TDDIndexDefs.Create(ATableName: String);
 begin
 begin
   FPrefix:='Index';
   FPrefix:='Index';
@@ -2898,6 +2966,37 @@ begin
 end;
 end;
 
 
 
 
+{ TDDTableCollection }
+
+function TDDTableCollection.GetTableName: String;
+begin
+  If Assigned(FTableDef) then
+    Result:=FTableDef.TableName
+  else
+    Result:=FTableName;
+end;
+
+procedure TDDTableCollection.SetTableDef(ATableDef: TDDTableDef);
+begin
+  FTableDef:=ATableDef;
+  If Assigned(FTableDef) then
+    TableName:=FTableDef.TableName;
+end;
+
+procedure TDDTableCollection.SetTableName(const AValue: String);
+begin
+  FTableName:=AValue;
+end;
+
+
+function TDDTableCollection.DataDictionary: TFPDataDictionary;
+begin
+  If Assigned(FTableDef) then
+    Result:=FTableDef.DataDictionary
+  else
+    Result:=Nil;
+end;
+
 initialization
 initialization
 
 
 finalization
 finalization