Class Utilities


  • public class Utilities
    extends java.lang.Object
    Author:
    Collin Alpert
    • Constructor Summary

      Constructors 
      Constructor Description
      Utilities()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List<TableColumnReference> getAllFields​(java.lang.Class<? extends BaseEntity> instanceClass)
      Gets all the fields and the fields of foreign key objects in this entity.
      static java.util.List<TableColumnReference> getAllFields​(java.lang.Class<? extends BaseEntity> instanceClass, java.lang.String alias)
      Gets all the fields and the fields of foreign key objects in this entity.
      static java.lang.String getColumnName​(java.lang.reflect.Field field)
      Gets the corresponding table column name of a field.
      static java.util.List<java.lang.reflect.Field> getEntityFields​(java.lang.Class<? extends BaseEntity> instanceClass)  
      static java.util.List<java.lang.reflect.Field> getEntityFields​(java.lang.Class<? extends BaseEntity> instanceClass, boolean includeForeignKeys)  
      static java.util.List<java.lang.reflect.Field> getEntityFields​(java.lang.Class<? extends BaseEntity> instanceClass, java.lang.Class<?> delimiter)  
      static java.lang.String getTableName​(java.lang.Class<?> type)
      Gets the database table name from the TableName attribute on the class.
      static void log​(java.lang.Object text)
      Prints messages to the query, while considering the DBConnection.LOG_QUERIES constant.
      static void logf​(java.lang.String text, java.lang.Object... params)
      Prints formatted messages to the query, while considering the DBConnection.LOG_QUERIES constant.
      static java.lang.Runnable runnableHandling​(ThrowableRunnable<java.sql.SQLException> runnable, java.util.function.Consumer<java.sql.SQLException> exceptionHandling)
      Handles an SQLException that gets thrown inside a Runnable.
      static <V> java.util.function.Supplier<V> supplierHandling​(ThrowableSupplier<V,​java.sql.SQLException> supplier, java.util.function.Consumer<java.sql.SQLException> exceptionHandling)
      Handles an SQLException that gets thrown inside a Supplier.
      static <E extends java.lang.Throwable>
      void
      tryAction​(ThrowableRunnable<E> runnable)
      Tries to perform a certain action while considering a checked exception that could occur.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Utilities

        public Utilities()
    • Method Detail

      • getEntityFields

        public static java.util.List<java.lang.reflect.Field> getEntityFields​(java.lang.Class<? extends BaseEntity> instanceClass)
      • getEntityFields

        public static java.util.List<java.lang.reflect.Field> getEntityFields​(java.lang.Class<? extends BaseEntity> instanceClass,
                                                                              boolean includeForeignKeys)
      • getEntityFields

        public static java.util.List<java.lang.reflect.Field> getEntityFields​(java.lang.Class<? extends BaseEntity> instanceClass,
                                                                              java.lang.Class<?> delimiter)
      • getAllFields

        public static java.util.List<TableColumnReference> getAllFields​(java.lang.Class<? extends BaseEntity> instanceClass)
        Gets all the fields and the fields of foreign key objects in this entity.
        Parameters:
        instanceClass - The class to get the fields from.
        Returns:
        A list of columns including references to their table.
      • getAllFields

        public static java.util.List<TableColumnReference> getAllFields​(java.lang.Class<? extends BaseEntity> instanceClass,
                                                                        java.lang.String alias)
        Gets all the fields and the fields of foreign key objects in this entity.
        Parameters:
        instanceClass - The class to get the fields from.
        alias - The alias that nested properties will use.
        Returns:
        A list of columns including references to their table.
      • log

        public static void log​(java.lang.Object text)
        Prints messages to the query, while considering the DBConnection.LOG_QUERIES constant.
        Parameters:
        text - The message to print.
      • logf

        public static void logf​(java.lang.String text,
                                java.lang.Object... params)
        Prints formatted messages to the query, while considering the DBConnection.LOG_QUERIES constant.
        Parameters:
        text - The formatted text.
        params - The parameters to be inserted into the string.
      • getTableName

        public static java.lang.String getTableName​(java.lang.Class<?> type)
        Gets the database table name from the TableName attribute on the class. If there is no attribute, the class name in lower case characters is returned.
        Parameters:
        type - The entity to get the table name of.
        Returns:
        The table name.
      • getColumnName

        public static java.lang.String getColumnName​(java.lang.reflect.Field field)
        Gets the corresponding table column name of a field.
        Parameters:
        field - The field representing the column in a table.
        Returns:
        The column name in the table.
      • supplierHandling

        public static <V> java.util.function.Supplier<V> supplierHandling​(ThrowableSupplier<V,​java.sql.SQLException> supplier,
                                                                          java.util.function.Consumer<java.sql.SQLException> exceptionHandling)
        Handles an SQLException that gets thrown inside a Supplier.
        Type Parameters:
        V - The return type of the operation.
        Parameters:
        supplier - The Supplier that throws the exception.
        exceptionHandling - The exception handling supplied for this exception.
        Returns:
        The original Supplier but now with the added exception handling.
      • runnableHandling

        public static java.lang.Runnable runnableHandling​(ThrowableRunnable<java.sql.SQLException> runnable,
                                                          java.util.function.Consumer<java.sql.SQLException> exceptionHandling)
        Handles an SQLException that gets thrown inside a Runnable.
        Parameters:
        runnable - The Runnable that throws the exception.
        exceptionHandling - The exception handling supplied for this exception.
        Returns:
        The original Runnable but now with the added exception handling.
      • tryAction

        public static <E extends java.lang.Throwable> void tryAction​(ThrowableRunnable<E> runnable)
        Tries to perform a certain action while considering a checked exception that could occur.
        Type Parameters:
        E - The type of checked exception.
        Parameters:
        runnable - The Runnable to try to execute.