Interface KeyGenerator

All Known Implementing Classes:
DefaultNetworkEntityKeyGenerator, GuidKeyGenerator, PersistentKeyGenerator, PKGenerator, PrefixablePersistentKeyGenerator, PrefixablePersistentKeyGenerator, PrefixablePersistentKeyGenerator, SystemTimeGenerator

public interface KeyGenerator
A KeyGenerator provides methods for getting a unique key for example a serial number. The kind of key depends on used implementation. It can be a String with numbers ot letters but also data objects can be provided like the hybris PK class.
Since:
4.0
  • Method Summary

    Modifier and Type
    Method
    Description
    Generates a new unique key.
    Generates a new unique key in relation to given object.
    void
    Resets the key generation so that an already generated key can be generated once again.
  • Method Details

    • generate

      Object generate()
      Generates a new unique key. If this method is called twice it will never return the same key twice (if key A is returned by first call and key B by second call, A does not equals B). A order of returned keys is not guaranteed (depends on implementation). After a call of the reset() method the generator is reseted so that a key can be returned which already was returned before calling reset().
      Returns:
      unique key
    • generateFor

      Object generateFor(Object object)
      Generates a new unique key in relation to given object. The key will be unique overall as in generate() method and furthermore it is guaranteed that the key will only be produced for this object (think of a PK which contains the type information, a media PK will not be generated for a product, nevertheless it is unique overall).
      Parameters:
      object - object for which a key will be generated
      Returns:
      unique key in relation to given object
    • reset

      void reset()
      Resets the key generation so that an already generated key can be generated once again.