Class TableReflection

java.lang.Object
no.sikt.graphitron.mappings.TableReflection

public class TableReflection extends Object
Helper class that takes care of any table reflection operations the code generator might require towards the jOOQ source.
  • Constructor Details

    • TableReflection

      public TableReflection()
  • Method Details

    • findImplicitKey

      public static Optional<String> findImplicitKey(String leftTableName, String rightTableName)
      Returns:
      The implicit key between these two tables.
    • getForeignKeysBetweenTables

      public static Optional<List<? extends org.jooq.ForeignKey<?,?>>> getForeignKeysBetweenTables(String leftTableName, String rightTableName)
    • getNumberOfForeignKeysBetweenTables

      public static int getNumberOfForeignKeysBetweenTables(String leftTableName, String rightTableName)
    • inferRelationType

      public static TableRelationType inferRelationType(String leftTableName, String rightTableName, JOOQMapping preferredKey)
      Returns:
      The kind of relation that is present between these tables.
    • hasSelfRelation

      public static boolean hasSelfRelation(String tableName)
      Returns:
      Does this table have any references to itself?
    • recordUsesFSHack

      public static boolean recordUsesFSHack(String tableName)
      NEW FS hack! Some methods do not use getId(), but getId_() methods for ID...
    • tableExists

      public static boolean tableExists(String tableName)
      Returns:
      Does this table exist in the generated jOOQ code?
    • keyExists

      public static boolean keyExists(String keyName)
      Returns:
      Does this key exist in the generated jOOQ code?
    • tableOrKeyExists

      public static boolean tableOrKeyExists(String name)
      Returns:
      Does this table or key exist in the generated jOOQ code?
    • getKeyTargetTableJavaName

      public static Optional<String> getKeyTargetTableJavaName(String keyName)
      Returns:
      Which table does this key point to?
    • getKeySourceTableJavaName

      public static Optional<String> getKeySourceTableJavaName(String keyName)
      Returns:
      Which table does this key belong to?
    • resolveKeyOtherTable

      public static Optional<String> resolveKeyOtherTable(String keyName, String sourceTable)
      Given a foreign key and a known source table, resolve the table on the other side of the key.
      Parameters:
      keyName - The foreign key name
      sourceTable - 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<?,?>,org.jooq.TableField<?,?>>> getKeyFields(JOOQMapping key)
    • getRequiredFields

      public static Set<String> getRequiredFields(String tableName)
      Returns:
      Set of the names for all the fields that are set as required in the jOOQ table.
    • fieldIsNullable

      public static Optional<Boolean> fieldIsNullable(String tableName, String fieldName)
      Returns:
      Is this field nullable in the jOOQ table?.
    • tableFieldHasDefaultValue

      public static boolean tableFieldHasDefaultValue(String tableName, String fieldName)
      Returns:
      Does this field have a default value in this jOOQ table? Does not work for views.
    • tableHasIndex

      public static boolean tableHasIndex(String tableName, String indexName)
      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

      public static Optional<org.jooq.Index> getIndex(String tableName, String indexName)
    • searchTableForMethodWithName

      public static Optional<String> searchTableForMethodWithName(String tableName, String name)
      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 Table
      keyName - Name of the jOOQ ForeignKey
      Returns:
      The name of a path method on the table that matches the provided key
    • getTableByJavaFieldName

      public static Optional<org.jooq.Table<?>> getTableByJavaFieldName(String name)
    • getTableJavaFieldNameByTableName

      public static Optional<String> getTableJavaFieldNameByTableName(String name)
    • getTableNames

      public static Set<String> getTableNames()
      Returns:
      Set of all table names in the jOOQ generated code.
    • getForeignKey

      public static Optional<org.jooq.ForeignKey<?,?>> getForeignKey(String name)
    • getJavaFieldNamesForTable

      public static Set<String> getJavaFieldNamesForTable(String tableName)
      Returns:
      Set of field names for this table.
    • getJavaFieldNamesForKey

      public static List<String> getJavaFieldNamesForKey(String tableName, org.jooq.Key<?> key)
    • getJavaFieldName

      public static Optional<String> getJavaFieldName(String tableName, String fieldName)
    • getClassFromSchemas

      public static Set<Class<?>> getClassFromSchemas(String className)
    • getTablesByJavaFieldName

      protected static Map<String,org.jooq.Table<?>> getTablesByJavaFieldName()
    • getForeignKeysByJavaFieldName

      protected static Map<String,org.jooq.ForeignKey<?,?>> getForeignKeysByJavaFieldName()
    • getField

      public static Optional<org.jooq.Field<?>> getField(String tableName, String name)
    • getFieldType

      public static Optional<Class<?>> getFieldType(String table, String name)
    • isArrayField

      public static boolean isArrayField(String tableName, String fieldName)
    • fieldTypeIsCLOB

      public static boolean fieldTypeIsCLOB(String table, String name)
    • getTableClass

      public static Optional<Class<?>> getTableClass(String name)
    • getRecordClass

      public static Optional<Class<?>> getRecordClass(String name)
    • tableHasPrimaryKey

      public static boolean tableHasPrimaryKey(String tableName)
    • getPrimaryKeyForTable

      public static Optional<? extends org.jooq.UniqueKey<?>> getPrimaryKeyForTable(String tableName)
    • getUniqueKeysForTable

      public static Optional<List<? extends org.jooq.UniqueKey<?>>> getUniqueKeysForTable(String tableName)
    • getPrimaryAndUniqueKeysForTable

      public static Set<? extends org.jooq.UniqueKey<?>> getPrimaryAndUniqueKeysForTable(String tableName)
    • getPrimaryOrUniqueKeyMatchingFields

      public static Optional<? extends org.jooq.UniqueKey<?>> getPrimaryOrUniqueKeyMatchingFields(String table, List<String> fields)
    • getMethodFromReference

      public static Optional<Method> getMethodFromReference(String reference, String tableName, String methodName)
    • getTableJavaFieldNameForRecordClass

      public static Optional<String> getTableJavaFieldNameForRecordClass(Class<?> recordClass)
      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

      public static @NonNull String getTableName(Class<?> jooqRecordClass)