Skip to content

SQL-297: PolicyOutputDocumentExtensions.GeneratePacket

This statement is a read operation invoked through ORM (NHibernate LINQ). Executed by PolicyOutputDocumentExtensions.GeneratePacket.

Classification

Field Value
SQL ID SQL-297
Operation type Read
Execution method ORM (NHibernate LINQ)
Database Oracle*
Schema [unqualified]**
Command type N/A (ORM-generated)
Business object PolicyOutputDocumentExtensions
Criteria property N/A — ORM
Lifecycle method GeneratePacket

Parameters

Parameter Direction Type Max length Description
config Input PacketGenerationConfig N/A Method argument of PolicyOutputDocumentExtensions.GeneratePacket bound into the ORM expression; NHibernate generates the bind variable at runtime

Tables

Table Access Columns used
output_document_type_code SELECT (hypothetical) code, code_descr, agency_view_flag, agency_inbox_flag, manual_add_flag, freeform_flag, sort_priority_num, SOURCE_SYSTEM_CODE, PACKAGE_NAME, image_file_code, image_category_code, image_document_type_code, output_document_category_code, Direct_Write_Notify_Text_Code

LINQ statement

Source: Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyOutputDocumentExtensions.cs:1550.

// Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyOutputDocumentExtensions.cs:1550-1551
var types = uow.GetRepository<OutputDocumentTypeCode>().Query()
    .Where(x => docs.Contains(x.Code) && x.IsAgencyViewable && !xdocs.Contains(x.Code)).ToList();

// Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyOutputDocumentExtensions.cs:1555-1557
var packetTypes = uow.GetRepository<OutputDocumentTypeCode>().Query()
    .Where(x => x.IsAgencyViewable &&
                !docs.Contains(x.Code) && !xdocs.Contains(x.Code)).Take(config.DocumentCount).ToList();

// Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyOutputDocumentExtensions.cs:1568-1570
var otypes = uow.GetRepository<OutputDocumentTypeCode>().Query()
.Where(x => x.IsAgencyViewable &&
     !codes.Contains(x.Code) && !xdocs.Contains(x.Code)).Take(config.OtherPolicyDocumentCount);

Sample SQL

Test double — no runtime SQL. This statement executes against TestUnitOfWork/TestRepository<T> (in-memory, List<TEntity>-backed test doubles in SAIF.Framework.Core); no NHibernate session is opened and no SQL is issued at runtime. The SQL below is the hypothetical statement the same expression would produce against a real NHibernate IUnitOfWork using the in-repo mappings, shown to document the mapping shape only — no database table is accessed when this code runs.

Inferred SQL: This SQL was inferred from the LINQ statement above and the NHibernate mappings. It is not concrete SQL from source code; NHibernate generates the executed statement at runtime, so aliases, column order, join syntax, and bind-parameter names may differ.

-- Inferred from LINQ (NHibernate mapping translation); not concrete SQL
-- (a) lines 1550-1551
SELECT
  ODTC.code,
  ODTC.code_descr,
  ODTC.agency_view_flag,
  ODTC.agency_inbox_flag,
  ODTC.manual_add_flag,
  ODTC.freeform_flag,
  ODTC.sort_priority_num,
  ODTC.SOURCE_SYSTEM_CODE,
  ODTC.PACKAGE_NAME,
  ODTC.image_file_code,
  ODTC.image_category_code,
  ODTC.image_document_type_code,
  ODTC.output_document_category_code,
  ODTC.Direct_Write_Notify_Text_Code
FROM output_document_type_code ODTC
WHERE ODTC.code IN (:docs0, :docs1, ...)
  AND ODTC.agency_view_flag = 'Y'
  AND NOT (ODTC.code IN (:xdocs0, ...))

-- (b) lines 1555-1557, only when config.DocumentCount > 0
SELECT *
FROM (
  SELECT
    ODTC.code,
    ODTC.code_descr,
    ODTC.agency_view_flag,
    ODTC.agency_inbox_flag,
    ODTC.manual_add_flag,
    ODTC.freeform_flag,
    ODTC.sort_priority_num,
    ODTC.SOURCE_SYSTEM_CODE,
    ODTC.PACKAGE_NAME,
    ODTC.image_file_code,
    ODTC.image_category_code,
    ODTC.image_document_type_code,
    ODTC.output_document_category_code,
    ODTC.Direct_Write_Notify_Text_Code
  FROM output_document_type_code ODTC
  WHERE ODTC.agency_view_flag = 'Y'
    AND NOT (ODTC.code IN (:docs0, ...))
    AND NOT (ODTC.code IN (:xdocs0, ...)))
WHERE ROWNUM <= :DocumentCount

-- (c) lines 1568-1570, only when config.OtherPolicyDocumentCount > 0
SELECT *
FROM (
  SELECT
    ODTC.code,
    ODTC.code_descr,
    ODTC.agency_view_flag,
    ODTC.agency_inbox_flag,
    ODTC.manual_add_flag,
    ODTC.freeform_flag,
    ODTC.sort_priority_num,
    ODTC.SOURCE_SYSTEM_CODE,
    ODTC.PACKAGE_NAME,
    ODTC.image_file_code,
    ODTC.image_category_code,
    ODTC.image_document_type_code,
    ODTC.output_document_category_code,
    ODTC.Direct_Write_Notify_Text_Code
  FROM output_document_type_code ODTC
  WHERE ODTC.agency_view_flag = 'Y'
    AND NOT (ODTC.code IN (:codes0, ...))
    AND NOT (ODTC.code IN (:xdocs0, ...)))
WHERE ROWNUM <= :OtherPolicyDocumentCount

Translation notes: - Not accessed: output_doc_image_type_xref (old page) — HasManyToMany(ImageDocumentTypes) join table, lazy and never navigated. image_document_type_code, output_document_category_code, output_doc_notify_text_code — FK columns only. - array.Contains(x.Code) → IN (...) with one bind per element. When xdocs is empty (new string[0], the default at line 1545) NHibernate 4.0 may emit an empty IN () list, which is invalid Oracle SQL — translation of the empty case is uncertain. - x.IsAgencyViewable (YesNoType) → agency_view_flag = 'Y'. Take(n) → ROWNUM <= n wrapper (Oracle10 dialect). - No OrderBy: the rows chosen by Take are database-order dependent.

Sources

  • Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyOutputDocumentExtensions.cs:1550