• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Mapper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.mongodb.morphia.mapping.Mapper的典型用法代码示例。如果您正苦于以下问题:Java Mapper类的具体用法?Java Mapper怎么用?Java Mapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Mapper类属于org.mongodb.morphia.mapping包,在下文中一共展示了Mapper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: update

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Override
public void update(List<Provider> entityList) throws DBException {
    for (Provider provider : entityList) {
        List<Provider> providers = fetchById(new ArrayList<String>() {{
            add(provider.getCloudProvider());
        }});
        Provider existingProvider = null;
        if (providers != null && !providers.isEmpty()) {
            existingProvider = providers.get(0);
        }
        if (existingProvider != null) {
            UpdateOperations<Provider> ops = this.createUpdateOperations();
            if (provider.getCommands() != null) {
                ops.set("commands", provider.getCommands());
            }
            if (provider.getDockerImage() != null) {
                ops.set("dockerImage", provider.getDockerImage());
            }

            Query<Provider> updateQuery = this.createQuery().field(Mapper.ID_KEY).equal(provider.getCloudProvider());
            UpdateResults results = this.update(updateQuery, ops);
        }
    }
}
 
开发者ID:sjsucohort6,项目名称:amigo-chatbot,代码行数:25,代码来源:ProviderDAO.java


示例2: createManager

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
protected MoManager createManager() throws NotFoundException {
	 MongoDataSource ds = getMongoDataSource();
	 MongoClient client = ds.getConnection();
	 MoSchema schema = doCreateSchema();
	 
	 BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
	 MoManager manager = new MoManager(client,schema) {
			@Override
			protected Mapper createMapper() {
				Mapper m = super.createMapper();
				m.getOptions().setObjectFactory(new BundleObjectFactory(bundleContext));
				return m;
			}

	 };

	return manager;
}
 
开发者ID:mhus,项目名称:mhus-osgi-tools,代码行数:19,代码来源:MoManagerServiceImpl.java


