com.orientechnologies.orient.core.metadata.schema.OSchema Java Examples

The following examples show how to use com.orientechnologies.orient.core.metadata.schema.OSchema. 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: LuceneFacetTest.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void init() {
  initDB();
  OSchema schema = databaseDocumentTx.getMetadata().getSchema();
  OClass oClass = schema.createClass("Item");

  oClass.createProperty("name", OType.STRING);
  oClass.createProperty("category", OType.STRING);

  databaseDocumentTx
      .command(
          new OCommandSQL(
              "create index Item.name_category on Item (name,category) FULLTEXT ENGINE LUCENE METADATA { 'facetFields' : ['category']}"))
      .execute();

}
 
Example #2
Source File: TestInAppOrientDBCompatibility.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore
public void testClassChange()
{
	ODatabaseDocument db = wicket.getTester().getDatabase();
	OSchema schema = db.getMetadata().getSchema();
	OClass classA = schema.createClass("TestClassChangeA");
	OClass classB = schema.createClass("TestClassChangeB");
	ODocument doc = new ODocument(classA);
	doc.save();
	doc = doc.getIdentity().getRecord();
	doc.setClassName(classB.getName());
	assertEquals(classB.getName(), doc.getClassName());
	doc = doc.getIdentity().getRecord();
	assertEquals(classB.getName(), doc.getClassName());
	ORID id = doc.getIdentity();
	db.commit(true);
	db.close();
	db = wicket.getTester().getDatabase();
	doc = id.getRecord();
	assertEquals(classB.getName(), doc.getClassName());
}
 
Example #3
Source File: OrientQuartzSchema.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private static void firedTriggers(final OSchema schema) {
  OClass type = maybeCreateClass(schema, "QRTZ_FIRED_TRIGGERS");
  maybeCreateProperty(type, SCHED_NAME, STRING, true);
  maybeCreateProperty(type, "ENTRY_ID", STRING, true);
  maybeCreateProperty(type, TRIGGER_NAME, STRING, true);
  maybeCreateProperty(type, TRIGGER_GROUP, STRING, true);
  maybeCreateProperty(type, INSTANCE_NAME, STRING, true);
  maybeCreateProperty(type, "FIRED_TIME", LONG, true);
  maybeCreateProperty(type, "SCHED_TIME", LONG, true);
  maybeCreateProperty(type, "PRIORITY", INTEGER, true);
  maybeCreateProperty(type, "STATE", STRING, true);
  maybeCreateProperty(type, JOB_NAME, STRING, false);
  maybeCreateProperty(type, JOB_GROUP, STRING, false);
  maybeCreateProperty(type, "IS_NONCONCURRENT", BOOLEAN, false);
  maybeCreateProperty(type, "REQUESTS_RECOVERY", BOOLEAN, false);
  maybeCreateIndex(type, "PK_QRTZ_FIRED_TRIGGERS", SCHED_NAME, "ENTRY_ID");
}
 
Example #4
Source File: TestInAppOrientDBCompatibility.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemovingReadonlyField()
{
	ODatabaseDocument db = wicket.getTester().getDatabase();
	OSchema schema = db.getMetadata().getSchema();
	OClass classA = schema.createClass("TestRemovingField");
	classA.createProperty("name", OType.STRING);
	OProperty property = classA.createProperty("property", OType.STRING);
	property.setReadonly(true);
	
	ODocument doc = new ODocument(classA);
	doc.field("name", "My Name");
	doc.field("property", "value1");
	doc.save();
	
	doc.field("name", "My Name 2");
	doc.field("property", "value2");
	doc.undo("property");
	doc.save();
}
 
Example #5
Source File: LuceneInsertDeleteTest.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
@Test
public void testInsertUpdateWithIndex() throws Exception {

  databaseDocumentTx.getMetadata().reload();
  OSchema schema = databaseDocumentTx.getMetadata().getSchema();

  ODocument doc = new ODocument("City");
  doc.field("name", "Rome");
  databaseDocumentTx.save(doc);

  OIndex idx = schema.getClass("City").getClassIndex("City.name");
  Collection<?> coll = (Collection<?>) idx.get("Rome");
  Assert.assertEquals(coll.size(), 1);
  Assert.assertEquals(idx.getSize(), 1);
  doc = databaseDocumentTx.load((ORID) coll.iterator().next());

  databaseDocumentTx.delete(doc);

  coll = (Collection<?>) idx.get("Rome");
  Assert.assertEquals(coll.size(), 0);
  Assert.assertEquals(idx.getSize(), 0);

}
 
Example #6
Source File: OrientQuartzSchema.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private static void triggers(final OSchema schema) {
  OClass type = maybeCreateClass(schema, "QRTZ_TRIGGERS");
  maybeCreateProperty(type, SCHED_NAME, STRING, true);
  maybeCreateProperty(type, TRIGGER_NAME, STRING, true);
  maybeCreateProperty(type, TRIGGER_GROUP, STRING, true);
  maybeCreateProperty(type, JOB_NAME, STRING, true);
  maybeCreateProperty(type, JOB_GROUP, STRING, true);
  maybeCreateProperty(type, "DESCRIPTION", STRING, false);
  maybeCreateProperty(type, "NEXT_FIRE_TIME", LONG, false);
  maybeCreateProperty(type, "PREV_FIRE_TIME", LONG, false);
  maybeCreateProperty(type, "PRIORITY", INTEGER, false);
  maybeCreateProperty(type, "TRIGGER_STATE", STRING, true);
  maybeCreateProperty(type, "TRIGGER_TYPE", STRING, true);
  maybeCreateProperty(type, "START_TIME", LONG, true);
  maybeCreateProperty(type, "END_TIME", LONG, false);
  maybeCreateProperty(type, CALENDAR_NAME, STRING, false);
  maybeCreateProperty(type, "MISFIRE_INSTR", SHORT, false);
  maybeCreateProperty(type, "JOB_DATA", BINARY, false);
  maybeCreateIndex(type, "PK_QRTZ_TRIGGERS", SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP);
}
 
Example #7
Source File: TestInAppOrientDBCompatibility.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testGettingFields()
{
	OSchema schema = wicket.getTester().getSchema();
	OClass classA = schema.createClass("GettingFields");
	classA.createProperty("title", OType.STRING);
	classA.createProperty("link", OType.LINK).setLinkedClass(classA);
	classA.createProperty("multi", OType.LINKLIST).setLinkedClass(classA);
	ODocument doc = new ODocument(classA);
	doc.field("title", "test");
	doc.save();
	doc.field("link", doc);
	doc.field("multi", Arrays.asList(doc));
	doc.save();
	doc.reload();
	assertNotNull(doc.field("title"));
	assertNotNull(doc.field("link"));
	assertNotNull(doc.field("multi"));
}
 
Example #8
Source File: LuceneListIndexing.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void init() {
  initDB();

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

  OClass person = schema.createClass("Person");

  person.createProperty("name", OType.STRING);
  person.createProperty("tags", OType.EMBEDDEDLIST, OType.STRING);

  oClass.createProperty("name", OType.STRING);
  oClass.createProperty("tags", OType.EMBEDDEDLIST, OType.STRING);

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

  databaseDocumentTx.command(new OCommandSQL("create index Person.name_tags on Person (name,tags) FULLTEXT ENGINE LUCENE"))
      .execute();
}
 
Example #9
Source File: LuceneVsLuceneTest.java    From orientdb-lucene with Apache License 2.0 6 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);

  try {
    Directory dir = getDirectory();
    Analyzer analyzer = new StandardAnalyzer(OLuceneIndexManagerAbstract.LUCENE_VERSION);
    IndexWriterConfig iwc = new IndexWriterConfig(OLuceneIndexManagerAbstract.LUCENE_VERSION, analyzer);
    iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
    indexWriter = new IndexWriter(dir, iwc);

  } catch (IOException e) {
    e.printStackTrace();
  }
  databaseDocumentTx.command(new OCommandSQL("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE")).execute();

}
 
