mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
(refs #464)Experimental implementation of Scala based plugin
This commit is contained in:
29
src/main/scala/plugin/package.scala
Normal file
29
src/main/scala/plugin/package.scala
Normal file
@@ -0,0 +1,29 @@
|
||||
import util.ControlUtil._
|
||||
import scala.collection.mutable.ListBuffer
|
||||
|
||||
package object plugin {
|
||||
|
||||
object db {
|
||||
// TODO Use JavaScript Map instead of java.util.Map
|
||||
def select(sql: String): Seq[Map[String, String]] = {
|
||||
defining(PluginConnectionHolder.threadLocal.get){ conn =>
|
||||
using(conn.prepareStatement(sql)){ stmt =>
|
||||
using(stmt.executeQuery()){ rs =>
|
||||
val list = new ListBuffer[Map[String, String]]()
|
||||
while(rs.next){
|
||||
defining(rs.getMetaData){ meta =>
|
||||
val map = Range(1, meta.getColumnCount + 1).map { i =>
|
||||
val name = meta.getColumnName(i)
|
||||
(name, rs.getString(name))
|
||||
}.toMap
|
||||
list += map
|
||||
}
|
||||
}
|
||||
list
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user