group TagDao: EntitySqlDao;

tableName() ::= "tags"

tableFields(prefix) ::= <<
  <prefix>tag_definition_id
, <prefix>object_id
, <prefix>object_type
, <prefix>created_by
, <prefix>created_date
, <prefix>updated_by
, <prefix>updated_date
>>

tableValues() ::= <<
  :tagDefinitionId
, :objectId
, :objectType
, :createdBy
, :createdDate
, :updatedBy
, :updatedDate
>>

historyTableName() ::= "tag_history"

deleteById() ::= <<
delete from <tableName()>
where id = :id
<AND_CHECK_TENANT()>
;
>>

getTagsForObject() ::= <<
select
<allTableFields()>
from <tableName()>
where
object_id = :objectId AND object_type = :objectType
<AND_CHECK_TENANT()>
;
>>

findTag() ::= <<
    SELECT <fields()> FROM tags
    WHERE tag_definition_id = :tagDefinitionId
    AND object_id = :objectId AND object_type = :objectType
    <AND_CHECK_TENANT()>
    ;
>>

getRecordIds() ::= <<
    SELECT record_id, id
    FROM tags
    WHERE object_id = :objectId AND object_type = :objectType
    <AND_CHECK_TENANT()>
    ;
>>

getHistoryRecordIds() ::= <<
    SELECT history_record_id, record_id
    FROM tag_history
    WHERE history_record_id > :maxHistoryRecordId
    <AND_CHECK_TENANT()>
    ;
>>

load() ::= <<
  SELECT <fields()>
    FROM tags
  WHERE object_id = :objectId AND object_type = :objectType
  <AND_CHECK_TENANT()>;
>>