Example #10
Source File: TestModels.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testOIndexDataProvider()
{
	OSchema schema = wicket.getTester().getSchema();
	OClass oClass = schema.getClass("OUser");
	OIndexesDataProvider provider = new OIndexesDataProvider(oClass, true);
	provider.setSort("name", SortOrder.ASCENDING);
	Iterator<? extends OIndex<?>> it = provider.iterator(0, -1);
	List<OIndex<?>> allIndexes = new ArrayList<OIndex<?>>(oClass.getIndexes());
	while(it.hasNext())
	{
		OIndex<?> oIndex = it.next();
		assertTrue(allIndexes.remove(provider.model(oIndex).getObject()));
	}
	assertTrue(allIndexes.size()==0);
	provider.detach();
}
 
Example #11
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 #12
Source File: LuceneMixIndexTest.java    From orientdb-lucene with Apache License 2.0 6 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("lyrics", OType.STRING);

  databaseDocumentTx.command(new OCommandSQL("create index Song.author on Song (author) NOTUNIQUE")).execute();

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

  InputStream stream = ClassLoader.getSystemResourceAsStream("testLuceneIndex.sql");

  databaseDocumentTx.command(new OCommandScript("sql", getScriptFromStream(stream))).execute();

}
 
Example #13
Source File: TestModels.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testOClassesDataProvider()
{
	OClassesDataProvider provider = new OClassesDataProvider();
	provider.setSort("name", SortOrder.ASCENDING);
	assertTrue(provider.size()>5);
	Iterator<? extends OClass> it = provider.iterator(0, -1);
	OSchema schema = wicket.getTester().getSchema();
	List<OClass> allClasses = new ArrayList<OClass>(schema.getClasses());
	while(it.hasNext())
	{
		OClass oClass = it.next();
		assertTrue(allClasses.remove(provider.model(oClass).getObject()));
	}
	assertTrue(allClasses.size()==0);
	provider.detach();
}
 
Example #14
Source File: TestModels.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testOPropertiesDataProvider()
{
	OSchema schema = wicket.getTester().getSchema();
	OClass oClass = schema.getClass("ClassA");
	OPropertiesDataProvider provider = new OPropertiesDataProvider(oClass, true);
	provider.setSort("name", SortOrder.ASCENDING);
	Iterator<? extends OProperty> it = provider.iterator(0, -1);
	List<OProperty> allProperties = new ArrayList<OProperty>(oClass.properties());
	while(it.hasNext())
	{
		OProperty oProperty = it.next();
		assertTrue(allProperties.remove(provider.model(oProperty).getObject()));
	}
	assertTrue(allProperties.size()==0);
	provider.detach();
}
 
Example #15
Source File: LuceneInsertUpdateSingleDocumentNoTxTest.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
@Test
public void testInsertUpdateTransactionWithIndex() throws Exception {

  databaseDocumentTx.close();
  databaseDocumentTx.open("admin", "admin");
  OSchema schema = databaseDocumentTx.getMetadata().getSchema();
  schema.reload();
  ODocument doc = new ODocument("City");
  doc.field("name", "");
  ODocument doc1 = new ODocument("City");
  doc1.field("name", "");
  doc = databaseDocumentTx.save(doc);
  doc1 = databaseDocumentTx.save(doc1);

  doc = databaseDocumentTx.load(doc);
  doc1 = databaseDocumentTx.load(doc1);
  doc.field("name", "Rome");
  doc1.field("name", "Rome");
  databaseDocumentTx.save(doc);
  databaseDocumentTx.save(doc1);
  OIndex idx = schema.getClass("City").getClassIndex("City.name");
  Collection<?> coll = (Collection<?>) idx.get("Rome");
  Assert.assertEquals(coll.size(), 2);
  Assert.assertEquals(idx.getSize(), 2);
}
 
