Java Code Examples for com.orientechnologies.orient.core.metadata.schema.OClass#createProperty()

The following examples show how to use com.orientechnologies.orient.core.metadata.schema.OClass#createProperty() . 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: TestModels.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testOPropertyModel()
{
	OProperty userNameProperty = wicket.getTester().getSchema().getClass("OUser").getProperty("name");
	OPropertyModel propertyModel = new OPropertyModel("OUser", "name");
	assertModelObjectEquals(userNameProperty, propertyModel);
	//Test for null
	propertyModel.setObject(null);
	assertModelObjectEquals(null, propertyModel);
	//Test for classRename
	OClass newClass = wicket.getTester().getSchema().createClass("TestRenameOProperty");
	OProperty property = newClass.createProperty("newProperty", OType.STRING);
	propertyModel.setObject(property);
	assertModelObjectEquals(property, propertyModel);
	property.setName("newProperty2");
	assertModelObjectEquals(property, propertyModel);
}
 
Example 2
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 3
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 4
Source File: OrientConfigurationEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void defineType(final OClass type) {
  type.createProperty(P_REPOSITORY_NAME, OType.STRING)
      .setCollate(new OCaseInsensitiveCollate())
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_RECIPE_NAME, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_ROUTING_RULE_ID, OType.LINK);
  type.createProperty(P_ONLINE, OType.BOOLEAN)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_ATTRIBUTES, OType.EMBEDDEDMAP);
  type.createIndex(I_REPOSITORY_NAME, INDEX_TYPE.UNIQUE, P_REPOSITORY_NAME);
}
 
Example 5
Source File: WicketOrientDbFilterTesterScope.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
private OClass createOClass(ODatabaseDocument db, String className, boolean complexTypes) {
    OClass oClass = db.getMetadata().getSchema().createClass(className);
    oClass.createProperty(STRING_FIELD, OType.STRING);
    oClass.createProperty(NUMBER_FIELD, OType.INTEGER);
    oClass.createProperty(DATE_FIELD, OType.DATE);
    oClass.createProperty(DATETIME_FIELD, OType.DATETIME);
    if (complexTypes) {
        oClass.createProperty(LINK_FIELD, OType.LINK);
        oClass.createProperty(LINK_LIST_FIELD, OType.LINKLIST);
        oClass.createProperty(LINK_SET_FIELD, OType.LINKSET);
        oClass.createProperty(LINK_MAP_FIELD, OType.LINKMAP);
        oClass.createProperty(EMBEDDED_FIELD, OType.EMBEDDED);
        oClass.createProperty(EMBEDDED_LIST_FIELD, OType.EMBEDDEDLIST);
        oClass.createProperty(EMBEDDED_SET_FIELD, OType.EMBEDDEDSET);
        oClass.createProperty(EMBEDDED_MAP_FIELD, OType.EMBEDDEDMAP);
        oClass.createProperty(EMBEDDED_LIST_STRING_FIELD, OType.EMBEDDEDLIST);
        oClass.createProperty(EMBEDDED_SET_STRING_FIELD, OType.EMBEDDEDSET);
    }
    initPropertiesMap(oClass.propertiesMap());
    db.commit();
    return oClass;
}
 
Example 6
Source File: ApplyEditorChangesBehavior.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
private void addPropertiesToOClass(OSchema schema, OClass oClass, List<OArchitectOProperty> properties) {
    for (OArchitectOProperty property : properties) {
        if (!property.isSubClassProperty()) {
            OProperty oProperty = oClass.getProperty(property.getName());
            if (oProperty == null && !property.isExistsInDb()) {
                oProperty = oClass.createProperty(property.getName(), property.getType());
            } else if (oProperty != null && !property.isExistsInDb() && oProperty.getType() != property.getType()) {
                oProperty.setType(property.getType());
            }
            if (!Strings.isNullOrEmpty(property.getLinkedClass())) {
                setLinkedClassForProperty(property, oProperty, schema);
            }
            CustomAttribute.ORDER.setValue(oProperty, property.getOrder());
        }
    }
}
 
