You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

uYitIdHelper.pas 1.1 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. unit uYitIdHelper;
  2. interface
  3. uses System.SysUtils, uIIdGenerator, uIdGeneratorOptions;
  4. type
  5. TYitIdHelper = class
  6. private
  7. IdGenInstance: IIdGenerator;
  8. public
  9. function GetIdGenInstance(): IIdGenerator;
  10. /// <summary>
  11. /// òʼʱִһ
  12. /// </summary>
  13. /// <param name="options"></param>
  14. procedure SetIdGenerator(options: TIdGeneratorOptions);
  15. /// <summary>
  16. /// µId
  17. /// ñǰȷ SetIdGenerator ʼ
  18. /// </summary>
  19. /// <returns></returns>
  20. function NextId(): Int64;
  21. end;
  22. implementation
  23. uses
  24. uDefaultIdGenerator;
  25. { TYitIdHelper }
  26. function TYitIdHelper.GetIdGenInstance: IIdGenerator;
  27. begin
  28. Result := IdGenInstance;
  29. end;
  30. procedure TYitIdHelper.SetIdGenerator(options: TIdGeneratorOptions);
  31. begin
  32. IdGenInstance := TDefaultIdGenerator.Create(options);
  33. end;
  34. function TYitIdHelper.NextId(): Int64;
  35. begin
  36. if (IdGenInstance = nil) then
  37. raise Exception.Create('Please initialize Yitter.IdGeneratorOptions first.');
  38. Result := IdGenInstance.NewLong();
  39. end;
  40. end.