Search in sources :

Example 46 with ODatabaseDocument

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

the class ODocumentValidationTest method testRegExpValidation.

@Test
public void testRegExpValidation() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + ODocumentValidationTest.class.getSimpleName());
    db.create();
    try {
        OClass clazz = db.getMetadata().getSchema().createClass("Validation");
        clazz.createProperty("string", OType.STRING).setRegexp("[^Z]*");
        ODocument d = new ODocument(clazz);
        d.field("string", "yeah");
        d.validate();
        checkField(d, "string", "yaZah");
    } finally {
        db.drop();
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Test(org.testng.annotations.Test)

Example 47 with ODatabaseDocument

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

the class ODocumentValidationTest method testValidLinkCollectionsUpdate.

@Test
public void testValidLinkCollectionsUpdate() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + ODocumentValidationTest.class.getSimpleName());
    db.create();
    try {
        OClass clazz = db.getMetadata().getSchema().createClass("Validation");
        OClass clazz1 = db.getMetadata().getSchema().createClass("Validation1");
        clazz.createProperty("linkList", OType.LINKLIST).setLinkedClass(clazz1);
        clazz.createProperty("linkSet", OType.LINKSET).setLinkedClass(clazz1);
        clazz.createProperty("linkMap", OType.LINKMAP).setLinkedClass(clazz1);
        clazz.createProperty("linkBag", OType.LINKBAG).setLinkedClass(clazz1);
        ODocument d = new ODocument(clazz);
        d.field("link", new ODocument(clazz1));
        d.field("embedded", new ODocument(clazz1));
        List<ODocument> list = Arrays.asList(new ODocument(clazz1));
        d.field("linkList", list);
        Set<ODocument> set = new HashSet<ODocument>(list);
        d.field("linkSet", set);
        d.field("linkBag", new ORidBag());
        Map<String, ODocument> map = new HashMap<String, ODocument>();
        map.put("a", new ODocument(clazz1));
        d.field("linkMap", map);
        db.save(d);
        try {
            ODocument newD = d.copy();
            ((Collection) newD.field("linkList")).add(new ODocument(clazz));
            newD.validate();
            AssertJUnit.fail();
        } catch (OValidationException v) {
        }
        try {
            ODocument newD = d.copy();
            ((Collection) newD.field("linkSet")).add(new ODocument(clazz));
            newD.validate();
            AssertJUnit.fail();
        } catch (OValidationException v) {
        }
        try {
            ODocument newD = d.copy();
            ((ORidBag) newD.field("linkBag")).add(new ODocument(clazz));
            newD.validate();
            AssertJUnit.fail();
        } catch (OValidationException v) {
        }
        try {
            ODocument newD = d.copy();
            ((Map<String, ODocument>) newD.field("linkMap")).put("a", new ODocument(clazz));
            newD.validate();
            AssertJUnit.fail();
        } catch (OValidationException v) {
        }
    } finally {
        db.drop();
    }
}
Also used : OValidationException(com.orientechnologies.orient.core.exception.OValidationException) ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.testng.annotations.Test)

Example 48 with ODatabaseDocument

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

the class ODocumentValidationTest method testRequiredValidation.

