-
Notifications
You must be signed in to change notification settings - Fork 16
Creating Model Objects
Model objects should be created following the technical requirements outlined in the Overview page. Here are a list of general steps to take in their creation:
-
To save time we will be using JAXB class extensions in BeATS as model object templates and database reader and writer classes from Scenario Database Access. Look in beats simulator sub-package to see if an extended model object already exists which you can use as a template. Copy this file into the correct sub-package within model-objects package.
-
Add the following before the Java class definition:
@XmlRootElement(name = "class"). Replacing class with the model object class name. This is needed for serialization of the model object. -
Add setters and getters for each attribute within base model object. Note: There are base getters and setters which return underlying JAXB generated classes. These should be changed to instead return the attribute housed within them. For example, links have a getter which returns an End class which houses the end node id associated with the link. Instead a getter and setter was added to return the actual end node id, not the End class.
-
Extra fields which are in the database may need to be added to the schema. For example model objects should be keeping track of modTimeStamps (which are passed back on update to ensure the records have not been modified since the model object was retrieved). These attributes can be added under the appropriate schema element and xsd file within src/main/resources directory. An example of the modTimeStamp is in the network schema where it references the extended DateTime class in the generic sub-package.
-
Keep any generic attributes and functions within the extended model object. If you are unsure what constitutes generic functionality send out an email.
-
Ensure there are getters and setters which allow for passing in and retrieving extended model objects nested inside another model object. For instance in the network class there were methods to get and set extended link and node object lists within a network, not just the default methods to set base objects.
-
Create Model Object Unit tests which do at least one assertions on every setter and getter.
-
If no factory exists in the sub-package add one.
- The scenario database access layer contains a somewhat complete list of readers and writers on the scenario level. This layer is dependent on the core project largely for it's database and monitoring classes. This code should be recycled for model objects as much as possible, and so these readers and writers should be added to the model database access layer. However we are now using the Oracle specific database classes within Core (anything that begins with Ora). They have a slightly different interface and exception handling than the older Database classes. First of all exceptions are now handled within the oraDatabase classes and most methods return true or false based on success. The next change is that the writers will use stored procedure packages and the readers will use the JDBC result getters instead of type specific functions within DatabaseReader.java to convert resultset column values to typed java variables. Here is a list of the refactoring changes which need to be done:
Refactoring Readers
-
Readers extend DBBase.java instead of ReaderBase.java
-
There should be 4 constructors: The first with no parameters, Another which takes in only a factory, Another which takes in only an Core.oraDatabase connection object and one which takes in both a factory and Core.oraDatabase connection object.
-
Use appropriate model object instead of model elements and convert all setters and getters to appropriate model objects.
-
All query/stored procedure calls should reference the DBBase objects dbSchema attribute instead of 'VIA'.
-
Use psSetParam function in oraDatabaseReader to set query parameters instead of the old psSet methods which were in DatabaseReader.
-
Use returnRS function in oraDatabaseReader to return result set and then use JDBC get value as type functions to cast resultset values to java types.
-
Get modstamps from all table records by using to_char oracle function in the following format: DD-MON-YYYY HH24:MI:SS:FF6
Refactoring Writers
-
Writers extend DBBase.java instead of WriterBase.java
-
Writers should have two constructors, one which takes in no parameters and another which takes in connection object.
-
Use Stored procedures instead of queries. Note: Developers currently do not have write permission to the Via database, so writers are first priority to be changed to user stored procedure. An example on how to implement stored procedures can be found here.
-
Change all transaction support to use OraDatabase beginTransaction, rollbackTransaction and commitTransaction methods.
-
All stored procedure calls should reference the DBBase objects dbSchema attribute instead of 'VIA'.