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

The following examples show how to use com.orientechnologies.orient.core.metadata.schema.OClass#setClusterSelection() . 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: 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 2
Source File: TestPrototypers.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@Test
public void testOClassPrototyper() throws Exception
{
	OClass newClass = OClassPrototyper.newPrototype();
	assertNull(wicket.getTester().getSchema().getClass("NewClass"));
	newClass.setName("NewClass");
	assertEquals("NewClass", newClass.getName());
	newClass.setClusterSelection(ORoundRobinClusterSelectionStrategy.NAME);
	assertEquals(ORoundRobinClusterSelectionStrategy.NAME, newClass.getClusterSelection().getName());
	Collection<OProperty> properties = newClass.properties();
	assertNotNull(properties);
	assertTrue(properties.size()==0);
	properties = newClass.declaredProperties();
	assertNotNull(properties);
	assertTrue(properties.size()==0);
	assertFalse(newClass.hasSuperClasses());
	OClass oRoleClass = wicket.getTester().getSchema().getClass("ORole");
	newClass.addSuperClass(oRoleClass);
	assertTrue(newClass.hasSuperClasses());
	assertTrue(newClass.getSuperClassesNames().contains("ORole"));
	assertTrue(newClass.getSuperClasses().contains(oRoleClass));
	assertTrue(newClass.isSubClassOf(oRoleClass));
	newClass.removeSuperClass(oRoleClass);
	assertFalse(newClass.hasSuperClasses());
	assertFalse(newClass.isSubClassOf(oRoleClass));
	//Realization
	assertTrue(newClass instanceof IPrototype); 
	OClass realizedNewClass = ((IPrototype<OClass>)newClass).realizePrototype();
	assertEquals(wicket.getTester().getSchema().getClass("NewClass"), realizedNewClass);
	assertFalse(realizedNewClass instanceof IPrototype);
	assertEquals("NewClass", realizedNewClass.getName());
	assertEquals(ORoundRobinClusterSelectionStrategy.NAME, realizedNewClass.getClusterSelection().getName());
	wicket.getTester().getSchema().dropClass(realizedNewClass.getName());
}
 
Example 3
Source File: OClassMetaPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
protected void setValue(OClass entity, String critery, V value) {
	ODatabaseDocument db = OrientDbWebSession.get().getDatabase();
	db.commit();
	try
	{
		CustomAttribute custom;
		if(OClassPrototyper.CLUSTER_SELECTION.equals(critery))
		{
			if(value!=null) entity.setClusterSelection(value.toString());
		}
		else if((CustomAttribute.ON_CREATE_FIELDS.getName().equals(critery)) && (custom = CustomAttribute.getIfExists(critery)) != null)
		{
			custom.setValue(entity, value!=null?Joiner.on(",").join((List<String>) value):null);
		}
		else if((custom = CustomAttribute.getIfExists(critery))!=null)
		{
			custom.setValue(entity, value);
		}
		else if (OClassPrototyper.SUPER_CLASSES.equals(critery))
		{
			if(value!=null) entity.setSuperClasses((List<OClass>) value);
		}
		else
		{
			PropertyResolver.setValue(critery, entity, value, new PropertyResolverConverter(Application.get().getConverterLocator(),
					Session.get().getLocale()));
		}
	} finally
	{
		db.begin();
	}
}