/** * Decode an encoded property name to a qualified name * * @param encodedProperty the encoded property name * @return the qualified property name */ protected QName decodeProperty(String encodedProperty) { try { // decode name & unmap namespace return ONamespaceMap.decode(encodedProperty); } catch (Throwable e) { throw new RuntimeException("Could not encode property name", e); } }
/** * Encode a qualified property name to a string * * @param propertyName the qualified property name * @return the name encoded as a single string */ protected String encodeProperty(QName propertyName) { // encode name & map namespace return ONamespaceMap.encode(propertyName); }
private void configureDocument( ORecordAbstract<?> document, ODatabaseRecord db, DefinitionGroup definition) { // configure document // as of OrientDB 1.0rc8 the database may no longer be set on the // document // instead the current database can be set using // ODatabaseRecordThreadLocal.INSTANCE.set(db); // document.setDatabase(db); if (document instanceof ODocument) { // reset class name ODocument doc = (ODocument) document; /* * Attention: Two long class names cause problems as file names will * be based on them. */ String className = null; if (definition != null) { className = ONamespaceMap.encode(determineName(definition)); } else if (doc.containsField(OSerializationHelper.BINARY_WRAPPER_FIELD) || doc.containsField(OSerializationHelper.FIELD_SERIALIZATION_TYPE)) { className = OSerializationHelper.BINARY_WRAPPER_CLASSNAME; } if (className != null) { OSchema schema = db.getMetadata().getSchema(); if (!schema.existsClass(className)) { // if the class doesn't exist yet, create a physical cluster // manually for it int cluster = db.addCluster(className, CLUSTER_TYPE.PHYSICAL); schema.createClass(className, cluster); } doc.setClassName(className); } // configure children for (Entry<String, Object> field : doc) { List<ODocument> docs = new ArrayList<ODocument>(); List<ORecordAbstract<?>> recs = new ArrayList<ORecordAbstract<?>>(); if (field.getValue() instanceof Collection<?>) { for (Object value : (Collection<?>) field.getValue()) { if (value instanceof ODocument && !getSpecialFieldNames().contains(field.getKey())) { docs.add((ODocument) value); } else if (value instanceof ORecordAbstract<?>) { recs.add((ORecordAbstract<?>) value); } } } else if (field.getValue() instanceof ODocument && !getSpecialFieldNames().contains(field.getKey())) { docs.add((ODocument) field.getValue()); } else if (field.getValue() instanceof ORecordAbstract<?>) { recs.add((ORecordAbstract<?>) field.getValue()); } if (definition != null) { for (ODocument valueDoc : docs) { ChildDefinition<?> child = definition.getChild(decodeProperty(field.getKey())); DefinitionGroup childGroup; if (child.asProperty() != null) { childGroup = child.asProperty().getPropertyType(); } else if (child.asGroup() != null) { childGroup = child.asGroup(); } else { throw new IllegalStateException( "Document is associated neither with a property nor a property group."); } configureDocument(valueDoc, db, childGroup); } } for (ORecordAbstract<?> fieldRec : recs) { configureDocument(fieldRec, db, null); } } } }