示例3: prePersist

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Override
public void prePersist(final Object entity, final DBObject dbObj, final Mapper mapper) {
  MappedClass mclass = mapper.getMappedClass(entity);
  Field id = mclass.getIdField();
  if (id != null && id.getAnnotation(GeneratedValue.class) != null) {
    try {
      id.setAccessible(true);
      final String collName = gen.value(mclass.getClazz());
      final Query<StoredId> q = db.find(StoredId.class, "_id", collName);
      final UpdateOperations<StoredId> uOps = db.createUpdateOperations(StoredId.class)
          .inc("value");
      StoredId newId = db.findAndModify(q, uOps);
      if (newId == null) {
        newId = new StoredId(collName);
        db.save(newId);
      }
      id.set(entity, newId.value);
    } catch (Exception ex) {
      throw new IllegalStateException("Can't generate ID on " + mclass, ex);
    }
  }
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:23,代码来源:AutoIncID.java


示例4: createInstanceFromClazz

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Test
public void createInstanceFromClazz() throws Exception {
  Injectable injectable = new Injectable();

  new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class)
      .expect(boot)
      .expect(unit -> {
        Registry injector = unit.get(Registry.class);
        expect(injector.require(Injectable.class)).andReturn(injectable);
      })
      .run(unit -> {
        assertEquals(injectable,
            new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
                .createInstance(Injectable.class));

      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:18,代码来源:GuiceObjectFactoryTest.java


示例5: createInstanceFromClazzNoInjectable

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Test
public void createInstanceFromClazzNoInjectable() throws Exception {
  GuiceObjectFactoryTest expected = new GuiceObjectFactoryTest();

  new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class)
      .expect(boot)
      .expect(unit -> {
        ObjectFactory injector = unit.get(ObjectFactory.class);
        expect(injector.createInstance(GuiceObjectFactoryTest.class)).andReturn(expected);
      })
      .run(unit -> {
        assertEquals(expected,
            new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
                .createInstance(GuiceObjectFactoryTest.class));

      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:18,代码来源:GuiceObjectFactoryTest.java


示例6: createInstanceFromClazzWithDBObject

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Test
public void createInstanceFromClazzWithDBObject() throws Exception {
  Injectable injectable = new Injectable();

  new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class, DBObject.class)
      .expect(boot)
      .expect(unit -> {
        Registry injector = unit.get(Registry.class);
        expect(injector.require(Injectable.class)).andReturn(injectable);
      })
      .run(unit -> {
        assertEquals(injectable,
            new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
                .createInstance(Injectable.class, unit.get(DBObject.class)));

      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:18,代码来源:GuiceObjectFactoryTest.java


示例7: createInstanceFromClazzWithDBObjectNoInjectable

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Test
public void createInstanceFromClazzWithDBObjectNoInjectable() throws Exception {
  GuiceObjectFactoryTest expected = new GuiceObjectFactoryTest();

  new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class, DBObject.class)
      .expect(boot)
      .expect(unit -> {
        ObjectFactory factory = unit.get(ObjectFactory.class);
        expect(factory.createInstance(GuiceObjectFactoryTest.class, unit.get(DBObject.class)))
            .andReturn(expected);
      })
      .run(unit -> {
        assertEquals(expected,
            new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
                .createInstance(GuiceObjectFactoryTest.class, unit.get(DBObject.class)));

      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:19,代码来源:GuiceObjectFactoryTest.java


示例8: createInstanceFully

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Test
public void createInstanceFully() throws Exception {
  Injectable injectable = new Injectable();

  new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class, DBObject.class,
      MappedField.class)
      .expect(boot)
      .expect(unit -> {
        MappedField mf = unit.get(MappedField.class);
        expect(mf.getType()).andReturn(Injectable.class);

        Registry injector = unit.get(Registry.class);
        expect(injector.require(Injectable.class)).andReturn(injectable);
      })
      .run(
          unit -> {
            assertEquals(
                injectable,
                new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
                    .createInstance(unit.get(Mapper.class), unit.get(MappedField.class),
                        unit.get(DBObject.class)));

          });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:25,代码来源:GuiceObjectFactoryTest.java


示例9: createInstanceFullyNoInjectable

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Test
public void createInstanceFullyNoInjectable() throws Exception {
  GuiceObjectFactoryTest expected = new GuiceObjectFactoryTest();

  new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class, DBObject.class,
      MappedField.class)
      .expect(boot)
      .expect(unit -> {
        MappedField mf = unit.get(MappedField.class);
        expect(mf.getType()).andReturn(GuiceObjectFactoryTest.class);

        ObjectFactory factory = unit.get(ObjectFactory.class);
        expect(factory.createInstance(unit.get(Mapper.class), mf, unit.get(DBObject.class)))
            .andReturn(expected);
      })
      .run(unit -> {
        assertEquals(
            expected,
            new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
                .createInstance(unit.get(Mapper.class), unit.get(MappedField.class),
                    unit.get(DBObject.class)));

      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:25,代码来源:GuiceObjectFactoryTest.java


示例10: createMap

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Test
public void createMap() throws Exception {
  Map<String, Object> expected = Collections.emptyMap();

  new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class,
      MappedField.class)
      .expect(boot)
      .expect(unit -> {
        ObjectFactory factory = unit.get(ObjectFactory.class);
        expect(factory.createMap(unit.get(MappedField.class))).andReturn(expected);
      })
      .run(unit -> {
        assertEquals(
            expected,
            new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
                .createMap(unit.get(MappedField.class)));

      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:20,代码来源:GuiceObjectFactoryTest.java


示例11: createSet

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Test
public void createSet() throws Exception {
  Set<String> expected = Collections.emptySet();

  new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class,
      MappedField.class)
      .expect(boot)
      .expect(unit -> {
        ObjectFactory factory = unit.get(ObjectFactory.class);
        expect(factory.createSet(unit.get(MappedField.class))).andReturn(expected);
      })
      .run(unit -> {
        assertEquals(
            expected,
            new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
                .createSet(unit.get(MappedField.class)));

      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:20,代码来源:GuiceObjectFactoryTest.java


示例12: createList

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Test
public void createList() throws Exception {
  List<String> expected = Collections.emptyList();

  new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class,
      MappedField.class)
      .expect(boot)
      .expect(unit -> {
        ObjectFactory factory = unit.get(ObjectFactory.class);
        expect(factory.createList(unit.get(MappedField.class))).andReturn(expected);
      })
      .run(unit -> {
        assertEquals(
            expected,
            new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
                .createList(unit.get(MappedField.class)));

      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:20,代码来源:GuiceObjectFactoryTest.java


示例13: shouldSkipNullID

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Test
public void shouldSkipNullID() throws Exception {
  Object entity = new Object();
  new MockUnit(Datastore.class, DBObject.class, Mapper.class, MappedClass.class, Field.class,
      GeneratedValue.class)
          .expect(unit -> {

            MappedClass mclass = unit.get(MappedClass.class);
            expect(mclass.getIdField()).andReturn(null);
            Mapper mapper = unit.get(Mapper.class);
            expect(mapper.getMappedClass(entity)).andReturn(mclass);
          })
          .run(unit -> {
            new AutoIncID(unit.get(Datastore.class), IdGen.LOCAL)
                .prePersist(entity, unit.get(DBObject.class), unit.get(Mapper.class));
          });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:18,代码来源:Issue569.java


示例14: fromDBObject

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Override
public void fromDBObject(DBObject dbObject, MappedField mf, Object entity, EntityCache cache, Mapper mapper) {
    BasicDBList cowlist = (BasicDBList) dbObject.get(mf.getNameToStore());

    if (cowlist == null)
        throw new IllegalArgumentException("Improperly formatted DBObject for CopyOnWriteList");

    List core = new ArrayList();
    for (Object obj : cowlist) {
        DBObject listEntryDbObj = (DBObject) obj;

        // Hack until we can coax MappedField to understand what CopyOnWriteList is. Eliminate as soon as possible.
        // Currently mf.getSubType() is null because MappedField does not use Iterable to determine a list and thus
        // does not check for subtypes.
        Class clazz = mapper.getOptions().getObjectFactory().createInstance(mapper, mf, listEntryDbObj).getClass();

        core.add(mapper.fromDBObject(clazz, listEntryDbObj, cache));
    }
    mf.setFieldValue(entity, new CopyOnWriteList(core));
}
 
开发者ID:groupon,项目名称:DotCi,代码行数:21,代码来源:CopyOnWriteListMapper.java


示例15: fromDBObject

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Override
public void fromDBObject(final DBObject dbObject, final MappedField mf, final Object entity, final EntityCache cache, final Mapper mapper) {

    final Key key = extractKey(mapper, mf, (DBObject) dbObject.get(mf.getNameToStore()));
    if (key != null && cache.getEntity(key) != null) {
        final Object object = cache.getEntity(key);
        mf.setFieldValue(entity, object);
    } else if (this.customMappers.containsKey(mf.getType())) {
        this.customMappers.get(mf.getType()).fromDBObject(dbObject, mf, entity, cache, mapper);
    } else if (isAwkwardMap(mf)) {
        this.awkwardMapper.fromDBObject(dbObject, mf, entity, cache, mapper);
    } else {
        // the first two conditions (isMap and isMultipleValues) are part of the hack to fix handling primitives
        if (mf.isMap()) {
            readMap(dbObject, mf, entity, cache, mapper);
        } else if (mf.isMultipleValues()) {
            readCollection(dbObject, mf, entity, cache, mapper);
        } else {
            mapper.getOptions().getEmbeddedMapper().fromDBObject(dbObject, mf, entity, cache, mapper);
        }

        this.serializationMethodInvoker.callReadResolve(mf.getFieldValue(entity));
    }


}
 
开发者ID:groupon,项目名称:DotCi,代码行数:27,代码来源:JenkinsEmbeddedMapper.java


示例16: should_get_cause_from_dbObject

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Test
public void should_get_cause_from_dbObject() throws Exception {
    BasicDBObject cause1DbObject = new BasicDBObject("cause1", "cause1");
    DBObject causes = new BasicDBObjectBuilder().add("causes", Arrays.asList(cause1DbObject)).get();

    Mapper mapper = Mockito.mock(Mapper.class);
    Cause cause1 = new NullBuildCause();
    when(mapper.fromDBObject(null, cause1DbObject, null)).thenReturn(cause1);

    CauseActionConverter converter = new CauseActionConverter();
    converter.setMapper(mapper);
    CauseAction action = converter.decode(CauseAction.class, causes, Mockito.mock(MappedField.class));

    Assert.assertEquals(1, action.getCauses().size());
    Assert.assertEquals(cause1, action.getCauses().get(0));

}
 
开发者ID:groupon,项目名称:DotCi,代码行数:18,代码来源:CauseActionConverterTest.java


示例17: should_convert_cause_action_to_old_format

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@Test
public void should_convert_cause_action_to_old_format() throws Exception {
    Cause cause1 = new NullBuildCause();
    Mapper mapper = Mockito.mock(Mapper.class);
    when(mapper.toDBObject(cause1)).thenReturn(new BasicDBObject("cause1", "cause1"));

    CauseAction causeAction = new CauseAction(cause1);
    CauseActionConverter converter = new CauseActionConverter();
    converter.setMapper(mapper);

    DBObject dbObject = (DBObject) converter.encode(causeAction, null);

    Assert.assertEquals(dbObject.get("className"), CauseAction.class.getName());
    Assert.assertNotNull(dbObject.get("causes"));
    List dbCauses = ((List) dbObject.get("causes"));
    Assert.assertEquals(1, dbCauses.size());
    Assert.assertEquals("cause1", ((BasicDBObject) dbCauses.get(0)).get("cause1"));
}
 
开发者ID:groupon,项目名称:DotCi,代码行数:19,代码来源:CauseActionConverterTest.java


示例18: deref

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected <T> Iterable<T> deref(Class<T> clazz, List<Key<T>> keys) {
    if (keys == null || keys.isEmpty()) {
        return Collections.emptyList();
    }
    ListMultimap<String, Key<T>> kindMap = getKindMap(clazz, keys);
    List<Iterable<T>> fetched = Lists.newLinkedList();
    for (String kind : kindMap.keySet()) {
        List<Key<T>> kindKeys = kindMap.get(kind);
        List<Object> objIds = new ArrayList<>(kindKeys.size());
        Class<T> kindClass = clazz == null
                             ? (Class<T>) kindKeys.get(0).getType()
                             : clazz;
        kindKeys.stream().map(Key::getId).forEach(objIds::add);
        fetched.add(getDatastore()
                .find(kindClass)
                .disableValidation()
                .field(Mapper.ID_KEY)
                .in(objIds)
                .fetch());
    }
    return Iterables.concat(fetched);
}
 
开发者ID:enviroCar,项目名称:enviroCar-server,代码行数:24,代码来源:MongoDB.java


示例19: setupDatabase

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
private void setupDatabase(MongoClient mongoCl, String dbName) {
	// Initialize Morphia
	Morphia morphia = new Morphia();
	morphia.map(Company.class).map(LinkedChest.class);

	// Setup datastore
	MapperOptions opts = new MapperOptions();
	opts.objectFactory = new CustomCreator(this.getClassLoader());
	Mapper mapper = new Mapper(opts);
	Datastore ds = new DatastoreImpl(mapper, mongoCl, dbName);

	// Setup DAOs
	companyDAO = new CompanyDAO(ds);
	companyDAO.ensureIndexes();
	linkedChestDAO = new LinkedChestDAO(ds);
	linkedChestDAO.ensureIndexes();
}
 
开发者ID:stephenmac7,项目名称:Incorporate,代码行数:18,代码来源:Incorporate.java


示例20: toCommand

import org.mongodb.morphia.mapping.Mapper; //导入依赖的package包/类
@SuppressWarnings("deprecation")
MapReduceCommand toCommand(final Mapper mapper) {
    if (query.getOffset() != 0 || query.getFieldsObject() != null) {
        throw new QueryException("mapReduce does not allow the offset/retrievedFields query ");
    }

    final DBCollection dbColl = inputCollection != null ? getQuery().getCollection().getDB().getCollection(inputCollection)
                                                        : query.getCollection();
    final String target = outputCollection != null ? outputCollection : mapper.getMappedClass(resultType).getCollectionName();

    final MapReduceCommand command = new MapReduceCommand(dbColl, map, reduce, target, outputType, query.getQueryObject());
    command.setBypassDocumentValidation(bypassDocumentValidation);
    command.setCollation(collation);
    command.setFinalize(finalize);
    command.setJsMode(jsMode);
    command.setLimit(limit);
    command.setMaxTime(maxTimeMS, TimeUnit.MILLISECONDS);
    command.setOutputDB(outputDB);
    command.setReadPreference(readPreference);
    command.setScope(scope);
    command.setSort(query.getSortObject());
    command.setVerbose(verbose);

    return command;
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:26,代码来源:MapReduceOptions.java



注:本文中的org.mongodb.morphia.mapping.Mapper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Interval类代码示例发布时间:2022-05-22
下一篇:
Java Decoder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap