📚
Szczurowsky Industries
RatORM
RatORM
  • 🖐️Welcome!
  • ⚡Quick Start
  • 🎓Features
  • 🧑‍🎓Basic
    • Model
    • Operation
  • 🙉Annotations
    • Model
    • ModelField
Powered by GitBook
On this page
  • What is operation?
  • When should I use operation
  • How i am supposed to create operation?
  1. Basic

Operation

What is operation?

Operation is organised type of more complex database query. It's really important when you executing an atomic query or you've got types of query which are executed multiple times in diffrent places.

When should I use operation

Every time when you executing an atomic query. For example if you are bank institution and user is transfering money. If anything in that action goes wrong we don't want to execute any query. That's why we're using transactions option in our operations.

Another example is when you've type of query which is executed multiple times in diffrent places. Then you can create one operation and execute it in only one line across your app

How i am supposed to create operation?

Creating model is just creating new runnable class

Example

TestOperation.java
public class TestOperation<T extends BaseModel> extends MongoOperation {


    private final Collection<T> models;
    private final Class<T> tClass;
    Database mongodb;

    public TestOperation(Database mongodb, Collection<T> models, Class<T> tClass) throws PassedWrongDriverToOperationException {
        super(mongodb);
        this.mongodb = mongodb;
        this.models = models;
        this.tClass = tClass;
        // Do we want to use transaction?
        this.useTransactions = true;
    }

    @Override
    public void execute(HashMap<String, Object> options) {
        for (T model : models) {
            mongodb.save(model, tClass, options);
            System.out.println("Saved: " + model.toString());
        }
        System.out.println("DONE");
    }
}RT
int id = mongodb.getOperationManager().execute(new TestOperation<>(mongodb, List.of(testModel), TestModel.class));
PreviousModelNextModel

Last updated 3 years ago

🧑‍🎓