Examples of ODatabaseRecord


Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

      System.out.printf("\nRotating to the right the node %s", ((OMVRBTreeEntryPersistent<K, V>) p).record.getIdentity());
    super.rotateRight(p);
  }

  protected ODatabaseRecord getDatabase() {
    final ODatabaseRecord database = ODatabaseRecordThreadLocal.INSTANCE.get();
    record.setDatabase(database);
    return database;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

    try {
      final OClusterPositionIterator iterator = cluster.absoluteIterator(iBeginRange, iEndRange);

      final ORecordId rid = new ORecordId(cluster.getId());
      final ODatabaseRecord database = ioRecord.getDatabase();

      // BROWSE ALL THE RECORDS
      while (iterator.hasNext()) {
        positionInPhyCluster = iterator.next();

        if (positionInPhyCluster == -1)
          // NOT VALID POSITION (IT HAS BEEN DELETED)
          continue;

        rid.clusterPosition = positionInPhyCluster;

        record = database.load(rid);

        if (record != null && record.getRecordType() != ODocument.RECORD_TYPE)
          // WRONG RECORD TYPE: JUMP IT
          continue;
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

      final String iName, final String iValue) {

    if (iValue == null)
      return null;

    final ODatabaseRecord database = iSourceRecord.getDatabase();

    switch (iType) {
    case EMBEDDEDLIST:
    case EMBEDDEDSET:
      return embeddedCollectionFromStream(database, (ODocument) iSourceRecord, iType, iLinkedClass, iLinkedType, iValue);

    case LINKLIST:
    case LINKSET: {
      if (iValue.length() == 0)
        return null;

      // REMOVE BEGIN & END COLLECTIONS CHARACTERS IF IT'S A COLLECTION
      final String value = iValue.startsWith("[") ? iValue.substring(1, iValue.length() - 1) : iValue;

      return iType == OType.LINKLIST ? new ORecordLazyList(iSourceRecord).setStreamedContent(new StringBuilder(value))
          : new ORecordLazySet(iSourceRecord).setStreamedContent(new StringBuilder(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(iSourceRecord, ODocument.RECORD_TYPE);

      if (value.length() == 0)
        return map;

      final List<String> items = OStringSerializerHelper.smartSplit(value, OStringSerializerHelper.RECORD_SEPARATOR);

      // EMBEDDED LITERALS
      for (String item : items) {
        if (item != null && item.length() > 0) {
          final List<String> entry = OStringSerializerHelper.smartSplit(item, OStringSerializerHelper.ENTRY_SEPARATOR);
          if (entry.size() > 0) {
            String mapValue = entry.get(1);
            if (mapValue != null && mapValue.length() > 0)
              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);

    case LINK:
      if (iValue.length() > 1) {
        int pos = iValue.indexOf(OStringSerializerHelper.CLASS_SEPARATOR);
        if (pos > -1)
          iLinkedClass = database.getMetadata().getSchema().getClass(iValue.substring(1, pos));
        else
          pos = 0;

        return new ORecordId(iValue.substring(pos + 1));
      } else
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

        resultRid = iLinkedRecord;
      }

      if (iParentRecord != null && iParentRecord.getDatabase() instanceof ODatabaseRecord) {
        final ODatabaseRecord db = iParentRecord.getDatabase();
        if (!db.isRetainRecords())
          // REPLACE CURRENT RECORD WITH ITS ID: THIS SAVES A LOT OF MEMORY
          resultRid = iLinkedRecord.getIdentity();
      }
    }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

      if (iMarshalledRecords.contains(identityRecord)) {
        return iOutput;
      } else
        iMarshalledRecords.add(identityRecord);

    final ODatabaseRecord database = ODatabaseRecordThreadLocal.INSTANCE.get();

    if (!iOnlyDelta && record.getSchemaClass() != null) {
      // MARSHALL THE CLASSNAME
      iOutput.append(record.getSchemaClass().getStreamableName());
      iOutput.append(OStringSerializerHelper.CLASS_SEPARATOR);
    }

    OProperty prop;
    OType type;
    OClass linkedClass;
    OType linkedType;
    String fieldClassName;
    int i = 0;

    final String[] fieldNames = iOnlyDelta && record.isTrackingChanges() ? record.getDirtyFields() : record.fieldNames();

    // MARSHALL ALL THE FIELDS OR DELTA IF TRACKING IS ENABLED
    for (String fieldName : fieldNames) {
      Object fieldValue = record.rawField(fieldName);
      if (i > 0)
        iOutput.append(OStringSerializerHelper.RECORD_SEPARATOR);

      // SEARCH FOR A CONFIGURED PROPERTY
      prop = record.getSchemaClass() != null ? record.getSchemaClass().getProperty(fieldName) : null;
      fieldClassName = getClassName(fieldValue);

      type = record.fieldType(fieldName);
      linkedClass = null;
      linkedType = null;

      if (prop != null) {
        // RECOGNIZED PROPERTY
        type = prop.getType();
        linkedClass = prop.getLinkedClass();
        linkedType = prop.getLinkedType();

      } else if (fieldValue != null) {
        // NOT FOUND: TRY TO DETERMINE THE TYPE FROM ITS CONTENT
        if (type == null) {
          if (fieldValue.getClass() == byte[].class)
            type = OType.BINARY;
          else if (database != null && fieldValue instanceof ORecord<?>) {
            if (type == null)
              // DETERMINE THE FIELD TYPE
              if (fieldValue instanceof ODocument && ((ODocument) fieldValue).hasOwners())
                type = OType.EMBEDDED;
              else
                type = OType.LINK;

            linkedClass = getLinkInfo(database, fieldClassName);
          } else if (fieldValue instanceof ORID)
            // DETERMINE THE FIELD TYPE
            type = OType.LINK;

          else if (database != null && database.getDatabaseOwner() instanceof ODatabaseObject
              && ((ODatabaseObject) database.getDatabaseOwner()).getEntityManager().getEntityClass(fieldClassName) != null) {
            // DETERMINE THE FIELD TYPE
            type = OType.LINK;
            linkedClass = getLinkInfo(database, fieldClassName);
          } else if (fieldValue instanceof Date)
            type = OType.DATETIME;
          else if (fieldValue instanceof String)
            type = OType.STRING;
          else if (fieldValue instanceof Integer)
            type = OType.INTEGER;
          else if (fieldValue instanceof Long)
            type = OType.LONG;
          else if (fieldValue instanceof Float)
            type = OType.FLOAT;
          else if (fieldValue instanceof Short)
            type = OType.SHORT;
          else if (fieldValue instanceof Byte)
            type = OType.BYTE;
          else if (fieldValue instanceof Double)
            type = OType.DOUBLE;
        }

        if (fieldValue instanceof Collection<?> || fieldValue.getClass().isArray()) {
          int size = OMultiValue.getSize(fieldValue);

          if (size > 0) {
            final Object firstValue = OMultiValue.getFirstValue(fieldValue);

            if (firstValue != null) {
              if (firstValue instanceof ORID) {
                linkedClass = null;
                linkedType = OType.LINK;
                if (fieldValue instanceof Set<?>)
                  type = OType.LINKSET;
                else
                  type = OType.LINKLIST;
              } else if (database != null
                  && (firstValue instanceof ORecordSchemaAware<?> || (database.getDatabaseOwner() instanceof ODatabaseObject && ((ODatabaseObject) database
                      .getDatabaseOwner()).getEntityManager().getEntityClass(getClassName(firstValue)) != null))) {
                linkedClass = getLinkInfo(database, getClassName(firstValue));
                if (type == null) {
                  // LINK: GET THE CLASS
                  linkedType = OType.LINK;

                  if (fieldValue instanceof Set<?>)
                    type = OType.LINKSET;
                  else
                    type = OType.LINKLIST;
                } else
                  linkedType = OType.EMBEDDED;
              } else {
                if (firstValue instanceof Enum<?>)
                  linkedType = OType.STRING;
                else {
                  linkedType = OType.getTypeByClass(firstValue.getClass());

                  if (linkedType != OType.LINK) {
                    // EMBEDDED FOR SURE SINCE IT CONTAINS JAVA TYPES
                    if (linkedType == null) {
                      linkedType = OType.EMBEDDED;
                      // linkedClass = new OClass(firstValue.getClass());
                    }
                  }
                }

                if (type == null)
                  if (fieldValue instanceof Set<?>)
                    type = OType.EMBEDDEDSET;
                  else
                    type = OType.EMBEDDEDLIST;
              }
            }
          } else if (type == null)
            type = OType.EMBEDDEDLIST;

        } else if (fieldValue instanceof Map<?, ?>) {
          if (type == null)
            type = OType.EMBEDDEDMAP;

          if (OMultiValue.getSize(fieldValue) > 0) {
            Object firstValue = OMultiValue.getFirstValue(fieldValue);

            if (firstValue instanceof ORID) {
              linkedClass = null;
              linkedType = OType.LINK;
              type = OType.LINKMAP;
            } else if (database != null
                && (firstValue instanceof ORecordSchemaAware<?> || (database.getDatabaseOwner() instanceof ODatabaseObject && ((ODatabaseObject) database
                    .getDatabaseOwner()).getEntityManager().getEntityClass(getClassName(firstValue)) != null))) {
              if (((ORecordInternal<?>) firstValue).getIdentity().isValid())
                type = OType.LINKMAP;

              // LINK: GET THE CLASS
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

      lock.releaseExclusiveLock();
    }
  }

  public void create() {
    final ODatabaseRecord db = getDatabase();
    super.save(OStorage.CLUSTER_INTERNAL_NAME);
    db.getStorage().getConfiguration().schemaRecordId = document.getIdentity().toString();
    db.getStorage().getConfiguration().update();
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

    // WRITE ENTITY SCHEMA IF ANY
    if (iRecords != null && iRecords.size() > 0) {
      ORecord<?> first = iRecords.get(0);
      if (first != null && first instanceof ODocument) {
        ODatabaseRecord db = ((ODocument) first).getDatabase();

        final String className = ((ODocument) first).getClassName();
        exportClassSchema(db, json, db.getMetadata().getSchema().getClass(className));
      }
    }

    final String format = iFetchPlan != null ? JSON_FORMAT + ",fetchPlan:" + iFetchPlan : JSON_FORMAT;
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

      lock.releaseExclusiveLock();
    }
  }

  public void create() {
    final ODatabaseRecord db = getDatabase();
    super.save(OStorage.CLUSTER_INTERNAL_NAME);
    db.getStorage().getConfiguration().schemaRecordId = document.getIdentity().toString();
    db.getStorage().getConfiguration().update();
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

      if (iMarshalledRecords.contains(identityRecord)) {
        return iOutput;
      } else
        iMarshalledRecords.add(identityRecord);

    final ODatabaseRecord database = record.getDatabase();

    if (record.getClassName() != null) {
      // MARSHALL THE CLASSNAME
      iOutput.append(record.getClassName());
      iOutput.append(OStringSerializerHelper.CLASS_SEPARATOR);
    }

    OProperty prop;
    Object fieldValue;
    OType type;
    OClass linkedClass;
    OType linkedType;
    String fieldClassName;
    int i = 0;

    // MARSHALL ALL THE CONFIGURED FIELDS
    for (Entry<String, Object> f : record) {
      if (i > 0)
        iOutput.append(OStringSerializerHelper.RECORD_SEPARATOR);

      // SEARCH FOR A CONFIGURED PROPERTY
      prop = record.getSchemaClass() != null ? record.getSchemaClass().getProperty(f.getKey()) : null;
      fieldValue = f.getValue();
      fieldClassName = getClassName(fieldValue);

      type = record.fieldType(f.getKey());
      linkedClass = null;
      linkedType = null;

      if (prop != null) {
        // RECOGNIZED PROPERTY
        type = prop.getType();
        linkedClass = prop.getLinkedClass();
        linkedType = prop.getLinkedType();

      } else if (fieldValue != null) {
        // NOT FOUND: TRY TO DETERMINE THE TYPE FROM ITS CONTENT
        if (fieldValue.getClass() == byte[].class) {
          type = OType.BINARY;
        } else if (fieldValue instanceof Collection<?> || fieldValue.getClass().isArray()) {
          int size = OMultiValue.getSize(fieldValue);

          if (size > 0) {
            Object firstValue = OMultiValue.getFirstValue(fieldValue);

            if (firstValue != null) {
              if (firstValue instanceof ORID) {
                linkedClass = null;
                linkedType = OType.LINK;
                if (fieldValue instanceof Set<?>)
                  type = OType.LINKSET;
                else
                  type = OType.LINKLIST;
              } else if (database != null
                  && (firstValue instanceof ORecordSchemaAware<?> || (database.getDatabaseOwner() instanceof ODatabaseObject && ((ODatabaseObject) database
                      .getDatabaseOwner()).getEntityManager().getEntityClass(getClassName(firstValue)) != null))) {
                linkedClass = getLinkInfo(database, getClassName(firstValue));
                if (type == null) {
                  // LINK: GET THE CLASS
                  linkedType = OType.LINK;

                  if (fieldValue instanceof Set<?>)
                    type = OType.LINKSET;
                  else
                    type = OType.LINKLIST;
                } else
                  linkedType = OType.EMBEDDED;
              } else {
                linkedType = OType.getTypeByClass(firstValue.getClass());

                if (linkedType != OType.LINK) {
                  // EMBEDDED FOR SURE SINCE IT CONTAINS JAVA TYPES
                  if (linkedType == null) {
                    linkedType = OType.EMBEDDED;
                    // linkedClass = new OClass(firstValue.getClass());
                  }

                  if (type == null)
                    if (fieldValue instanceof Set<?>)
                      type = OType.EMBEDDEDSET;
                    else
                      type = OType.EMBEDDEDLIST;
                }
              }
            }
          } else if (type == null)
            type = OType.EMBEDDEDLIST;

        } else if (fieldValue instanceof Map<?, ?>) {
          if (type == null)
            type = OType.EMBEDDEDMAP;

          if (OMultiValue.getSize(fieldValue) > 0) {
            Object firstValue = OMultiValue.getFirstValue(fieldValue);

            if (firstValue instanceof ORID) {
              linkedClass = null;
              linkedType = OType.LINK;
              type = OType.LINKMAP;
            } else if (database != null
                && (firstValue instanceof ORecordSchemaAware<?> || (database.getDatabaseOwner() instanceof ODatabaseObject && ((ODatabaseObject) database
                    .getDatabaseOwner()).getEntityManager().getEntityClass(getClassName(firstValue)) != null))) {
              if (((ORecordInternal<?>) firstValue).getIdentity().isValid())
                type = OType.LINKMAP;

              // LINK: GET THE CLASS
              linkedType = type == OType.EMBEDDEDLIST || type == OType.EMBEDDEDSET || type == OType.EMBEDDEDMAP ? OType.EMBEDDED
                  : OType.LINK;
              linkedClass = getLinkInfo(database, getClassName(firstValue));
            } else {
              linkedType = OType.getTypeByClass(firstValue.getClass());
              if (linkedType == OType.LINK && type == OType.EMBEDDEDMAP)
                type = OType.LINKMAP;
            }
          }
        } else if (database != null && fieldValue instanceof ORecord<?>) {
          if (type == null)
            // DETERMINE THE FIELD TYPE
            if (fieldValue instanceof ODocument && ((ODocument) fieldValue).hasOwners())
              type = OType.EMBEDDED;
            else
              type = OType.LINK;

          linkedClass = getLinkInfo(database, fieldClassName);
        } else if (fieldValue instanceof ORID) {
          if (type == null)
            // DETERMINE THE FIELD TYPE
            type = OType.LINK;

        } else if (database != null && database.getDatabaseOwner() instanceof ODatabaseObject
            && ((ODatabaseObject) database.getDatabaseOwner()).getEntityManager().getEntityClass(fieldClassName) != null) {
          // DETERMINE THE FIELD TYPE
          if (type == null)
            type = OType.LINK;
          linkedClass = getLinkInfo(database, fieldClassName);
        } else if (fieldValue instanceof Date) {
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

      final String iName, final String iValue) {

    if (iValue == null)
      return null;

    final ODatabaseRecord database = iSourceRecord.getDatabase();

    switch (iType) {
    case EMBEDDEDLIST:
    case EMBEDDEDSET:
      return embeddedCollectionFromStream(database, (ODocument) iSourceRecord, iType, iLinkedClass, iLinkedType, iValue);

    case LINKLIST:
    case LINKSET: {
      if (iValue.length() == 0)
        return null;

      // REMOVE BEGIN & END COLLECTIONS CHARACTERS IF IT'S A COLLECTION
      final String value = iValue.startsWith("[") ? iValue.substring(1, iValue.length() - 1) : iValue;

      return iType == OType.LINKLIST ? new ORecordLazyList(iSourceRecord).setStreamedContent(new StringBuilder(value))
          : new ORecordLazySet(iSourceRecord).setStreamedContent(new StringBuilder(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(iSourceRecord, ODocument.RECORD_TYPE);

      if (value.length() == 0)
        return map;

      final List<String> items = OStringSerializerHelper.smartSplit(value, OStringSerializerHelper.RECORD_SEPARATOR);

      // EMBEDDED LITERALS
      List<String> entry;
      String mapValue;

      for (String item : items) {
        if (item != null && item.length() > 0) {
          entry = OStringSerializerHelper.smartSplit(item, OStringSerializerHelper.ENTRY_SEPARATOR);
          if (entry.size() > 0) {
            mapValue = entry.get(1);
            if (mapValue != null && mapValue.length() > 0)
              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);

    case LINK:
      if (iValue.length() > 1) {
        int pos = iValue.indexOf(OStringSerializerHelper.CLASS_SEPARATOR);
        if (pos > -1)
          iLinkedClass = database.getMetadata().getSchema().getClass(iValue.substring(1, pos));
        else
          pos = 0;

        return new ORecordId(iValue.substring(pos + 1));
      } else
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.