@Test
public void testRequiredValidation() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + ODocumentValidationTest.class.getSimpleName());
    db.create();
    try {
        ODocument doc = new ODocument();
        OIdentifiable id = db.save(doc).getIdentity();
        OClass embeddedClazz = db.getMetadata().getSchema().createClass("EmbeddedValidation");
        embeddedClazz.createProperty("int", OType.INTEGER).setMandatory(true);
        OClass clazz = db.getMetadata().getSchema().createClass("Validation");
        clazz.createProperty("int", OType.INTEGER).setMandatory(true);
        clazz.createProperty("long", OType.LONG).setMandatory(true);
        clazz.createProperty("float", OType.FLOAT).setMandatory(true);
        clazz.createProperty("boolean", OType.BOOLEAN).setMandatory(true);
        clazz.createProperty("binary", OType.BINARY).setMandatory(true);
        clazz.createProperty("byte", OType.BYTE).setMandatory(true);
        clazz.createProperty("date", OType.DATE).setMandatory(true);
        clazz.createProperty("datetime", OType.DATETIME).setMandatory(true);
        clazz.createProperty("decimal", OType.DECIMAL).setMandatory(true);
        clazz.createProperty("double", OType.DOUBLE).setMandatory(true);
        clazz.createProperty("short", OType.SHORT).setMandatory(true);
        clazz.createProperty("string", OType.STRING).setMandatory(true);
        clazz.createProperty("link", OType.LINK).setMandatory(true);
        clazz.createProperty("embedded", OType.EMBEDDED, embeddedClazz).setMandatory(true);
        clazz.createProperty("embeddedListNoClass", OType.EMBEDDEDLIST).setMandatory(true);
        clazz.createProperty("embeddedSetNoClass", OType.EMBEDDEDSET).setMandatory(true);
        clazz.createProperty("embeddedMapNoClass", OType.EMBEDDEDMAP).setMandatory(true);
        clazz.createProperty("embeddedList", OType.EMBEDDEDLIST, embeddedClazz).setMandatory(true);
        clazz.createProperty("embeddedSet", OType.EMBEDDEDSET, embeddedClazz).setMandatory(true);
        clazz.createProperty("embeddedMap", OType.EMBEDDEDMAP, embeddedClazz).setMandatory(true);
        clazz.createProperty("linkList", OType.LINKLIST).setMandatory(true);
        clazz.createProperty("linkSet", OType.LINKSET).setMandatory(true);
        clazz.createProperty("linkMap", OType.LINKMAP).setMandatory(true);
        ODocument d = new ODocument(clazz);
        d.field("int", 10);
        d.field("long", 10);
        d.field("float", 10);
        d.field("boolean", 10);
        d.field("binary", new byte[] {});
        d.field("byte", 10);
        d.field("date", new Date());
        d.field("datetime", new Date());
        d.field("decimal", 10);
        d.field("double", 10);
        d.field("short", 10);
        d.field("string", "yeah");
        d.field("link", id);
        d.field("linkList", new ArrayList<ORecordId>());
        d.field("linkSet", new HashSet<ORecordId>());
        d.field("linkMap", new HashMap<String, ORecordId>());
        d.field("embeddedListNoClass", new ArrayList<ORecordId>());
        d.field("embeddedSetNoClass", new HashSet<ORecordId>());
        d.field("embeddedMapNoClass", new HashMap<String, ORecordId>());
        ODocument embedded = new ODocument("EmbeddedValidation");
        embedded.field("int", 20);
        embedded.field("long", 20);
        d.field("embedded", embedded);
        ODocument embeddedInList = new ODocument("EmbeddedValidation");
        embeddedInList.field("int", 30);
        embeddedInList.field("long", 30);
        final ArrayList<ODocument> embeddedList = new ArrayList<ODocument>();
        embeddedList.add(embeddedInList);
        d.field("embeddedList", embeddedList);
        ODocument embeddedInSet = new ODocument("EmbeddedValidation");
        embeddedInSet.field("int", 30);
        embeddedInSet.field("long", 30);
        final Set<ODocument> embeddedSet = new HashSet<ODocument>();
        embeddedSet.add(embeddedInSet);
        d.field("embeddedSet", embeddedSet);
        ODocument embeddedInMap = new ODocument("EmbeddedValidation");
        embeddedInMap.field("int", 30);
        embeddedInMap.field("long", 30);
        final Map<String, ODocument> embeddedMap = new HashMap<String, ODocument>();
        embeddedMap.put("testEmbedded", embeddedInMap);
        d.field("embeddedMap", embeddedMap);
        d.validate();
        checkRequireField(d, "int");
        checkRequireField(d, "long");
        checkRequireField(d, "float");
        checkRequireField(d, "boolean");
        checkRequireField(d, "binary");
        checkRequireField(d, "byte");
        checkRequireField(d, "date");
        checkRequireField(d, "datetime");
        checkRequireField(d, "decimal");
        checkRequireField(d, "double");
        checkRequireField(d, "short");
        checkRequireField(d, "string");
        checkRequireField(d, "link");
        checkRequireField(d, "embedded");
        checkRequireField(d, "embeddedList");
        checkRequireField(d, "embeddedSet");
        checkRequireField(d, "embeddedMap");
        checkRequireField(d, "linkList");
        checkRequireField(d, "linkSet");
        checkRequireField(d, "linkMap");
    } finally {
        db.drop();
    }
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.testng.annotations.Test)

