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

The following examples show how to use com.orientechnologies.orient.core.metadata.schema.OSchema#createClass() . 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: ComponentDatabaseUpgrade_1_13_Test.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testClassDropped() throws Exception {
  try (ODatabaseDocumentTx db = componentDatabase.getInstance().connect()) {
    OSchema schema = db.getMetadata().getSchema();
    schema.createClass(DB_CLASS);
    db.browseClass(DB_CLASS);
  }

  underTest.apply();

  try (ODatabaseDocumentTx db = componentDatabase.getInstance().connect()) {
    try {
      db.browseClass(DB_CLASS);
      fail("Expected exception thrown");
    }
    catch (IllegalArgumentException e) {
      assertThat(e.getMessage(), is("Class 'assetdownloadcount' not found in current database"));
    }
  }
}
 
Example 2
Source File: LegacyKeyStoreUpgradeService.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
public void upgradeSchema() throws Exception {
  log.debug("Updgrading schema for trust store");
  try (ODatabaseDocumentTx db = databaseInstance.get().connect()) {
    OSchema schema = db.getMetadata().getSchema();
    OClass type = schema.getClass(DB_CLASS);
    if (type == null) {
      type = schema.createClass(DB_CLASS);
      type.createProperty(P_NAME, OType.STRING).setMandatory(true).setNotNull(true);
      type.createProperty(P_BYTES, OType.BINARY).setMandatory(true).setNotNull(true);
      type.createIndex(I_NAME, INDEX_TYPE.UNIQUE, P_NAME);
      log.debug("Created schema type {}: properties={}, indexes={}", type, type.properties(), type.getIndexes());
    }
    else {
      // NOTE: Upgrade steps run on each node but within a cluster, another node might already have upgraded the db
      log.debug("Skipped creating existing schema type {}: properties={}, indexes={}", type, type.properties(),
          type.getIndexes());
    }
  }
}
 
Example 3
Source File: OrientQuartzSchema.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private static OClass maybeCreateClass(final OSchema schema, final String className) {
  OClass clazz = schema.getClass(className);
  if (clazz == null) {
    clazz = schema.createClass(className);
  }
  return clazz;
}
 
Example 4
Source File: TestInAppOrientDBCompatibility.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example 5
Source File: LuceneInsertUpdateTest.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void init() {
  initDB();

  OSchema schema = databaseDocumentTx.getMetadata().getSchema();
  OClass oClass = schema.createClass("City");

  oClass.createProperty("name", OType.STRING);
  databaseDocumentTx.command(new OCommandSQL("create index City.name on City (name) FULLTEXT ENGINE LUCENE")).execute();
}
 
Example 6
Source File: TestInAppOrientDBCompatibility.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore
public void testTransactions2() throws Exception {
	ODatabaseDocument db = wicket.getTester().getDatabase();
	try {
		assertFalse(db.getTransaction().isActive());
		OSchema schema = db.getMetadata().getSchema();
		OClass classA = schema.createClass("TransB");
		classA.createProperty("name", OType.STRING);
		ODocument doc = new ODocument(classA);
		doc.field("name", "test1");
		doc.save();
		ORID orid = doc.getIdentity();
		
		db.begin();
		assertTrue(db.getTransaction().isActive());
		doc = orid.getRecord();
		assertEquals("test1", doc.field("name"));
		doc.field("name", "test2");
		doc.save();
		doc = orid.getRecord();
		assertEquals("test2", doc.field("name"));
		doc.field("name", "test3");
		assertEquals("test3", doc.field("name"));
		//There is NO SAVE!
		db.commit();
		db.getLocalCache().clear();
		/* COMMENT START */
		//db.close();
		//db = wicket.getTester().getDatabase();
		/* COMMENT STOP */
		doc = orid.getRecord();
		assertEquals("test2", doc.field("name"));
		
	} finally {
		db.commit();
	}
}
 
Example 7
Source File: LuceneQueryErrorTest.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void init() {
  initDB();
  OSchema schema = databaseDocumentTx.getMetadata().getSchema();
  OClass v = schema.getClass("V");
  OClass song = schema.createClass("Song");
  song.setSuperClass(v);
  song.createProperty("title", OType.STRING);
  song.createProperty("author", OType.STRING);

  databaseDocumentTx.command(new OCommandSQL("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE")).execute();

}
 
Example 8
Source File: HooksTest.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: LuceneInsertUpdateSingleDocumentNoTxTest.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void init() {
  initDB();
  OSchema schema = databaseDocumentTx.getMetadata().getSchema();

  if (schema.getClass("City") == null) {
    OClass oClass = schema.createClass("City");
    oClass.createProperty("name", OType.STRING);
  }
  databaseDocumentTx.command(new OCommandSQL("create index City.name on City (name) FULLTEXT ENGINE LUCENE")).execute();

}
 
