Create your own DSL just by inheriting Jpql class and adding your own functions.
Jpql has all the default DSL functions provided by Kotlin JDSL. You can use them to create your own functions. You can also create your own Model that implements Expression or Predicate and create a function to return this Model. You can implement JpqlSerializer to let Kotlin JDSL to render Model to String.
There are two ways to pass your own DSL to jpql(). The first is to implement JpqlDsl.Constructor as a companion object to create a DSL object, and the second is to create a DSL instance.
JpqlDsl.Constructor
With this way, you don't need to create an instance and a new instance is automatically created for each query creation.
Implement JpqlSerializer and add it to RenderContext to render your own Model to String.
JpqlSerializer provides JpqlWriter and RenderContext for you to implement rendering. You can get JpqlRenderSerializer from RenderContext and use it to render other Model in your Model. You can also get JpqlRenderStatement and JpqlRenderClause from RenderContext, which let you know which statement and clause are currently being rendered. You can use them to render your Model as String.