Part I. Getting started

Part II. UML modeling

Part III. Project glossary

Part IV. BPMN toolset

Part V. Project management

Part VI. Modeling toolset

Part VII. ArchiMate tools

Part VIII. Team collaboration

Part IX. Code engineering

Part X. Database design and engineering

Part XI. Advanced modeling toolset

Part XII. Document production

Part XIII. Business modeling

Part XIV. Business rule

Part XV. Agile development

Part XVI. Wireframe

Part XVII. Impact analysis

Part XVIII. CMMN toolset

Part XIX. SoaML modeling

Part XX. Design animation

Part XXI. IDE Integration

Part XXII. Interoperability and integration

Part XXIII. Process simulation

Part XXIV. Zachman and BMM

Part XXV. Appendix A - Application Options

Part XXVI. Appendix B - Project Options

Part XXVII. Appendix C

 

How to Use the Generate ORM Code?

The following sections demonstrate how to use the generate ORM code with factory method persistent API.

Inserting records

  1. Create persistent object with factory create method.
  2. Save persistent object with save method.

The following codes demonstrate how to insert a Product record:

PersistentTransaction t = ErdPersistentManager.instance().getSession().beginTransaction();
try {
Product product = ProductFactory.createProduct();
product.setName("ABC Keyboard");
product.setPrice(24.5);
product.save();
}
catch (Exception e) {
t.rollback();
}

Selecting records

Factory method provides a convinient listByQuery method, accept condition and order by as parameter` and return array of persistent object.

The following codes demonstrate how to select a list of Product records, null for condition parameter will select all records, null for order by parameter does not sort in any order:

Product[] products = ProductFactory.listProductByQuery(null, null);
for (int i = 0; i < products.length; i++) {
System.out.println(products[i]);
}

Another useful method to select a persistent object by ID is loadByORMID. The following codes demonstrate how to select a lProuct record by ID.

Product product = ProductFactory.loadProductByORMID(1);

Updating records

  1. Select a persistent object from database.
  2. Update the persistent object.
  3. Save persistent object with save method.

The following codes demonstrate how to update a Product record:

PersistentTransaction t = ErdPersistentManager.instance().getSession().beginTransaction();
try {
Product product = ProductFactory.loadProductByORMID(1);
product.setName("DEF Keyboard");
product.save();
}
catch (Exception e) {
t.rollback();
}

Deleting records

  1. Select a persistent object from database.
  2. Delete persistent object with delete method.

The following codes demonstrate how to delete a Product record:

PersistentTransaction t = ErdPersistentManager.instance().getSession().beginTransaction();
try {
Product product = ProductFactory.loadProductByORMID(1);
product.delete();
}
catch (Exception e) {
t.rollback();
}

Related Resources

The following resources may help you to learn more about the topic discussed in this page.

 
3. Persistent API Table of Contents 5. Customizing getter and setter body

We use cookies to offer you a better experience. By visiting our website, you agree to the use of cookies as described in our Cookie Policy.OK