-
Notifications
You must be signed in to change notification settings - Fork 2
Home
At Kenshoo, we need to persist entities to DB in bulks, we need it to perform fast and we have tons of business logic on the way like validators, enrichers, etc…
So we wrote PL, a Java library built for performance that allows us to define a flow for the business logic.
It currently supports only MySQL.
Like any other framework, some wiring and definitions are required before you can start building and executing commands.
Let’s first start with executing commands so you can get a taste of the user experience, and the rest of the book will be dedicated to the wiring and flow definition.
Compared to our old service layer, which used to persist entities one-by-one and run validations one-by-one (where each validation might access the DB to fetch some required context), moving to PL boosted performance by a factor of 2 up to 50, depending on the complexity of the flow.
After some wiring, persisting a new Campaign entity shall look like this:
var cmd = new CreateCampaignCmd();
cmd.set(Campaign.NAME, "bla bla");
cmd.set(Campaign.BUDGET, 150);
cmd.set(Campaign.STATUS, Status.ToPause);
var results = campaignPersistence.update(asList(cmd));
In this sample we make use of:
-
EntityType - (The
Campaign
) a static declaration of fields (likeBUDGET
) -
Command - (The
CreateCampaignCmd
) a strongly typed map from fields to values - EntityPersistence - executes the commands
Note that the update method accepts a list of commands because we want to encourage you to persist in bulks whenever possible. Remember that PL optimizations are most effective when working with bulks.
The result object may contain validation errors that you may want to check.
- Only MySQL is currently Supported
- JOOQ DefaultTransactionProvider is not supported
Setting up an Entity Persistence
Query language
Building the Flow
- Adding Simple Validators
- State Consumers
- Adding a Custom Validator
- Enrichers
- Output Generators
- Customizing Flows
- Primary and Secondary Tables (detailed example)
- State Consumers and Relations (what can we fetch)
- Child Commands
- Cascade Delete