Search in sources :

Example 31 with OSchema

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));
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OStorage(com.orientechnologies.orient.core.storage.OStorage) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) Test(org.testng.annotations.Test)

Example 32 with OSchema

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");
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.testng.annotations.Test)

Example 33 with OSchema

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());
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OStorage(com.orientechnologies.orient.core.storage.OStorage) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) Test(org.testng.annotations.Test)

Example 34 with OSchema

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);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OStorage(com.orientechnologies.orient.core.storage.OStorage) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 35 with OSchema

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);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)203 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)165 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)122 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)54 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)46 Test (org.testng.annotations.Test)35 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)31 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)23 Test (org.junit.Test)19 Before (org.junit.Before)16 ORID (com.orientechnologies.orient.core.id.ORID)15 OIndex (com.orientechnologies.orient.core.index.OIndex)15 Collection (java.util.Collection)15 Set (java.util.Set)15 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)9 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)9 BeforeClass (org.testng.annotations.BeforeClass)9 OStorage (com.orientechnologies.orient.core.storage.OStorage)6 ArrayList (java.util.ArrayList)5 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)4