Example 49 with ODatabaseDocument

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

the class OEmbeddedRidBagBasicTest method embeddedRidBagSerializationTest.

@Test
public void embeddedRidBagSerializationTest() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + OEmbeddedRidBag.class.getSimpleName());
    db.create();
    try {
        OEmbeddedRidBag bag = new OEmbeddedRidBag();
        bag.add(new ORecordId(3, 1000));
        bag.convertLinks2Records();
        bag.convertRecords2Links();
        byte[] bytes = new byte[1024];
        UUID id = UUID.randomUUID();
        bag.serialize(bytes, 0, id);
        OEmbeddedRidBag bag1 = new OEmbeddedRidBag();
        bag1.deserialize(bytes, 0);
        assertEquals(bag.size(), 1);
        assertEquals(null, bag1.iterator().next());
    } finally {
        db.drop();
    }
}
Also used : OEmbeddedRidBag(com.orientechnologies.orient.core.db.record.ridbag.embedded.OEmbeddedRidBag) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) UUID(java.util.UUID) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test)

Example 50 with ODatabaseDocument

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

the class OServerCommandGetGephi method execute.

@Override
public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
    String[] urlParts = checkSyntax(iRequest.url, 4, "Syntax error: gephi/<database>/<language>/<query-text>[/<limit>][/<fetchPlan>].<br>Limit is optional and is setted to 20 by default. Set expressely to 0 to have no limits.");
    final String language = urlParts[2];
    final String text = urlParts[3];
    final int limit = urlParts.length > 4 ? Integer.parseInt(urlParts[4]) : 20;
    final String fetchPlan = urlParts.length > 5 ? urlParts[5] : null;
    iRequest.data.commandInfo = "Gephi";
    iRequest.data.commandDetail = text;
    final ODatabaseDocument db = getProfiledDatabaseInstance(iRequest);
    final OModifiableBoolean shutdownFlag = new OModifiableBoolean();
    final OrientBaseGraph graph = OGraphCommandExecutorSQLFactory.getAnyGraph(shutdownFlag);
    try {
        final Iterable<OrientElement> vertices;
        if (language.equals("sql"))
            vertices = graph.command(new OSQLSynchQuery<OrientVertex>(text, limit).setFetchPlan(fetchPlan)).execute();
        else if (language.equals("gremlin")) {
            List<Object> result = new ArrayList<Object>();
            OGremlinHelper.execute(graph, text, null, null, result, null, null);
            vertices = new ArrayList<OrientElement>(result.size());
            for (Object o : result) {
                ((ArrayList<OrientElement>) vertices).add(graph.getVertex(o));
            }
        } else
            throw new IllegalArgumentException("Language '" + language + "' is not supported. Use 'sql' or 'gremlin'");
        sendRecordsContent(iRequest, iResponse, vertices, fetchPlan);
    } finally {
        if (graph != null && shutdownFlag.getValue())
            graph.shutdown(false, false);
        if (db != null)
            db.close();
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) OrientElement(com.tinkerpop.blueprints.impls.orient.OrientElement) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ArrayList(java.util.ArrayList) List(java.util.List) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean)

Aggregations

ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)187 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)81 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)68 Test (org.testng.annotations.Test)53 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)47 ORecordId (com.orientechnologies.orient.core.id.ORecordId)23 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)17 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)16 ORecord (com.orientechnologies.orient.core.record.ORecord)14 Test (org.junit.Test)14 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)12 ORID (com.orientechnologies.orient.core.id.ORID)11 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)10 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)9 OValidationException (com.orientechnologies.orient.core.exception.OValidationException)9 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)9 ArrayList (java.util.ArrayList)9 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)8 HashSet (java.util.HashSet)8