Java Code Examples for com.orientechnologies.orient.core.metadata.schema.OSchema#existsClass()

The following examples show how to use com.orientechnologies.orient.core.metadata.schema.OSchema#existsClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExistsOClassBehavior.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
protected void respond(AjaxRequestTarget target) {
    IRequestParameters params = RequestCycle.get().getRequest().getRequestParameters();
    String json = params.getParameterValue(EXISTS_CLASS_VAR).toString();
    String className = getClassNameFromJson(json);
    Boolean exists = false;
    if (!Strings.isNullOrEmpty(className)) {
        OSchema schema = OrienteerWebApplication.get().getDatabase().getMetadata().getSchema();
        exists = schema.existsClass(className);
    }
    target.appendJavaScript(String.format("app.executeCallback(%s);", exists.toString()));
}
 
Example 2
Source File: ApplyEditorChangesBehavior.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private void addSuperClassesToOClass(OSchema schema, OClass oClass, List<String> superClassNames) {
    if (superClassNames != null && !superClassNames.isEmpty()) {
        List<OClass> superClasses = Lists.newArrayList();
        for (String architectSuperClass : superClassNames) {
            if (schema.existsClass(architectSuperClass)) {
                OClass superClass = schema.getClass(architectSuperClass);
                superClasses.add(superClass);
            }
        }
        oClass.setSuperClasses(superClasses);
    }
}
 
Example 3
Source File: GetNewChangesBehavior.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private List<OClass> getClasses(List<String> classNames) {
    List<OClass> classes = new ArrayList<>(classNames.size());
    OSchema schema = OrienteerWebApplication.get().getDatabase().getMetadata().getSchema();
    for (String name : classNames) {
        if (schema.existsClass(name))
            classes.add(schema.getClass(name));
    }
    return classes;
}
 
Example 4
Source File: DAOTest.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Test
@Sudo
public void testDescriber() {
	OSchema schema = tester.getMetadata().getSchema();
	try {
		DAO.describe(OSchemaHelper.bind(tester.getDatabase()), IDAOTestClassA.class);
		assertTrue(schema.existsClass("DAOTestClassRoot"));
		assertTrue(schema.existsClass("DAOTestClassA"));
		assertTrue(schema.existsClass("DAOTestClassB"));
		OClass daoTestClassRoot = schema.getClass("DAOTestClassRoot");
		OClass daoTestClassA = schema.getClass("DAOTestClassA");
		OClass daoTestClassB = schema.getClass("DAOTestClassB");
		
		assertTrue(daoTestClassRoot.isAbstract());
		assertProperty(daoTestClassRoot, "root", OType.STRING);
		
		OProperty root = assertProperty(daoTestClassA, "root", OType.STRING);
		assertEquals("DAOTestClassRoot.root", root.getFullName());
		
		assertProperty(daoTestClassA, "name", OType.STRING);
		assertProperty(daoTestClassA, "bSingle", OType.LINK, daoTestClassB, null);
		assertProperty(daoTestClassA, "bOtherField", OType.LINK, daoTestClassB, null);
		assertProperty(daoTestClassA, "selfType", OType.LINK, daoTestClassA, null);
		assertProperty(daoTestClassA, "linkAsDoc", OType.LINK, daoTestClassB, null);
		assertProperty(daoTestClassA, "embeddedStringList", OType.EMBEDDEDLIST, OType.STRING);
		assertProperty(daoTestClassA, "linkList", OType.LINKLIST, daoTestClassB, null);
		
		assertProperty(daoTestClassB, "alias", OType.STRING);
		assertProperty(daoTestClassB, "linkToA", OType.LINK, daoTestClassA, null);
	} finally {
		if(schema.existsClass("DAOTestClassA")) schema.dropClass("DAOTestClassA");
		if(schema.existsClass("DAOTestClassB")) schema.dropClass("DAOTestClassB");
		if(schema.existsClass("DAOTestClassRoot")) schema.dropClass("DAOTestClassRoot");
	}
}
 
