Interface BusinessObjectHelper


public interface BusinessObjectHelper
Facilitates manipulating BusinessObjects in bulk.

Supported API: true

Extendable: false
CREATE

final Locale locale = SessionHelper.getLocale();
final CreateOperationIdentifier createOperationId = new CreateOperationIdentifier();
final BusinessObjectHelper busObjHelper = BusinessObjectHelperFactory.getBusinessObjectHelper();
final List busObjs =
busObjHelper.newBusinessObjects( locale, createOperationId, true, typeIdentifiers );
busObjHelper.load( busObjs, businessFields );
for ( BusinessObject aBusObj : busObjs ) {
for ( BusinessField aBusinessField : businessFields ) {
aBusObj.set( aBusinessField, theValueForTheField );
}
}
busObjHelper.persist( busObjs );

RETRIEVE

final Locale locale = SessionHelper.getLocale();
final DisplayOperationIdentifier displayOperationId = new DisplayOperationIdentifier();
final BusinessObjectHelper busObjHelper = BusinessObjectHelperFactory.getBusinessObjectHelper();
final List busObjs =
busObjHelper.newBusinessObjects( locale, displayOperationId, false, persistables );
busObjHelper.load( busObjs, businessFields );
for ( BusinessObject aBusObj : busObjs ) {
for ( BusinessField aBusinessField : businessFields ) {
final Object aFieldValue = aBusObj.get( aBusinessField );
}
}

UPDATE

final Locale locale = SessionHelper.getLocale();
final UpdateOperationIdentifier updateOperationId = new UpdateOperationIdentifier();
final BusinessObjectHelper busObjHelper = BusinessObjectHelperFactory.getBusinessObjectHelper();
final List busObjs =
busObjHelper.newBusinessObjects( locale, updateOperationId, true, persistables );
busObjHelper.load( busObjs, businessFields );
for ( BusinessObject aBusObj : busObjs ) {
for ( BusinessField aBusinessField : businessFields ) {
aBusObj.set( aBusinessField, theValueForTheField );
}
}
final List modifiedPersistables = busObjHelper.apply( busObjs );
...
PersistenceHelper.manager.modify( new WTArrayList(modifiedPersistables) );
  • Method Details

    • newBusinessObjects

      List<BusinessObject> newBusinessObjects(Locale locale, OperationIdentifier operationId, boolean includeConstraints, Persistable... persistables) throws WTException
      Create business objects for the persistables provided. It is the caller's responsibility to ensure attributes are marked as loaded appropriately.
      Parameters:
      locale - The locale the operation is being performed for. May be null.
      operationId - The operation being performed on the business objects. May be null.
      includeConstraints - Whether or not the constraint data should be retrieved for the business objects. Also, this impacts the behavior of validate() later. If constraints were not retrieved, nothing is done.
      persistables - The persistables to create business objects for. May be null.
      Returns:
      The business objects representing the persistables provided. Will not return null.
      Throws:
      WTException - If there were errors creating the business objects.
      See Also:
    • newBusinessObjects

      List<BusinessObject> newBusinessObjects(Locale locale, OperationIdentifier operationId, boolean includeConstraints, TypeIdentifier... typeIdentifiers) throws WTException
      Create business objects for the type identifiers provided. It is the caller's responsibility to ensure attributes are marked as loaded appropriately.
      Parameters:
      locale - The locale the operation is being performed for. May be null.
      operationId - The operation being performed on the business objects. May be null.
      includeConstraints - Whether or not the constraint data should be retrieved for the business objects. Also, this impacts the behavior of validate() later. If constraints were not retrieved, nothing is done.
      typeIdentifiers - The type identifiers to create business objects for. May be null.
      Returns:
      The business objects representing the type instances provided. Will not return null.
      Throws:
      WTException - If there were errors creating the business objects.
      See Also:
    • newBusinessObjects

      List<BusinessObject> newBusinessObjects(Locale locale, OperationIdentifier operationId, boolean includeConstraints, TypeInstance... typeInstances) throws WTException
      Create business objects for the type instances provided. It is the caller's responsibility to ensure attributes are marked as loaded appropriately.
      Parameters:
      locale - The locale the operation is being performed for. May be null.
      operationId - The operation being performed on the business objects. May be null.
      includeConstraints - Whether or not the constraint data should be retrieved for the business objects. Also, this impacts the behavior of validate() later. If constraints were not retrieved, nothing is done.
      typeInstances - The type instances to create business objects for. May be null.
      Returns:
      The business objects representing the type instances provided. Will not return null.
      Throws:
      WTException - If there were errors creating the business objects.
      See Also:
    • markAsLoaded

      void markAsLoaded(List<BusinessObject> businessObjects, Collection<BusinessField> loadedFields) throws WTException
      Updates each of the specified business objects by marking the relevant fields as loaded.

      Supported API: true
      Parameters:
      businessObjects - The business objects to mark the fields as loaded on.
      loadedFields - The fields to mark as loaded on the business objects.
      Throws:
      WTException - If there were errors marking the fields as loaded on the business objects.
    • markAsLoaded

      void markAsLoaded(List<BusinessObject> businessObjects, BusinessFieldNamespaceIdentifier namespace) throws WTException
      Updates each of the specified business objects by marking the fields for the namespace as loaded.

      Supported API: true
      Parameters:
      businessObjects - The business objects to mark the fields as loaded on.
      namespace - The namespace to a mark fields as loaded for.
      Throws:
      WTException - If there were errors marking the fields as loaded on the business objects.
    • load

      void load(List<BusinessObject> businessObjects, Collection<BusinessField> fieldsToLoad) throws WTException
      Loads the values and constraints for the fields into the business objects as applicable.

      Supported API: true
      Parameters:
      businessObjects - The business objects to load data on.
      fieldsToLoad - The fields to load data for on the business objects.
      Throws:
      WTException - If there were errors loading data.
    • persist

      List<TypeInstanceIdentifier> persist(List<BusinessObject> businessObjects) throws WTException
      Persist the business objects to the db.

      Supported API: true
      Parameters:
      businessObjects - The business objects to persist.
      Returns:
      The type instance identifiers of the persisted objects. Will not return null.
      Throws:
      WTException - If there were errors persisting the objects.
    • apply

      List<Persistable> apply(List<BusinessObject> businessObjects) throws WTException
      Apply all business object's loaded data to persistables. Validates all loaded data against all loaded constraints. Throws an exception if any constraint is violated. If there is no current underlying Persistable, retrieve it from the db or construct it. Apply the loaded changes to the underlying Persistable. This method does not persist the changes. A subsequent call to persist the changes to the Persistable is required.

      Supported API: true
      Parameters:
      businessObjects - The business objects to apply loaded data to.
      Returns:
      The underlying Persistables. Will not return null.
      Throws:
      WTException - If any loaded constraints were violated. If there were any other issues applying the loaded data to the persistables.
    • validate

      default void validate(List<BusinessObject> businessObjects) throws ConstraintException
      Validate the values of the loaded fields on the loaded objects. If all values for loaded fields are valid, nothing happens.

      Supported API: true
      Parameters:
      businessObjects - The objects to validate fields for.
      Throws:
      ConstraintException - For the first invalid value encountered for a loaded field.
    • applyAndSave

      default WTCollection applyAndSave(List<BusinessObject> businessObjects) throws WTException
      Apply apply(List) all business object's loaded data to persistables and save them PersistenceHelper.manager.save.

      Supported API: true
      Parameters:
      businessObjects - The business objects to apply loaded data and saved.
      Returns:
      saved Persistables. Will not return null
      Throws:
      WTException - Any issues while applying or saving.