Skip navigation links

Package org.sormula.operation

Classes that perform SQL operations such as select, update, insert, save, and delete.

See: Description

Package org.sormula.operation Description

Classes that perform SQL operations such as select, update, insert, save, and delete.

There are two types of operations: select operations and modify operations. All select operations are derived from SelectOperation. Insert, save, update, and, delete operations are derived from ModifyOperation.

Use operation classes instead of Table methods if you need to perform the same operation many times but only want to prepare it once for efficiency.

For example, select all students by type 3 and then by type 4 with the same operation. "byType" is name of Where annotation on Student:

 Database database = ...
 Table<Student> table = database.getTable(Student.class);
 ArrayListSelectOperation<Student> op = 
     new ArrayListSelectOperation<>(table, "byType");
 op.setParameters(3);
 op.execute(); // JDBC prepare occurs here
 List<Student> selectedList3 = op.readAll();    
 op.setParameters(4);
 op.execute(); // no prepare needed
 List<Student> selectedList4 = op.readAll();
 op.close();
 
To update rows (insert, save, and delete are similar):
 Database database = ...
 Table<Student> table = database.getTable(Student.class);
 UpdateOperation<Student> op = new UpdateOperation<>(table);
 List<Student> list1 = ...;    
 op.setRows(list1);
 op.execute(); // JDBC prepare occurs here
 List<Student> list2 = ...; 
 op.setRows(list2);
 op.execute(); // no prepare needed
 op.close();
 
Skip navigation links