use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ClassTest method testRename.
@Test
public void testRename() {
OSchema schema = db.getMetadata().getSchema();
OClass oClass = schema.createClass("ClassName");
final OStorage storage = db.getStorage();
final OAbstractPaginatedStorage paginatedStorage = (OAbstractPaginatedStorage) storage;
final OWriteCache writeCache = paginatedStorage.getWriteCache();
Assert.assertTrue(writeCache.exists("classname" + OPaginatedCluster.DEF_EXTENSION));
oClass.setName("ClassNameNew");
Assert.assertTrue(!writeCache.exists("classname" + OPaginatedCluster.DEF_EXTENSION));
Assert.assertTrue(writeCache.exists("classnamenew" + OPaginatedCluster.DEF_EXTENSION));
oClass.setName("ClassName");
Assert.assertTrue(!writeCache.exists("classnamenew" + OPaginatedCluster.DEF_EXTENSION));
Assert.assertTrue(writeCache.exists("classname" + OPaginatedCluster.DEF_EXTENSION));
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ClassTest method testOClassAndOPropertyDescription.
@Test
public void testOClassAndOPropertyDescription() {
final OSchema oSchema = db.getMetadata().getSchema();
OClass oClass = oSchema.createClass("DescriptionTest");
OProperty oProperty = oClass.createProperty("property", OType.STRING);
oClass.setDescription("DescriptionTest-class-description");
oProperty.setDescription("DescriptionTest-property-description");
assertEquals(oClass.getDescription(), "DescriptionTest-class-description");
assertEquals(oProperty.getDescription(), "DescriptionTest-property-description");
oSchema.reload();
oClass = oSchema.getClass("DescriptionTest");
oProperty = oClass.getProperty("property");
assertEquals(oClass.getDescription(), "DescriptionTest-class-description");
assertEquals(oProperty.getDescription(), "DescriptionTest-property-description");
oClass = db.getMetadata().getImmutableSchemaSnapshot().getClass("DescriptionTest");
oProperty = oClass.getProperty("property");
assertEquals(oClass.getDescription(), "DescriptionTest-class-description");
assertEquals(oProperty.getDescription(), "DescriptionTest-property-description");
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ClassTest method testShortName.
@Test
public void testShortName() {
OSchema schema = db.getMetadata().getSchema();
OClass oClass = schema.createClass(SHORTNAME_CLASS_NAME);
Assert.assertNull(oClass.getShortName());
Assert.assertNull(queryShortName());
final OStorage storage = db.getStorage();
if (storage instanceof OAbstractPaginatedStorage) {
final OAbstractPaginatedStorage paginatedStorage = (OAbstractPaginatedStorage) storage;
final OWriteCache writeCache = paginatedStorage.getWriteCache();
Assert.assertTrue(writeCache.exists(SHORTNAME_CLASS_NAME.toLowerCase() + OPaginatedCluster.DEF_EXTENSION));
}
String shortName = "shortname";
oClass.setShortName(shortName);
Assert.assertEquals(shortName, oClass.getShortName());
Assert.assertEquals(shortName, queryShortName());
// FAILS, saves null value and stores "null" string (not null value) internally
shortName = "null";
oClass.setShortName(shortName);
Assert.assertEquals(shortName, oClass.getShortName());
Assert.assertEquals(shortName, queryShortName());
oClass.setShortName(null);
Assert.assertNull(oClass.getShortName());
Assert.assertNull(queryShortName());
oClass.setShortName("");
Assert.assertNull(oClass.getShortName());
Assert.assertNull(queryShortName());
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ClassTest method testRenameClusterAlreadyExists.
@Test
public void testRenameClusterAlreadyExists() {
OSchema schema = db.getMetadata().getSchema();
OClass classOne = schema.createClass("ClassOne");
OClass classTwo = schema.createClass("ClassTwo");
final int clusterId = db.addCluster("classthree");
classTwo.addClusterId(clusterId);
ODocument document = new ODocument("ClassTwo");
document.save("classthree");
document = new ODocument("ClassTwo");
document.save();
document = new ODocument("ClassOne");
document.save();
Assert.assertEquals(db.countClass("ClassTwo"), 2);
Assert.assertEquals(db.countClass("ClassOne"), 1);
classOne.setName("ClassThree");
final OStorage storage = db.getStorage();
final OAbstractPaginatedStorage paginatedStorage = (OAbstractPaginatedStorage) storage;
final OWriteCache writeCache = paginatedStorage.getWriteCache();
Assert.assertTrue(writeCache.exists("classone" + OPaginatedCluster.DEF_EXTENSION));
Assert.assertEquals(db.countClass("ClassTwo"), 2);
Assert.assertEquals(db.countClass("ClassThree"), 1);
classOne.setName("ClassOne");
Assert.assertTrue(writeCache.exists("classone" + OPaginatedCluster.DEF_EXTENSION));
Assert.assertEquals(db.countClass("ClassTwo"), 2);
Assert.assertEquals(db.countClass("ClassOne"), 1);
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ODocumentSchemafullSerializationTest method before.
@BeforeMethod
public void before() {
ODatabaseDocumentTx.setDefaultSerializer(serializer);
databaseDocument = new ODatabaseDocumentTx("memory:" + ODocumentSchemafullSerializationTest.class.getSimpleName()).create();
// databaseDocument.getMetadata().
OSchema schema = databaseDocument.getMetadata().getSchema();
address = schema.createClass("Address");
address.createProperty(NAME, OType.STRING);
address.createProperty(NUMBER, OType.INTEGER);
address.createProperty(CITY, OType.STRING);
simple = schema.createClass("Simple");
simple.createProperty(STRING_FIELD, OType.STRING);
simple.createProperty(INT_FIELD, OType.INTEGER);
simple.createProperty(SHORT_FIELD, OType.SHORT);
simple.createProperty(LONG_FIELD, OType.LONG);
simple.createProperty(FLOAT_NUMBER, OType.FLOAT);
simple.createProperty(DOUBLE_NUMBER, OType.DOUBLE);
simple.createProperty(BYTE_FIELD, OType.BYTE);
simple.createProperty(BOOLEAN_FIELD, OType.BOOLEAN);
simple.createProperty(DATE_FIELD, OType.DATETIME);
simple.createProperty(RECORDID_FIELD, OType.LINK);
simple.createProperty(EMBEDDED_FIELD, OType.EMBEDDED, address);
simple.createProperty(ANY_FIELD, OType.ANY);
embSimp = schema.createClass("EmbeddedCollectionSimple");
embSimp.createProperty(LIST_BOOLEANS, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_BYTES, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_DATES, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_DOUBLES, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_FLOATS, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_INTEGERS, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_LONGS, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_SHORTS, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_STRINGS, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_MIXED, OType.EMBEDDEDLIST);
embMapSimple = schema.createClass("EmbeddedMapSimple");
embMapSimple.createProperty(MAP_BYTES, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_DATE, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_DOUBLE, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_FLOAT, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_INT, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_LONG, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_SHORT, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_STRING, OType.EMBEDDEDMAP);
OClass clazzEmbComp = schema.createClass("EmbeddedComplex");
clazzEmbComp.createProperty("addresses", OType.EMBEDDEDLIST, address);
clazzEmbComp.createProperty("uniqueAddresses", OType.EMBEDDEDSET, address);
clazzEmbComp.createProperty("addressByStreet", OType.EMBEDDEDMAP, address);
}
Aggregations