Class PK

java.lang.Object
de.hybris.platform.core.PK
All Implemented Interfaces:
Serializable, Comparable<PK>

public final class PK extends Object implements Serializable, Comparable<PK>
Calculation rules long->pk:
 typecode = (int) ((longValue & 0xFFFF000000000000l) >> 48);
 clusterid = ((byte) ((longValue & 0x0000F00000000000l) >> 44 | ((longValue & 0x000000000000000Cl) << 2)));
 creationtime = ((longValue & 0x00000FFFFFFFFFF0l) >> 4) + DATE_01_01_1995;
 millicnt = (byte) ((longValue & 0x0000000000000003l));

 

Calculation rules pk->long:

 longValue = ((typecode << 48) & 0xFFFF000000000000l);
 longValue += (((clusterid & 0x000000000000000Fl) << 44) & 0x0000F00000000000l);
 longValue += ((creationtime - DATE_01_01_1995 << 4) & 0x00000FFFFFFFFFF0l);
 longValue += ((clusterid >> 2) & 0x000000000000000Cl);
 longValue += ((millicnt) & 0x0000000000000003l);

 

*NOTE* CHANGE 081209: only the last two bits (&0x3) of millicnt are treated as millicount, the upper two bits (&0xC) are added to clusterID - See https://jira.hybris.com/browse/PLA-6829 - See https://wiki.hybris.com/x/XIRvAg Sample of an Serialized PK object:
(in base64 format, see e.g. http://www.motobit.com/util /base64-decoder-encoder.asp to decode it online):
rO0ABXNyABlkZS5oeWJyaXMuamFrYXJ0YS5jb3JlLlBLwtpyLOiZLJICAAFKAAlsb25nVmFsdWV4cFdm7dLIEAAY
This pk has approx 66 bytes in binary format. Only the longValue is serialized.

See Also:
  • Field Details

    • COUNTER_PK_GENERATOR_FACTORY

      public static final String COUNTER_PK_GENERATOR_FACTORY
      See Also:
    • NULL_PK

      public static final PK NULL_PK
    • BIG_PK

      public static final PK BIG_PK
    • LEGACY_PK_31_DETECTION

      public static final String LEGACY_PK_31_DETECTION
      See Also:
  • Method Details

    • createFixedPK

      @Deprecated(since="ages", forRemoval=true) public static PK createFixedPK(int typecode, long fixNr)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since ages - call createFixedUUIDPK instead
    • createFixedUUIDPK

      public static PK createFixedUUIDPK(int typecode, long fixNr)
    • createFixedCounterPK

      public static PK createFixedCounterPK(int typecode, long fixNr)
    • createPK

      @Deprecated(since="ages", forRemoval=true) public static PK createPK(int typecode)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since ages - call createUUIDPK instead
    • createUUIDPK

      public static PK createUUIDPK(int typecode)
      create a UUID based PK. UUID based PK's include the current time and does NOT need a database access
    • createCounterPK

      public static PK createCounterPK(int typecode)
      create a Counter based PK. Database access is needed, numberseries are used to create a sequence
    • fromLong

      public static PK fromLong(long longValue)
    • getCurrentTimeOffsetInMillis

      public static long getCurrentTimeOffsetInMillis()
      Returns:
      the current time offset in milliseconds
    • getMaxTimeOffsetInMillis

      public static long getMaxTimeOffsetInMillis()
    • isCounterBased

      public boolean isCounterBased()
      bit 43 is 0 -> definitely a UUID PK(returning false),

      bit 43 is 1 -> is counter if

      • 3.1 (UUID) is not enabled(returning true), or
      • it's not a 3.1 (UUID)pk(returning true);
      • otherwise, false will be returned.
    • isCounterBased

      public boolean isCounterBased(boolean legacyDetectionEnabled)
      Parameters:
      legacyDetectionEnabled - if true, will try to parse the pk to check if it is 3.1 legacy style
      See Also:
    • getTypeCode

      public int getTypeCode()
    • getCreationTime

      public long getCreationTime()
      returns the creation time (for UUID based PK's) or the 'counter' value for counter based PK's
    • getCounter

      public long getCounter()
    • getClusterID

      @Deprecated(since="ages", forRemoval=true) public byte getClusterID()
      Deprecated, for removal: This API element is subject to removal in a future version.
      since ages
    • getMilliCnt

      @Deprecated(since="ages", forRemoval=true) public byte getMilliCnt()
      Deprecated, for removal: This API element is subject to removal in a future version.
      since ages
    • getLong

      public Long getLong()
    • getLongValue

      public long getLongValue()
    • getTypeCodeAsString

      public String getTypeCodeAsString()
    • getLongValueAsString

      public String getLongValueAsString()
    • hashCode

      public int hashCode()
      see http://www.concentric.net/~Ttwang/tech/inthash.htm
      Overrides:
      hashCode in class Object
    • hashCode

      public static int hashCode(long longValue)
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getHex

      public String getHex()
      Returns a string representation of the PK as an unsigned integer in base 16.
      This method is an alias for PK.toHexString() that can be used within the Expression Language.
      Returns:
      the string representation of the PK in hexadecimal (base 16).
    • parseHex

      public static PK parseHex(String hexPkString)
      Decodes a hexadecimal String into a PK.
      Parameters:
      hexPkString - hexadecimal represantation of the PK object.
      Returns:
      PK object
      Throws:
      NumberFormatException - - if the String does not contain a parsable long.
    • compareTo

      public int compareTo(PK pk)
      The implementation is taken from java.lang.Long#compareTo(java.lang.Long). It will compare the long value of this PK with the long value of the other PK
      Specified by:
      compareTo in interface Comparable<PK>
      See Also:
    • parse

      public static PK parse(String pkString)
      Parses the given String (in decimal Long format, e.g '1234939953093') and returns an PK object if the input string was null, null is returned
      Throws:
      PK.PKException - if a number format error occurs
    • parse

      public static Collection<PK> parse(Collection<String> pkStrings)
      Parses the collection of String (in decimal Long format, e.g '123493920953093') and returns a Collection of PK objects
      Throws:
      PK.PKException - if a number format error occurs