Package de.hybris.platform.core
Class PK
java.lang.Object
de.hybris.platform.core.PK
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic class -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionintThe implementation is taken from java.lang.Long#compareTo(java.lang.Long).static PKcreateCounterPK(int typecode) create a Counter based PK.static PKcreateFixedCounterPK(int typecode, long fixNr) static PKcreateFixedPK(int typecode, long fixNr) Deprecated, for removal: This API element is subject to removal in a future version.since ages - call createFixedUUIDPK insteadstatic PKcreateFixedUUIDPK(int typecode, long fixNr) static PKcreatePK(int typecode) Deprecated, for removal: This API element is subject to removal in a future version.since ages - call createUUIDPK insteadstatic PKcreateUUIDPK(int typecode) create a UUID based PK.booleanstatic PKfromLong(long longValue) byteDeprecated, for removal: This API element is subject to removal in a future version.since ageslonglongreturns the creation time (for UUID based PK's) or the 'counter' value for counter based PK'sstatic longgetHex()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.getLong()longstatic longbyteDeprecated, for removal: This API element is subject to removal in a future version.since agesintinthashCode()see http://www.concentric.net/~Ttwang/tech/inthash.htmstatic inthashCode(long longValue) booleanbit 43 is 0 -> definitely a UUID PK(returning false),booleanisCounterBased(boolean legacyDetectionEnabled) static PKParses the given String (in decimal Long format, e.g '1234939953093') and returns an PK object if the input string was null, null is returnedstatic Collection<PK>parse(Collection<String> pkStrings) Parses the collection of String (in decimal Long format, e.g '123493920953093') and returns a Collection of PK objectsstatic PKDecodes a hexadecimal String into a PK.toString()
-
Field Details
-
COUNTER_PK_GENERATOR_FACTORY
- See Also:
-
NULL_PK
-
BIG_PK
-
LEGACY_PK_31_DETECTION
- See Also:
-
-
Method Details
-
createFixedPK
Deprecated, for removal: This API element is subject to removal in a future version.since ages - call createFixedUUIDPK instead -
createFixedUUIDPK
-
createFixedCounterPK
-
createPK
Deprecated, for removal: This API element is subject to removal in a future version.since ages - call createUUIDPK instead -
createUUIDPK
create a UUID based PK. UUID based PK's include the current time and does NOT need a database access -
createCounterPK
create a Counter based PK. Database access is needed, numberseries are used to create a sequence -
fromLong
-
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, for removal: This API element is subject to removal in a future version.since ages -
getMilliCnt
Deprecated, for removal: This API element is subject to removal in a future version.since ages -
getLong
-
getLongValue
public long getLongValue() -
getTypeCodeAsString
-
getLongValueAsString
-
hashCode
public int hashCode()see http://www.concentric.net/~Ttwang/tech/inthash.htm -
hashCode
public static int hashCode(long longValue) -
equals
-
toString
-
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
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
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:
compareToin interfaceComparable<PK>- See Also:
-
parse
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
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
-