All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.killbill.billing.util.entity.dao.EntitySqlDao.sql.stg Maven / Gradle / Ivy

There is a newer version: 0.24.11
Show newest version
/******************   To override in each EntitySqlDao template file *****************************/

tableName() ::= ""

/** Leave out id, account_record_id and tenant_record_id **/
tableFields(prefix) ::= ""

tableValues() ::= ""

historyTableName() ::= ""

historyTableFields(prefix) ::= <<
  
, 
, 
>>

historyTableValues() ::= <<
  
, 
, 
>>

/** Used for entities that can be soft deleted to make we exclude those entries in base calls getById(), get() **/
andCheckSoftDeletionWithComma(prefix) ::= ""


/** Add extra fields for SELECT queries **/
extraTableFieldsWithComma(prefix) ::= ""

defaultOrderBy(prefix) ::= <<
order by  ASC
>>

/******************   To override in each EntitySqlDao template file   *****************************/


idField(prefix) ::= <<
id
>>

idValue() ::= ":id"

recordIdField(prefix) ::= <<
record_id
>>

recordIdValue() ::= ":recordId"

changeTypeField(prefix) ::= <<
change_type
>>

changeTypeValue() ::= ":changeType"

targetRecordIdField(prefix) ::= <<
target_record_id
>>

targetRecordIdValue() ::= ":targetRecordId"

/** Override this if the Entity isn't tied to an account **/
accountRecordIdField(prefix) ::= <<
account_record_id
>>


accountRecordIdFieldWithComma(prefix) ::= <<
, 
>>

accountRecordIdValue() ::= ":accountRecordId"

accountRecordIdValueWithComma() ::= <<
, 
>>

tenantRecordIdField(prefix) ::= <<
tenant_record_id
>>

tenantRecordIdFieldWithComma(prefix) ::= <<
, 
>>


tenantRecordIdValue() ::= ":tenantRecordId"

tenantRecordIdValueWithComma() ::= <<
, 
>>


allTableFields(prefix) ::= <<
  
, 
, 



>>



allTableValues() ::= <<
  
, 
, 


>>


allHistoryTableFields(prefix) ::= <<
  
, 
, 
, 


>>

allHistoryTableValues() ::= <<
  
, 
,  
, 


>>


/** Macros used for multi-tenancy (almost any query should use them!) */
CHECK_TENANT(prefix) ::= "tenant_record_id = :tenantRecordId"
AND_CHECK_TENANT(prefix) ::= "and "

getAll() ::= <<
select

from  t
where 


;
>>

get(offset, rowCount, orderBy, ordering) ::= <<
select

from  t
join (
  select 
  from 
  where 
  
  order by  
  limit :rowCount offset :offset
) optimization on  = 
order by t. 
;
>>

getRecordIdAtOffset(offset) ::= <<
select 
from 
order by  ASC
limit 1 offset :offset
;
>>

getRecordIdAtOffsetWithAccountRecordId(offset) ::= <<
select 
from 
where  = :accountRecordId
order by  ASC
limit 1 offset :offset
;
>>

getCount() ::= <<
select
count(1) as count
from  t
where 

;
>>

getCountWithAccountRecordId() ::= <<
select
count(1) as count
from  t
where 
and  = :accountRecordId

;
>>

getById(id) ::= <<
select

from  t
where  = :id


;
>>

getByRecordId(recordId) ::= <<
select

from  t
where  = :recordId


;
>>

getByRecordIds(recordIds) ::= <<
select

from  t
where  in ()


;
>>


getByIds(ids) ::= <<
select
  
from  t
where  in ()



;
>>

getByIdsIncludedDeleted(ids) ::= <<
select

from  t
where  in ()


;
>>

/** Note: account_record_id can be NULL **/
getByAccountRecordId(accountRecordId) ::= <<
select

from  t
where  = :accountRecordId



;
>>

getByAccountRecordIdWithPaginationEnabled(accountRecordId) ::= <<
select

from  t
where  = :accountRecordId



limit :rowCount offset :offset
;
>>

getByAccountRecordIdIncludedDeleted(accountRecordId) ::= <<
select

from  t
where  = :accountRecordId


;
>>

getHistoryTargetRecordId(recordId) ::= <<
select

from  t
where  = :recordId


;
>>

getRecordId(id) ::= <<
select
  
from  t
where  = :id


;
>>

getRecordIdForTable(tableName) ::= <<
select
  
from  t
where  = :id


;
>>

getHistoryRecordId(targetRecordId) ::= <<
select
  max()
from  t
where  = :targetRecordId


;
>>

getHistoryRecordIdsForTable(historyTableName) ::= <<
select
  
from  t
where  = :targetRecordId


;
>>

searchQuery(prefix) ::= <<
1 = 1
>>

search(ordering) ::= <<
select

from  t
where ()


order by  
limit :rowCount offset :offset
;
>>

getSearchCount() ::= <<
select
  count(1) as count
from  t
where ()


;
>>

create() ::= <<
insert into  (
  
, 


)
values (
  
, 


)
>>

/** Audits, History **/
auditTableName() ::= "audit_log"

auditTableFields(prefix) ::= <<
  id
, table_name
, target_record_id
, change_type
, created_by
, reason_code
, comments
, user_token
, created_date
, 
, 
>>

auditTableValues() ::= <<
  :id
, :tableName
, :targetRecordId
, :changeType
, :createdBy
, :reasonCode
, :comments
, :userToken
, :createdDate
, 
, 
>>

getHistoryForTargetRecordId() ::= <<
select
  
, t.record_id as history_record_id
, 


from  t
where  = :targetRecordId

order by  ASC
;
>>

addHistoriesFromTransaction() ::= <<
insert into  (
  
, 


)
values (
  
, 


)
;
>>


insertAuditsFromTransaction() ::= <<
insert into  (

)
values (

)
;
>>

getAuditLogsForAccountRecordId() ::= <<
select
  
from  t
where  = :accountRecordId


order by t.table_name,  ASC
;
>>

getAuditLogsForTableNameAndAccountRecordId() ::= <<
select
  
from  t
where  = :accountRecordId
and t.table_name = :tableName



;
>>

getAuditLogsForTargetRecordId() ::= <<
select
  
from  t
where t.target_record_id = :targetRecordId
and t.table_name = :tableName



;
>>

getAuditLogsViaHistoryForTargetRecordId(historyTableName) ::= <<
select
  
from  t
join (
  select
     record_id
  from  h
  where  = :targetRecordId
  
  
) history_record_ids on t.target_record_id = history_record_ids.record_id
where t.table_name = :tableName


;
>>

test() ::= <<
select

from  t
where 

limit 1
;
>>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy