Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if class exists or not in orientdb

Tags:

java

orientdb

How to check if a class exists or not in orient db if it is not exiting in the database i need to create it and insert a record if exists i need to insert the record . I need to do the same using JAVA

like image 606
Surya Prakash Avatar asked Nov 03 '15 10:11

Surya Prakash


1 Answers

You can retrieve schema information via SQL with the following statement:

 select expand(classes) from metadata:schema 

In particular, to retrieve a single class:

 select from (
    select expand(classes) from metadata:schema
 ) where name = 'YourClassName'

From Java:

 ODatabaseDocumentTx db = ...
 if(db.getMetadata().getSchema().existsClass("ClassName")){
   ...
 }

If you have an OrientGraph, you can get the underlying ODatabaseDocumentTx with

 graph.getRawGraph();
like image 122
Luigi Dell'Aquila Avatar answered Oct 14 '22 21:10

Luigi Dell'Aquila