Example 7
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 8
Source File: TestPrototypers.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@Test
public void testOPropertyPrototyper() throws Exception
{
	OClass newClass = wicket.getTester().getSchema().createClass("NewClass");
	OProperty toCompare = newClass.createProperty("toCompare", OType.STRING);
	try
	{
		OProperty newProperty = OPropertyPrototyper.newPrototype("NewClass");
		assertNull(newClass.getProperty("newProperty"));
		newProperty.setName("newProperty");
		assertEquals("newProperty", newProperty.getName());
		assertNull(newClass.getProperty("newProperty"));
		assertEquals("NewClass.newProperty", newProperty.getFullName());
		newProperty.setType(OType.STRING);
		assertEquals(OType.STRING, newProperty.getType());
		newProperty.setCustom("myCustom", "myCustomValue");
		assertEquals("myCustomValue", newProperty.getCustom("myCustom"));
		assertTrue(newProperty.compareTo(toCompare)<0);
		
		//Realization
		assertTrue(newProperty instanceof IPrototype);
		OProperty realizedNewProperty = ((IPrototype<OProperty>)newProperty).realizePrototype();
		assertEquals(newClass.getProperty("newProperty"), realizedNewProperty);
		assertEquals("myCustomValue", realizedNewProperty.getCustom("myCustom"));
	}
	finally
	{
		//Drop
		wicket.getTester().getSchema().dropClass(newClass.getName());
	}
}
 
Example 9
Source File: OrientCUserEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void defineType(final OClass type) {
  type.createProperty(P_ID, OType.STRING)
      .setNotNull(true);
  type.createProperty(P_FIRST_NAME, OType.STRING);
  type.createProperty(P_LAST_NAME, OType.STRING);
  type.createProperty(P_PASSWORD, OType.STRING)
      .setNotNull(true);
  type.createProperty(P_STATUS, OType.STRING)
      .setNotNull(true);
  type.createProperty(P_EMAIL, OType.STRING)
      .setNotNull(true);

  type.createIndex(I_ID, INDEX_TYPE.UNIQUE, P_ID);
}
 
Example 10
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 11
Source File: OrientSelectorConfigurationEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void defineType(final OClass type) {
  type.createProperty(P_NAME, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_TYPE, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_DESCRIPTION, OType.STRING);
  type.createProperty(P_ATTRIBUTES, OType.EMBEDDEDMAP)
      .setMandatory(true)
      .setNotNull(true);
  type.createIndex(I_NAME, INDEX_TYPE.UNIQUE, P_NAME);
}
 
Example 12
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 13
Source File: AssetEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void defineType(final ODatabaseDocumentTx db, final OClass type) {
  super.defineType(type);
  type.createProperty(P_COMPONENT, OType.LINK, componentEntityAdapter.getSchemaType());
  type.createProperty(P_NAME, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_SIZE, OType.LONG);
  type.createProperty(P_CONTENT_TYPE, OType.STRING);
  type.createProperty(P_BLOB_REF, OType.STRING);
  type.createProperty(P_LAST_DOWNLOADED, OType.DATETIME);
  type.createProperty(P_BLOB_CREATED, OType.DATETIME);
  type.createProperty(P_BLOB_UPDATED, OType.DATETIME);
  type.createProperty(P_CREATED_BY, OType.STRING);
  type.createProperty(P_CREATED_BY_IP, OType.STRING);

  ODocument metadata = db.newInstance()
      .field("ignoreNullValues", false)
      .field("mergeKeys", false);
  type.createIndex(I_BUCKET_COMPONENT_NAME, INDEX_TYPE.UNIQUE.name(), null, metadata,
      new String[]{P_BUCKET, P_COMPONENT, P_NAME}
  );
  type.createIndex(I_BUCKET_NAME, INDEX_TYPE.NOTUNIQUE, P_BUCKET, P_NAME);
  type.createIndex(I_COMPONENT, INDEX_TYPE.NOTUNIQUE, P_COMPONENT);

  new OIndexBuilder(type, I_NAME_CASEINSENSITIVE, INDEX_TYPE.NOTUNIQUE)
      .property(P_NAME, OType.STRING)
      .caseInsensitive()
      .build(db);
}
 
Example 14
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 15
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 16
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 17
Source File: ComponentDatabaseUpgrade_1_3.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private void maybeCreateProperty(final OClass oClass, final String property, final OType oType) {
  if (!oClass.existsProperty(property)) {
    oClass.createProperty(property, oType);
  }
}
 
Example 18
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();
}
 
Example 19
Source File: DeconflictStepTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void defineType(OClass type) {
  type.createProperty("text", OType.STRING);
  type.createProperty("time", OType.DATETIME);
}
 
Example 20
Source File: OrientRealmConfigurationEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void defineType(final OClass type) {
  type.createProperty(P_REALM_NAMES, OType.EMBEDDEDLIST);
}