Package no.sikt.graphitron.mappings
Class TableReflection
java.lang.Object
no.sikt.graphitron.mappings.TableReflection
Helper class that takes care of any table reflection operations the code generator might require towards the jOOQ source.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfieldIsNullable(String tableName, String fieldName) static booleanfieldTypeIsCLOB(String table, String name) findImplicitKey(String leftTableName, String rightTableName) getClassFromSchemas(String className) static Optional<org.jooq.Field<?>> getFieldType(String table, String name) static Optional<org.jooq.ForeignKey<?, ?>> getForeignKey(String name) getForeignKeysBetweenTables(String leftTableName, String rightTableName) static Optional<org.jooq.Index> getJavaFieldName(String tableName, String fieldName) getJavaFieldNamesForKey(String tableName, org.jooq.Key<?> key) getJavaFieldNamesForTable(String tableName) getKeyFields(JOOQMapping key) getKeySourceTableJavaName(String keyName) getKeyTargetTableJavaName(String keyName) getMethodFromReference(String reference, String tableName, String methodName) static intgetNumberOfForeignKeysBetweenTables(String leftTableName, String rightTableName) static Set<? extends org.jooq.UniqueKey<?>> getPrimaryAndUniqueKeysForTable(String tableName) static Optional<? extends org.jooq.UniqueKey<?>> getPrimaryKeyForTable(String tableName) static Optional<? extends org.jooq.UniqueKey<?>> getPrimaryOrUniqueKeyMatchingFields(String table, List<String> fields) getRecordClass(String name) getRequiredFields(String tableName) static Optional<org.jooq.Table<?>> getTableClass(String name) getTableJavaFieldNameForRecordClass(Class<?> recordClass) Gets the table name (Java field name) for a jOOQ record class.static @NonNull StringgetTableName(Class<?> jooqRecordClass) getUniqueKeysForTable(String tableName) static booleanhasSelfRelation(String tableName) static TableRelationTypeinferRelationType(String leftTableName, String rightTableName, JOOQMapping preferredKey) static booleanisArrayField(String tableName, String fieldName) static booleanstatic booleanrecordUsesFSHack(String tableName) NEW FS hack!resolveKeyOtherTable(String keyName, String sourceTable) Given a foreign key and a known source table, resolve the table on the other side of the key.searchTableForKeyMethodNameGivenJavaFieldNames(String tableName, String keyName) Search this jOOQ table for a path method that matches the provided key name.searchTableForMethodWithName(String tableName, String name) Search this jOOQ table for a method that matches this name.static booleantableExists(String tableName) static booleantableFieldHasDefaultValue(String tableName, String fieldName) static booleantableHasIndex(String tableName, String indexName) Checks if a table has an index with the specified name.static booleantableHasPrimaryKey(String tableName) static booleantableOrKeyExists(String name)
-
Constructor Details
-
TableReflection
public TableReflection()
-
-
Method Details
-
findImplicitKey
- Returns:
- The implicit key between these two tables.
-
getForeignKeysBetweenTables
-
getNumberOfForeignKeysBetweenTables
-
inferRelationType
public static TableRelationType inferRelationType(String leftTableName, String rightTableName, JOOQMapping preferredKey) - Returns:
- The kind of relation that is present between these tables.
-
hasSelfRelation
- Returns:
- Does this table have any references to itself?
-
recordUsesFSHack
NEW FS hack! Some methods do not use getId(), but getId_() methods for ID... -
tableExists
- Returns:
- Does this table exist in the generated jOOQ code?
-
keyExists
- Returns:
- Does this key exist in the generated jOOQ code?
-
tableOrKeyExists
- Returns:
- Does this table or key exist in the generated jOOQ code?
-
getKeyTargetTableJavaName
- Returns:
- Which table does this key point to?
-
getKeySourceTableJavaName
- Returns:
- Which table does this key belong to?
-
resolveKeyOtherTable
Given a foreign key and a known source table, resolve the table on the other side of the key.- Parameters:
keyName- The foreign key namesourceTable- The table we're coming from- Returns:
- The table on the other side, or empty if unresolvable
-
getKeyFields
public static Optional<Map<org.jooq.TableField<?,?>, getKeyFieldsorg.jooq.TableField<?, ?>>> (JOOQMapping key) -
getRequiredFields
- Returns:
- Set of the names for all the fields that are set as required in the jOOQ table.
-
fieldIsNullable
- Returns:
- Is this field nullable in the jOOQ table?.
-
tableFieldHasDefaultValue
- Returns:
- Does this field have a default value in this jOOQ table? Does not work for views.
-
tableHasIndex
Checks if a table has an index with the specified name.- Parameters:
tableName- The name of the table to check for the index.indexName- The name of the index- Returns:
- Returns true if the table has an index with the same name as provided, false otherwise.
-
getIndex
-
searchTableForMethodWithName
Search this jOOQ table for a method that matches this name.- Parameters:
tableName- Name of the jOOQ table.name- Name that might have a method associated with it.- Returns:
- The name of a method that matches the provided name if it exists.
-
searchTableForKeyMethodNameGivenJavaFieldNames
public static Optional<String> searchTableForKeyMethodNameGivenJavaFieldNames(String tableName, String keyName) Search this jOOQ table for a path method that matches the provided key name.- Parameters:
tableName- Java field name of the jOOQ TablekeyName- Name of the jOOQ ForeignKey- Returns:
- The name of a path method on the table that matches the provided key
-
getTableByJavaFieldName
-
getTableJavaFieldNameByTableName
-
getTableNames
- Returns:
- Set of all table names in the jOOQ generated code.
-
getForeignKey
-
getJavaFieldNamesForTable
- Returns:
- Set of field names for this table.
-
getJavaFieldNamesForKey
-
getJavaFieldName
-
getClassFromSchemas
-
getTablesByJavaFieldName
-
getForeignKeysByJavaFieldName
-
getField
-
getFieldType
-
isArrayField
-
fieldTypeIsCLOB
-
getTableClass
-
getRecordClass
-
tableHasPrimaryKey
-
getPrimaryKeyForTable
-
getUniqueKeysForTable
-
getPrimaryAndUniqueKeysForTable
-
getPrimaryOrUniqueKeyMatchingFields
-
getMethodFromReference
-
getTableJavaFieldNameForRecordClass
Gets the table name (Java field name) for a jOOQ record class.- Parameters:
recordClass- The jOOQ record class to find the table for- Returns:
- The table name if found, empty otherwise
-
getTableName
-