Package oracle.pgx.api.keys
Class KeyUtils
- java.lang.Object
-
- oracle.pgx.api.keys.KeyUtils
-
@BetaApi public class KeyUtils extends java.lang.ObjectCommon utilities for handling key declarations and configurations.- Since:
- 25.2.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_KEY_NAMEDefault name of key columns.static java.lang.StringGENERATED_DESTINATION_VERTEX_KEY_COLUMN_NAMEDefault generated name of source vertex key column, this is a generated name used when the destination vertex provider has a composite key or an unsupported key typestatic java.lang.StringGENERATED_KEY_COLUMN_NAMEDefault generated name of key column, this is a generated name used when an entity provider has a composite key or an unsupported key typestatic java.lang.StringGENERATED_SOURCE_VERTEX_KEY_COLUMN_NAMEDefault generated name of source vertex key column, this is a generated name used when the source vertex provider has a composite key or an unsupported key type
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidassertHasOneKeyColumnLegacy(int numKeyColumns)Check if the number of key columns is exactly one.static java.util.List<KeyColumnDescriptor>createKeyDescriptors(java.lang.String keyColumnName, IdType keyColumnType)Create a list of key column descriptors for a single key column.static java.util.List<KeyColumnDescriptor>createKeyDescriptors(java.util.List<java.lang.String> keyColumnNames, java.util.List<IdType> keyColumnTypes)Create a list of key column descriptors from lists of key column names and types.static ForeignKeyColumnDescriptorgetForeignKeyColumnDescriptorOrDefault(java.util.List<? extends ForeignKeyColumnDescriptor> keyColumnDescriptors, java.lang.String defaultName)static java.lang.StringgetForeignKeyColumnName(java.util.List<? extends ForeignKeyColumnDescriptor> foreignKeyColumns)Get the name of a foreign key column, if and only if there is exactly one foreign key column.static KeyColumnDescriptorgetKeyColumnDescriptorOrDefault(java.util.List<? extends KeyColumnDescriptor> keyColumns, java.lang.String defaultName)static java.lang.StringgetNameOrNull(ForeignKeyColumnDescriptor foreignKeyColumnDescriptor)Get the name of aforeign key column.static java.lang.StringgetNameOrNull(KeyColumnDescriptor keyColumnDescriptor)Get the name of aprimary key column.static <K> KgetSingleKeyColumn(java.util.List<? extends K> keyColumns)Get the key column descriptor for the first key column in the list of key columns, if and only if there is exactly one key column.static <K> KgetSingleKeyColumnOrNull(java.util.List<? extends K> keyColumns)Similar togetSingleKeyColumn(List), except returnsnull, if the provided list is empty.static IdTypegetType(java.util.List<? extends KeyColumnDescriptor> keyColumns)Get the type of the first key column in a list of key columns, if and only if there is exactly one key column.static IdTypegetTypeOrDefault(java.util.List<? extends KeyColumnDescriptor> keyColumns, IdType defaultType)Get the type of the only key column if and only if there is exactly one, otherwise return the default typestatic voidvalidateForeignKey(java.util.List<? extends ForeignKeyColumnDescriptor> foreignKeyColumns)Validate foreign key columns of an edge provider.static voidvalidateForeignKeyToPrimaryKey(java.util.List<? extends ForeignKeyColumnDescriptor> foreignKeys, java.util.List<? extends KeyColumnDescriptor> primaryKeys)Check is a foreign key definition matches a primary key definition.static voidvalidateKey(java.util.List<? extends KeyColumnDescriptor> keyColumns)Validate key columns for an entity provider.
-
-
-
Field Detail
-
DEFAULT_KEY_NAME
public static final java.lang.String DEFAULT_KEY_NAME
Default name of key columns. This is not a valid key column name, but can be used in case an entity provider only has one key column. While it is allowed to use this name in such cases, it is always recommended to set key column names for every key column in every provider.- See Also:
- Constant Field Values
-
GENERATED_KEY_COLUMN_NAME
public static final java.lang.String GENERATED_KEY_COLUMN_NAME
Default generated name of key column, this is a generated name used when an entity provider has a composite key or an unsupported key type- See Also:
- Constant Field Values
-
GENERATED_SOURCE_VERTEX_KEY_COLUMN_NAME
public static final java.lang.String GENERATED_SOURCE_VERTEX_KEY_COLUMN_NAME
Default generated name of source vertex key column, this is a generated name used when the source vertex provider has a composite key or an unsupported key type- See Also:
- Constant Field Values
-
GENERATED_DESTINATION_VERTEX_KEY_COLUMN_NAME
public static final java.lang.String GENERATED_DESTINATION_VERTEX_KEY_COLUMN_NAME
Default generated name of source vertex key column, this is a generated name used when the destination vertex provider has a composite key or an unsupported key type- See Also:
- Constant Field Values
-
-
Method Detail
-
createKeyDescriptors
public static java.util.List<KeyColumnDescriptor> createKeyDescriptors(java.lang.String keyColumnName, IdType keyColumnType)
Create a list of key column descriptors for a single key column. This will also validate the resulting key column list.- Parameters:
keyColumnName- The key column name.keyColumnType- The key column type.- Returns:
- A list of key column descriptors matching the single key column.
-
createKeyDescriptors
public static java.util.List<KeyColumnDescriptor> createKeyDescriptors(java.util.List<java.lang.String> keyColumnNames, java.util.List<IdType> keyColumnTypes)
Create a list of key column descriptors from lists of key column names and types. The resulting list of key columns will have the same size as both of the lists. Input lists must have the same size. This will also validate the resulting key column list.- Parameters:
keyColumnNames- A list of key column names (if there is only one key column, the name can benull).keyColumnTypes- A list of key column types with the same length as the previous list.- Returns:
- A list of key column descriptors.
-
getType
public static IdType getType(java.util.List<? extends KeyColumnDescriptor> keyColumns)
Get the type of the first key column in a list of key columns, if and only if there is exactly one key column.- Parameters:
keyColumns- The list of key column.- Returns:
- Type of the first and only key column.
- Throws:
java.lang.IllegalArgumentException- if there is not exactly one key column in the list.
-
getTypeOrDefault
public static IdType getTypeOrDefault(java.util.List<? extends KeyColumnDescriptor> keyColumns, IdType defaultType)
Get the type of the only key column if and only if there is exactly one, otherwise return the default type- Parameters:
keyColumns- The list of key column.defaultType- the default type- Returns:
- Type of the first and only key column or default type.
-
getSingleKeyColumn
public static <K> K getSingleKeyColumn(java.util.List<? extends K> keyColumns)
Get the key column descriptor for the first key column in the list of key columns, if and only if there is exactly one key column. An exception will be thrown if there is any other number of key column in the list. Note that this function is generic and can be used with any list.- Type Parameters:
K- Key object type.- Parameters:
keyColumns- A list of object (typically key column descriptors).- Returns:
- The first (and only) element in the list.
- Throws:
java.lang.IllegalArgumentException- if there is not exactly one element in the list.
-
getSingleKeyColumnOrNull
public static <K> K getSingleKeyColumnOrNull(java.util.List<? extends K> keyColumns)
Similar togetSingleKeyColumn(List), except returnsnull, if the provided list is empty.- Type Parameters:
K- The object type.- Parameters:
keyColumns- A list of objects (key column descriptors).- Returns:
- The single object in the list, or
null.
-
getNameOrNull
public static java.lang.String getNameOrNull(KeyColumnDescriptor keyColumnDescriptor)
Get the name of aprimary key column. If the column descriptor isnullor the key column name is not specified, this will also returnnull.- Parameters:
keyColumnDescriptor- Primary key column descriptor.- Returns:
- The key column name or
null.
-
getNameOrNull
public static java.lang.String getNameOrNull(ForeignKeyColumnDescriptor foreignKeyColumnDescriptor)
- Parameters:
foreignKeyColumnDescriptor- Foreign key column descriptor.- Returns:
- The foreign key column name or
null.
-
getForeignKeyColumnName
public static java.lang.String getForeignKeyColumnName(java.util.List<? extends ForeignKeyColumnDescriptor> foreignKeyColumns)
Get the name of a foreign key column, if and only if there is exactly one foreign key column.- Parameters:
foreignKeyColumns- The list of foreign key column.- Returns:
- The name of the column.
- Throws:
java.lang.IllegalArgumentException- if there is not exactly one element in the list.
-
assertHasOneKeyColumnLegacy
public static void assertHasOneKeyColumnLegacy(int numKeyColumns)
Check if the number of key columns is exactly one. This function should be used to check if legacy APIs can still be used.- Parameters:
numKeyColumns- The number of key columns.- Throws:
java.lang.IllegalArgumentException- if the number of key columns is not exactly1.
-
validateKey
public static void validateKey(java.util.List<? extends KeyColumnDescriptor> keyColumns)
Validate key columns for an entity provider. This will check:- that name and type of each column are set
- that names of key columns are unique, if there is more than key column
- Parameters:
keyColumns- The list of key columns to validate.
-
validateForeignKey
public static void validateForeignKey(java.util.List<? extends ForeignKeyColumnDescriptor> foreignKeyColumns)
Validate foreign key columns of an edge provider. This will check:- that each column has a valid name, see
NameValidator.validate(String...) - that the
referenced columnhas a valid name, if set - that the
referenced columnis set, if there is more than one foreign key column
- Parameters:
foreignKeyColumns- The list of foreign key columns.- See Also:
additional cross-validation of foreign keys to primary keys
- that each column has a valid name, see
-
validateForeignKeyToPrimaryKey
public static void validateForeignKeyToPrimaryKey(java.util.List<? extends ForeignKeyColumnDescriptor> foreignKeys, java.util.List<? extends KeyColumnDescriptor> primaryKeys)
Check is a foreign key definition matches a primary key definition. Both keys should previously be validated byvalidateKey(List)andvalidateForeignKey(List).- Parameters:
foreignKeys- Foreign keys.primaryKeys- Primary keys.
-
getForeignKeyColumnDescriptorOrDefault
public static ForeignKeyColumnDescriptor getForeignKeyColumnDescriptorOrDefault(java.util.List<? extends ForeignKeyColumnDescriptor> keyColumnDescriptors, java.lang.String defaultName)
-
getKeyColumnDescriptorOrDefault
public static KeyColumnDescriptor getKeyColumnDescriptorOrDefault(java.util.List<? extends KeyColumnDescriptor> keyColumns, java.lang.String defaultName)
-
-