Description

Linked Generators can be used when you want to populate test data into a non-empty database. In this case, the Primary Key should be generated after the max value in the table.


This can be achieved by using the QueryOnceGen Generator to obtain the maximum count from a specified table and by referencing the StartRange of the RangeGen Generator. 


In order to pick the last inserted ID, you can use the QueryOnceGen Generator to get the maximum Id from the table using the query below:

select max(id) + 1 from <tableName>


And then, within the same Attribute, you can add another Generator RangeGen. In the startRange of RangeGen, refer to gen1 (self.gen1).


In This Article


Step 1 - Add the QueryOnceGen Generator to the Attribute

  • Click the Add Generator button within the Attribute Dashboard.


  • Enter QueryOnceGen in the filter input field and click the Plus (+).


Step 2 - Configure the QueryOnceGen Generator Parameters

Configure the Parameters below and click the Save Generator button: 

  • resourceName = resource.jdbc.directory resource
  • query = select max(id) + 1 from <tableName> Note: Replace <tableName> with the actual table name.
  • sampleValue* = 5001



Step 3 - Add the RangeGen Generator to the Attribute

Note: If the RangeGen Generator has already been assigned to the Attribute, this step can be skipped.

  • Click the Add Generator button within the Attribute Dashboard.


  • Enter RangeGen in the filter input field and click the Plus (+).


  • The RangeGen Generator has been added to the Attribute.


Step 4 - Reference the QueryOnceGen Generator for the startRange Parameter

  • Double click on the startRange Parameter for the RandomGen Generator.


  • Select the Attribute Generator Tab and click on the Plus (+) for gen1.


  • Click the Save Generator button. The Primary Keys will now begin after the Max Value that is obtained by the QueryOnceGen Generator for the specified table.