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);
}
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;
}
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);
}
}
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;
}
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());
}
Aggregations