Example #16
Source File: OClassPrototyper.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Override
protected OClass createInstance(OClass proxy) {
	OSchema schema = OrientDbWebSession.get().getDatabase().getMetadata().getSchema();
	OClass oClass = schema.createClass(proxy.getName());
	oClass.setSuperClasses(proxy.getSuperClasses());
	String clusterSelection = (String) values.get(CLUSTER_SELECTION);
	if(clusterSelection!=null) {
		oClass.setClusterSelection(clusterSelection);
	}

	values.remove(NAME);
	values.remove(SUPER_CLASSES);
	values.remove(SUPER_CLASSES_NAMES);
	values.remove(CLUSTER_SELECTION);
	return oClass;
}
 
Example #17
Source File: DatabaseExternalizerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void createSampleDb() {
  try (ODatabaseDocumentTx db = database.getInstance().connect()) {
    OSchema schema = db.getMetadata().getSchema();

    OClass cityType = schema.createClass("City");
    cityType.createProperty("name", OType.STRING);
    cityType.createProperty("country", OType.STRING);
    cityType.createIndex("name_country_idx", INDEX_TYPE.UNIQUE, "name", "country");

    OClass personType = schema.createClass("Person");
    personType.createProperty("name", OType.STRING);
    personType.createProperty("surname", OType.STRING);
    personType.createIndex("name_surname_idx", INDEX_TYPE.UNIQUE, "name", "surname");

    ODocument doc = db.newInstance("Person");
    doc.field("name", "Luke")
        .field("surname", "Skywalker")
        .field("city", new ODocument("City")
            .field("name", "Rome")
            .field("country", "Italy"));
    doc.save();
  }
}
 
Example #18
Source File: ODocumentTextChoiceProvider.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
public void query(String term, int page, Response<ODocument> response) {
    OSchema schema = OrienteerWebApplication.lookupApplication().getDatabase().getMetadata().getSchema();
    if (classNamesModel.getObject() != null && !classNamesModel.getObject().isEmpty()) {
        for (String className : classNamesModel.getObject()) {
            OClass oClass = schema.getClass(className);
            if (oClass != null) {
                OQueryModel<ODocument> queryModel = new OQueryModel<>("SELECT FROM " + className);
                String nameProperty = getOClassIntrospector().getNameProperty(oClass).getName();
                IFilterCriteriaManager manager = new FilterCriteriaManager(
                        new OPropertyModel(getOClassIntrospector().getNameProperty(oClass)));
                manager.addFilterCriteria(manager.createContainsStringFilterCriteria(Model.of(term), Model.of(true)));
                queryModel.addFilterCriteriaManager(nameProperty, manager);
                response.addAll(queryModel.getObject());
            }
        }
    }
}
 
Example #19
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 #20
Source File: LuceneInsertUpdateSingleDocumentTransactionTest.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@Test
public void testInsertUpdateTransactionWithIndex() throws Exception {

  databaseDocumentTx.close();
  databaseDocumentTx.open("admin", "admin");
  OSchema schema = databaseDocumentTx.getMetadata().getSchema();
  schema.reload();
  databaseDocumentTx.begin();
  ODocument doc = new ODocument("City");
  doc.field("name", "");
  ODocument doc1 = new ODocument("City");
  doc1.field("name", "");
  doc = databaseDocumentTx.save(doc);
  doc1 = databaseDocumentTx.save(doc1);
  databaseDocumentTx.commit();
  databaseDocumentTx.begin();
  doc = databaseDocumentTx.load(doc);
  doc1 = databaseDocumentTx.load(doc1);
  doc.field("name", "Rome");
  doc1.field("name", "Rome");
  databaseDocumentTx.save(doc);
  databaseDocumentTx.save(doc1);
  databaseDocumentTx.commit();
  OIndex idx = schema.getClass("City").getClassIndex("City.name");
  Collection<?> coll = (Collection<?>) idx.get("Rome");
  Assert.assertEquals(coll.size(), 2);
  Assert.assertEquals(idx.getSize(), 2);
}
 
Example #21
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 #22
Source File: LuceneCreateIndexTest.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@BeforeClass
@Override
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);
}
 
