-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Apache OfBiz Cookbook
Writing data to the database using the Entity Engine to handle database connections, transactions, data transfers, and data type conversions is preferred over direct SQL calls in almost all situations. To write data to an Entity Engine-managed data source, use the following code snippet as a guide:
// To add a row to a database table
// or update an existing table, you must first create a
// GenericValue object
// representing the table as an entity as shown here
GenericValue recipe = delegator.makeValue('Recipe");
// Add any updated fields to the
recipe.set("recipeName", "A new recipe w/raisins an apples");
recipe.set("recipeTypeId", "cake");
// cake better be a valid recipeTypeId or an error is thrown
// This will be an update to the existing row where the
// primary key is r001
recipe.set("partyId", "r001");
try {
delegator.store(recipe);
}
catch {
// Process errors
}
Other GenericDelegator write methods are shown here:
|
GenericDelegator.method() |
Usage |
|---|---|
|
|
Creates and stores the |
|
|
Stores the |
|
|
Will create the |
|
|
Stores all the |
Please see the GenericDelegator Javadocs API for more information:
Change the font size
Change margin width
Change background colour