Example 10
Source File: TestInAppOrientDBCompatibility.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransactions() throws Exception {
	ODatabaseDocument db = wicket.getTester().getDatabase();
	try {
		assertFalse(db.getTransaction().isActive());
		OSchema schema = db.getMetadata().getSchema();
		OClass classA = schema.createClass("TransA");
		classA.createProperty("name", OType.STRING);
		ODocument doc = new ODocument(classA);
		doc.field("name", "test1");
		doc.save();
		ORID orid = doc.getIdentity();
		db.begin();
		assertTrue(db.getTransaction().isActive());
		doc = orid.getRecord();
		assertEquals("test1", doc.field("name"));
		doc.field("name", "test2");
		doc = orid.getRecord();
		assertEquals("test2", doc.field("name"));
		//There is NO SAVE!
		db.commit();
		db.getLocalCache().clear();
		/* COMMENT START */
		//db.close();
		//db = wicket.getTester().getDatabase();
		/* COMMENT STOP */
		doc = orid.getRecord();
		assertEquals("test1", doc.field("name"));
		
	} finally {
		db.commit();
	}
}
 
Example 11
Source File: LuceneSkipLimitTest.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void init() {
    initDB();
    OSchema schema = databaseDocumentTx.getMetadata().getSchema();
    OClass v = schema.getClass("V");
    OClass song = schema.createClass("Song");
    song.setSuperClass(v);
    song.createProperty("title", OType.STRING);
    song.createProperty("author", OType.STRING);

    databaseDocumentTx.command(new OCommandSQL("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE")).execute();
    databaseDocumentTx.command(new OCommandSQL("create index Song.author on Song (author) FULLTEXT ENGINE LUCENE")).execute();

}
 
Example 12
Source File: LuceneInsertIntegrityRemoteTest.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void init() {
  initDB();

  OSchema schema = databaseDocumentTx.getMetadata().getSchema();
  OClass oClass = schema.createClass("City");

  oClass.createProperty("name", OType.STRING);
  databaseDocumentTx.command(new OCommandSQL("create index City.name on City (name) FULLTEXT ENGINE LUCENE")).execute();
}
 
Example 13
Source File: LuceneGetSearcherTest.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void init() {
  initDB();
  OSchema schema = databaseDocumentTx.getMetadata().getSchema();
  OClass v = schema.getClass("V");
  OClass song = schema.createClass("Person");
  song.setSuperClass(v);
  song.createProperty("isDeleted", OType.BOOLEAN);

  databaseDocumentTx.command(new OCommandSQL("create index Person.isDeleted on Person (isDeleted) FULLTEXT ENGINE LUCENE"))
      .execute();

}
 
Example 14
Source File: LuceneMassiveInsertDeleteTest.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void init() {
  initDB();
  OSchema schema = databaseDocumentTx.getMetadata().getSchema();
  OClass v = schema.getClass("V");
  OClass song = schema.createClass("City");
  song.setSuperClass(v);
  song.createProperty("name", OType.STRING);

  databaseDocumentTx.command(new OCommandSQL("create index City.name on City (name) FULLTEXT ENGINE LUCENE")).execute();

}
 
Example 15
Source File: LuceneInsertMultithreadTest.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@Test
public void testConcurrentInsertWithIndex() throws Exception {

  databaseDocumentTx = new ODatabaseDocumentTx(url);
  if (!url.contains("remote:") && databaseDocumentTx.exists()) {
    databaseDocumentTx.open("admin", "admin");
    databaseDocumentTx.drop();
    databaseDocumentTx.create();
  } else {
    databaseDocumentTx.create();
  }

  OSchema schema = databaseDocumentTx.getMetadata().getSchema();
  if (schema.getClass("City") == null) {
    OClass oClass = schema.createClass("City");

    oClass.createProperty("name", OType.STRING);
    oClass.createIndex("City.name", "FULLTEXT", null, null, "LUCENE", new String[] { "name" });
  }

  Thread[] threads = new Thread[THREADS + RTHREADS];
  for (int i = 0; i < THREADS; ++i)
    threads[i] = new Thread(new LuceneInsertThread(CYCLE), "ConcurrentWriteTest" + i);

  for (int i = THREADS; i < THREADS + RTHREADS; ++i)
    threads[i] = new Thread(new LuceneReadThread(CYCLE), "ConcurrentReadTest" + i);

  for (int i = 0; i < THREADS + RTHREADS; ++i)
    threads[i].start();

  for (int i = 0; i < THREADS + RTHREADS; ++i)
    threads[i].join();

  OIndex idx = schema.getClass("City").getClassIndex("City.name");

  Assert.assertEquals(idx.getSize(), THREADS * CYCLE);
  databaseDocumentTx.drop();
}
 
