/** * If a class with given name already exists, it's just returned, otherwise the method creates a new class and returns it. * * @param className the class name * @param superclasses a list of superclasses for the class (can be empty) * * @return the class with the given name * * @throws OSchemaException if one of the superclasses does not exist in the schema */ default OClass createClassIfNotExist(String className, String... superclasses) throws OSchemaException { OSchema schema = getMetadata().getSchema(); schema.reload(); OClass result = schema.getClass(className); if (result == null) { result = createClass(className, superclasses); } return result; }
public void createClass(final String className, final OClass superClass) { makeActive(); OSchema schema = database.getMetadata().getSchema(); OClass cls = schema.getClass(className); if (cls == null) { try { executeOutsideTx((db) -> { OSchema s = db.getMetadata().getSchema(); s.createClass(className, superClass); return null; }); if (this.tx().isOpen()) schema.reload(); } catch (OException e) { throw new IllegalArgumentException(e); } OLogManager.instance().info(this, "created class '" + className + "' as subclass of '" + superClass + "'"); } else { if (!cls.isSubClassOf(superClass)) { throw new IllegalArgumentException( "unable to create class '" + className + "' as subclass of '" + superClass + "'. different super class."); } } }
schema.reload(); OClass[] superclassInstances = null; if (superclasses != null) {
@Test public void testPropertyRenaming() { ODatabaseDocument db = wicket.getTester().getDatabase(); OSchema schema = db.getMetadata().getSchema(); OClass classA = schema.createClass("TestPropertyRenaming"); OProperty property = classA.createProperty("propertyOld", OType.STRING); assertEquals(property, classA.getProperty("propertyOld")); assertNull(classA.getProperty("propertyNew")); property.setName("propertyNew"); schema.reload(); classA = schema.getClass("TestPropertyRenaming"); assertNull(classA.getProperty("propertyOld")); assertEquals(property, classA.getProperty("propertyNew")); }