@@ -288,6 +288,7 @@ function has_association(
288288 )
289289end
290290
291+ # component UUIDS from attribute
291292const _QUERY_LIST_ASSOCIATED_COMP_UUIDS = """
292293 SELECT DISTINCT component_uuid
293294 FROM $SUPPLEMENTAL_ATTRIBUTE_TABLE_NAME
@@ -309,6 +310,38 @@ function list_associated_component_uuids(
309310 return Base. UUID .(table. component_uuid)
310311end
311312
313+ # attribute UUIDS from component
314+ const _QUERY_LIST_ASSOCIATED_SUPPLEMENTAL_ATTRIBUTE_UUIDS = """
315+ SELECT DISTINCT attribute_uuid
316+ FROM $SUPPLEMENTAL_ATTRIBUTE_TABLE_NAME
317+ WHERE component_uuid = ?
318+ """
319+
320+ """
321+ Return the distinct attribute UUIDs associated with the component.
322+ """
323+ function list_associated_supplemental_attribute_uuids (
324+ associations:: SupplementalAttributeAssociations ,
325+ component:: InfrastructureSystemsComponent ,
326+ :: Nothing ,
327+ )
328+ params = (string (get_uuid (component)),)
329+ table = Tables. columntable (
330+ _execute_cached (
331+ associations,
332+ _QUERY_LIST_ASSOCIATED_SUPPLEMENTAL_ATTRIBUTE_UUIDS,
333+ params,
334+ ),
335+ )
336+ return Base. UUID .(table. attribute_uuid)
337+ end
338+
339+ list_associated_supplemental_attribute_uuids (
340+ associations:: SupplementalAttributeAssociations ,
341+ component:: InfrastructureSystemsComponent ,
342+ ) = list_associated_supplemental_attribute_uuids (associations, component, nothing )
343+
344+ # component UUIDS from attribute plus component type
312345const _QUERY_LIST_ASSOCIATED_COMP_UUIDS_BY_C_TYPE = StringTemplates. @template """
313346 SELECT DISTINCT component_uuid
314347 FROM $table_name
@@ -336,6 +369,36 @@ function list_associated_component_uuids(
336369 return Base. UUID .(table. component_uuid)
337370end
338371
372+ # attribute UUIDS from component plus attribute type
373+ const _QUERY_LIST_ASSOCIATED_SUPPLEMENTAL_ATTRIBUTE_UUIDS_BY_A_TYPE =
374+ StringTemplates. @template """
375+ SELECT DISTINCT attribute_uuid
376+ FROM $table_name
377+ WHERE component_uuid = ? AND $attribute_type_clause
378+ """
379+
380+ """
381+ Return the distinct attribute UUIDs associated with the component, filter by attribute type.
382+ """
383+ function list_associated_supplemental_attribute_uuids (
384+ associations:: SupplementalAttributeAssociations ,
385+ component:: InfrastructureSystemsComponent ,
386+ attribute_type:: Type{<:SupplementalAttribute} ,
387+ )
388+ params = [string (get_uuid (component))]
389+ attribute_type_clause = _get_type_clause! (params, attribute_type, " attribute_type" )
390+ query = StringTemplates. render (
391+ _QUERY_LIST_ASSOCIATED_SUPPLEMENTAL_ATTRIBUTE_UUIDS_BY_A_TYPE;
392+ table_name = SUPPLEMENTAL_ATTRIBUTE_TABLE_NAME,
393+ attribute_type_clause = attribute_type_clause,
394+ )
395+ table = Tables. columntable (
396+ _execute_cached (associations, query, params),
397+ )
398+ return Base. UUID .(table. attribute_uuid)
399+ end
400+
401+ # component UUIDS from attribute type driver function
339402"""
340403Return the distinct component UUIDs associated with the attribute type.
341404"""
@@ -352,6 +415,27 @@ function list_associated_component_uuids(
352415 return _list_associated_component_uuids (associations, subtypes)
353416end
354417
418+ # attribute UUIDS from component type driver function
419+ """
420+ Return the distinct attribute UUIDs associated with the component type.
421+ """
422+ function list_associated_supplemental_attribute_uuids (
423+ associations:: SupplementalAttributeAssociations ,
424+ component_type:: Type{<:InfrastructureSystemsComponent} ,
425+ :: Nothing ,
426+ )
427+ if isconcretetype (component_type)
428+ return _list_associated_supplemental_attribute_uuids (
429+ associations,
430+ (component_type,),
431+ )
432+ end
433+
434+ subtypes = get_all_concrete_subtypes (component_type)
435+ return _list_associated_supplemental_attribute_uuids (associations, subtypes)
436+ end
437+
438+ # component UUIDS from attribute type plus component type
355439const _QUERY_LIST_ASSOCIATED_COMP_UUIDS_BY_TYPES = StringTemplates. @template """
356440 SELECT DISTINCT component_uuid
357441 FROM $table_name
@@ -380,6 +464,36 @@ function list_associated_component_uuids(
380464 return Base. UUID .(table. component_uuid)
381465end
382466
467+ # attribute UUIDS from attribute type plus component type
468+ const _QUERY_LIST_ASSOCIATED_SUPPLEMENTAL_ATTRIBUTE_UUIDS_BY_TYPES =
469+ StringTemplates. @template """
470+ SELECT DISTINCT attribute_uuid
471+ FROM $table_name
472+ WHERE $attribute_type_clause AND $component_type_clause
473+ """
474+
475+ """
476+ Return the distinct attribute UUIDs associated with the component type, filter by
477+ attribute_type.
478+ """
479+ function list_associated_supplemental_attribute_uuids (
480+ associations:: SupplementalAttributeAssociations ,
481+ component_type:: Type{<:InfrastructureSystemsComponent} ,
482+ attribute_type:: Type{<:SupplementalAttribute} ,
483+ )
484+ params = String[]
485+ attribute_type_clause = _get_type_clause! (params, attribute_type, " attribute_type" )
486+ component_type_clause = _get_type_clause! (params, component_type, " component_type" )
487+ query = StringTemplates. render (
488+ _QUERY_LIST_ASSOCIATED_SUPPLEMENTAL_ATTRIBUTE_UUIDS_BY_TYPES;
489+ table_name = SUPPLEMENTAL_ATTRIBUTE_TABLE_NAME,
490+ attribute_type_clause = attribute_type_clause,
491+ component_type_clause = component_type_clause,
492+ )
493+ table = Tables. columntable (_execute_cached (associations, query, params))
494+ return Base. UUID .(table. attribute_uuid)
495+ end
496+
383497const _QUERY_LIST_ASSOCIATED_PAIR_UUIDS = StringTemplates. @template """
384498 SELECT DISTINCT component_uuid, attribute_uuid
385499 FROM $table_name
@@ -431,6 +545,7 @@ function _get_type_clause!(
431545 return type_clause
432546end
433547
548+ # component UUIDs from attribute type implementation
434549const _QUERY_LIST_ASSOCIATED_COMP_UUIDS_BY_ONE_TYPE = """
435550 SELECT DISTINCT component_uuid
436551 FROM $SUPPLEMENTAL_ATTRIBUTE_TABLE_NAME
@@ -468,32 +583,41 @@ function _list_associated_component_uuids(
468583 return Base. UUID .(table. component_uuid)
469584end
470585
471- const _QUERY_LIST_ASSOCIATED_SUPPLEMENTAL_ATTRIBUTE_UUIDS = StringTemplates . @template """
472- SELECT attribute_uuid
473- FROM $table_name
474- WHERE $where_clause
475- """
586+ # attribute UUIDs from component type implementation
587+ const _QUERY_LIST_ASSOCIATED_SUPPLEMENTAL_ATTRIBUTE_UUIDS_BY_ONE_TYPE = """
588+ SELECT DISTINCT attribute_uuid
589+ FROM $SUPPLEMENTAL_ATTRIBUTE_TABLE_NAME
590+ WHERE component_type = ?
476591"""
477- Return the supplemental attribute UUIDs associated with the component and attribute type.
592+
593+ const _QUERY_LIST_ASSOCIATED_SUPPLEMENTAL_ATTRIBUTE_UUIDS_BY_MULTIPLE_TYPES =
594+ StringTemplates. @template """
595+ SELECT DISTINCT attribute_uuid
596+ FROM $table_name
597+ WHERE component_type IN ($placeholder )
478598"""
479- function list_associated_supplemental_attribute_uuids (
599+
600+ function _list_associated_supplemental_attribute_uuids (
480601 associations:: SupplementalAttributeAssociations ,
481- component:: InfrastructureSystemsComponent ;
482- attribute_type:: Union{Nothing, Type{<:SupplementalAttribute}} = nothing ,
602+ component_types,
483603)
484- c_str = " component_uuid = ?"
485- params = [string (get_uuid (component))]
486- if isnothing (attribute_type)
487- where_clause = c_str
604+ len = length (component_types)
605+ if len == 0
606+ # This would require an abstract type with no subtypes. Just here for completeness.
607+ return Base. UUID[]
608+ elseif len == 1
609+ query = _QUERY_LIST_ASSOCIATED_SUPPLEMENTAL_ATTRIBUTE_UUIDS_BY_ONE_TYPE
610+ params = (string (nameof (first (component_types))),)
488611 else
489- a_str = _get_attribute_type_string! (params, attribute_type)
490- where_clause = " $c_str AND $a_str "
612+ placeholder = chop (repeat (" ?," , length (component_types)))
613+ params = Tuple (string (nameof (type)) for type in component_types)
614+ query = StringTemplates. render (
615+ _QUERY_LIST_ASSOCIATED_SUPPLEMENTAL_ATTRIBUTE_UUIDS_BY_MULTIPLE_TYPES;
616+ table_name = SUPPLEMENTAL_ATTRIBUTE_TABLE_NAME,
617+ placeholder = placeholder,
618+ )
491619 end
492- query = StringTemplates. render (
493- _QUERY_LIST_ASSOCIATED_SUPPLEMENTAL_ATTRIBUTE_UUIDS;
494- table_name = SUPPLEMENTAL_ATTRIBUTE_TABLE_NAME,
495- where_clause = where_clause,
496- )
620+
497621 table = Tables. columntable (_execute_cached (associations, query, params))
498622 return Base. UUID .(table. attribute_uuid)
499623end
0 commit comments