Package de.hybris.platform.core
Class PK
- java.lang.Object
-
- de.hybris.platform.core.PK
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<PK>
public final class PK extends java.lang.Object implements java.io.Serializable, java.lang.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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfacePK.PKCounterGeneratorstatic classPK.PKException
-
Field Summary
Fields Modifier and Type Field Description static PKBIG_PKstatic java.lang.StringCOUNTER_PK_GENERATOR_FACTORYstatic java.lang.StringLEGACY_PK_31_DETECTIONstatic PKNULL_PK
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description intcompareTo(PK pk)The 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.since ages - call createFixedUUIDPK insteadstatic PKcreateFixedUUIDPK(int typecode, long fixNr)static PKcreatePK(int typecode)Deprecated.since ages - call createUUIDPK insteadstatic PKcreateUUIDPK(int typecode)create a UUID based PK.booleanequals(java.lang.Object object)static PKfromLong(long longValue)bytegetClusterID()Deprecated.since ageslonggetCounter()longgetCreationTime()returns the creation time (for UUID based PK's) or the 'counter' value for counter based PK'sstatic longgetCurrentTimeOffsetInMillis()java.lang.StringgetHex()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.java.lang.LonggetLong()longgetLongValue()java.lang.StringgetLongValueAsString()static longgetMaxTimeOffsetInMillis()bytegetMilliCnt()Deprecated.since agesintgetTypeCode()java.lang.StringgetTypeCodeAsString()inthashCode()see http://www.concentric.net/~Ttwang/tech/inthash.htmstatic inthashCode(long longValue)booleanisCounterBased()bit 43 is 0 -> definitely a UUID PK(returning false),booleanisCounterBased(boolean legacyDetectionEnabled)static PKparse(java.lang.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 returnedstatic java.util.Collection<PK>parse(java.util.Collection<java.lang.String> pkStrings)Parses the collection of String (in decimal Long format, e.g '123493920953093') and returns a Collection of PK objectsstatic PKparseHex(java.lang.String hexPkString)Decodes a hexadecimal String into a PK.java.lang.StringtoString()
-
-
-
Field Detail
-
COUNTER_PK_GENERATOR_FACTORY
public static final java.lang.String COUNTER_PK_GENERATOR_FACTORY
- See Also:
- Constant Field Values
-
NULL_PK
public static final PK NULL_PK
-
BIG_PK
public static final PK BIG_PK
-
LEGACY_PK_31_DETECTION
public static final java.lang.String LEGACY_PK_31_DETECTION
- See Also:
- Constant Field Values
-
-
Method Detail
-
createFixedPK
@Deprecated public static PK createFixedPK(int typecode, long fixNr)
Deprecated.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 public static PK createPK(int typecode)
Deprecated.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:
isCounterBased()
-
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 public byte getClusterID()
Deprecated.since ages
-
getMilliCnt
@Deprecated public byte getMilliCnt()
Deprecated.since ages
-
getLong
public java.lang.Long getLong()
-
getLongValue
public long getLongValue()
-
getTypeCodeAsString
public java.lang.String getTypeCodeAsString()
-
getLongValueAsString
public java.lang.String getLongValueAsString()
-
hashCode
public int hashCode()
see http://www.concentric.net/~Ttwang/tech/inthash.htm- Overrides:
hashCodein classjava.lang.Object
-
hashCode
public static int hashCode(long longValue)
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getHex
public java.lang.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(java.lang.String hexPkString)
Decodes a hexadecimal String into a PK.- Parameters:
hexPkString- hexadecimal represantation of the PK object.- Returns:
- PK object
- Throws:
java.lang.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:
compareToin interfacejava.lang.Comparable<PK>- See Also:
Comparable.compareTo(java.lang.Object)
-
parse
public static PK parse(java.lang.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 java.util.Collection<PK> parse(java.util.Collection<java.lang.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
-
-