Examples of OProperty


Examples of com.orientechnologies.orient.core.metadata.schema.OProperty

    if (OSerializationThreadLocal.INSTANCE.get().contains(identityRecord))
      return iRecord;

    OSerializationThreadLocal.INSTANCE.get().add(identityRecord);

    OProperty schemaProperty;

    final Class<?> pojoClass = iPojo.getClass();

    final List<Field> properties = getClassFields(pojoClass);

    // CHECK FOR ID BINDING
    final String idFieldName = fieldIds.get(pojoClass);
    if (idFieldName != null) {
      Object id = getFieldValue(iPojo, idFieldName);
      if (id != null) {
        // FOUND
        if (id instanceof ORecordId) {
          iRecord.setIdentity((ORecordId) id);
        } else if (id instanceof Number) {
          // TREATS AS CLUSTER POSITION
          ((ORecordId) iRecord.getIdentity()).clusterId = schemaClass.getDefaultClusterId();
          ((ORecordId) iRecord.getIdentity()).clusterPosition = ((Number) id).longValue();
        } else if (id instanceof String)
          ((ORecordId) iRecord.getIdentity()).fromString((String) id);
        else if (id.getClass().equals(Object.class))
          iRecord.setIdentity((ORecordId) id);
        else
          OLogManager.instance().warn(OObjectSerializerHelper.class,
              "@Id field has been declared as %s while the supported are: ORID, Number, String, Object", id.getClass());
      }
    }

    // CHECK FOR VERSION BINDING
    final String vFieldName = fieldVersions.get(pojoClass);
    boolean versionConfigured = false;
    if (vFieldName != null) {
      versionConfigured = true;
      Object ver = getFieldValue(iPojo, vFieldName);
      if (ver != null) {
        // FOUND
        if (ver instanceof Number) {
          // TREATS AS CLUSTER POSITION
          iRecord.setVersion(((Number) ver).intValue());
        } else if (ver instanceof String)
          iRecord.setVersion(Integer.parseInt((String) ver));
        else if (ver.getClass().equals(Object.class))
          iRecord.setVersion((Integer) ver);
        else
          OLogManager.instance().warn(OObjectSerializerHelper.class,
              "@Version field has been declared as %s while the supported are: Number, String, Object", ver.getClass());
      }
    }

    if (!versionConfigured && iRecord.getDatabase().getTransaction() instanceof OTransactionOptimistic)
      throw new OTransactionException("Can't involve an object of class '" + pojoClass
          + "' in an Optimistic Transaction commit because it doesn't define @Version or @OVersion and therefore can't handle MVCC");

    // SET OBJECT CLASS
    iRecord.setClassName(schemaClass != null ? schemaClass.getName() : null);

    String fieldName;
    Object fieldValue;

    // CALL BEFORE MARSHALLING
    invokeCallback(iPojo, iRecord, OBeforeSerialization.class);

    for (Field p : properties) {
      fieldName = p.getName();

      if (fieldName.equals(idFieldName) || fieldName.equals(vFieldName))
        continue;

      fieldValue = serializeFieldValue(iPojo, fieldName, getFieldValue(iPojo, fieldName));

      schemaProperty = schemaClass != null ? schemaClass.getProperty(fieldName) : null;

      fieldValue = typeToStream(fieldValue, schemaProperty != null ? schemaProperty.getType() : null, iEntityManager,
          iObj2RecHandler, db, iSaveOnlyDirty);

      iRecord.field(fieldName, fieldValue);
    }
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.schema.OProperty

    if (iType != null)
      setFieldType(iPropertyName, iType);
    else if (_clazz != null) {
      // SCHEMAFULL?
      final OProperty prop = _clazz.getProperty(iPropertyName);
      if (prop != null)
        iType = prop.getType();
    }

    if (iType != null)
      convertField(iPropertyName, iType.getDefaultJavaType(), iPropertyValue);
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.schema.OProperty

    else
      fieldValue = iCondition.getLeft().toString();

    String className = iTargetClasses.get(0);

    final OProperty prop = iDatabase.getMetadata().getSchema().getClass(className).getProperty(fieldName);
    if (prop == null)
      // NO PROPERTY DEFINED
      return null;

    final OPropertyIndex index = prop.getIndex();
    if (index == null || !(index.getUnderlying() instanceof OIndexFullText))
      // NO FULL TEXT INDEX
      return null;

    return index.getUnderlying().get(fieldValue);
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.schema.OProperty

    if (iItem == null || !(iItem instanceof OSQLFilterItemField))
      return null;

    OSQLFilterItemField item = (OSQLFilterItemField) iItem;

    final OProperty prop = iSchemaClass.getProperty(item.getName());
    if (prop != null && prop.isIndexed()) {
      // TODO: IMPROVE THIS MANAGEMENT
      // ONLY EQUALS IS SUPPORTED NOW!
      OIndex idx = prop.getIndex().getUnderlying();
      if (((idx instanceof OIndexUnique || idx instanceof OIndexNotUnique) && iCondition.getOperator() instanceof OQueryOperatorEquals)
          || idx instanceof OIndexFullText && iCondition.getOperator() instanceof OQueryOperatorContainsText) {
        Object value = iCondition.getLeft() == iItem ? iCondition.getRight() : iCondition.getLeft();
        if (value != null) {
          if (value instanceof OSQLFilterItemParameter)
            value = ((OSQLFilterItemParameter) value).getValue(null);

          final Set<?> resultSet = prop.getIndex().getUnderlying().get(value);
          if (resultSet != null && resultSet.size() > 0)
            for (Object o : resultSet) {
              if (o instanceof ORID)
                iResultSet.add(database.load((ORID) o));
              else
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.schema.OProperty

      }

      if (total > 0) {
        if (inverse) {
          // REMOVE THE OLD PROPERTY IF ANY
          OProperty prop = destClass.getProperty(linkName);
          if (prop != null)
            destClass.dropProperty(linkName);

          // CREATE THE PROPERTY
          destClass.createProperty(linkName, multipleRelationship ? OType.LINKLIST : OType.LINK, sourceClass);

        } else {

          // REMOVE THE OLD PROPERTY IF ANY
          OProperty prop = sourceClass.getProperty(linkName);
          if (prop != null)
            sourceClass.dropProperty(linkName);

          // CREATE THE PROPERTY
          sourceClass.createProperty(linkName, OType.LINK, destClass);
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.schema.OProperty

        indexName = value;
      else if (attrib.equals("\"index-type\""))
        indexType = value;
    }

    OProperty prop = iClass.getProperty(propName);
    if (prop == null) {
      // CREATE IT
      prop = iClass.createProperty(propName, type);
    } else {
      if (prop.getId() != id)
        throw new OSchemaException("Imported property '" + iClass.getName() + "." + propName
            + "' has an id different from the original: " + id);
    }

    if (min != null)
      prop.setMin(min);
    if (max != null)
      prop.setMax(max);
    if (linkedClass != null)
      linkedClasses.put(prop, linkedClass);
    if (linkedType != null)
      prop.setLinkedType(linkedType);
    if (indexName != null)
      // PUSH INDEX TO CREATE AFTER ALL
      propertyIndexes.put(prop, indexName);
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.schema.OProperty

      iRequest.data.commandInfo = "Studio add property";

      try {
        OType type = OType.valueOf(fields.get("type"));

        OProperty prop;
        if (type == OType.LINK || type == OType.LINKLIST || type == OType.LINKSET || type == OType.LINKMAP)
          prop = cls.createProperty(fields.get("name"), type, db.getMetadata().getSchema().getClass(fields.get("linkedClass")));
        else
          prop = cls.createProperty(fields.get("name"), type);

        if (fields.get("linkedType") != null)
          prop.setLinkedType(OType.valueOf(fields.get("linkedType")));
        if (fields.get("mandatory") != null)
          prop.setMandatory("on".equals(fields.get("mandatory")));
        if (fields.get("notNull") != null)
          prop.setNotNull("on".equals(fields.get("notNull")));
        if (fields.get("min") != null)
          prop.setMin(fields.get("min"));
        if (fields.get("max") != null)
          prop.setMax(fields.get("max"));
        if (fields.get("indexed") != null)
          prop.createIndex(fields.get("indexed").equals("Unique") ? OProperty.INDEX_TYPE.UNIQUE : OProperty.INDEX_TYPE.NOTUNIQUE);

        db.getMetadata().getSchema().save();

        sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_TEXT_PLAIN,
            "Property " + fields.get("name") + " created successfully with id=" + prop.getId());

      } catch (Exception e) {
        sendTextContent(iRequest, OHttpUtils.STATUS_INTERNALERROR, "Error on creating a new property in class " + rid + ": " + e,
            null, OHttpUtils.CONTENT_TEXT_PLAIN, "Error on creating a new property in class " + rid + ": " + e);
      }
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.schema.OProperty

      if (db.getMetadata().getSchema().getClass(urlParts[2]) == null)
        throw new IllegalArgumentException("Invalid class '" + urlParts[2] + "'");

      final OClass cls = db.getMetadata().getSchema().getClass(urlParts[2]);

      final OProperty prop = cls.createProperty(urlParts[3], OType.STRING);

      db.getMetadata().getSchema().save();

      sendTextContent(iRequest, OHttpUtils.STATUS_CREATED_CODE, OHttpUtils.STATUS_CREATED_DESCRIPTION, null,
          OHttpUtils.CONTENT_TEXT_PLAIN, prop.getId());

    } finally {
      if (db != null)
        OSharedDocumentDatabase.release(db);
    }
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.schema.OProperty

    for (Map.Entry<String, Object> entry : addEntries.entrySet()) {
      coll = null;
      if (!record.containsField(entry.getKey())) {
        // GET THE TYPE IF ANY
        if (record.getSchemaClass() != null) {
          OProperty prop = record.getSchemaClass().getProperty(entry.getKey());
          if (prop != null && prop.getType() == OType.LINKSET)
            // SET TYPE
            coll = new HashSet<Object>();
        }

        if (coll == null)
          // IN ALL OTHER CASES USE A LIST
          coll = new ArrayList<Object>();

        record.field(entry.getKey(), coll);
      } else {
        fieldValue = record.field(entry.getKey());

        if (fieldValue instanceof Collection<?>)
          coll = (Collection<Object>) fieldValue;
        else
          continue;
      }

      v = entry.getValue();

      if (v instanceof OSQLFilterItem)
        v = ((OSQLFilterItem) v).getValue(record);
      else if (v instanceof OSQLFunctionRuntime)
        v = ((OSQLFunctionRuntime) v).execute(record);

      coll.add(v);
      recordUpdated = true;
    }

    // BIND VALUES TO PUT (AS MAP)
    Map<String, Object> map;
    OPair<String, Object> pair;
    for (Entry<String, OPair<String, Object>> entry : putEntries.entrySet()) {
      fieldValue = record.field(entry.getKey());

      if (fieldValue == null) {
        if (record.getSchemaClass() != null) {
          final OProperty property = record.getSchemaClass().getProperty(entry.getKey());
          if (property != null
              && (property.getType() != null && (!property.getType().equals(OType.EMBEDDEDMAP) && !property.getType().equals(
                  OType.LINKMAP)))) {
            throw new OCommandExecutionException("field " + entry.getKey() + " is not defined as a map");
          }
        }
        fieldValue = new HashMap();
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.schema.OProperty

      }

      if (total > 0) {
        if (inverse) {
          // REMOVE THE OLD PROPERTY IF ANY
          OProperty prop = destClass.getProperty(linkName);
          if (prop != null)
            destClass.removeProperty(linkName);

          // CREATE THE PROPERTY
          destClass.createProperty(linkName, multipleRelationship ? OType.LINKLIST : OType.LINK, sourceClass);
          database.getMetadata().getSchema().save();

        } else {

          // REMOVE THE OLD PROPERTY IF ANY
          OProperty prop = sourceClass.getProperty(linkName);
          if (prop != null)
            sourceClass.removeProperty(linkName);

          // CREATE THE PROPERTY
          sourceClass.createProperty(linkName, OType.LINK, destClass);
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.