本文整理汇总了Java中org.mongodb.morphia.mapping.Mapper类的典型用法代码示例。如果您正苦于以下问题:Java Mapper类的具体用法?Java Mapper怎么用?Java Mapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Mapper类属于org.mongodb.morphia.mapping包,在下文中一共展示了Mapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例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;
}
示例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);
}
}
}
示例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));
});
}
示例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));
});
}
示例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)));
});
}
示例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)));
});
}
示例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)));
});
}
示例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)));
});
}
示例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)));
});
}
示例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)));
});
}
示例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)));
});
}
示例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));
});
}
示例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));
}
示例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));
}
}