"Batch processing" means to perform some processing at the timing of button press or time specification.We will assume that database updating is involved in particular.
Developers can grasp the table structure of all the applications developed by Wagby.The table schema based on the model design is also automatically generated.Therefore, you can reference/update the table from another program.Based on this idea, we explain four ways to realize batch processing.
|method||Characteristic||Points to consider|
|Stored procedure type||It is completed in the database.The trigger function provided by the database and the scheduler function can also be used.(*)||It is not possible to refer to Java objects prepared in the JVM.It is necessary to control locks and caches provided by Wagby from this batch program.|
|External program type||You can use languages other than Java.Call a program created with .NET or RPG, for example.|
|Java||You can reuse Java code generated by Wagby.||Job execution control is not performed.|
|Java (using SpringBatch)||You can reuse Java code generated by Wagby. Job execution control is provided by the framework.||I need to learn SpringBatch 's style.|
When implementing batch processing with "stored procedure" or "external program (other than Java)", you need to consider locking and caching.Let's talk about locking here.
If the batch process to be realized falls under the following, you do not need to consider locking.
In other cases, updating by batch processing is also executed in a state where there is a user using Wagby (may update).In this case, you need to properly lock the data and control write conflicts.
Wagby isYou can choose optimistic locks and pessimistic locks.From the viewpoint of creating a batch processing program, there are the following differences.
|Lock method||Optimistic lock||Pessimist lock|
|Implementation method||The table generated by Wagby includes "version control column".In the batch processing program, the value (numerical value) of this column is stored at the time of reading, and this value is updated by adding it to the where clause.If other users were updating this data, updating the data will fail because the version value has changed.||Change the behavior of the lock manager provided by Wagby.Normally, lock objects are managed in memory, but they are written to the jfclockobject table.In the batch processing program, if there is a lock key in the jfclockobject table, do not update it.|
In general, from the viewpoint of creating a batch processing program, the difficulty level of optimistic lock control is low.Although Wagby's standard is "pessimistic lock", it is a good idea to consider changing to an optimistic locking model that is also updated simultaneously from the batch processing program.
Even if it is written in Java, lock control is necessary if it is a program that directly executes SQL without using the Service class automatically generated by Wagby.
Lock control can be omitted if it is a program that reuses Service class automatically generated by Wagby.(All of these are controlled automatically by the Service class.This will be described in detail later.
Wagby keeps the value read from the database as a cache in the memory.This reduces the number of SQL occurrences and improves application performance.
Therefore, when implementing batch processing with "stored procedure" or "(external program other than (Java)"), it is necessary to clear the cache of the model that updated.
From an external program,REST API to clear cacheYou can call.This method is the easiest.
If the program that reuses the Service class automatically generated by Wagby is used, the cache clear processing can be omitted.(All of these are controlled automatically by the Service class.This will be described in detail later.