Data Load Tool
Use the Data Load Tool to import and export class instance data and model structures to and from a relational database.
With the Data Load Tool, you can create any of the tables needed to begin developing against your models.
Note
The Data Load Tool operates against a data source, and makes critical changes to a model's data. It is meant for development purposes only.
For a production database, the database or system administrator should review the schema modifications before applying them. To generate an SQL file containing the same schema modification steps that the Data Load Tool applies, use the Database Schema Tool. The administrator can review the script prior to committing it with the database console tools. See Generating database schema SQL for more information.
Data sources
A data source is a logical representation of physical storage that is used to create, read, update, and delete object instances.
Persistence mapping specifies how class instances will be persisted in a given data source.
The NexJ Framework supports the following types of data sources:
RelationalDatabase
Persists instances in a relational database.
FileStorage
Persists instances in a file system.
XML
Persists instances in an XML file.
Service
Persists instances using a collection of services such as web services or store procedures.
Composite
Provides a dynamic choice of possible alternative mappings at run time.
Data sources are configured and bound to physical storage addresses using connection. Data sources support a CRUD interface for interaction with external systems, whereas channels support a send/receive interface. The persistence interface for data sources is synchronous. In NexJ Studio, data sources appear as a tab in the Persistence layer of the model navigator.
Info
The Data Load Tool deals only with relational data sources.
Modifying database data
You use the Data Load Tool primarily to load new class instance data and model structures to your model.
The tool allows you to modify your model's databases using its import
, upgrade
, recreate
, recreateschema
, and reset
commands.
Note
The import
, upgrade
, recreate
, recreateschema
, and reset
commands replace existing table structures. In a non-test environment, you must make sure that data is properly backed up before running any of these commands. Back up your data by publishing your model from the Model Library before proceeding.
Upgrading databases
Model-specific upgrade files contain one or more upgrades, which are associated with a version of the model.
Each upgrade contains steps that explicitly define the data store changes that are required to move from supporting a previous version of the model to supporting the version associated with the upgrade. Once you define an upgrade file for the current version of a model, it can be used to alter the structure or attributes of a database to fit with the current model version.
You can use the upgrade
command to use the upgrade file to migrate the data store for any previous version of the model to the current version.
Before upgrading a database, make sure you have updated your model's upgrade file.
To upgrade a database:
Verifying the upgrade
Verify that the version record in the Version table matches the version of your model.
- In Microsoft SQL Server or DB2, issue the following statement to return the value of the version record in the Version table:
select version from NJVersion
In MySQL, issue the following statement to return the value of the version record in the Version table:
use <modelName>; select version from NJVersion;
where
<modelName>
is your model's name.
Recreating databases
Use the Data Load Tool's recreate
or recreateschema
command to drop and recreate all tables in the database associated with the environment. Use the recreate
command to import the data after recreating all tables.
The recreate
or recreateschema
commands drop all tables defined in the selected datasource. The process then creates new tables based on the current model's datasource definitions. This method differs from the reset
command in that a recreated database will always contain correctly structured tables for the current model.
Differences between recreate, recreateschema, and reset commands
Command | Truncates tables | Drops tables | Creates tables | Inserts data |
---|---|---|---|---|
recreate | No | Yes | Yes | Yes |
recreateschema | No | Yes | Yes | No |
reset | Yes | No | No | Yes |
To recreate a database:
Resetting databases
The reset
command truncates tables by systematically traversing the selected datasource and deleting the data from each table. This method differs from the recreate
and recreateschema
commands in that it maintains model structure. If any tables or classes have been physically changed, the reset will fail because it will attempt to import an outdated model structure.
To reset a database:
Printing the current model version in the system
The final three lines should be in the following format:
; <systemTime> INFO [MetadataLoaderDispatcher] Completed loading metadata from "file:/<modelPath>" <modelNamespace>#<versionNumber> ; <systemTime> INFO [GenericTool] Exit code = 0
where:
<systemTime>
is your system time when the output is completed.<modelPath>
is the current model's file path.<modelNamespace>
is the current model's namespace.<versionNumber>
is the current model's version number.
For example, in the following output, the model version is 5.18:
; 16:23:32,919 INFO [MetadataLoaderDispatcher] Completed loading metadata from "file:/C:/work/WS/training-101/meta/" http://www.nexj.com/ns/training101#5.18 ; 16:23:33,415 INFO [GenericTool] Exit code = 0
Setting virtual machine requirements
These can alter parameters such as allocation of memory or boot state of the machine.
The following are examples of two VM arguments you could use:
Ddump.format=JSON
Serializes to json rather than to the standard format.
Ddump.compressed=false
Specifies whether to use gzip or not. The default is true.
- Click Advanced in the Data Load Tool to open the VM Arguments field.
- Enter your VM arguments in the VM Arguments field.