import "org/killbill/billing/util/entity/dao/EntitySqlDao.sql.stg"
tableName() ::= "bundles"
tableFields(prefix) ::= <<
<prefix>external_key
, <prefix>account_id
, <prefix>last_sys_update_date
, <prefix>original_created_date
, <prefix>created_by
, <prefix>created_date
, <prefix>updated_by
, <prefix>updated_date
>>
tableValues() ::= <<
:externalKey
, :accountId
, :lastSysUpdateDate
, :originalCreatedDate
, :createdBy
, :createdDate
, :updatedBy
, :updatedDate
>>
updateBundleLastSysTime() ::= <<
update <tableName()>
set
last_sys_update_date = :lastSysUpdateDate
, updated_by = :createdBy
, updated_date = :updatedDate
where id = :id
<AND_CHECK_TENANT("")>
;
>>
updateBundleExternalKey() ::= <<
update <tableName()>
set
external_key = :externalKey
, updated_by = :createdBy
, updated_date = :updatedDate
where id = :id
<AND_CHECK_TENANT("")>
;
>>
renameBundleExternalKey(prefix) ::= <<
update bundles b
join (select
record_id
, external_key
from
bundles
where external_key = :externalKey <AND_CHECK_TENANT("")>) t
on b.record_id = t.record_id
set b.external_key = concat('kb', '<prefix>', '-', t.record_id, ':', t.external_key)
;
>>
getBundlesForLikeKey() ::= <<
select <allTableFields("")>
from bundles
where
external_key = :externalKey
or external_key like concat('kb%-%:', :externalKey)
<AND_CHECK_TENANT("")>
<defaultOrderBy("")>
;
>>
getBundlesFromAccountAndKey() ::= <<
select <allTableFields("")>
from bundles
where
external_key = :externalKey
and account_id = :accountId
<AND_CHECK_TENANT("")>
<defaultOrderBy("")>
;
>>
getBundleFromAccount() ::= <<
select <allTableFields("")>
from bundles
where
account_id = :accountId
<AND_CHECK_TENANT("")>
<defaultOrderBy("")>
;
>>
searchQuery(prefix) ::= <<
<idField(prefix)> = :searchKey
or <prefix>external_key = :searchKey
or <prefix>account_id = :searchKey
>>