Search in sources :

Example 16 with OProperty

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

the class DynamicPropertyValueModel method setObject.

@Override
public void setObject(T object) {
    ODocument doc = docModel.getObject();
    OProperty prop = propertyModel != null ? propertyModel.getObject() : null;
    if (doc == null)
        return;
    if (prop == null) {
        if (object instanceof OIdentifiable)
            docModel.setObject((ODocument) object);
    } else {
        doc.field(prop.getName(), object);
    }
    super.setObject(object);
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 17 with OProperty

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

the class OSecurityShared method createOrUpdateORoleClass.

private OClass createOrUpdateORoleClass(final ODatabaseDocument database, OClass identityClass) {
    OClass roleClass = database.getMetadata().getSchema().getClass("ORole");
    boolean unsafe = false;
    if (roleClass == null) {
        roleClass = database.getMetadata().getSchema().createClass("ORole", identityClass);
        unsafe = true;
    } else if (!roleClass.getSuperClasses().contains(identityClass))
        // MIGRATE AUTOMATICALLY TO 1.2.0
        roleClass.setSuperClasses(Arrays.asList(identityClass));
    if (!roleClass.existsProperty("name")) {
        roleClass.createProperty("name", OType.STRING, (OType) null, unsafe).setMandatory(true).setNotNull(true).setCollate("ci");
        roleClass.createIndex("ORole.name", INDEX_TYPE.UNIQUE, ONullOutputListener.INSTANCE, "name");
    } else {
        final OProperty name = roleClass.getProperty("name");
        if (name.getAllIndexes().isEmpty())
            roleClass.createIndex("ORole.name", INDEX_TYPE.UNIQUE, ONullOutputListener.INSTANCE, "name");
    }
    if (!roleClass.existsProperty("mode"))
        roleClass.createProperty("mode", OType.BYTE, (OType) null, unsafe);
    if (!roleClass.existsProperty("rules"))
        roleClass.createProperty("rules", OType.EMBEDDEDMAP, OType.BYTE, unsafe);
    if (!roleClass.existsProperty("inheritedRole"))
        roleClass.createProperty("inheritedRole", OType.LINK, roleClass, unsafe);
    return roleClass;
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OType(com.orientechnologies.orient.core.metadata.schema.OType)

Example 18 with OProperty

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

the class OSecurityShared method load.

public void load() {
    final OClass userClass = getDatabase().getMetadata().getSchema().getClass("OUser");
    if (userClass != null) {
        // @COMPATIBILITY <1.3.0
        if (!userClass.existsProperty("status")) {
            userClass.createProperty("status", OType.STRING).setMandatory(true).setNotNull(true);
        }
        OProperty p = userClass.getProperty("name");
        if (p == null)
            p = userClass.createProperty("name", OType.STRING).setMandatory(true).setNotNull(true).setMin("1").setRegexp("\\S+(.*\\S+)*");
        if (userClass.getInvolvedIndexes("name") == null)
            p.createIndex(INDEX_TYPE.UNIQUE);
        // ROLE
        final OClass roleClass = getDatabase().getMetadata().getSchema().getClass("ORole");
        final OProperty rules = roleClass.getProperty("rules");
        if (rules != null && !OType.EMBEDDEDMAP.equals(rules.getType())) {
            roleClass.dropProperty("rules");
        }
        if (!roleClass.existsProperty("inheritedRole")) {
            roleClass.createProperty("inheritedRole", OType.LINK, roleClass);
        }
        p = roleClass.getProperty("name");
        if (p == null)
            p = roleClass.createProperty("name", OType.STRING).setMandatory(true).setNotNull(true);
        if (roleClass.getInvolvedIndexes("name") == null)
            p.createIndex(INDEX_TYPE.UNIQUE);
    }
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 19 with OProperty

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

the class OCommandExecutorSQLSetAware method convertValue.

protected Object convertValue(OClass iClass, String fieldName, Object v) {
    if (iClass != null) {
        // CHECK TYPE AND CONVERT IF NEEDED
        final OProperty p = iClass.getProperty(fieldName);
        if (p != null) {
            final OClass embeddedType = p.getLinkedClass();
            switch(p.getType()) {
                case EMBEDDED:
                    // CONVERT MAP IN DOCUMENTS ASSIGNING THE CLASS TAKEN FROM SCHEMA
                    if (v instanceof Map)
                        v = createDocumentFromMap(embeddedType, (Map<String, Object>) v);
                    break;
                case EMBEDDEDSET:
                    // CONVERT MAPS IN DOCUMENTS ASSIGNING THE CLASS TAKEN FROM SCHEMA
                    if (v instanceof Map)
                        return createDocumentFromMap(embeddedType, (Map<String, Object>) v);
                    else if (OMultiValue.isMultiValue(v)) {
                        final Set set = new HashSet();
                        for (Object o : OMultiValue.getMultiValueIterable(v)) {
                            if (o instanceof Map) {
                                final ODocument doc = createDocumentFromMap(embeddedType, (Map<String, Object>) o);
                                set.add(doc);
                            } else if (o instanceof OIdentifiable)
                                set.add(((OIdentifiable) o).getRecord());
                            else
                                set.add(o);
                        }
                        v = set;
                    }
                    break;
                case EMBEDDEDLIST:
                    // CONVERT MAPS IN DOCUMENTS ASSIGNING THE CLASS TAKEN FROM SCHEMA
                    if (v instanceof Map)
                        return createDocumentFromMap(embeddedType, (Map<String, Object>) v);
                    else if (OMultiValue.isMultiValue(v)) {
                        final List set = new ArrayList();
                        for (Object o : OMultiValue.getMultiValueIterable(v)) {
                            if (o instanceof Map) {
                                final ODocument doc = createDocumentFromMap(embeddedType, (Map<String, Object>) o);
                                set.add(doc);
                            } else if (o instanceof OIdentifiable)
                                set.add(((OIdentifiable) o).getRecord());
                            else
                                set.add(o);
                        }
                        v = set;
                    }
                    break;
                case EMBEDDEDMAP:
                    // CONVERT MAPS IN DOCUMENTS ASSIGNING THE CLASS TAKEN FROM SCHEMA
                    if (v instanceof Map) {
                        final Map<String, Object> map = new HashMap<String, Object>();
                        for (Map.Entry<String, Object> entry : ((Map<String, Object>) v).entrySet()) {
                            if (entry.getValue() instanceof Map) {
                                final ODocument doc = createDocumentFromMap(embeddedType, (Map<String, Object>) entry.getValue());
                                map.put(entry.getKey(), doc);
                            } else if (entry.getValue() instanceof OIdentifiable)
                                map.put(entry.getKey(), ((OIdentifiable) entry.getValue()).getRecord());
                            else
                                map.put(entry.getKey(), entry.getValue());
                        }
                        v = map;
                    }
                    break;
            }
        }
    }
    return v;
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 20 with OProperty

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

the class OChainIndexFetchTest method testFetchChaninedIndex.

@Test
public void testFetchChaninedIndex() {
    OClass baseClass = db.getMetadata().getSchema().createClass("BaseClass");
    OProperty propr = baseClass.createProperty("ref", OType.LINK);
    OClass linkedClass = db.getMetadata().getSchema().createClass("LinkedClass");
    OProperty id = linkedClass.createProperty("id", OType.STRING);
    id.createIndex(INDEX_TYPE.UNIQUE);
    propr.setLinkedClass(linkedClass);
    propr.createIndex(INDEX_TYPE.NOTUNIQUE);
    ODocument doc = new ODocument(linkedClass);
    doc.field("id", "referred");
    db.save(doc);
    ODocument doc1 = new ODocument(baseClass);
    doc1.field("ref", doc);
    db.save(doc1);
    List<ODocument> res = db.query(new OSQLSynchQuery(" select from BaseClass where ref.id ='wrong_referred' "));
    assertEquals(0, res.size());
}
Also used : 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) Test(org.testng.annotations.Test)

Aggregations

OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)121 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)84 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)41 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)32 Test (org.testng.annotations.Test)30 Test (org.junit.Test)28 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)25 OType (com.orientechnologies.orient.core.metadata.schema.OType)15 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11 FilterCriteriaManager (ru.ydn.wicket.wicketorientdb.utils.query.filter.FilterCriteriaManager)10 IFilterCriteriaManager (ru.ydn.wicket.wicketorientdb.utils.query.filter.IFilterCriteriaManager)10 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)8 OIndex (com.orientechnologies.orient.core.index.OIndex)8 Date (java.util.Date)8 Set (java.util.Set)8 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)7 Map (java.util.Map)7 ODatabaseObject (com.orientechnologies.orient.core.db.object.ODatabaseObject)6 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)6 Collection (java.util.Collection)6