@Override
 public Object propertyValueOf(QualifiedName stateName) {
   try {
     Object json = state.getJSONObject(JSONKeys.PROPERTIES).opt(stateName.name());
     if (JSONObject.NULL.equals(json)) {
       return null;
     } else {
       PropertyDescriptor descriptor =
           entityDescriptor.state().findPropertyModelByQualifiedName(stateName);
       if (descriptor == null) {
         return null;
       }
       return valueSerialization.deserialize(descriptor.valueType(), json.toString());
     }
   } catch (ValueSerializationException | JSONException e) {
     throw new EntityStoreException(e);
   }
 }
Beispiel #2
0
  /**
   * Creates information about specified qualified name which represents a property.
   *
   * @param qName The qualified name of property.
   * @param tableName The table name where the values of all instances of propertiy with this
   *     qualified name will be stored. May be {@code null} if it is to be decided later.
   * @param propertyDescriptor {@link PropertyDescriptor} of this property.
   * @return An object representing information about property with this qualified name, and how
   *     instances of this property are stored in database.
   */
  public static QNameInfo fromProperty( //
      QualifiedName qName, //
      String tableName, //
      PropertyDescriptor propertyDescriptor //
      ) {
    Type vType = propertyDescriptor.type();
    List<Class<?>> collectionClasses = new ArrayList<>();
    while (vType instanceof ParameterizedType
        && Collection.class.isAssignableFrom((Class<?>) ((ParameterizedType) vType).getRawType())) {
      collectionClasses.add((Class<?>) ((ParameterizedType) vType).getRawType());
      vType = ((ParameterizedType) vType).getActualTypeArguments()[0];
    }

    return new QNameInfo(
        qName,
        QNameType.PROPERTY,
        collectionClasses,
        tableName,
        vType,
        propertyDescriptor,
        null,
        null);
  }