Package net.solarnetwork.central.domain
Interface CompositeKey
- All Known Subinterfaces:
CompositeKey2<K1,,K2> CompositeKey3<K1,K2, K3>
- All Known Implementing Classes:
LongIntegerCompositePK,LongStringCompositePK,UserLongCompositePK,UserLongIntegerCompositePK,UserLongStringCompositePK,UserStringCompositePK,UserUuidIntegerCompositePK,UserUuidLongCompositePK,UserUuidPK
public interface CompositeKey
API for a composite key.
-
Method Summary
Modifier and TypeMethodDescriptioncreateKey(CompositeKey template, Object... components) Create a new key instance based on a template and component arguments.keyComponent(int index) Get the key component for a specific index.booleankeyComponentIsAssigned(int index) Test if a given key component is assigned a value or not.intGet the number of components in the composite key.<T> TkeyComponentValue(int index, Object val) Convert a value into a key component value.
-
Method Details
-
keyComponentLength
int keyComponentLength()Get the number of components in the composite key.- Returns:
- the number of components
-
keyComponentIsAssigned
boolean keyComponentIsAssigned(int index) Test if a given key component is assigned a value or not.This method is designed to support cases when the key component is generated by an external system (such as a database) but the value is not allowed to be null. In this situation a placeholder value representing "not a value" can be used, and this method should return false if that value has been set on the instance.
- Parameters:
index- the component index to test, starting from 0- Returns:
- true if the key component's value should be considered "assigned", false otherwise
-
keyComponent
Get the key component for a specific index.- Parameters:
index- the index of the key component to get, starting from 0- Returns:
- the associated key component, or null if the component is not assigned, or the index is out of range
-
keyComponentValue
Convert a value into a key component value.- Type Parameters:
T- the expected key component type- Parameters:
index- the index of the key component to convert the value forval- the value to convert, or null to use an "unassigned" value- Returns:
- the key component value
- Throws:
IllegalArgumentException- ifvalis not a supported type, orindexis out of range of the key component length- Since:
- 1.2
-
createKey
Create a new key instance based on a template and component arguments.If less component values are provided than the length of the given key type, then "unassigned" values will be used for those components.
- Parameters:
template- the template key, or the implementation may support null to create a new key from scratch, or elseUnsupportedOperationExceptionwill be throwncomponents- the component values to use- Returns:
- the new key instance
- Throws:
IllegalArgumentException- if the component values are not appropriate for the key type- Since:
- 1.2
-