Class 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.

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ClassAdder​(java.lang.String[] classNames, java.io.Writer writer, int isolationLevel)
      Constructs a new class adder transaction that will add the given classes to the RDBMSManager.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addClassTable​(org.datanucleus.metadata.ClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr)
      Method to add a new table object (ie ClassTable or ClassView).
      void addClassTables​(java.lang.String[] classNames, org.datanucleus.ClassLoaderResolver clr)
      Adds a new table object (ie ClassTable or ClassView) for every class in the given list.
      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.
      private boolean hasDuplicateTablesFromList​(java.util.List<Table> newTables)
      Check if duplicated tables are in the list.
      private java.util.List<Table>[] initializeClassTables​(java.lang.String[] classNames, org.datanucleus.ClassLoaderResolver clr)
      Initialisation of tables.
      private java.util.List[] performTablesValidation​(java.util.List<Table> tablesToValidate, org.datanucleus.ClassLoaderResolver clr, java.util.List<java.lang.Throwable> autoCreateErrors)
      Validate tables.
      private java.util.List<Table> performViewsValidation​(java.util.List<Table> viewsToValidate, java.util.List<java.lang.Throwable> autoCreateErrors)
      Validate the supplied views.
      private void rollbackSchemaCreation​(java.util.List<Table> viewsCreated, java.util.List<Table> tableConstraintsCreated, java.util.List<Table> tablesCreated)
      Rollback / Compensate schema creation by dropping tables, views, constraints and deleting entries in the auto start mechanism.
      protected void run​(org.datanucleus.ClassLoaderResolver clr)
      Method to perform the class addition.
      java.lang.String toString()
      Method to give a string version of this object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • JOIN_TABLE_COLLECTION

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

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

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

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

        private java.io.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 java.util.Set<RDBMSStoreData> schemaDataAdded
        tracks the SchemaData currrently being added - used to rollback the AutoStart added classes
      • classNames

        private final java.lang.String[] classNames
      • tablesRecentlyInitialized

        private java.util.List<Table> tablesRecentlyInitialized
      • addClassTablesRecursionCounter

        private int addClassTablesRecursionCounter
    • Constructor Detail

      • ClassAdder

        private ClassAdder​(java.lang.String[] classNames,
                           java.io.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 Detail

      • toString

        public java.lang.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 java.sql.SQLException
        Method to perform the class addition.
        Specified by:
        run in class AbstractSchemaTransaction
        Parameters:
        clr - the ClassLoaderResolver
        Throws:
        java.sql.SQLException - Thrown if an error occurs in execution.
      • addClassTables

        public void addClassTables​(java.lang.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 java.util.List<Table>[] initializeClassTables​(java.lang.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 java.util.List[] performTablesValidation​(java.util.List<Table> tablesToValidate,
                                                         org.datanucleus.ClassLoaderResolver clr,
                                                         java.util.List<java.lang.Throwable> autoCreateErrors)
                                                  throws java.sql.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:
        java.sql.SQLException - When an error occurs in validation
      • hasDuplicateTablesFromList

        private boolean hasDuplicateTablesFromList​(java.util.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 java.util.List<Table> performViewsValidation​(java.util.List<Table> viewsToValidate,
                                                             java.util.List<java.lang.Throwable> autoCreateErrors)
                                                      throws java.sql.SQLException
        Validate the supplied views.
        Parameters:
        viewsToValidate - list of ViewImpl to validate
        Returns:
        list of the views created
        Throws:
        java.sql.SQLException
      • rollbackSchemaCreation

        private void rollbackSchemaCreation​(java.util.List<Table> viewsCreated,
                                            java.util.List<Table> tableConstraintsCreated,
                                            java.util.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