Example #23
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 #24
Source File: ODocumentAliasRepository.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public static List<Pair<String, OClass>> getAliasClasses(ODatabaseDocument db) {
    String sql = "select name from (select expand(classes) from metadata:schema) where customFields containsKey ?";
    List<ODocument> result = db.query(new OSQLSynchQuery<>(sql), PagesModule.ALIAS.getName(), PagesModule.ALIAS.getName());

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

    return result.stream()
            .map(d -> (String) d.field("name"))
            .map(schema::getClass)
            .map(oClass -> Pair.of((String) PagesModule.ALIAS.getValue(oClass), oClass))
            .collect(Collectors.toCollection(LinkedList::new));
}
 
Example #25
Source File: ContentStore.java    From jbake with MIT License 5 votes vote down vote up
private void createDocType(final OSchema schema, final String docType) {
    logger.debug("Create document class '{}'", docType);


    OClass page = schema.createClass(docType);

    // Primary key
    String attribName = DocumentAttributes.SOURCE_URI.toString();
    page.createProperty(attribName, OType.STRING).setNotNull(true);
    page.createIndex(docType + "sourceUriIndex", OClass.INDEX_TYPE.UNIQUE, attribName);

    attribName = DocumentAttributes.SHA1.toString();
    page.createProperty(attribName, OType.STRING).setNotNull(true);
    page.createIndex(docType + "sha1Index", OClass.INDEX_TYPE.NOTUNIQUE, attribName);

    attribName = DocumentAttributes.CACHED.toString();
    page.createProperty(attribName, OType.BOOLEAN).setNotNull(true);
    page.createIndex(docType + "cachedIndex", OClass.INDEX_TYPE.NOTUNIQUE, attribName);

    attribName = DocumentAttributes.RENDERED.toString();
    page.createProperty(attribName, OType.BOOLEAN).setNotNull(true);
    page.createIndex(docType + "renderedIndex", OClass.INDEX_TYPE.NOTUNIQUE, attribName);

    attribName = DocumentAttributes.STATUS.toString();
    page.createProperty(attribName, OType.STRING).setNotNull(true);
    page.createIndex(docType + "statusIndex", OClass.INDEX_TYPE.NOTUNIQUE, attribName);
}
 
Example #26
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 #27
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 #28
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 #29
Source File: TestInAppOrientDBCompatibility.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore
public void testSerialization() throws Exception
{
	ODatabaseDocument db = wicket.getTester().getDatabase();
	OSchema schema = db.getMetadata().getSchema();
	OClass classA = schema.createClass("SerA");
	OClass classB = schema.createClass("SerB");
	
	classA.createProperty("name", OType.STRING);
	classB.createProperty("name", OType.STRING);
	classA.createProperty("child", OType.LINKLIST, classB);
	classB.createProperty("parent", OType.LINK, classA);
	
	ODocument docA = new ODocument(classA);
	docA.field("name", "Doc A");
	doSerialization(docA);
	assertEquals(0, db.countClass(docA.getClassName()));
	ODocument docB = new ODocument(classB);
	docB.field("name", "Doc B");
	doSerialization(docB);
	assertEquals(0, db.countClass(docB.getClassName()));
	docA.field("child", Arrays.asList(docB));
	doSerialization(docA);
	assertEquals(0, db.countClass(docA.getClassName()));
	assertEquals(0, db.countClass(docB.getClassName()));
	doSerialization(docB);
	assertEquals(0, db.countClass(docA.getClassName()));
	assertEquals(0, db.countClass(docB.getClassName()));
	docB.field("parent", Arrays.asList(docA));
	doSerialization(docA);
	assertEquals(0, db.countClass(docA.getClassName()));
	assertEquals(0, db.countClass(docB.getClassName()));
	doSerialization(docB);
	assertEquals(0, db.countClass(docA.getClassName()));
	assertEquals(0, db.countClass(docB.getClassName()));
}
 
Example #30
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);
        }
    }