protected String checkForClassInSchema ( final String className ) { if ( className == null ) return null ; OrientBaseGraph graph = getGraph ( ) ; if ( graph == null ) return className ; final OSchema schema = graph . getRawGraph ( ) . getMetadata ( ) . getSchema ( ) ; if ( ! schema . existsClass ( className ) ) { // CREATE A NEW CLASS AT THE FLY try { graph . executeOutsideTx ( new OCallable < OClass , OrientBaseGraph > ( ) { @ Override public OClass call ( final OrientBaseGraph g ) { return schema . createClass ( className , schema . getClass ( getBaseClassName ( ) ) ) ; } } , "Committing the active transaction to create the new type '" , className , "' as subclass of '" , getBaseClassName ( ) , "'. The transaction will be reopen right after that. To avoid this behavior create the classes outside the transaction" ) ; } catch ( OSchemaException e ) { if ( ! schema . existsClass ( className ) ) throw e ; } } else { // CHECK THE CLASS INHERITANCE final OClass cls = schema . getClass ( className ) ; if ( ! cls . isSubClassOf ( getBaseClassName ( ) ) ) throw new IllegalArgumentException ( "Class '" + className + "' is not an instance of " + getBaseClassName ( ) ) ; } return className ; }
Check if a class already exists otherwise create it at the fly . If a transaction is running commit changes create the class and begin a new transaction .