Java Code Examples for com.orientechnologies.orient.core.metadata.schema.OProperty#setName()

The following examples show how to use com.orientechnologies.orient.core.metadata.schema.OProperty#setName() . 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 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 3
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 4
Source File: OClassIntrospector.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public OProperty virtualizeField(ODocument doc, String field) {
	OProperty property = OPropertyPrototyper.newPrototype(doc.getClassName());
	property.setName(field);
	OType oType = doc.fieldType(field);
	if(oType==null) oType=OType.ANY;
	property.setType(oType);
	switch (oType) {
		case LINK:
			OIdentifiable link = doc.field(field);
			if(link!=null && link instanceof ODocument) property.setLinkedClass(((ODocument)link).getSchemaClass());
			break;
		case LINKBAG:
			OCollection<OIdentifiable> bag = doc.field(field);
			if(bag!=null && bag.size()>0) {
				OIdentifiable linkIdentifiable = bag.iterator().next();
				ORecord record = linkIdentifiable!=null?linkIdentifiable.getRecord():null;
				if(record!=null && record instanceof ODocument) property.setLinkedClass(((ODocument)record).getSchemaClass());
			}
			break;
		case LINKLIST:
		case LINKSET:
			Collection<ODocument> collection = doc.field(field);
			if(collection!=null && !collection.isEmpty()) {
				link = collection.iterator().next();
				if(link!=null && link instanceof ODocument) property.setLinkedClass(((ODocument)link).getSchemaClass());
			}
			break;
		case LINKMAP:
			Map<String, ODocument> map = doc.field(field);
			if(map!=null && !map.isEmpty()) {
				link = map.values().iterator().next();
				if(link!=null && link instanceof ODocument) property.setLinkedClass(((ODocument)link).getSchemaClass());
			}
			break;
		case EMBEDDED:
			Object value = doc.field(field);
			OType linkedType = OType.getTypeByValue(value);
			if(OType.EMBEDDED.equals(linkedType)) property.setLinkedClass(((ODocument)value).getSchemaClass());
			else property.setLinkedType(linkedType);
			break;
		case EMBEDDEDSET:
		case EMBEDDEDLIST:
			Collection<Object> objectCollection = doc.field(field);
			if(objectCollection!=null && !objectCollection.isEmpty()) {
				value = objectCollection.iterator().next();
				property.setLinkedType(OType.getTypeByValue(value));
			}
			break;
		case EMBEDDEDMAP:
			Map<String, Object> objectMap = doc.field(field);
			if(objectMap!=null && !objectMap.isEmpty()) {
				value = objectMap.values().iterator().next();
				property.setLinkedType(OType.getTypeByValue(value));
			}
			break;
		default:
			break;
	}
	return property;
}