getTableSchemeImpl method

  1. @override
TableScheme? getTableSchemeImpl(
  1. String table,
  2. TableRelationshipReference? relationship, {
  3. Object? contextID,
})
override

Implementation that returns a TableScheme for table.

  • contextID should be Expando compatible. It informs that other calls to getTableSchemeImpl are in the same context and could have shared internal caches for the same contextID instance.

Implementation

@override
TableScheme? getTableSchemeImpl(
    String table, TableRelationshipReference? relationship,
    {Object? contextID}) {
  //_log.info('getTableSchemeImpl> $table ; relationship: $relationship');

  var tableScheme = tablesSchemes[table];
  if (tableScheme != null) return tableScheme;

  var entityHandler = getEntityHandler(tableName: table);
  if (entityHandler == null) {
    if (relationship != null) {
      var sourceId =
          '${relationship.sourceTable}_${relationship.sourceField}';
      var targetId =
          '${relationship.targetTable}_${relationship.targetField}';

      tableScheme = TableScheme(table,
          relationship: true,
          idFieldName: sourceId,
          fieldsTypes: {
            sourceId: relationship.sourceFieldType,
            targetId: relationship.targetFieldType,
          });

      _log.info('relationship> $tableScheme');

      return tableScheme;
    }

    throw StateError(
        "Can't resolve `TableScheme` for table `$table`. No `EntityHandler` found for table `$table`!");
  }

  var idFieldName = entityHandler.idFieldName();

  var entityFieldsTypes = entityHandler.fieldsTypes();

  var fieldsTypes =
      entityFieldsTypes.map((key, value) => MapEntry(key, value.type));

  tableScheme = TableScheme(table,
      relationship: relationship != null,
      idFieldName: idFieldName,
      fieldsTypes: fieldsTypes);

  _log.info('$tableScheme');

  return tableScheme;
}