public class Test {

/**
 * @param args
 */
public static void main(String[] args) {
ODatabaseDocumentTx db = new ODatabaseDocumentTx 
("memory:petshop").create();
OClass personClass =db.getMetadata().getSchema().getOrCreateClass("Person");
personClass.createProperty("child", OType.LINK,personClass);
personClass.createProperty("name", OType.STRING);
personClass.createIndex("indexName", OClass.INDEX_TYPE.NOTUNIQUE,"child");
 OIndex<?> idx = db.getMetadata().getIndexManager().getIndex("indexName");
 long start = System.currentTimeMillis();
Random rand = new Random();
for (long i = 0; i < 10; i++) {
int randomNum = rand.nextInt(1000000);
ODocument child = new ODocument("Person");
child.field( "name", "waledChild"+randomNum );
child.field( "age", i);
child.field("child");
ODocument person = new ODocument("Person");
person.field( "name", "waled"+randomNum );
person.field( "age", i);
person.field("child",child);
person.save();
idx.put(person, person.getIdentity());
}
idx.getFirstKey();
// db.commit();
long execution = System.currentTimeMillis() - start;
execution /= 1000;
System.out.println("save in database= " + execution);
long count = 0;
start = System.currentTimeMillis();
for (long i = 0; i < 1000000; i++) {
int randomNum = rand.nextInt(1000000);
String query = "select * from index:indexName where key='child.name'";
List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>(query));
if (result.size() != 0) {
for(ODocument document:result){
document.fieldNames();
ODocument doc = document.field("rid");
doc.field("age");
}
// System.out.println("size = " + result.size());
count++;
}
}
execution = System.currentTimeMillis() - start;
execution /= 1000;
System.out.println("query from database= " + execution);
System.out.println("count is " + count);
db.drop();

}

}



public class Person {
public Person(String name,long age,Person child){
this.age=age;
this.name=name;
this.child=child;
}
public Person(){
 }
private Person child;
protected Person getChild() {
return child;
}
protected void setChild(Person child) {
this.child = child;
}
private String name;
private long age;
protected String getName() {
return name;
}
protected void setName(String name) {
this.name = name;
}
protected long getAge() {
return age;
}
protected void setAge(long age) {
this.age = age;
}
}


i want to query for all person have childs name to "waled" like this " 
select * from person where child.name='waled' using index

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to