Skip to content

Instantly share code, notes, and snippets.

@isyufu
Created June 21, 2018 00:39
Show Gist options
  • Save isyufu/93feb5b95aca2f08adea4e3aff2cbb20 to your computer and use it in GitHub Desktop.
Save isyufu/93feb5b95aca2f08adea4e3aff2cbb20 to your computer and use it in GitHub Desktop.
JetBrains Xodus is a Java transactional schema-less embedded database
/* "org.jetbrains.xodus" % "xodus-openAPI" % "1.2.3",
"org.jetbrains.xodus" % "xodus-entity-store" % "1.2.3",
*/
object XodusApp extends App {
import jetbrains.exodus.bindings.StringBinding.{entryToString, stringToEntry}
import jetbrains.exodus.env.StoreConfig.WITHOUT_DUPLICATES
val env = Environments.newInstance("data")
val store = env.computeInTransaction[Store](t => env.openStore("MyStore",WITHOUT_DUPLICATES, t))
env.executeInTransaction(t => store.put(t, stringToEntry("sheetId1"),stringToEntry("lastId888")))
var v = ""
env.executeInTransaction(t => v = entryToString(store.get(t, stringToEntry("sheetId1"))))
println(v)
val v1 = env.computeInTransaction[String](t => entryToString(store.get(t, stringToEntry("sheetId1"))))
println(v1)
val store2 = PersistentEntityStores.newInstance("data2")
store2.computeInTransaction{t => val e = t.newEntity("sheets"); e.setProperty("id", 12345)}
store2.computeInTransaction{t =>
val e = t.find("sheets", "id", "12345")
e.iterator().asScala.foreach(e => println("find: "+e.getProperty("id")))
}
store2.computeInTransaction{t =>
val e = t.getAll("sheets")
e.iterator().asScala.foreach(e => println(e.getProperty("id")))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment