Removing data from the database (Java)

To remove one or more rows from an Entity Engine-managed database table, use the GenericDelegator object and call the appropriate methods as shown in the following code snippet:

Note

Note: the Entity Engine negotiates record removal with the target data source using standard SQL commands constructed from method parameters passed by the calling program. If the target table rows cannot be removed because deletion violates referential integrity, neither OFBiz nor the underlying database will remove the indicated rows. Instead, an error will be thrown and control passed to the calling program.

// Don't forget to add import statements
// First, get a GenericDelegator object from the context
GenericDelegator delegator = ctx.getDelegator();
// Before you can do anything, you must create a model of the
// Recipe table using the makeValue method
GenericValue recipe = delegator.makeValue("Recipe");
// Add the unique, primary key to the model
recipe.set("recipeId", "r001");
try {
// Use the GenericValue remove method
recipe.remove();
// Or you could use the GenericDelegator remove, but not both at
// the same time!
// delegator.removeValue(recipe);
}
catch (GenericEntityException ge) {
// process errors
}

To remove records from a database table using the Entity Engine, use the appropriate GenericDelegator method as described below:

GenericDelegator method

Usage

GenericDelegator.removeValue(GenericValue X)

Remove a single GenericValue. If removing the value causes referencing errors, the operation will fail with a GenericEntityException and control returns to the caller.

GenericDelegator.removeAll(List<GenericValue>)

Remove a list of GenericValues. If any one of the remove operations fail, a GenericEntityException will be thrown and all remove requests will be rolled back. No remove requests will be committed unless all requests can proceed successfully.

Please see the GenericDelegator Javadocs API for more information:

http://ci.apache.org/projects/ofbiz/site/javadocs/

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.85.181