load<T extends Entity> function

Future<T> load<T extends Entity>(
  1. Access access,
  2. String oid,
  3. T newInstance(
    1. String oid
    ), [
  4. Iterable<String>? fields,
  5. AccessOption? option,
])

Loads the data of the given OID from the storage into the given entity.

Note: it will invoke access[oid] first to see if there is a cached version. If so, return it directly.

  • newInstance - the method to instantiate the entity for holding the data loaded from database. You usually instantiate it with the be constructor (see Entity.be).
  • fields - a collection of fields to load. Note: if you'd like to load an expression (aka., virutal column, or calculated column), you can pass (SQL expression) name. For example: (due is not null and who is not null) active.
  • option - an option for loading the entity. Technically, you can pass anything that your access provider supports. For SQL, itt could be null, forShare and forUpdate. Default: null (means no lock at all).

It throws EntityNotFoundException if the entity is not found (including oid is null).

Implementation

Future<T> load<T extends Entity>(Access access, String oid,
      T newInstance(String oid), [Iterable<String>? fields,
      AccessOption? option]) async {
  final entity = await loadIfAny(access, oid, newInstance, fields, option);
  if (entity == null)
    throw EntityNotFoundException(oid);
  return entity;
}