@Override public Object apply(ODocument input) { return OType.convert(input.field("value"), linkedType.getDefaultJavaType()); } });
public void describe(Writer writer, OProperty oProperty) OType type = oProperty.getType(); String min = oProperty.getMin(); String max = oProperty.getMax(); String range = null; else if(type.isMultiValue()) boolean isEmbedded = type.equals(OType.EMBEDDED) || type.equals(OType.EMBEDDEDLIST) || type.equals(OType.EMBEDDEDMAP) || type.equals(OType.EMBEDDEDSET); if(oProperty.getLinkedClass()!=null && (isEmbedded || type.isLink())) out.append(oProperty.getOwnerClass().getName()); if(isEmbedded) out.append("\"1\" *-- "); else out.append(" -> "); if(range!=null) out.append('"').append(range).append("\" "); out.append(oProperty.getLinkedClass().getName()); out.append(" : ").append(oProperty.getName()); out.append(oProperty.getOwnerClass().getName()) .append(" : ") .append(oProperty.getName()).append(" : ").append(type.name());
@Override public void configure(final ODocument iConfiguration, OCommandContext iContext) { super.configure(iConfiguration, iContext); joinValue = iConfiguration.field("joinValue"); linkFieldName = iConfiguration.field("linkFieldName"); if (iConfiguration.containsField("linkFieldType")) linkFieldType = OType.valueOf((String) iConfiguration.field("linkFieldType")); }
/** * {@inheritDoc} */ public Object createValue(final Object... params) { return OType.convert(params[0], keyType.getDefaultJavaType()); }
@Override public Object execute(Object iThis, OIdentifiable iCurrentRecord, OCommandContext iContext, Object ioResult, Object[] iParams) { if (ioResult == null) { return null; } final OType t = OType.getTypeByValue(ioResult); if (t != null) { return t.toString(); } return null; } }
private void removeLink(ODocument doc, OProperty property, ODocument value) { if(doc==null || property ==null || value == null || isUnderTheLock(doc)) return; String field = property.getName(); if(doc.getSchemaClass().isSubClassOf(property.getOwnerClass())) { Object wrappedValue = value.getIdentity().isPersistent()?value.getIdentity():value; if(property.getType().isMultiValue()) { Collection<Object> objects = doc.field(field); if(objects!=null && objects.remove(wrappedValue)) { doc.field(field, objects); //It's safe for multivalue docs saveOutOfHook(doc); } } else { if(value.getIdentity().equals(doc.field(field, ORID.class))) { doc.field(field, (Object) null); doc.save(); } } } }
if (!includeClasses.contains(cls.getName().toUpperCase(Locale.ENGLISH))) continue; } else if (excludeClasses != null) { if (excludeClasses.contains(cls.getName().toUpperCase(Locale.ENGLISH))) continue; writer.writeAttribute(0, false, "name", cls.getName()); writer.writeAttribute(0, false, "default-cluster-id", cls.getDefaultClusterId()); writer.writeAttribute(0, false, "cluster-ids", cls.getClusterIds()); writer.writeAttribute(0, false, "name", p.getName()); writer.writeAttribute(0, false, "type", p.getType().toString()); if (p.isMandatory()) writer.writeAttribute(0, false, "mandatory", p.isMandatory()); if (p.isReadonly()) writer.writeAttribute(0, false, "linked-class", p.getLinkedClass().getName()); if (p.getLinkedType() != null) writer.writeAttribute(0, false, "linked-type", p.getLinkedType().toString()); if (p.getMin() != null) writer.writeAttribute(0, false, "min", p.getMin());
final OProperty property = oClass.getProperty(calcProperty); String script = CustomAttribute.CALC_SCRIPT.getValue(property); if(!Strings.isEmpty(script)) if(FULL_QUERY_PATTERN.matcher(script).find()) calculated = iDocument.getDatabase().query(new OSQLSynchQuery<Object>(script), iDocument); script = "select "+script+" as value from "+iDocument.getIdentity(); calculated = iDocument.getDatabase().query(new OSQLSynchQuery<Object>(script)); OType type = property.getType(); Object value; if(type.isMultiValue()) final OType linkedType = property.getLinkedType(); value = linkedType==null ?calculated value = calculated.get(0).field("value"); value = OType.convert(value, type.getDefaultJavaType()); Object oldValue = iDocument.field(calcProperty); if (oldValue!=value && (oldValue==null || !oldValue.equals(value))){
@Override public void setValue(Object object, Object value, PropertyResolverConverter converter) { ODocument doc = toODocument(object); if(value!=null && ! OType.isSimpleType(value)) { //Try to convert if type is not simple OClass schemaClass = doc.getSchemaClass(); OProperty property = schemaClass.getProperty(exp); if(property!=null) { value = converter.convert(value, property.getType().getDefaultJavaType()); } } doc.field(exp, value); }
iRecord = new ODocument(); doc.field(fieldName, v, type); continue; doc.field(fieldName, v, OType.EMBEDDEDMAP); continue; } else if (v instanceof ODocument && type != null && type.isLink()) { String className1 = ((ODocument) v).getClassName(); if (className1 != null && className1.length() > 0)
indexType = p.getValue().toString().toUpperCase(Locale.ENGLISH); else if (p.getKey().equals("keytype")) keyType = OType.valueOf(p.getValue().toString().toUpperCase(Locale.ENGLISH)); else if (p.getKey().equals("class")) className = p.getValue().toString(); else if (p.getKey().toString().startsWith("metadata.")) { if (metadata == null) metadata = new ODocument(); metadata.field(p.getKey().toString().substring("metadata.".length()), p.getValue()); final OProperty property = cls.getProperty(key); if (property != null) keyType = property.getType(); indexDefinition.setCollate(collate); db.getMetadata().getIndexManager() .createIndex(className + "." + key, indexType, indexDefinition, cls.getPolymorphicClusterIds(), null, metadata); return null;
@Override protected boolean onSelect(AjaxRequestTarget target, List<ODocument> objects, boolean selectMore) { if(objects==null || objects.isEmpty()) return true; OType oType = propertyModel.getObject().getType(); if(!oType.isMultiValue() && objects.size()>1) if(oType.isMultiValue()) Collection<ODocument> links = doc.field(property.getName()); if(links!=null) doc.field(property.getName(), objects); doc.save();
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); } }
@Override protected String getDefaultSql() { ODocument doc = getModelObject(); OClass oClass = doc.getSchemaClass(); OProperty multiProperty = null; for(OProperty property : oClass.properties()) { if(property.getType().isLink() && property.getType().isMultiValue()) { multiProperty = property; break; } } if(multiProperty!=null) { return "select expand("+multiProperty.getName()+") from :doc"; } else { return "select from :doc"; } }
/** * Create {@link OProperty} if required * @param propertyName property name to create * @param type type of property to create * @return this helper */ public OSchemaHelper oProperty(String propertyName, OType type) { checkOClass(); lastProperty = lastClass.getProperty(propertyName); if(lastProperty==null) { lastProperty = lastClass.createProperty(propertyName, type); } else { if(!type.equals(lastProperty.getType())) { lastProperty.setType(type); } } return this; }
protected void initMapping(OPersistenceSession session) { mappingFromDocToEntity = new HashMap<>(); mappingFromEntityToDoc = new HashMap<>(); OClass oClass = session.getClass(getSchemaClass()); Class<T> entityClass = getEntityClass(); for(OProperty property : oClass.properties()) { String propertyName = property.getName(); String beanPropertyName = propertyName; boolean isLink = property.getType().isLink(); if(isLink) beanPropertyName+="Id"; IGetAndSet getAndSet = getGetAndSetter(entityClass, beanPropertyName); if(getAndSet!=null) { if(isLink) { IEntityHandler<?> targetHandler = HandlersManager.get().getHandlerBySchemaClass(property.getLinkedClass().getName()); if(targetHandler==null || targetHandler.getPkField()==null) continue; propertyName+="."+targetHandler.getPkField(); } if(getAndSet.getSetter()!=null) mappingFromDocToEntity.put(propertyName, beanPropertyName); if(getAndSet.getGetter()!=null) mappingFromEntityToDoc.put(beanPropertyName, propertyName); } } }
protected void checkParametersConflict(final OClass baseClass) { final Collection<OProperty> baseClassProperties = baseClass.properties(); for (OProperty property : baseClassProperties) { OProperty thisProperty = getProperty(property.getName()); if (thisProperty != null && !thisProperty.getType().equals(property.getType())) { throw new OSchemaException( "Cannot add base class '" + baseClass.getName() + "', because of property conflict: '" + thisProperty + "' vs '" + property + "'"); } } }
Object record = iRecord.getRecord(); if (record instanceof ODocument) { OProperty property = ((ODocument) record).getSchemaClass().getProperty(fieldName); if (property != null && property.getType().isMultiValue()) { type = property.getLinkedType(); right = OType.convert(iRight, type.getDefaultJavaType()); Object convertedRight = iRight; if(val instanceof ODocument && iRight instanceof Map){ val = ((ODocument) val).toMap(); convertedRight = ((ODocument) iRight).toMap();