本文整理了Java中org.mongodb.morphia.Morphia
类的一些代码示例,展示了Morphia
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Morphia
类的具体详情如下:
包路径:org.mongodb.morphia.Morphia
类名称:Morphia
暂无
代码示例来源:origin: ltsopensource/light-task-scheduler
public static Datastore getDataStore(Config config) {
String[] addresses = config.getParameter(ExtConfig.MONGO_ADDRESSES, new String[]{"127.0.0.1:27017"});
String database = config.getParameter(ExtConfig.MONGO_DATABASE, "lts");
String username = config.getParameter(ExtConfig.MONGO_USERNAME);
String pwd = config.getParameter(ExtConfig.MONGO_PASSWORD);
String cachedKey = StringUtils.concat(StringUtils.concat(addresses), database, username, pwd);
Datastore datastore = DATA_STORE_MAP.get(cachedKey);
if (datastore == null) {
try {
synchronized (lock) {
datastore = DATA_STORE_MAP.get(cachedKey);
if (datastore != null) {
return datastore;
}
Morphia morphia = new Morphia();
MongoFactoryBean mongoFactoryBean = new MongoFactoryBean(addresses, username, database, pwd);
MongoClient mongo = mongoFactoryBean.createInstance();
datastore = morphia.createDatastore(mongo, database);
DATA_STORE_MAP.put(cachedKey, datastore);
}
} catch (Exception e) {
throw new IllegalStateException(
StringUtils.format("connect mongo failed! addresses: {}, database: {}",
addresses, database), e);
}
}
return datastore;
}
代码示例来源:origin: querydsl/querydsl
@Override
protected DBRef asReference(Object constant) {
Key<?> key = morphia.getMapper().getKey(constant);
return morphia.getMapper().keyToDBRef(key);
}
代码示例来源:origin: lievendoclo/cleanarch
public MongoDbBuildingEntityGateway(MongoClient mongo) {
Morphia morphia = new Morphia();
morphia.mapPackage("be.insaneprogramming.cleanarch.entitygatewayimpl.morphia");
this.datastore = morphia.createDatastore(mongo, "cleanarch");
}
代码示例来源:origin: stackoverflow.com
Morphia morphia = new Morphia();
morphia.map(Person.class);
/* You can reuse this datastore */
Datastore datastore = morphia.createDatastore(mongoClient, "myDatabase");
/*
* Jackson's ObjectMapper, which is reusable, too,
* does all the magic.
*/
ObjectMapper mapper = new ObjectMapper();
代码示例来源:origin: RentTheRunway/alchemy
private MongoStoreProvider(List<ServerAddress> hosts,
List<MongoCredential> credentials,
MongoClientOptions options,
String database) {
final Morphia morphia = new Morphia();
morphia.getMapper().getOptions().setStoreEmpties(true);
morphia.getMapper().getConverters().addConverter(DateTimeConverter.class);
client = options == null ? new MongoClient(hosts, credentials) : new MongoClient(hosts, credentials, options);
final AdvancedDatastore ds = (AdvancedDatastore) morphia.createDatastore(client, database);
final RevisionManager revisionManager = new RevisionManager(ds);
this.store = new MongoExperimentsStore(ds, revisionManager);
this.cache = new MongoExperimentsCache(ds, revisionManager);
}
代码示例来源:origin: protegeproject/webprotege
@Override
public Datastore get() {
return morphia.createDatastore(mongoClient, dbName);
}
}
代码示例来源:origin: protegeproject/webprotege
@Override
public Morphia get() {
Morphia morphia = new Morphia();
Mapper mapper = morphia.getMapper();
mapper.getOptions().setStoreEmpties(true);
converters.addConverter(new HashedApiKeyConverter());
converters.addConverter(new ApiKeyIdConverter());
morphia.map(EntityDiscussionThread.class);
morphia.map(UserActivityRecord.class);
morphia.map(RoleAssignment.class);
代码示例来源:origin: stackoverflow.com
import com.mongodb.MongoClient;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.DatastoreImpl;
import org.mongodb.morphia.Morphia;
import java.net.UnknownHostException;
.....
private Datastore createDataStore() throws UnknownHostException {
MongoClient client = new MongoClient("localhost", 27017);
// create morphia and map classes
Morphia morphia = new Morphia();
morphia.map(FooBar.class);
return new DatastoreImpl(morphia, client, "testmongo");
}
......
//with the Datastore from above you can save any mapped class to mongo
Datastore datastore;
final FooBar fb = new FooBar("hello", "world");
datastore.save(fb);
代码示例来源:origin: org.actframework/act-morphia
void init(final App app, Map<String, String> conf) {
morphia = new Morphia();
MapperOptions options = morphia.getMapper().getOptions();
options.setObjectFactory(new DefaultCreator(){
@Override
protected ClassLoader getClassLoaderForClass() {
return app.classLoader();
}
});
fieldNameLookup = new HashMap<>();
$.T2<MongoClientURI, MongoClient> t2 = ClientManager.register(this, conf);
initDataStore(t2, conf);
delayedEnsureIndexesAndCaps(app);
delayedMapExternalModels(app);
registerFastJsonConfig();
app.resolverManager().register(ObjectId.class, new StringValueResolver<ObjectId>() {
@Override
public ObjectId resolve(String s) {
return S.blank(s) ? null : new ObjectId(s);
}
});
initialized = true;
final MorphiaService me = this;
app.jobManager().post(SysEventId.SINGLETON_PROVISIONED, new Runnable() {
@Override
public void run() {
app.eventBus().emit(new DbServiceInitialized(me));
}
}, true);
}
代码示例来源:origin: jzyong/game-server
/**
* 创建mongodb连接
*
* @param configPath
*/
public void createConnect(String configPath) {
mongoConfig = FileUtil.getConfigXML(configPath, "mongoClientConfig.xml", MongoClientConfig.class);
if (mongoConfig == null) {
throw new RuntimeException(String.format("mongodb 配置文件 %s/MongoClientConfig.xml 未找到", configPath));
}
MongoClientURI uri = new MongoClientURI(mongoConfig.getUrl());
mongoClient = new MongoClient(uri);
morphia = new Morphia();
morphia.mapPackage("");
initDao();
}
代码示例来源:origin: stackoverflow.com
ds = new Morphia().mapPackage("com.test.entities").createDatastore(mongoClient, dbname);
代码示例来源:origin: org.mongodb.morphia/morphia
/**
* Tries to map all classes in the package specified. Fails if one of the classes is not valid for mapping.
*
* @param packageName the name of the package to process
* @return the Morphia instance
*/
public synchronized Morphia mapPackage(final String packageName) {
return mapPackage(packageName, false);
}
代码示例来源:origin: org.mongodb.morphia/morphia
/**
* Creates a Morphia instance with the given Mapper and class set.
*
* @param mapper the Mapper to use
* @param classesToMap the classes to map
*/
public Morphia(final Mapper mapper, final Set<Class> classesToMap) {
this.mapper = mapper;
for (final Class c : classesToMap) {
map(c);
}
}
代码示例来源:origin: com.github.sogyf/goja-mvt
/**
* Default .
*
* @param mongo mongo
* @param db mongo database.
* @param entity_package entity package name.
*/
private MorphiaKit(final MongoClient mongo, final String db, String entity_package) {
Preconditions.checkNotNull(mongo, "the mongo object is not null. ");
Preconditions.checkNotNull(db, "the mongodb database name is not null.");
Morphia morphia = new Morphia();
_datastore = morphia.createDatastore(mongo, db);
morphia.mapPackage(entity_package);
}
代码示例来源:origin: stackoverflow.com
MongoClient mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost"));
Morphia morphia = new Morphia();
morphia.map(LookupData.class);
//lookupdata collection is under my local db "tutorials" in this case
Datastore datastore = morphia.createDatastore(mongoClient, "tutorials");
Map<String,ArrayList> categotyLookUpMap = new HashMap<String,ArrayList>();
LookupData lookupData = datastore.find(LookupData.class).get();
categotyLookUpMap.put(lookupData.getKey(), lookupData.getValue());
代码示例来源:origin: acmeair/acmeair
private MongoConnectionManager (){
Morphia morphia = new Morphia();
MongoClient mongo = new MongoClient(mongoURI);
morphia.getMapper().getConverters().addConverter(new BigDecimalConverter());
datastore = morphia.createDatastore( mongo ,mongoURI.getDatabase());
} else {
morphia.getMapper().getConverters().addConverter(new BigDecimalConverter());
datastore = morphia.createDatastore(new MongoClient(db.getMongo().getConnectPoint(),builder.build()), db.getName());
代码示例来源:origin: org.mongodb.morphia/morphia
protected void initDS(final MongoClient mongoClient, final Morphia mor, final String db) {
ds = (org.mongodb.morphia.DatastoreImpl) mor.createDatastore(mongoClient, db);
}
代码示例来源:origin: stackoverflow.com
@Configuration
@PropertySource("classpath:mongo.properties")
public class AppConfig{
// some methods ...
@Bean
public Mongo mongo(@Value("${mongo.host.addr}")String host,@Value("${mongo.host.port}")int port){
return new Mongo(host,port);
}
@Bean
public Morphia morphia(){
return new Morphia();
}
}
代码示例来源:origin: org.mongodb.morphia/morphia
/**
* Maps all the classes found in the package to which the given class belongs.
*
* @param clazz the class to use when trying to find others to map
* @return this
*/
public Morphia mapPackageFromClass(final Class clazz) {
return mapPackage(clazz.getPackage().getName(), false);
}
代码示例来源:origin: BlackLabs/play-morphia
try {
debug("mapping class: %1$s", clz.getName());
morphia_.map(clz);
} catch (ConstraintViolationException e) {
throw new RuntimeException(e);
内容来源于网络,如有侵权,请联系作者删除!