OObjectDatabaseTx db = OObjectDatabasePool.global().acquire("remote:localhost:2424/graphtest1", "admin", "admin");
db.getEntityManager().registerEntityClass(Profile.class);
db.getEntityManager().registerEntityClass(Knows.class);
OGraphDatabase graph = OGraphDatabasePool.global().acquire("remote:localhost:2424/graphtest1", "admin", "admin");
try {
db.begin(TXTYPE.OPTIMISTIC);
// One person's profile
Profile suan = db.newInstance(Profile.class);
suan.setName("Suan Jua");
suan.setLanguage("en");
suan.setEmail("su...@example.com");
db.save(suan);
// Another person's profile
Profile nikito = db.newInstance(Profile.class);
nikito.setName("Nikito Jamahona");
nikito.setLanguage("Japanese");
nikito.setEmail("nik...@example.com");
db.save(nikito);
// RID is temporary before a transaction is committed.
//System.out.println("RID: " + db.getRecordByUserObject(suan, false).getIdentity().toString());
db.commit();
// RID is actual after a transaction is committed.
System.out.println("RID: " + db.getRecordByUserObject(suan, false).getIdentity().toString()); System.out.println(db.getRecordByUserObject(nikito, false).toJSON());
graph.begin(TXTYPE.OPTIMISTIC);
//graph.createEdgeType("Knows");
ODocument e = graph.createEdge(db.getRecordByUserObject(suan, false).getIdentity(),
db.getRecordByUserObject(nikito, false).getIdentity(), "Knows");
e = e.save();
graph.commit();
System.out.println("-----------: " + e.getIdentity());
// Method 1:
List<Knows> suanKnowsnikitoList = db.query(new OSQLSynchQuery<Knows>("select from " + e.getIdentity().toString()));
Knows suanKnowsnikito = suanKnowsnikitoList.get(0);
suanKnowsnikito.setKnowHow("peers");
Calendar cal = Calendar.getInstance();
cal.set(Integer.parseInt("2010"), Integer.parseInt("06"), Integer.parseInt("21"));
suanKnowsnikito.setSince(cal.getTime());
db.save(suanKnowsnikito);
System.out.println("-----------: pojo= " + suanKnowsnikito.getKnowHow());
// Method 2:
Object o = db.getUserObjectByRecord(e, null);
Knows k = (Knows)o;
k.setKnowHow("friend");
db.save(k); // Without a transaction.
System.out.println("-----------: pojo= " + k.getKnowHow());
} catch (Exception e) {
e.printStackTrace();
db.rollback();
} finally {
db.close();
graph.close();
}
hi,OrientDB provides a very rich API and query language to do a variety of things we can think as a DB.But I see a small effort needs to be done to use it in a more powerful and convenient way. e.g. use Java native classes (POJOs) as first class Documents and also Vertices and Edges of Graph.I was doing a small test to do this. Kindly consider the code below:
OObjectDatabaseTx db = OObjectDatabasePool.global().acquire("remote:localhost:2424/graphtest1", "admin", "admin");
db.getEntityManager().registerEntityClass(Profile.class);
db.getEntityManager().registerEntityClass(Knows.class);
OGraphDatabase graph = OGraphDatabasePool.global().acquire("remote:localhost:2424/graphtest1", "admin", "admin");
try {
db.begin(TXTYPE.OPTIMISTIC);
// One person's profile
Profile suan = db.newInstance(Profile.class);
suan.setName("Suan Jua");
suan.setLanguage("en");
db.save(suan);
// Another person's profile
Profile nikito = db.newInstance(Profile.class);
nikito.setName("Nikito Jamahona");
nikito.setLanguage("Japanese");
--
db.save(suan);
// Another person's profile
Profile nikito = db.newInstance(Profile.class);
nikito.setName("Nikito Jamahona");
nikito.setLanguage("Japanese");
--
--
---
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 orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Hi
How can I save my pojo class as vertex in Graph API. (I know, how to do in object and from command operations) looking only from Graph API.
public class Customer implements Serializable {
@OId
private String rid;
@OVersion
private Long version;
private String firstName;
private String lastName;
}
I want how directly I can save this pojo ?
I know this also.
OrientGraph graph = new OrientGraph("remote:localhost/test", "admin", "admin");
graph.createVertexType("Customer");
Vertex cust = graph.addVertex("class:Customer");
cust.setProperty("firstName", "John");
cust.setProperty("lastName", "Smith");
is there any API that directly save pojo as vertex. Pls let me know