Search in sources :

Example 76 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class OServerCommandGetDatabase method exportClass.

public static void exportClass(final ODatabaseDocument db, final OJSONWriter json, final OClass cls) throws IOException {
    json.beginObject();
    json.writeAttribute("name", cls.getName());
    json.writeAttribute("superClass", cls.getSuperClass() != null ? cls.getSuperClass().getName() : "");
    json.beginCollection("superClasses");
    int i = 0;
    for (OClass oClass : cls.getSuperClasses()) {
        json.write((i > 0 ? "," : "") + "\"" + oClass.getName() + "\"");
        i++;
    }
    json.endCollection();
    json.writeAttribute("alias", cls.getShortName());
    json.writeAttribute("abstract", cls.isAbstract());
    json.writeAttribute("strictmode", cls.isStrictMode());
    json.writeAttribute("clusters", cls.getClusterIds());
    json.writeAttribute("defaultCluster", cls.getDefaultClusterId());
    json.writeAttribute("clusterSelection", cls.getClusterSelection().getName());
    if (cls instanceof OClassImpl) {
        final Map<String, String> custom = ((OClassImpl) cls).getCustomInternal();
        if (custom != null && !custom.isEmpty()) {
            json.writeAttribute("custom", custom);
        }
    }
    try {
        json.writeAttribute("records", db.countClass(cls.getName()));
    } catch (OSecurityAccessException e) {
        json.writeAttribute("records", "? (Unauthorized)");
    } catch (Exception e) {
        json.writeAttribute("records", "? (Error)");
    }
    if (cls.properties() != null && cls.properties().size() > 0) {
        json.beginCollection("properties");
        for (final OProperty prop : cls.properties()) {
            json.beginObject();
            json.writeAttribute("name", prop.getName());
            if (prop.getLinkedClass() != null)
                json.writeAttribute("linkedClass", prop.getLinkedClass().getName());
            if (prop.getLinkedType() != null)
                json.writeAttribute("linkedType", prop.getLinkedType().toString());
            json.writeAttribute("type", prop.getType().toString());
            json.writeAttribute("mandatory", prop.isMandatory());
            json.writeAttribute("readonly", prop.isReadonly());
            json.writeAttribute("notNull", prop.isNotNull());
            json.writeAttribute("min", prop.getMin());
            json.writeAttribute("max", prop.getMax());
            json.writeAttribute("regexp", prop.getRegexp());
            json.writeAttribute("collate", prop.getCollate() != null ? prop.getCollate().getName() : "default");
            json.writeAttribute("defaultValue", prop.getDefaultValue());
            if (prop instanceof OPropertyImpl) {
                final Map<String, String> custom = ((OPropertyImpl) prop).getCustomInternal();
                if (custom != null && !custom.isEmpty()) {
                    json.writeAttribute("custom", custom);
                }
            }
            json.endObject();
        }
        json.endCollection();
    }
    final Set<OIndex<?>> indexes = cls.getIndexes();
    if (!indexes.isEmpty()) {
        json.beginCollection("indexes");
        for (final OIndex<?> index : indexes) {
            json.beginObject();
            json.writeAttribute("name", index.getName());
            json.writeAttribute("type", index.getType());
            final OIndexDefinition indexDefinition = index.getDefinition();
            if (indexDefinition != null && !indexDefinition.getFields().isEmpty())
                json.writeAttribute("fields", indexDefinition.getFields());
            json.endObject();
        }
        json.endCollection();
    }
    json.endObject();
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OClassImpl(com.orientechnologies.orient.core.metadata.schema.OClassImpl) OPropertyImpl(com.orientechnologies.orient.core.metadata.schema.OPropertyImpl) IOException(java.io.IOException) OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 77 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class CRUDObjectInheritanceTestSchemaFull method checkNoLinkedProperty.

protected void checkNoLinkedProperty(OClass iClass, String iPropertyName, OType iType) {
    OProperty prop = iClass.getProperty(iPropertyName);
    Assert.assertNotNull(prop);
    Assert.assertNull(prop.getLinkedType());
    Assert.assertNull(prop.getLinkedClass());
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty)

Example 78 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class CollateTest method testCompositeIndexQueryCS.

public void testCompositeIndexQueryCS() {
    final OSchema schema = database.getMetadata().getSchema();
    OClass clazz = schema.createClass("CompositeIndexQueryCSTest");
    OProperty csp = clazz.createProperty("csp", OType.STRING);
    csp.setCollate(ODefaultCollate.NAME);
    OProperty cip = clazz.createProperty("cip", OType.STRING);
    cip.setCollate(OCaseInsensitiveCollate.NAME);
    clazz.createIndex("collateCompositeIndexCS", OClass.INDEX_TYPE.NOTUNIQUE, "csp", "cip");
    for (int i = 0; i < 10; i++) {
        ODocument document = new ODocument("CompositeIndexQueryCSTest");
        if (i % 2 == 0) {
            document.field("csp", "VAL");
            document.field("cip", "VAL");
        } else {
            document.field("csp", "val");
            document.field("cip", "val");
        }
        document.save();
    }
    String query = "select from CompositeIndexQueryCSTest where csp = 'VAL'";
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 5);
    for (ODocument document : result) Assert.assertEquals(document.field("csp"), "VAL");
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateCompositeIndexCS"));
    query = "select from CompositeIndexQueryCSTest where csp = 'VAL' and cip = 'VaL'";
    result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 5);
    for (ODocument document : result) {
        Assert.assertEquals(document.field("csp"), "VAL");
        Assert.assertEquals((document.<String>field("cip")).toUpperCase(), "VAL");
    }
    explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateCompositeIndexCS"));
    result = database.query(new OSQLSynchQuery<ODocument>("select from index:collateCompositeIndexCS where key = ['VAL', 'VaL']"));
    Assert.assertEquals(result.size(), 5);
    for (ODocument document : result) {
        final OCompositeKey key = document.field("key");
        final List keys = key.getKeys();
        Assert.assertEquals(keys.get(0), "VAL");
        Assert.assertTrue("val".compareToIgnoreCase((String) keys.get(1)) == 0);
        final ODocument record = document.<OIdentifiable>field("rid").getRecord();
        Assert.assertEquals(record.field("csp"), "VAL");
        Assert.assertEquals((record.<String>field("cip")).toUpperCase(), "VAL");
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) Set(java.util.Set) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) List(java.util.List) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 79 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class CollateTest method testQuery.

