Class RDBMSStoreManager.ClassAdder

java.lang.Object
org.datanucleus.store.rdbms.AbstractSchemaTransaction
org.datanucleus.store.rdbms.RDBMSStoreManager.ClassAdder
Enclosing class:
RDBMSStoreManager

private class RDBMSStoreManager.ClassAdder extends AbstractSchemaTransaction
A schema transaction that adds a set of classes to the RDBMSManager, making them usable for persistence.

This class embodies the work necessary to activate a persistent class and ready it for storage management. It is the primary mutator of a RDBMSManager.

Adding classes is an involved process that includes the creation and/or validation in the database of tables, views, and table constraints, and their corresponding Java objects maintained by the RDBMSManager. Since it's a management transaction, the entire process is subject to retry on SQLExceptions. It is responsible for ensuring that the procedure either adds all of the requested classes successfully, or adds none of them and preserves the previous state of the RDBMSManager exactly as it was.

  • Field Details

    • JOIN_TABLE_COLLECTION

      public static final int JOIN_TABLE_COLLECTION
      join table for Collection.
      See Also:
    • JOIN_TABLE_MAP

      public static final int JOIN_TABLE_MAP
      join table for Map.
      See Also:
    • JOIN_TABLE_ARRAY

      public static final int JOIN_TABLE_ARRAY
      join table for Array.
      See Also:
    • JOIN_TABLE_PERSISTABLE

      public static final int JOIN_TABLE_PERSISTABLE
      join table for persistable.
      See Also:
    • ddlWriter

      private Writer ddlWriter
      Optional writer to dump the DDL for any classes being added.
    • checkExistTablesOrViews

      private final boolean checkExistTablesOrViews
      Whether to check if table/view exists
    • schemaDataAdded

      private Set<RDBMSStoreData> schemaDataAdded
      tracks the SchemaData currrently being added - used to rollback the AutoStart added classes
    • classNames

      private final String[] classNames
    • tablesRecentlyInitialized

      private List<Table> tablesRecentlyInitialized
    • addClassTablesRecursionCounter

      private int addClassTablesRecursionCounter
  • Constructor Details

    • ClassAdder

      private ClassAdder(String[] classNames, Writer writer, int isolationLevel)
      Constructs a new class adder transaction that will add the given classes to the RDBMSManager.
      Parameters:
      classNames - Names of the (initial) class(es) to be added.
      writer - Optional writer for DDL when we want the DDL outputting to file instead of creating the tables
      isolationLevel - Txn isolation level to use for schema "class" addition
  • Method Details

    • toString

      public String toString()
      Method to give a string version of this object.
      Specified by:
      toString in class AbstractSchemaTransaction
      Returns:
      The String version of this object.
    • run

      protected void run(org.datanucleus.ClassLoaderResolver clr) throws SQLException
      Method to perform the class addition.
      Specified by:
      run in class AbstractSchemaTransaction
      Parameters:
      clr - the ClassLoaderResolver
      Throws:
      SQLException - Thrown if an error occurs in execution.
    • addClassTables

      public void addClassTables(String[] classNames, org.datanucleus.ClassLoaderResolver clr)
      Adds a new table object (ie ClassTable or ClassView) for every class in the given list. These classes
      1. require a table
      2. do not yet have a table initialized in the store manager.

      This doesn't initialize or validate the tables, it just adds the table objects to the RDBMSManager's internal data structures.

      Parameters:
      classNames - Names of class(es) whose tables are to be added.
      clr - the ClassLoaderResolver
    • addClassTable

      private void addClassTable(org.datanucleus.metadata.ClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr)
      Method to add a new table object (ie ClassTable or ClassView). Doesn't initialize or validate the tables, just adding the table objects to the internal data structures.
      Parameters:
      cmd - the ClassMetaData
      clr - the ClassLoaderResolver
    • initializeClassTables

      private List<Table>[] initializeClassTables(String[] classNames, org.datanucleus.ClassLoaderResolver clr)
      Initialisation of tables. Updates the internal representation of the table to match what is required for the class(es). Each time a table object is initialized, it may cause other associated table objects to be added (via callbacks to addClasses()) so the loop is repeated until no more initialisation is needed.
      Parameters:
      classNames - String array of class names
      clr - the ClassLoaderResolver
      Returns:
      an array of List where index == 0 is list of the tables created, index == 1 is list of the views created
    • performTablesValidation

      private List[] performTablesValidation(List<Table> tablesToValidate, org.datanucleus.ClassLoaderResolver clr, List<Throwable> autoCreateErrors) throws SQLException
      Validate tables.
      Parameters:
      tablesToValidate - list of TableImpl to validate
      clr - the ClassLoaderResolver
      Returns:
      an array of List where index == 0 has a list of the tables created, index == 1 has a list of the contraints created
      Throws:
      SQLException - When an error occurs in validation
    • hasDuplicateTablesFromList

      private boolean hasDuplicateTablesFromList(List<Table> newTables)
      Check if duplicated tables are in the list.
      Parameters:
      newTables - the list of DatastoreContainerObject
      Returns:
      true if duplicated tables are in the list
    • performViewsValidation

      private List<Table> performViewsValidation(List<Table> viewsToValidate, List<Throwable> autoCreateErrors) throws SQLException
      Validate the supplied views.
      Parameters:
      viewsToValidate - list of ViewImpl to validate
      Returns:
      list of the views created
      Throws:
      SQLException
    • rollbackSchemaCreation

      private void rollbackSchemaCreation(List<Table> viewsCreated, List<Table> tableConstraintsCreated, List<Table> tablesCreated)
      Rollback / Compensate schema creation by dropping tables, views, constraints and deleting entries in the auto start mechanism.
      Parameters:
      viewsCreated - the views created that must be dropped
      tableConstraintsCreated - the constraints created that must be dropped
      tablesCreated - the tables created that must be dropped
    • addJoinTableForContainer

      private Table addJoinTableForContainer(Table ownerTable, org.datanucleus.metadata.AbstractMemberMetaData mmd, org.datanucleus.ClassLoaderResolver clr, int type)
      Called by Mapping objects in the midst of RDBMSManager.addClasses() to request the creation of a join table to hold a containers' contents.
      Parameters:
      ownerTable - Table of the owner of this member
      mmd - The member metadata for this member
      type - The type of the join table