Search in sources :

Example 26 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class OCommandExecutorSQLCreatePropertyTest method testBasicCreateProperty.

@Test
public void testBasicCreateProperty() throws Exception {
    final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OCommandExecutorSQLCreatePropertyTest" + System.nanoTime());
    db.create();
    db.command(new OCommandSQL("CREATE class company")).execute();
    db.command(new OCommandSQL("CREATE property company.name STRING")).execute();
    OClass companyClass = db.getMetadata().getSchema().getClass("company");
    OProperty property = companyClass.getProperty(PROP_NAME);
    assertEquals(property.getName(), PROP_NAME);
    assertEquals(property.getFullName(), PROP_FULL_NAME);
    assertEquals(property.getType(), OType.STRING);
    assertFalse(property.isMandatory());
    assertFalse(property.isNotNull());
    assertFalse(property.isReadonly());
    db.close();
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Test(org.testng.annotations.Test)

Example 27 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class OCommandExecutorSQLCreatePropertyTest method testLowerCase.

@Test
public void testLowerCase() throws Exception {
    final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OCommandExecutorSQLCreatePropertyTest" + System.nanoTime());
    db.create();
    db.command(new OCommandSQL("CREATE class division")).execute();
    db.command(new OCommandSQL("CREATE class company")).execute();
    db.command(new OCommandSQL("CREATE property company.division LINK division (mandatory, readonly, notnull, default 3, min 4, max 5, collate ci) unsafe")).execute();
    OClass companyClass = db.getMetadata().getSchema().getClass("company");
    OProperty property = companyClass.getProperty(PROP_DIVISION);
    assertEquals(property.getName(), PROP_DIVISION);
    assertEquals(property.getFullName(), PROP_FULL_DIVISION);
    assertEquals(property.getType(), OType.LINK);
    assertEquals(property.getLinkedClass().getName(), "division");
    assertTrue(property.isMandatory());
    assertTrue(property.isNotNull());
    assertTrue(property.isReadonly());
    assertEquals(property.getDefaultValue(), "3");
    assertEquals(property.getMin(), "4");
    assertEquals(property.getMax(), "5");
    assertEquals(property.getCollate().getName(), "ci");
    db.close();
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Test(org.testng.annotations.Test)

Example 28 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class OCommandExecutorSQLDropPropertyTest method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    db = new ODatabaseDocumentTx(DB_STORAGE + ":" + DB_NAME);
    db.create();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) BeforeClass(org.testng.annotations.BeforeClass)

Example 29 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class OCommandExecutorSQLCreateClassTest method init.

@BeforeClass
public static void init() throws Exception {
    db = new ODatabaseDocumentTx("memory:" + OCommandExecutorSQLCreateClassTest.class.getSimpleName());
    if (db.exists()) {
        db.open("admin", "admin");
        db.drop();
    }
    db.create();
    final OSchema schema = db.getMetadata().getSchema();
    schema.createClass("User", schema.getClass("V"));
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)

Example 30 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class ORecordSerializerBinaryDebugTest method testSimpleBrokenDocumentDebug.

@Test
public void testSimpleBrokenDocumentDebug() {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + ORecordSerializerBinaryDebugTest.class.getSimpleName());
    db.create();
    try {
        ODocument doc = new ODocument();
        doc.field("test", "test");
        doc.field("anInt", 2);
        doc.field("anDouble", 2D);
        byte[] bytes = doc.toStream();
        byte[] brokenBytes = new byte[bytes.length - 10];
        System.arraycopy(bytes, 0, brokenBytes, 0, bytes.length - 10);
        ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug();
        ORecordSerializationDebug debug = debugger.deserializeDebug(brokenBytes, db);
        assertEquals(debug.properties.size(), 3);
        assertEquals(debug.properties.get(0).name, "test");
        assertEquals(debug.properties.get(0).type, OType.STRING);
        assertEquals(debug.properties.get(0).faildToRead, true);
        assertNotNull(debug.properties.get(0).readingException);
        assertEquals(debug.properties.get(1).name, "anInt");
        assertEquals(debug.properties.get(1).type, OType.INTEGER);
        assertEquals(debug.properties.get(1).faildToRead, true);
        assertNotNull(debug.properties.get(1).readingException);
        assertEquals(debug.properties.get(2).name, "anDouble");
        assertEquals(debug.properties.get(2).type, OType.DOUBLE);
        assertEquals(debug.properties.get(2).faildToRead, true);
        assertNotNull(debug.properties.get(2).readingException);
    } finally {
        db.drop();
    }
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ORecordSerializationDebug(com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializationDebug) ORecordSerializerBinaryDebug(com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryDebug) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)590 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)257 Test (org.testng.annotations.Test)182 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)120 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)81 Test (org.junit.Test)79 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)61 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)47 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)46 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)41 ORID (com.orientechnologies.orient.core.id.ORID)39 ORecordId (com.orientechnologies.orient.core.id.ORecordId)34 Before (org.junit.Before)34 File (java.io.File)33 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)25 ArrayList (java.util.ArrayList)25 BeforeClass (org.testng.annotations.BeforeClass)23 BeforeMethod (org.testng.annotations.BeforeMethod)23 OStorage (com.orientechnologies.orient.core.storage.OStorage)21 List (java.util.List)20