Class RDBMSStoreManager.ClassAdder
- Enclosing class:
RDBMSStoreManager
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 Summary
FieldsModifier and TypeFieldDescriptionprivate int
private final boolean
Whether to check if table/view existsprivate final String[]
private Writer
Optional writer to dump the DDL for any classes being added.static final int
join table for Array.static final int
join table for Collection.static final int
join table for Map.static final int
join table for persistable.private Set
<RDBMSStoreData> tracks the SchemaData currrently being added - used to rollback the AutoStart added classesFields inherited from class org.datanucleus.store.rdbms.AbstractSchemaTransaction
isolationLevel, maxRetries, mconn, rdbmsMgr
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ClassAdder
(String[] classNames, Writer writer, int isolationLevel) Constructs a new class adder transaction that will add the given classes to the RDBMSManager. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addClassTable
(org.datanucleus.metadata.ClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr) Method to add a new table object (ie ClassTable or ClassView).void
addClassTables
(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
(List<Table> newTables) Check if duplicated tables are in the list.initializeClassTables
(String[] classNames, org.datanucleus.ClassLoaderResolver clr) Initialisation of tables.private List[]
performTablesValidation
(List<Table> tablesToValidate, org.datanucleus.ClassLoaderResolver clr, List<Throwable> autoCreateErrors) Validate tables.performViewsValidation
(List<Table> viewsToValidate, List<Throwable> autoCreateErrors) Validate the supplied views.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.protected void
run
(org.datanucleus.ClassLoaderResolver clr) Method to perform the class addition.toString()
Method to give a string version of this object.Methods inherited from class org.datanucleus.store.rdbms.AbstractSchemaTransaction
execute, getCurrentConnection
-
Field Details
-
JOIN_TABLE_COLLECTION
public static final int JOIN_TABLE_COLLECTIONjoin table for Collection.- See Also:
-
JOIN_TABLE_MAP
public static final int JOIN_TABLE_MAPjoin table for Map.- See Also:
-
JOIN_TABLE_ARRAY
public static final int JOIN_TABLE_ARRAYjoin table for Array.- See Also:
-
JOIN_TABLE_PERSISTABLE
public static final int JOIN_TABLE_PERSISTABLEjoin table for persistable.- See Also:
-
ddlWriter
Optional writer to dump the DDL for any classes being added. -
checkExistTablesOrViews
private final boolean checkExistTablesOrViewsWhether to check if table/view exists -
schemaDataAdded
tracks the SchemaData currrently being added - used to rollback the AutoStart added classes -
classNames
-
tablesRecentlyInitialized
-
addClassTablesRecursionCounter
private int addClassTablesRecursionCounter
-
-
Constructor Details
-
ClassAdder
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 tablesisolationLevel
- Txn isolation level to use for schema "class" addition
-
-
Method Details
-
toString
Method to give a string version of this object.- Specified by:
toString
in classAbstractSchemaTransaction
- Returns:
- The String version of this object.
-
run
Method to perform the class addition.- Specified by:
run
in classAbstractSchemaTransaction
- Parameters:
clr
- the ClassLoaderResolver- Throws:
SQLException
- Thrown if an error occurs in execution.
-
addClassTables
Adds a new table object (ie ClassTable or ClassView) for every class in the given list. These classes- require a table
- 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 ClassMetaDataclr
- 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 namesclr
- 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 validateclr
- 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
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 droppedtableConstraintsCreated
- the constraints created that must be droppedtablesCreated
- 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 membermmd
- The member metadata for this membertype
- The type of the join table
-