Example 5
Source File: ContentStore.java    From jbake with MIT License 5 votes vote down vote up
public final void updateSchema() {

        OSchema schema = db.getMetadata().getSchema();

        for (String docType : DocumentTypes.getDocumentTypes()) {
            if (!schema.existsClass(docType)) {
                createDocType(schema, docType);
            }
        }
        if (!schema.existsClass("Signatures")) {
            createSignatureType(schema);
        }
    }
 
Example 6
Source File: OrientDbLoader.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
@Override
public void init() {
    log.debug("Init loader");
    documentDatabase = new ODatabaseDocumentTx(dbUrl, false);
    String databaseName = documentDatabase.getName();

    if (documentDatabase.exists() && dbAutoDropIfExists) {
        log.debug("Dropping existent database '{}'", databaseName);
        documentDatabase.open(dbUser, dbPassword).drop();
    }

    if (documentDatabase.exists()) {
        log.debug("Open database '{}'", databaseName);
        documentDatabase.open(dbUser, dbPassword);

        if ((className != null) && autoDropClass) {
            OSchema schema = documentDatabase.getMetadata().getSchema();
            if (schema.existsClass(className)) {
                log.debug("Dropping class '{}'", className);
                documentDatabase.command(new OCommandSQL("DELETE FROM " + className)).execute();
                schema.dropClass(className);
            }
        }
    } else {
        long time = System.currentTimeMillis();
        log.debug("Create database '{}'", databaseName);
        documentDatabase.create();
        time = System.currentTimeMillis() - time;
        log.debug("Created database '{}' in {} ms", databaseName, time);
    }

    documentDatabase.declareIntent(new OIntentMassiveInsert());
}
 
Example 7
Source File: OrientDbLoader.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
protected OClass getOrCreateClass(String className) {
    OClass clazz;

    OSchema schema = documentDatabase.getMetadata().getSchema();
    if (schema.existsClass(className)) {
        clazz = schema.getClass(className);
    } else {
        clazz = schema.createClass(className);
        log.debug("Created class '{}'", className);
    }

    return clazz;
}
 
Example 8
Source File: OrientDbUtils.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
public static void dropClass(ODatabaseDocument database, String className) {
    OSchema schema = database.getMetadata().getSchema();
    if (schema.existsClass(className)) {
        database.command(new OCommandSQL("DELETE FROM " + className)).execute();
        schema.dropClass(className);
    }
}
 
Example 9
Source File: OrientDbUtils.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
public static long duplicateClass(ODatabaseDocument database, String className, String newClassName) {
    OSchema schema = database.getMetadata().getSchema();
    if (!schema.existsClass(newClassName)) {
        schema.createClass(newClassName);
    }

    String sql = "INSERT INTO " + newClassName + " FROM SELECT FROM " + className;
    database.command(new OCommandSQL(sql)).execute();

    long count = schema.getClass(newClassName).count();

    return count;
}
 
Example 10
Source File: OrienteerLocalizationModule.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public void onUninstall(OrienteerWebApplication app, ODatabaseDocument db) {
	OSchema schema = app.getDatabase().getMetadata().getSchema();
	if(schema.existsClass(OCLASS_LOCALIZATION)) schema.dropClass(OCLASS_LOCALIZATION);
}
 
Example 11
Source File: DAOTest.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Test
@Sudo
public void testDescribeAllTypes() {
	OSchema schema = tester.getMetadata().getSchema();
	try {
		DAO.describe(OSchemaHelper.bind(tester.getDatabase()), IDAOAllTypesTestClass.class);
		assertTrue(schema.existsClass("DAOAllTypesTestClass"));
		assertTrue(schema.existsClass("IDAODummyClass"));
		OClass oClass = schema.getClass("DAOAllTypesTestClass");
		OClass dummyClass = schema.getClass("IDAODummyClass");
		
		assertTrue(!oClass.isAbstract());
		
		assertProperty(oClass, "boolean", OType.BOOLEAN, false);
		assertProperty(oClass, "booleanPrimitive", OType.BOOLEAN, true);
		assertProperty(oClass, "booleanDeclared", OType.BOOLEAN, true);
		
		assertProperty(oClass, "integer", OType.INTEGER);
		assertProperty(oClass, "short", OType.SHORT);
		assertProperty(oClass, "long", OType.LONG);
		assertProperty(oClass, "float", OType.FLOAT);
		assertProperty(oClass, "double", OType.DOUBLE);
		assertProperty(oClass, "dateTime", OType.DATETIME);
		assertProperty(oClass, "date", OType.DATE);
		assertProperty(oClass, "string", OType.STRING);
		assertProperty(oClass, "binary", OType.BINARY);
		assertProperty(oClass, "decimal", OType.DECIMAL);
		assertProperty(oClass, "byte", OType.BYTE);
		assertProperty(oClass, "custom", OType.CUSTOM);
		assertProperty(oClass, "transient", OType.TRANSIENT);
		assertProperty(oClass, "any", OType.ANY);
		
		assertProperty(oClass, "link", OType.LINK, dummyClass, null);
		assertProperty(oClass, "linkList", OType.LINKLIST, dummyClass, null);
		assertProperty(oClass, "linkSet", OType.LINKSET, dummyClass, null);
		assertProperty(oClass, "linkMap", OType.LINKMAP, dummyClass, null);
		assertProperty(oClass, "linkBag", OType.LINKBAG, dummyClass, null);
		
		assertProperty(oClass, "embedded", OType.EMBEDDED, dummyClass, null);
		assertProperty(oClass, "embeddedList", OType.EMBEDDEDLIST, dummyClass, null);
		assertProperty(oClass, "embeddedSet", OType.EMBEDDEDSET, dummyClass, null);
		assertProperty(oClass, "embeddedMap", OType.EMBEDDEDMAP, dummyClass, null);
		
		assertProperty(oClass, "embeddedStringSet", OType.EMBEDDEDSET, OType.STRING);
		assertProperty(oClass, "embeddedStringList", OType.EMBEDDEDLIST, OType.STRING);
		assertProperty(oClass, "embeddedStringMap", OType.EMBEDDEDMAP, OType.STRING);

		assertProperty(oClass, "docs", OType.LINKLIST, dummyClass, null);

	} finally {
		if(schema.existsClass("DAOAllTypesTestClass")) schema.dropClass("DAOAllTypesTestClass");
		if(schema.existsClass("IDAODummyClass")) schema.dropClass("IDAODummyClass");
	}
}
 
Example 12
Source File: HooksTest.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Test
@Sudo
public void testCalculableHook() throws Exception
{
	ODatabaseDocument db = OrientDbWebSession.get().getDatabase();
	OSchema schema = db.getMetadata().getSchema();
	
	assertFalse(db.isClosed());
	db.commit();
	if(schema.existsClass(TEST_CLASS_A)) schema.dropClass(TEST_CLASS_A);
	OClass oClass = schema.createClass(TEST_CLASS_A);
	try
	{
		oClass.createProperty("a", OType.INTEGER);
		oClass.createProperty("b", OType.INTEGER);
		OProperty cProperty = oClass.createProperty("c", OType.INTEGER);
		OProperty dProperty = oClass.createProperty("d", OType.INTEGER);
		CustomAttribute.CALCULABLE.setValue(cProperty, true);
		CustomAttribute.CALCULABLE.setValue(dProperty, true);
		CustomAttribute.CALC_SCRIPT.setValue(cProperty, "select sum(a, b) as value from TestClassA where @rid = ?");
		CustomAttribute.CALC_SCRIPT.setValue(dProperty, "sum(a, b)");
		
		ODocument doc = new ODocument(oClass);
		doc.field("a", 2);
		doc.field("b", 2);
		doc.save();
		doc.reload();
		assertEquals(4, (Object) doc.field("c"));
		assertEquals(4, (Object) doc.field("d"));
		doc.field("a", 3);
		doc.field("b", 3);
		doc.save();
		doc.reload();
		assertEquals(6, (Object) doc.field("c"));
		assertEquals(6, (Object) doc.field("d"));
		db.begin();
		doc.field("a", 4);
		doc.field("b", 4);
		doc.save();
		doc.reload();
		assertEquals(8, (Object) doc.field("c"));
		assertEquals(8, (Object) doc.field("d"));
		db.commit();
		db.begin();
		doc.field("a", 5);
		doc.field("b", 5);
		doc.save();
		doc.reload();
		assertEquals(10, (Object) doc.field("c"));
		assertEquals(10, (Object) doc.field("d"));
		db.commit();
	} finally
	{
		if(db.getTransaction().isActive()) db.commit();
		schema.dropClass(TEST_CLASS_A);
	}
}
 
Example 13
Source File: HooksTest.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Test
@Sudo
public void testReferencesHookDeepCase() throws Exception
{
	ODatabaseDocument db = OrientDbWebSession.get().getDatabase();
	OSchema schema = db.getMetadata().getSchema();
	
	assertFalse(db.isClosed());
	db.commit();
	if(schema.existsClass(TEST_CLASS_C)) schema.dropClass(TEST_CLASS_C);
	OClass classC = schema.createClass(TEST_CLASS_C);
	try
	{
		OProperty parent = classC.createProperty("parent", OType.LINK);
		OProperty child = classC.createProperty("child", OType.LINKLIST);
		CustomAttribute.PROP_INVERSE.setValue(parent, child);
		CustomAttribute.PROP_INVERSE.setValue(child, parent);
		
		ODocument doc1 = new ODocument(classC).save();
		ODocument doc2 = new ODocument(classC).save();
		ODocument doc3 = new ODocument(classC).save();
		
		doc1.field("child", Arrays.asList(doc2));
		doc1.save();
		doc2.reload();
		assertEquals(doc1, doc2.field("parent"));
		
		doc3.field("child", Arrays.asList(doc2));
		doc3.save();
		doc2.reload();
		assertEquals(doc3, doc2.field("parent"));
		doc1.reload();
		List<ODocument> childs = doc1.field("child");
		assertNotNull(childs);
		assertArrayEquals(new ODocument[0], childs.toArray(new ODocument[0]));
		
	} finally
	{
		schema.dropClass(TEST_CLASS_C);
	}
}
 
Example 14
Source File: HooksTest.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Test
@Sudo
public void testReferencesHookChangeParent() throws Exception
{
	ODatabaseDocument db = OrientDbWebSession.get().getDatabase();
	OSchema schema = db.getMetadata().getSchema();
	
	assertFalse(db.isClosed());
	db.commit();
	if(schema.existsClass(TEST_CLASS_C)) schema.dropClass(TEST_CLASS_C);
	OClass classC = schema.createClass(TEST_CLASS_C);
	try
	{
		OProperty parent = classC.createProperty("parent", OType.LINK);
		OProperty child = classC.createProperty("child", OType.LINKLIST);
		CustomAttribute.PROP_INVERSE.setValue(parent, child);
		CustomAttribute.PROP_INVERSE.setValue(child, parent);
		
		ODocument doc1 = new ODocument(classC).save();
		ODocument doc2 = new ODocument(classC).save();
		ODocument doc3 = new ODocument(classC).save();
		
		doc1.field("child", Arrays.asList(doc2));
		doc1.save();
		doc2.reload();
		assertEquals(doc1, doc2.field("parent"));
		
		doc2.field("parent", doc3);
		doc2.save();
		
		doc1.reload();
		doc3.reload();
		List<ODocument> childs = doc1.field("child");
		assertNotNull(childs);
		assertArrayEquals(new ODocument[0], childs.toArray(new ODocument[0]));
		childs = doc3.field("child");
		assertNotNull(childs);
		assertArrayEquals(new ODocument[]{doc2}, childs.toArray(new ODocument[0]));
		
	} finally
	{
		schema.dropClass(TEST_CLASS_C);
	}
}