Search in sources :

Example 16 with OMetadataInternal

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

the class ODocument method fetchSchemaIfCan.

private void fetchSchemaIfCan() {
    if (_schema == null) {
        ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
        if (db != null && !db.isClosed()) {
            OMetadataInternal metadata = (OMetadataInternal) db.getMetadata();
            _schema = metadata.getImmutableSchemaSnapshot();
        }
    }
}
Also used : OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 17 with OMetadataInternal

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

the class ODocument method getGlobalPropertyById.

protected OGlobalProperty getGlobalPropertyById(int id) {
    if (_schema == null) {
        OMetadataInternal metadata = (OMetadataInternal) getDatabase().getMetadata();
        _schema = metadata.getImmutableSchemaSnapshot();
    }
    OGlobalProperty prop = _schema.getGlobalPropertyById(id);
    if (prop == null) {
        ODatabaseDocument db = getDatabase();
        if (db == null || db.isClosed())
            throw new ODatabaseException("Cannot unmarshall the document because no database is active, use detach for use the document outside the database session scope");
        OMetadataInternal metadata = (OMetadataInternal) db.getMetadata();
        if (metadata.getImmutableSchemaSnapshot() != null)
            metadata.clearThreadLocalSchemaSnapshot();
        metadata.reload();
        metadata.makeThreadLocalSchemaSnapshot();
        _schema = metadata.getImmutableSchemaSnapshot();
        prop = _schema.getGlobalPropertyById(id);
    }
    return prop;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal)

Example 18 with OMetadataInternal

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

the class ORecordSerializerCSVAbstract method fieldFromStream.

public Object fieldFromStream(final ORecord iSourceRecord, final OType iType, OClass iLinkedClass, OType iLinkedType, final String iName, final String iValue) {
    if (iValue == null)
        return null;
    switch(iType) {
        case EMBEDDEDLIST:
        case EMBEDDEDSET:
            return embeddedCollectionFromStream((ODocument) iSourceRecord, iType, iLinkedClass, iLinkedType, iValue);
        case LINKSET:
        case LINKLIST:
            {
                if (iValue.length() == 0)
                    return null;
                // REMOVE BEGIN & END COLLECTIONS CHARACTERS IF IT'S A COLLECTION
                final String value = iValue.startsWith("[") || iValue.startsWith("<") ? iValue.substring(1, iValue.length() - 1) : iValue;
                if (iType == OType.LINKLIST) {
                    return new ORecordLazyList((ODocument) iSourceRecord).setStreamedContent(new StringBuilder(value));
                } else {
                    return unserializeSet((ODocument) iSourceRecord, value);
                }
            }
        case LINKMAP:
            {
                if (iValue.length() == 0)
                    return null;
                // REMOVE BEGIN & END MAP CHARACTERS
                String value = iValue.substring(1, iValue.length() - 1);
                @SuppressWarnings("rawtypes") final Map map = new ORecordLazyMap((ODocument) iSourceRecord, ODocument.RECORD_TYPE);
                if (value.length() == 0)
                    return map;
                final List<String> items = OStringSerializerHelper.smartSplit(value, OStringSerializerHelper.RECORD_SEPARATOR, true, false);
                // EMBEDDED LITERALS
                for (String item : items) {
                    if (item != null && !item.isEmpty()) {
                        final List<String> entry = OStringSerializerHelper.smartSplit(item, OStringSerializerHelper.ENTRY_SEPARATOR);
                        if (!entry.isEmpty()) {
                            String mapValue = entry.get(1);
                            if (mapValue != null && !mapValue.isEmpty())
                                mapValue = mapValue.substring(1);
                            map.put(fieldTypeFromStream((ODocument) iSourceRecord, OType.STRING, entry.get(0)), new ORecordId(mapValue));
                        }
                    }
                }
                return map;
            }
        case EMBEDDEDMAP:
            return embeddedMapFromStream((ODocument) iSourceRecord, iLinkedType, iValue, iName);
        case LINK:
            if (iValue.length() > 1) {
                int pos = iValue.indexOf(OStringSerializerHelper.CLASS_SEPARATOR);
                if (pos > -1)
                    ((OMetadataInternal) ODatabaseRecordThreadLocal.INSTANCE.get().getMetadata()).getImmutableSchemaSnapshot().getClass(iValue.substring(1, pos));
                else
                    pos = 0;
                final String linkAsString = iValue.substring(pos + 1);
                try {
                    return new ORecordId(linkAsString);
                } catch (IllegalArgumentException e) {
                    OLogManager.instance().error(this, "Error on unmarshalling field '%s' of record '%s': value '%s' is not a link", iName, iSourceRecord, linkAsString);
                    return new ORecordId();
                }
            } else
                return null;
        case EMBEDDED:
            if (iValue.length() > 2) {
                // REMOVE BEGIN & END EMBEDDED CHARACTERS
                final String value = iValue.substring(1, iValue.length() - 1);
                final Object embeddedObject = OStringSerializerEmbedded.INSTANCE.fromStream(value);
                if (embeddedObject instanceof ODocument)
                    ODocumentInternal.addOwner((ODocument) embeddedObject, iSourceRecord);
                // RECORD
                return embeddedObject;
            } else
                return null;
        case LINKBAG:
            final String value = iValue.charAt(0) == OStringSerializerHelper.BAG_BEGIN ? iValue.substring(1, iValue.length() - 1) : iValue;
            return ORidBag.fromStream(value);
        default:
            return fieldTypeFromStream((ODocument) iSourceRecord, iType, iValue);
    }
}
Also used : ORecordLazyList(com.orientechnologies.orient.core.db.record.ORecordLazyList) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) ORecordLazyList(com.orientechnologies.orient.core.db.record.ORecordLazyList) List(java.util.List) OTrackedList(com.orientechnologies.orient.core.db.record.OTrackedList) ODatabaseObject(com.orientechnologies.orient.core.db.object.ODatabaseObject) OTrackedMap(com.orientechnologies.orient.core.db.record.OTrackedMap) ORecordLazyMap(com.orientechnologies.orient.core.db.record.ORecordLazyMap) Map(java.util.Map) ORecordLazyMap(com.orientechnologies.orient.core.db.record.ORecordLazyMap) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 19 with OMetadataInternal

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

