Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.kyuubi.service.authentication.ldap
import java.util
import javax.naming.directory.SearchControls

import org.stringtemplate.v4.ST
import org.stringtemplate.v4.{ST, STGroup}

/**
* The object that encompasses all components of a Directory Service search query.
Expand All @@ -40,6 +40,8 @@ object Query {
* A builder of the [[Query]].
*/
final class QueryBuilder {
/** The [[STGroup]] used only for this builder's filter template; unloaded in [[build]]. */
private var filterTemplateGroup: Option[STGroup] = None
private var filterTemplate: ST = _
private val controls: SearchControls = {
val _controls = new SearchControls
Expand All @@ -56,7 +58,9 @@ object Query {
* @return the current instance of the builder
*/
def filter(filterTemplate: String): Query.QueryBuilder = {
this.filterTemplate = new ST(filterTemplate)
val group = new STGroup()
this.filterTemplateGroup = Some(group)
this.filterTemplate = new ST(group, filterTemplate)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does cache only happen in filterTemplate.render?

what will happen if we call def filter multi times?

this
}

Expand Down Expand Up @@ -127,6 +131,8 @@ object Query {
def build: Query = {
validate()
val filter: String = createFilter
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you update the def createFilter to add a () to the signature? because it actually has a side-effect.

// Unload template cache after render to avoid CompiledST/STToken retention
filterTemplateGroup.foreach(_.unload())
updateControls()
new Query(filter, controls)
}
Expand Down
Loading