Class AbstractEntitySqlGeneratorTest

java.lang.Object
org.fastnate.generator.test.AbstractEntitySqlGeneratorTest
Direct Known Subclasses:
AccessTest, CollectionsTest, DateEntityTest, EmbeddedTest, IdsTest, InheritanceTest, MapsTest, OverridesTest, PerformanceTest, PrimitiveEntityTest, RecursiveEntityTest, ReferenceEntityTest, SchemaTest, SpringDataTest, VersionTest

public class AbstractEntitySqlGeneratorTest extends Object
Test the EntitySqlGenerator framework.
Author:
Tobias Liefke
  • Field Details

    • WRITER_KEY

      public static final String WRITER_KEY
      The settings key that indicates which StatementsWriter to use for tests.
      See Also:
  • Constructor Details

    • AbstractEntitySqlGeneratorTest

      public AbstractEntitySqlGeneratorTest()
  • Method Details

    • createQuery

      public <E> jakarta.persistence.TypedQuery<E> createQuery(String query, Class<E> entityClass, String... parameters) throws IOException
      Creates a typed JPQL query.
      Parameters:
      query - the JPQL query
      entityClass - the type of the result object
      parameters - the list of parameter names and values
      Returns:
      the typed query
      Throws:
      IOException - if the generator throws one during flush
    • executeSql

      protected void executeSql(SqlRunnable work) throws SQLException
      Execute some SQL using the current JDBC connection.
      Parameters:
      work - The work to be performed.
      Throws:
      SQLException - if there is a problem with the work
    • findResults

      public <E> List<E> findResults(Class<E> entityClass) throws IOException
      Finds all entities of the given entity class.
      Parameters:
      entityClass - the class of the entity
      Returns:
      all entities of that class
      Throws:
      IOException - if the generator throws one during flush
    • findResults

      public <E> List<E> findResults(String query, Class<E> entityClass, String... parameters) throws IOException
      Finds all entities for the given query and entity class.
      Parameters:
      query - the JPA-QL query
      entityClass - the class of the entity
      parameters - the list of parameter names and values
      Returns:
      the result entities for the query
      Throws:
      IOException - if the generator throws one during flush
    • findSingleResult

      public <E> E findSingleResult(Class<E> entityClass) throws IOException
      Finds the only entity for the given entity class.
      Parameters:
      entityClass - the class of the entity
      Returns:
      the single entity of that class
      Throws:
      IOException - if the generator throws one during flush
    • findSingleResult

      public <E> E findSingleResult(String query, Class<E> entityClass, String... parameters) throws IOException
      Finds the entity for the given query and entity class.
      Parameters:
      query - the JPA-QL query
      entityClass - the class of the entity
      parameters - the list of parameter names and values
      Returns:
      the single result entity for the query
      Throws:
      IOException - if the generator throws one during flush
    • getConnection

      protected Connection getConnection() throws SQLException
      Resolves the connection from the session.
      Returns:
      the connection
      Throws:
      SQLException - Indicates a problem getting the connection
    • getGeneratorProperties

      protected Properties getGeneratorProperties()
      Properties for configuring the generator.
      Returns:
      the test specific properties for the generator
    • setup

      @BeforeEach public void setup()
      Build a entity manager factory (with an empty connected database) for testing.
    • setup

      protected void setup(String schemaCreation)
      Build a entity manager factory (with a connected database) for testing.
      Parameters:
      schemaCreation - indicates how to initialize the database ("create" vs. "")
    • tearDown

      @AfterEach public void tearDown()
      Close the entity manager factory.
    • write

      protected <E> void write(E entity) throws IOException
      Writes the entity with the generator.
      Parameters:
      entity - the entity to write
      Throws:
      IOException - if the generator throws one
    • getEm

      protected jakarta.persistence.EntityManager getEm()
    • getGenerator

      protected org.fastnate.generator.EntitySqlGenerator getGenerator()