Example 16
Source File: DatabaseFreezeServiceImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  File workDir = temporaryFolder.newFolder();
  when(applicationDirectories.getWorkDirectory("db")).thenReturn(workDir);

  databaseFrozenStateManager = new LocalDatabaseFrozenStateManager(applicationDirectories);

  when(distributedServerManager.getMessageService()).thenReturn(distributedMessageService);
  when(distributedMessageService.getDatabases()).thenReturn(Collections.singleton("test"));
  when(distributedServerManager.executeInDistributedDatabaseLock(eq("test"), anyLong(),
      any(OModifiableDistributedConfiguration.class),
      (OCallable<Object, OModifiableDistributedConfiguration>) notNull()))
      .then(invoc -> ((OCallable) invoc.getArguments()[3]).call(distributedConfiguration));
  when(distributedServerManager.getDatabaseConfiguration("test"))
      .thenReturn(distributedConfiguration);

  when(nodeAccess.isClustered()).thenReturn(false);

  providerSet = of(database.getInstanceProvider(), database2.getInstanceProvider()).collect(toSet());

  underTest = new DatabaseFreezeServiceImpl(
      providerSet,
      eventManager,
      databaseFrozenStateManager,
      () -> server,
      nodeAccess,
      securityHelper,
      ImmutableList.of());

  when(server.getDistributedManager()).thenReturn(distributedServerManager);

  for (Provider<DatabaseInstance> provider : providerSet) {
    try (ODatabaseDocumentTx db = provider.get().connect()) {
      OSchema schema = db.getMetadata().getSchema();
      schema.createClass(DB_CLASS);
    }
  }

  underTest.doStart();
}
 
Example 17
Source File: LuceneInsertUpdateSingleDocumentTransactionTest.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void init() {
  initDB();
  OSchema schema = databaseDocumentTx.getMetadata().getSchema();

  if (schema.getClass("City") == null) {
    OClass oClass = schema.createClass("City");
    oClass.createProperty("name", OType.STRING);
  }
  databaseDocumentTx.command(new OCommandSQL("create index City.name on City (name) FULLTEXT ENGINE LUCENE")).execute();

}
 
Example 18
Source File: LuceneCreateJavaApi.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void init() {
  initDB();
  OSchema schema = databaseDocumentTx.getMetadata().getSchema();
  OClass v = schema.getClass("V");
  OClass song = schema.createClass("Song");
  song.setSuperClass(v);
  song.createProperty("title", OType.STRING);
  song.createProperty("author", OType.STRING);
  song.createProperty("description", OType.STRING);
}
 
Example 19
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);
	}
}
 
Example 20
Source File: TestDataInstallator.java    From wicket-orientdb with Apache License 2.0 4 votes vote down vote up
@Override
protected void installData(OrientDbWebApplication app, ODatabaseDocument db) {
	OSchema schema = db.getMetadata().getSchema();
	OClass classA = schema.createClass("ClassA");
	classA.createProperty("name", OType.STRING);
	classA.createProperty("description", OType.STRING);
	classA.createProperty("other", OType.LINKLIST).setLinkedClass(classA);
	classA.createProperty("empty", OType.LINKLIST).setLinkedClass(classA);
	OClass classB = schema.createClass("ClassB");
	classB.createProperty("name", OType.STRING);
	classB.createProperty("description", OType.STRING);
	
	ODocument doc1 = new ODocument("ClassA").field("name", "doc1");
	ODocument doc2 = new ODocument("ClassA").field("name", "doc2");
	ODocument doc3 = new ODocument("ClassA").field("name", "doc3");
	doc1.field("other", Arrays.asList(doc2, doc3));
	doc2.field("other", Arrays.asList(doc1, doc3));
	doc3.field("other", Arrays.asList(doc1, doc2));
	
	doc1.save();
	doc2.save();
	doc3.save();
	
	OClass testRest = schema.createClass(TestRestApi.TEST_REST_CLASS);
	testRest.createProperty("a", OType.STRING);
	testRest.createProperty("b", OType.INTEGER);
	testRest.createProperty("c", OType.BOOLEAN);
	ODocument restDoc = new ODocument(testRest);
	restDoc.field("a", "test");
	restDoc.field("b", 10);
	restDoc.field("c", true);
	restDoc.save();
	
	OClass function = schema.getClass("OFunction");
	ODocument fun1 = new ODocument(function);
	fun1.field("name", "fun1");
	fun1.field("language", "javascript");
	fun1.field("idempotent", true);
	fun1.field("code", "return \"fun1\";");
	fun1.save();
	
	ODocument fun2 = new ODocument(function);
	fun2.field("name", "fun2");
	fun2.field("language", "javascript");
	fun2.field("idempotent", false);
	fun2.field("code", "return \"fun2\";");
	fun2.save();
	
	OClass classTestHooks = schema.createClass("TestHooks");
	classTestHooks.createProperty("name", OType.STRING);
	ODocument testHook = new ODocument(classTestHooks);
	testHook.field("name", "SAVED");
	testHook.save();
}