public void testQuery() {
    final OSchema schema = database.getMetadata().getSchema();
    OClass clazz = schema.createClass("collateTest");
    OProperty csp = clazz.createProperty("csp", OType.STRING);
    csp.setCollate(ODefaultCollate.NAME);
    OProperty cip = clazz.createProperty("cip", OType.STRING);
    cip.setCollate(OCaseInsensitiveCollate.NAME);
    for (int i = 0; i < 10; i++) {
        ODocument document = new ODocument("collateTest");
        if (i % 2 == 0) {
            document.field("csp", "VAL");
            document.field("cip", "VAL");
        } else {
            document.field("csp", "val");
            document.field("cip", "val");
        }
        document.save();
    }
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from collateTest where csp = 'VAL'"));
    Assert.assertEquals(result.size(), 5);
    for (ODocument document : result) Assert.assertEquals(document.field("csp"), "VAL");
    result = database.query(new OSQLSynchQuery<ODocument>("select from collateTest where cip = 'VaL'"));
    Assert.assertEquals(result.size(), 10);
    for (ODocument document : result) Assert.assertEquals((document.<String>field("cip")).toUpperCase(), "VAL");
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 80 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class CollateTest method testIndexQuery.

public void testIndexQuery() {
    final OSchema schema = database.getMetadata().getSchema();
    OClass clazz = schema.createClass("collateIndexTest");
    OProperty csp = clazz.createProperty("csp", OType.STRING);
    csp.setCollate(ODefaultCollate.NAME);
    OProperty cip = clazz.createProperty("cip", OType.STRING);
    cip.setCollate(OCaseInsensitiveCollate.NAME);
    clazz.createIndex("collateIndexCSP", OClass.INDEX_TYPE.NOTUNIQUE, "csp");
    clazz.createIndex("collateIndexCIP", OClass.INDEX_TYPE.NOTUNIQUE, "cip");
    for (int i = 0; i < 10; i++) {
        ODocument document = new ODocument("collateIndexTest");
        if (i % 2 == 0) {
            document.field("csp", "VAL");
            document.field("cip", "VAL");
        } else {
            document.field("csp", "val");
            document.field("cip", "val");
        }
        document.save();
    }
    String query = "select from collateIndexTest where csp = 'VAL'";
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 5);
    for (ODocument document : result) Assert.assertEquals(document.field("csp"), "VAL");
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateIndexCSP"));
    query = "select from collateIndexTest where cip = 'VaL'";
    result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 10);
    for (ODocument document : result) Assert.assertEquals((document.<String>field("cip")).toUpperCase(), "VAL");
    explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateIndexCIP"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) Set(java.util.Set) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)87 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)69 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)32 Test (org.testng.annotations.Test)30 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)25 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)23 OType (com.orientechnologies.orient.core.metadata.schema.OType)14 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)9 OIndex (com.orientechnologies.orient.core.index.OIndex)7 ODatabaseObject (com.orientechnologies.orient.core.db.object.ODatabaseObject)6 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)6 Map (java.util.Map)6 Set (java.util.Set)6 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)5 Collection (java.util.Collection)5 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)4 Field (java.lang.reflect.Field)4 Test (org.junit.Test)4 OException (com.orientechnologies.common.exception.OException)3