Skip to content

Instantly share code, notes, and snippets.

@rjenkins
Created July 2, 2012 22:16
Show Gist options
  • Save rjenkins/3036082 to your computer and use it in GitHub Desktop.
Save rjenkins/3036082 to your computer and use it in GitHub Desktop.
FindFor2i
def findFor2i(index: String, value: String, converter: Converter[T]): List[T] = {
get2iResults(getStringKeys(index, value), converter)
}
// Find all records of Type T for Matching 2i query
private def getStringKeys(index: String, value: String): List[String] = {
fetchBucket.fetchIndex(BinIndex.named(index)).withValue(value).execute().toList
}
private def get2iResults(keys: List[String], converter: Converter[T]): List[T] = {
val listBuffer = new ListBuffer[T]
keys.foreach({ key => listBuffer.prepend(converter.toDomain(fetchBucket.fetch(key).execute()))})
listBuffer.toList
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment