Java Code Examples for com.orientechnologies.orient.core.metadata.schema.OSchema#dropClass()
The following examples show how to use
com.orientechnologies.orient.core.metadata.schema.OSchema#dropClass() .
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: TestInAppOrientDBCompatibility.java From wicket-orientdb with Apache License 2.0 | 5 votes |
@Test @Ignore public void testDeletionOfDependentClass() { ODatabaseDocument db = wicket.getTester().getDatabase(); OSchema schema = db.getMetadata().getSchema(); OClass oRestricted = schema.getClass(OSecurityShared.RESTRICTED_CLASSNAME); OClass classA = schema.createClass("TestDeletionOfDependentClassA", oRestricted); OClass classB = schema.createClass("TestDeletionOfDependentClassB", classA); schema.dropClass(classB.getName()); }
Example 2
Source File: DAOTest.java From Orienteer with Apache License 2.0 | 5 votes |
@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 3
Source File: HooksTest.java From Orienteer with Apache License 2.0 | 5 votes |
@Test @Sudo public void testCallbackHook() throws Exception { ODatabaseDocument db = OrientDbWebSession.get().getDatabase(); OSchema schema = db.getMetadata().getSchema(); OClass oClass = schema.createClass(TEST_CLASS_CALLBACK); oClass.createProperty("name", OType.STRING); try { ODocument doc = new ODocument(oClass); doc.field("name", "testname"); TestCallback callback = new TestCallback(); CallbackHook.registerCallback(doc, TYPE.AFTER_CREATE, callback); CallbackHook.registerCallback(doc, TYPE.BEFORE_CREATE, callback); doc.save(); assertEquals("executed", doc.field("callback"+TYPE.AFTER_CREATE)); assertEquals("executed", doc.field("callback"+TYPE.BEFORE_CREATE)); assertFalse(doc.containsField("__callbacks__")); doc.reload(); assertFalse(doc.containsField("__callbacks__")); assertFalse(doc.containsField("callback"+TYPE.AFTER_READ)); CallbackHook.registerCallback(doc, TYPE.AFTER_READ, callback); doc.reload(); assertEquals("executed", doc.field("callback"+TYPE.AFTER_READ)); } finally { schema.dropClass(TEST_CLASS_CALLBACK); } }
Example 4
Source File: OrientDbLoader.java From nextreports-server with Apache License 2.0 | 5 votes |
@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 5
Source File: OrientDbUtils.java From nextreports-server with Apache License 2.0 | 5 votes |
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 6
Source File: OrienteerLocalizationModule.java From Orienteer with Apache License 2.0 | 4 votes |
@Override public void onUninstall(OrienteerWebApplication app, ODatabaseDocument db) { OSchema schema = app.getDatabase().getMetadata().getSchema(); if(schema.existsClass(OCLASS_LOCALIZATION)) schema.dropClass(OCLASS_LOCALIZATION); }
Example 7
Source File: DAOTest.java From Orienteer with Apache License 2.0 | 4 votes |
@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 8
Source File: HooksTest.java From Orienteer with Apache License 2.0 | 4 votes |
@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 9
Source File: HooksTest.java From Orienteer with Apache License 2.0 | 4 votes |
@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 10
Source File: HooksTest.java From Orienteer with Apache License 2.0 | 4 votes |
@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); } }