From: <dav...@us...> - 2012-01-28 16:52:14
|
Revision: 954 http://instantobjects.svn.sourceforge.net/instantobjects/revision/?rev=954&view=rev Author: davidvtaylor Date: 2012-01-28 16:52:07 +0000 (Sat, 28 Jan 2012) Log Message: ----------- + Add "unique" attribute keyword to specify that the index created should be unique Modified Paths: -------------- trunk/Source/Core/InstantCode.pas trunk/Source/Core/InstantMetadata.pas trunk/Source/Core/InstantPersistence.pas trunk/Source/Core/InstantTypes.pas trunk/Source/Design/InstantAttributeEditor.dfm trunk/Source/Design/InstantAttributeEditor.pas trunk/Source/Design/InstantModelExplorer.pas trunk/Source/ObjectFoundry/OFClasses.pas Modified: trunk/Source/Core/InstantCode.pas =================================================================== --- trunk/Source/Core/InstantCode.pas 2012-01-14 02:59:12 UTC (rev 953) +++ trunk/Source/Core/InstantCode.pas 2012-01-28 16:52:07 UTC (rev 954) @@ -604,6 +604,7 @@ function GetIsEnum: Boolean; function GetIsIndexed: Boolean; function GetIsRequired: Boolean; + function GetIsUnique: Boolean; function GetMetadata: TInstantAttributeMetadata; function GetMethodTypes: TInstantCodeContainerMethodTypes; function GetObjectClass: TInstantCodeClass; @@ -626,6 +627,7 @@ procedure SetIncludeRemoveMethod(const Value: Boolean); procedure SetIsIndexed(const Value: Boolean); procedure SetIsRequired(const Value: Boolean); + procedure SetIsUnique(const Value: Boolean); procedure SetMethodTypes(const Value: TInstantCodeContainerMethodTypes); procedure SetObjectClassName(const Value: string); procedure SetPropTypeName(const Value: string); @@ -713,6 +715,7 @@ write SetStorageKind; property IsIndexed: Boolean read GetIsIndexed write SetIsIndexed; property IsRequired: Boolean read GetIsRequired write SetIsRequired; + property IsUnique: Boolean read GetIsUnique write SetIsUnique; property Metadata: TInstantAttributeMetadata read GetMetadata; property MethodTypes: TInstantCodeContainerMethodTypes read GetMethodTypes write SetMethodTypes; @@ -1589,6 +1592,7 @@ MetaKeyFormat = 'format'; MetaKeyIndex = 'index'; MetaKeyRequired = 'required'; + MetaKeyUnique = 'unique'; MetaKeyMask = 'mask'; MetaKeyStored = 'stored'; MetaKeyEmbedded = 'embedded'; @@ -3741,6 +3745,7 @@ Self.IsDefault := IsDefault; Self.IsIndexed := IsIndexed; Self.IsRequired := IsRequired; + Self.IsUnique := IsUnique; Self.ReadOnly := ReadOnly; Self.SingularName := SingularName; Self.Visibility := Visibility; @@ -3942,6 +3947,11 @@ Result := Metadata.IsRequired; end; +function TInstantCodeAttribute.GetIsUnique: Boolean; +begin + Result := Metadata.IsUnique; +end; + function TInstantCodeAttribute.GetMetadata: TInstantAttributeMetadata; begin if not Assigned(FMetadata) then @@ -4128,6 +4138,8 @@ IsIndexed := True else if Token = MetaKeyRequired then IsRequired := True + else if Token = MetaKeyUnique then + IsUnique := True else if Token = MetaKeyMask then Metadata.EditMask := Reader.ReadStringValue else if Token = MetaKeyValid then @@ -4179,6 +4191,8 @@ WriteStr(MetaKeyLabel, Metadata.DisplayLabel); if IsIndexed then Writer.Write(' ' + MetaKeyIndex); + if IsUnique then + Writer.Write(' ' + MetaKeyUnique); if IsRequired then Writer.Write(' ' + MetaKeyRequired); if Metadata.UseNull then @@ -4287,6 +4301,11 @@ Metadata.IsRequired := Value; end; +procedure TInstantCodeAttribute.SetIsUnique(const Value: Boolean); +begin + Metadata.IsUnique := Value; +end; + procedure TInstantCodeAttribute.SetMethodTypes( const Value: TInstantCodeContainerMethodTypes); begin Modified: trunk/Source/Core/InstantMetadata.pas =================================================================== --- trunk/Source/Core/InstantMetadata.pas 2012-01-14 02:59:12 UTC (rev 953) +++ trunk/Source/Core/InstantMetadata.pas 2012-01-28 16:52:07 UTC (rev 954) @@ -469,6 +469,7 @@ FEditMask: string; FIsIndexed: Boolean; FIsRequired: Boolean; + FIsUnique: Boolean; FObjectClassName: string; FSize: Integer; FStorageName: string; @@ -550,6 +551,7 @@ write FStorageKind default skEmbedded; property IsIndexed: Boolean read FIsIndexed write FIsIndexed; property IsRequired: Boolean read FIsRequired write FIsRequired; + property IsUnique: Boolean read FIsUnique write FIsUnique; property ObjectClassName: string read FObjectClassName write FObjectClassName; property Size: Integer read FSize write FSize default 0; @@ -1332,9 +1334,17 @@ begin if AttributeMetadata.IsIndexed then begin - IndexMetadatas.AddIndexMetadata(Map.Name + - AttributeMetadata.FieldName, AttributeMetadata.FieldName, []); - Options := Options + [foIndexed]; + if AttributeMetadata.IsUnique then + begin + IndexMetadatas.AddIndexMetadata(Map.Name + + AttributeMetadata.FieldName, AttributeMetadata.FieldName, [ixUnique]); + Options := Options + [foIndexed, foUnique]; + end else + begin + IndexMetadatas.AddIndexMetadata(Map.Name + + AttributeMetadata.FieldName, AttributeMetadata.FieldName, []); + Options := Options + [foIndexed]; + end; end else if AttributeMetadata.IsRequired then begin @@ -1733,6 +1743,7 @@ FEditMask := LSource.EditMask; FIsIndexed := LSource.IsIndexed; FIsRequired := LSource.IsRequired; + FIsUnique := LSource.IsUnique; FUseNull := LSource.UseNull; FObjectClassName := LSource.ObjectClassName; FSize := LSource.Size; Modified: trunk/Source/Core/InstantPersistence.pas =================================================================== --- trunk/Source/Core/InstantPersistence.pas 2012-01-14 02:59:12 UTC (rev 953) +++ trunk/Source/Core/InstantPersistence.pas 2012-01-28 16:52:07 UTC (rev 954) @@ -160,6 +160,7 @@ FIsChanged: Boolean; function GetIsIndexed: Boolean; function GetIsRequired: Boolean; + function GetIsUnique: Boolean; function GetMetadata: TInstantAttributeMetadata; function GetName: string; function GetValue: Variant; @@ -224,6 +225,7 @@ property IsIndexed: Boolean read GetIsIndexed; property IsMandatory: Boolean read GetIsMandatory; property IsRequired: Boolean read GetIsRequired; + property IsUnique: Boolean read GetIsUnique; property IsNull: Boolean read GetIsNull; property Name: string read GetName; property Metadata: TInstantAttributeMetadata read GetMetadata write SetMetadata; @@ -2464,6 +2466,11 @@ Result := Assigned(Metadata) and Metadata.IsRequired; end; +function TInstantAttribute.GetIsUnique: Boolean; +begin + Result := Assigned(Metadata) and Metadata.IsUnique; +end; + function TInstantAttribute.GetMetadata: TInstantAttributeMetadata; begin Result := inherited GetMetadata as TInstantAttributeMetadata; Modified: trunk/Source/Core/InstantTypes.pas =================================================================== --- trunk/Source/Core/InstantTypes.pas 2012-01-14 02:59:12 UTC (rev 953) +++ trunk/Source/Core/InstantTypes.pas 2012-01-28 16:52:07 UTC (rev 954) @@ -65,7 +65,7 @@ TInstantDataType = (dtInteger, dtFloat, dtCurrency, dtBoolean, dtString, dtMemo, dtDateTime, dtBlob, dtDate, dtTime, dtEnum); TInstantDataTypes = set of TInstantDataType; - TInstantFieldOption = (foRequired, foIndexed); + TInstantFieldOption = (foRequired, foIndexed, foUnique); TInstantFieldOptions = set of TInstantFieldOption; TInstantCatalogFeature = (cfReadTableInfo, cfReadColumnInfo, cfReadIndexInfo); Modified: trunk/Source/Design/InstantAttributeEditor.dfm =================================================================== --- trunk/Source/Design/InstantAttributeEditor.dfm 2012-01-14 02:59:12 UTC (rev 953) +++ trunk/Source/Design/InstantAttributeEditor.dfm 2012-01-28 16:52:07 UTC (rev 954) @@ -292,7 +292,7 @@ TabOrder = 2 object OptionReadOnlyCheckBox: TCheckBox Left = 8 - Top = 48 + Top = 64 Width = 73 Height = 17 Caption = '&Read only' @@ -300,7 +300,7 @@ end object OptionDefaultCheckBox: TCheckBox Left = 8 - Top = 64 + Top = 80 Width = 73 Height = 17 Caption = '&Default' @@ -316,15 +316,23 @@ end object OptionRequiredCheckBox: TCheckBox Left = 8 + Top = 48 + Width = 73 + Height = 17 + Caption = 'Req&uired' + TabOrder = 5 + end + object OptionUniqueCheckBox: TCheckBox + Left = 8 Top = 32 Width = 73 Height = 17 - Caption = 'Req&uired' + Caption = 'Uni&que' TabOrder = 1 end object OptionUseNullCheckBox: TCheckBox Left = 8 - Top = 80 + Top = 96 Width = 73 Height = 17 Caption = 'Use &Null' @@ -346,7 +354,7 @@ object DisplayWidthLabel: TLabel Left = 8 Top = 88 - Width = 65 + Width = 64 Height = 13 Caption = 'Display &Width' FocusControl = DisplayWidthEdit Modified: trunk/Source/Design/InstantAttributeEditor.pas =================================================================== --- trunk/Source/Design/InstantAttributeEditor.pas 2012-01-14 02:59:12 UTC (rev 953) +++ trunk/Source/Design/InstantAttributeEditor.pas 2012-01-28 16:52:07 UTC (rev 954) @@ -96,6 +96,7 @@ OptionIndexedCheckBox: TCheckBox; OptionReadOnlyCheckBox: TCheckBox; OptionRequiredCheckBox: TCheckBox; + OptionUniqueCheckBox: TCheckBox; OptionsGroupBox: TGroupBox; PageControl: TPageControl; PresentationSheet: TTabSheet; @@ -255,6 +256,7 @@ begin OptionIndexedCheckBox.Checked := Subject.IsIndexed; OptionRequiredCheckBox.Checked := Subject.IsRequired; + OptionUniqueCheckBox.Checked := Subject.IsUnique; OptionReadOnlyCheckBox.Checked := Subject.ReadOnly; OptionDefaultCheckBox.Checked := Subject.IsDefault; OptionUseNullCheckBox.Checked := Subject.UseNull; @@ -529,6 +531,8 @@ Result := True; if SetChangedField('IsRequired', OptionRequiredCheckBox.Checked) then Result := True; + if SetChangedField('IsUnique', OptionUniqueCheckBox.Checked) then + Result := True; if SetChangedField('ReadOnly', OptionReadOnlyCheckBox.Checked) then Result := True; if SetChangedField('IsDefault', OptionDefaultCheckBox.Checked) then @@ -752,6 +756,7 @@ EnableCtrl(OptionsGroupBox, True); EnableCtrl(OptionIndexedCheckBox, True); EnableCtrl(OptionRequiredCheckBox, True); + EnableCtrl(OptionUniqueCheckBox, True); EnableCtrl(OptionUseNullCheckBox, not IsContainer); EnableCtrl(OkButton, IsValid); PresentationSheet.TabVisible := IsMaskable; Modified: trunk/Source/Design/InstantModelExplorer.pas =================================================================== --- trunk/Source/Design/InstantModelExplorer.pas 2012-01-14 02:59:12 UTC (rev 953) +++ trunk/Source/Design/InstantModelExplorer.pas 2012-01-28 16:52:07 UTC (rev 954) @@ -489,6 +489,7 @@ NewAttribute := NewClass.AddAttribute; NewAttribute.IsIndexed := ImportAttributeMetadata.IsIndexed; NewAttribute.IsRequired := ImportAttributeMetadata.IsRequired; + NewAttribute.IsUnique := ImportAttributeMetadata.IsUnique; NewAttribute.IsDefault := ImportAttributeMetadata.IsDefault; NewAttribute.AttributeType := ImportAttributeMetadata.AttributeType; NewAttribute.AttributeTypeName := ImportAttributeMetadata.AttributeTypeName; Modified: trunk/Source/ObjectFoundry/OFClasses.pas =================================================================== --- trunk/Source/ObjectFoundry/OFClasses.pas 2012-01-14 02:59:12 UTC (rev 953) +++ trunk/Source/ObjectFoundry/OFClasses.pas 2012-01-28 16:52:07 UTC (rev 954) @@ -341,6 +341,7 @@ TaggedBooleans['IsDefault'] := IsDefault; TaggedBooleans['IsIndexed'] := IsIndexed; TaggedBooleans['IsRequired'] := IsRequired; + TaggedBooleans['IsUnique'] := IsUnique; TaggedStrings['SingularName'] := SingularName; TaggedStrings['EditMask'] := Metadata.EditMask; TaggedStrings['ValidChars'] := Metadata.ValidCharsString; @@ -545,6 +546,7 @@ IsDefault := TaggedBooleans['IsDefault']; IsIndexed := TaggedBooleans['IsIndexed']; IsRequired := TaggedBooleans['IsRequired']; + IsUnique := TaggedBooleans['IsUnique']; SingularName := TaggedStrings['SingularName']; Metadata.Size := TaggedIntegers['Size']; Metadata.EditMask := TaggedStrings['EditMask']; |