use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class GraphGetVertices method test.
@Test
public void test() {
Iterator<Vertex> iterator = null;
OrientGraphNoTx graph = new OrientGraphNoTx("memory:/TestDB", "admin", "admin");
OrientVertexType personType = graph.createVertexType("Person");
personType.createProperty("person_id", OType.STRING);
personType.createProperty("name", OType.STRING);
// Adding 3 vertices to the orient graph
OrientVertex p1 = graph.addVertex("class:Person");
p1.setProperty("person_id", "01");
p1.setProperty("name", "Gabriel");
OrientVertex p2 = graph.addVertex("class:Person");
p2.setProperty("person_id", "02");
p2.setProperty("name", "Daniel");
OrientVertex p3 = graph.addVertex("class:Person");
p3.setProperty("person_id", "03");
p3.setProperty("name", "Emanuel");
/*
* CASE 1 GetVertices call without indexes, query on one key and one value
*/
// String key and value
String[] singleKey = { "person_id" };
String[] singleValue = { "01" };
iterator = graph.getVertices("Person", singleKey, singleValue).iterator();
int resultsAmount = 0;
while (iterator.hasNext()) {
iterator.next();
resultsAmount++;
}
assertEquals(1, resultsAmount);
iterator = graph.getVertices("Person", singleKey, singleValue).iterator();
Vertex firstVertex = iterator.next();
assertEquals(firstVertex.getProperty("person_id"), "01");
assertEquals(firstVertex.getProperty("name"), "Gabriel");
/*
* CASE 2 GetVertices call with index built on a single property, query on one key and one value
*/
// Defining an index (unique_hash_index) on a single property
String statement = "create index Person.pkey on Person (person_id) unique_hash_index";
OCommandSQL sqlCommand = new OCommandSQL(statement);
graph.getRawGraph().command(sqlCommand).execute();
// String key and value
singleValue[0] = "02";
iterator = graph.getVertices("Person", singleKey, singleValue).iterator();
resultsAmount = 0;
while (iterator.hasNext()) {
iterator.next();
resultsAmount++;
}
assertEquals(1, resultsAmount);
iterator = graph.getVertices("Person", singleKey, singleValue).iterator();
firstVertex = iterator.next();
assertEquals(firstVertex.getProperty("person_id"), "02");
assertEquals(firstVertex.getProperty("name"), "Daniel");
/*
* CASE 3 GetVertices call with index built on two properties (composite key), query on two key and two values in order to test
* "composite key behaviour"
*/
// Dropping precedent index and defining a new index (unique_hash_index) on two properties
graph.dropIndex("Person.pkey");
statement = "create index Person.pkey on Person (person_id,name) unique_hash_index";
sqlCommand = new OCommandSQL(statement);
graph.getRawGraph().command(sqlCommand).execute();
// String key and value
String[] keys = { "person_id", "name" };
String[] values = { "03", "Emanuel" };
iterator = graph.getVertices("Person", keys, values).iterator();
resultsAmount = 0;
while (iterator.hasNext()) {
iterator.next();
resultsAmount++;
}
assertEquals(1, resultsAmount);
iterator = graph.getVertices("Person", keys, values).iterator();
firstVertex = iterator.next();
assertEquals(firstVertex.getProperty("person_id"), "03");
assertEquals(firstVertex.getProperty("name"), "Emanuel");
graph.createVertexType("PersonDummy");
Iterator<Vertex> personDummy = graph.getVertices("PersonDummy", singleKey, singleValue).iterator();
resultsAmount = 0;
while (personDummy.hasNext()) {
personDummy.next();
resultsAmount++;
}
assertEquals(0, resultsAmount);
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class BackupTest method main.
public static void main(String[] args) throws IOException {
File backupFile = new File("testbackup.zip");
OutputStream oS = new FileOutputStream(backupFile);
OrientGraphFactory factory = new OrientGraphFactory("plocal:backupTest", "admin", "admin");
OrientGraphNoTx graphNoTx = factory.getNoTx();
graphNoTx.getRawGraph().backup(oS, null, null, null, 1, 1024);
ZipFile zipFile = new ZipFile(backupFile);
Enumeration enumeration = zipFile.entries();
System.out.format("ZipFile : %s%n", zipFile);
while (enumeration.hasMoreElements()) {
Object entry = enumeration.nextElement();
System.out.format(" Entry : %s%n", entry);
}
factory.close();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class DbCreationTest method testZipCompression.
public void testZipCompression() {
if (database == null || !database.getURL().startsWith("plocal:"))
return;
OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.setValue("gzip");
final String buildDirectory = System.getProperty("buildDirectory", ".");
String dburl = "plocal:" + buildDirectory + "/test-db/" + this.getClass().getSimpleName();
final OrientGraphFactory factory = new OrientGraphFactory(dburl, "admin", "admin");
if (factory.exists())
factory.drop();
factory.close();
OrientGraphNoTx db = factory.getNoTx();
db.drop();
OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.setValue(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getValue());
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class PLocalCreateVerticesMultiThreadSpeedTest method init.
@Override
public void init() {
final OrientGraphNoTx graph = factory.getNoTx();
try {
if (graph.getVertexType("Client") == null) {
final OrientVertexType clientType = graph.createVertexType("Client");
final OrientVertexType.OrientVertexProperty property = clientType.createProperty("uid", OType.STRING);
property.createIndex(OClass.INDEX_TYPE.UNIQUE_HASH_INDEX);
// CREATE ONE CLUSTER PER THREAD
for (int i = 0; i < getThreads(); ++i) {
System.out.println("Creating cluster: client_" + i + "...");
clientType.addCluster("client_" + i);
}
foundObjects = 0;
} else
foundObjects = graph.countVertices("Client");
} finally {
graph.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class PLocalCreateVerticesMultiThreadSpeedTest method deinit.
@Override
public void deinit() {
final OrientGraphNoTx graph = factory.getNoTx();
try {
final long total = graph.countVertices("Client");
System.out.println("\nTotal objects in Client cluster after the test: " + total);
System.out.println("Created " + (total - foundObjects));
Assert.assertEquals(total - foundObjects, threadCycles);
final long indexedItems = graph.getRawGraph().getMetadata().getIndexManager().getIndex("Client.uid").getSize();
System.out.println("\nTotal indexed objects after the test: " + indexedItems);
} finally {
graph.shutdown();
}
}
Aggregations