the class OQueryOperatorInstanceof method evaluateExpression.

@Override
protected boolean evaluateExpression(final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight, OCommandContext iContext) {
    final OSchema schema = ((OMetadataInternal) ODatabaseRecordThreadLocal.INSTANCE.get().getMetadata()).getImmutableSchemaSnapshot();
    final String baseClassName = iRight.toString();
    final OClass baseClass = schema.getClass(baseClassName);
    if (baseClass == null)
        throw new OCommandExecutionException("Class '" + baseClassName + "' is not defined in database schema");
    OClass cls = null;
    if (iLeft instanceof OIdentifiable) {
        // GET THE RECORD'S CLASS
        final ORecord record = ((OIdentifiable) iLeft).getRecord();
        if (record instanceof ODocument) {
            cls = ODocumentInternal.getImmutableSchemaClass(((ODocument) record));
        }
    } else if (iLeft instanceof String)
        // GET THE CLASS BY NAME
        cls = schema.getClass((String) iLeft);
    return cls != null ? cls.isSubClassOf(baseClass) : false;
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) ORecord(com.orientechnologies.orient.core.record.ORecord) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 20 with OMetadataInternal

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

the class OObjectDatabaseTx method open.

@Override
public <THISDB extends ODatabase> THISDB open(String iUserName, String iUserPassword) {
    super.open(iUserName, iUserPassword);
    entityManager.registerEntityClass(OUser.class);
    entityManager.registerEntityClass(ORole.class);
    metadata = new OMetadataObject((OMetadataInternal) underlying.getMetadata());
    return (THISDB) this;
}
Also used : OMetadataObject(com.orientechnologies.orient.object.metadata.OMetadataObject) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal)

Aggregations

OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)22 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)8 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)6 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 OQueryParsingException (com.orientechnologies.orient.core.exception.OQueryParsingException)2 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)2 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2 OCommandSQLParsingException (com.orientechnologies.orient.core.sql.OCommandSQLParsingException)2 OCluster (com.orientechnologies.orient.core.storage.OCluster)2 OMetadataObject (com.orientechnologies.orient.object.metadata.OMetadataObject)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 OException (com.orientechnologies.common.exception.OException)1 OSystemException (com.orientechnologies.common.exception.OSystemException)1