Created
December 16, 2017 19:47
-
-
Save dineshr93/95568c1db1fa926b4693d42d3e9a8a4f to your computer and use it in GitHub Desktop.
db simple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
import jetbrains.exodus.entitystore.Entity; | |
import jetbrains.exodus.entitystore.EntityIterable; | |
import jetbrains.exodus.entitystore.PersistentEntityStore; | |
import jetbrains.exodus.entitystore.PersistentEntityStores; | |
import jetbrains.exodus.entitystore.StoreTransaction; | |
//https://github.com/JetBrains/xodus/wiki/Entity-Stores#search-queries | |
//https://mvnrepository.com/artifact/org.jetbrains.xodus/xodus-entity-store/1.0.4 | |
//https://mvnrepository.com/artifact/org.jetbrains.xodus | |
public class LMDBTest { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
String path = "data/.myAppData"; | |
final PersistentEntityStore store = PersistentEntityStores.newInstance(path); | |
System.out.println(store.getLocation()); | |
store.clear();//clear the db | |
store.getBlobVault().clear(); | |
StoreTransaction txn = store.beginTransaction(); | |
//final StoreTransaction txn = store.beginReadonlyTransaction(); | |
try { | |
do { | |
// do something | |
Entity user = txn.newEntity("User"); | |
user.setProperty("name", "Xodus"); | |
user.setProperty("version", "1.0.4"); | |
user.setProperty("license", "Apache License 2.0 and OLDAP License"); | |
user = txn.newEntity("q"); | |
user.setProperty("name", "Xodus"); | |
user.setProperty("version", "1.0.4"); | |
user.setProperty("license", "Apache License 2.0 and OLDAP License"); | |
user = txn.newEntity("q"); | |
user.setProperty("name", "Xodus"); | |
user.setProperty("version", "1.0.4"); | |
user.setProperty("license", "Apache License 2.0 and OLDAP License"); | |
EntityIterable allUsers = txn.getAll("q"); | |
for (Entity u: allUsers) { | |
System.out.println(u.getProperty("name")); | |
} | |
long size = txn.getAll("q").size(); | |
System.out.println("Size of entity is "+size); | |
//MoreObjects.firstNonNull(u.getProperty("name") | |
final EntityIterable candidates = txn.find("User", "name","Xodus").intersect(txn.find("User", "version", "1.0.4")); | |
for (Entity candidate: candidates) { | |
System.out.println("license is "+candidate.getProperty("license")); | |
System.out.println("version is "+candidate.getProperty("version")); | |
System.out.println("property is "+candidate.getProperty("comment")); | |
} | |
// if txn has already been aborted in user codeore. | |
if (txn != store.getCurrentTransaction()) { | |
txn = null; | |
break; | |
} | |
} while (!txn.flush()); | |
} finally { | |
// if txn has not already been aborted in execute() | |
if (txn != null) { | |
txn.abort(); | |
txn=null; | |
System.out.println("Txn is nulled"); | |
} | |
} | |
store.getBlobVault().close(); | |
store.close();//closing the entity store | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment