Package com.googlecode.objectify

Examples of com.googlecode.objectify.ObjectifyFactory


    final Class<? extends Map<?, ?>> mapType = tk.getTypeAsClass();

    if (!Map.class.isAssignableFrom(mapType))
      return null// We might be here processing the component type of the mapify map!

    final ObjectifyFactory fact = ctx.getFactory();

    Type componentType = GenericUtils.getMapValueType(tk.getType());
    final Translator<Object, Object> componentTranslator = fact.getTranslators().get(new TypeKey(componentType, tk), ctx, path);

    @SuppressWarnings("unchecked")
    final Mapper<Object, Object> mapper = (Mapper<Object, Object>)fact.construct(mapify.value());

    return new TranslatorRecycles<Map<Object, Object>, Collection<Object>>() {
      @Override
      public Map<Object, Object> loadInto(Collection<Object> node, LoadContext ctx, Path path, Map<Object, Object> map) throws SkipException {
        if (node == null)
          throw new SkipException();

        if (map == null)
          //noinspection unchecked
          map = (Map<Object, Object>)fact.constructMap(mapType);
        else
          map.clear();

        for (Object child: node) {
          try {
View Full Code Here


    final Class<? extends Collection<?>> collectionType = tk.getTypeAsClass();

    if (!Collection.class.isAssignableFrom(collectionType))
      return null;

    final ObjectifyFactory fact = ctx.getFactory();

    Type componentType = GenericUtils.getCollectionComponentType(tk.getType());
    final Translator<Object, Object> componentTranslator = ctx.getTranslator(new TypeKey<>(componentType, tk), ctx, path);

    return new TranslatorRecycles<Collection<Object>, Collection<Object>>() {

      @Override
      public Collection<Object> loadInto(Collection<Object> node, LoadContext ctx, Path path, Collection<Object> collection) throws SkipException {
        // If the collection does not exist, skip it entirely. This mirrors the underlying behavior
        // of collections in the datastore; if they are empty, they don't exist.
        if (node == null)
          throw new SkipException();

        if (collection == null)
          //noinspection unchecked
          collection = (Collection<Object>)fact.constructCollection(collectionType, node.size());
        else
          collection.clear();

        for (Object child: node) {
          try {
View Full Code Here

      stringifierClass = KeyStringifier.class;

    if (stringifierClass == null)
      throw new IllegalStateException("Embedded Map keys must be of type String/Enum/Key<?> or field must specify @Stringify");

    final ObjectifyFactory fact = ctx.getFactory();

    @SuppressWarnings("unchecked")
    final Stringifier<Object> stringifier = (Stringifier<Object>)fact.construct(stringifierClass);
    if (stringifier instanceof InitializeStringifier)
      ((InitializeStringifier)stringifier).init(fact, keyType);

    Type componentType = GenericUtils.getMapValueType(tk.getType());
    final Translator<Object, Object> componentTranslator = fact.getTranslators().get(new TypeKey<>(componentType, tk), ctx, path);

    return new TranslatorRecycles<Map<Object,Object>, EmbeddedEntity>() {

      @Override
      public Map<Object, Object> loadInto(EmbeddedEntity node, LoadContext ctx, Path path, Map<Object, Object> into) {
        // Make this work more like collections than atomic values
        if (node == null)
          throw new SkipException();

        if (into == null)
          //noinspection unchecked
          into = (Map<Object, Object>)fact.constructMap(mapType);
        else
          into.clear();

        for (Map.Entry<String, Object> entry: node.getProperties().entrySet()) {
          Object key = stringifier.fromString(entry.getKey());
View Full Code Here

TOP

Related Classes of com.googlecode.objectify.ObjectifyFactory

Copyright © 2018 www.massapicom. 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.