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

Java DefaultCreator类代码示例

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

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



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

示例1: onEnable

import org.mongodb.morphia.mapping.DefaultCreator; //导入依赖的package包/类
@Override
protected void onEnable() throws Throwable
{
	config = new RaceConfig(new File(getDataDir(), "config.yml"));
	
	if (config.getDbUser().isEmpty() || config.getDbPass().isEmpty())
	{
		mongoClient = new MongoClient(config.getDbHost());
	}
	else
	{
		mongoClient = new MongoClient
		(
			Arrays.asList(new ServerAddress(config.getDbHost())),
			Arrays.asList(MongoCredential.createMongoCRCredential(config.getDbName(), config.getDbName(), config.getDbPass().toCharArray()))
		);
	}
	
	morphia = new Morphia();
	morphia.getMapper().getOptions().objectFactory = new DefaultCreator()
	{
           @Override
           protected ClassLoader getClassLoaderForClass(String clazz, DBObject object)
           {
               return getClass().getClassLoader();
           }
       };
	
	datastore = morphia.createDatastore(mongoClient, config.getDbName());
	
	vehicleManagerSerivce = new RaceServiceImpl(getEventManager(), this, datastore);
	registerService(RaceService.class, vehicleManagerSerivce);
	
	LOGGER.info(getDescription().getName() + " " + getDescription().getVersion() + " Enabled.");
}
 
开发者ID:GTAUN,项目名称:wl-race,代码行数:36,代码来源:RacePlugin.java


示例2: onEnable

import org.mongodb.morphia.mapping.DefaultCreator; //导入依赖的package包/类
@Override
protected void onEnable() throws Throwable
{
	config = new VehicleManagerConfig(new File(getDataDir(), "config.yml"));
	
	if (config.getDbUser().isEmpty() || config.getDbPass().isEmpty())
	{
		mongoClient = new MongoClient(config.getDbHost());
	}
	else
	{
		mongoClient = new MongoClient
		(
			Arrays.asList(new ServerAddress(config.getDbHost())),
			Arrays.asList(MongoCredential.createMongoCRCredential(config.getDbName(), config.getDbName(), config.getDbPass().toCharArray()))
		);
	}
	
	morphia = new Morphia();
	morphia.getMapper().getOptions().objectFactory = new DefaultCreator()
	{
		@Override
		protected ClassLoader getClassLoaderForClass(String clazz, DBObject object)
		{
			return getClass().getClassLoader();
		}
	};
	morphia.map(GlobalVehicleStatisticImpl.class);
	morphia.map(PlayerVehicleStatisticImpl.class);
	
	datastore = morphia.createDatastore(mongoClient, config.getDbName());
	
	vehicleManagerSerivce = new VehicleManagerServiceImpl(getEventManager(), this, datastore);
	registerService(VehicleManagerService.class, vehicleManagerSerivce);
	
	LOGGER.info(getDescription().getName() + " " + getDescription().getVersion() + " Enabled.");
}
 
开发者ID:GTAUN,项目名称:wl-vehicle-manager,代码行数:38,代码来源:VehicleManagerPlugin.java


示例3: MongoDB

import org.mongodb.morphia.mapping.DefaultCreator; //导入依赖的package包/类
@Inject
public MongoDB(Injector injector,
               Set<TypeConverter> converters,
               @Named(MAPPED_CLASSES) Set<Class<?>> mappedClasses,
               @Named(HOST_PROPERTY) String host,
               @Named(PORT_PROPERTY) int port,
               @Named(DATABASE_PROPERTY) String database,
               @Nullable @Named(USER_PROPERTY) String username,
               @Nullable @Named(PASS_PROPERTY) char[] password) {
    try {
        MorphiaLoggerFactory.registerLogger(SLF4JLoggerImplFactory.class);
        if (username == null) {
            mongo = new MongoClient(new ServerAddress(host, port));
        }
        else {
            mongo = new MongoClient(new ServerAddress(host, port), Collections.singletonList(
                MongoCredential.createMongoCRCredential(username, database, password)));
        }
        
        morphia = new Morphia();
        morphia.getMapper().getOptions().setObjectFactory(new CustomGuiceObjectFactory(new DefaultCreator(), injector));
        addConverters(converters);
        addMappedClasses(mappedClasses);
        
        datastore = morphia
                .createDatastore(mongo, database);
        datastore.ensureIndexes();
        ensureIndexes();
        datastore.ensureCaps();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:enviroCar,项目名称:enviroCar-server,代码行数:34,代码来源:MongoDB.java


示例4: testBasicMappingWithCachedClasses

import org.mongodb.morphia.mapping.DefaultCreator; //导入依赖的package包/类
@Test
public void testBasicMappingWithCachedClasses() throws Exception {
    getMorphia().getMapper().getOptions().setCacheClassLookups(true);
    try {
        performBasicMappingTest();
        final DefaultCreator objectFactory = (DefaultCreator) getMorphia().getMapper().getOptions().getObjectFactory();
        assertTrue(objectFactory.getClassNameCache().containsKey(Hotel.class.getName()));
        assertTrue(objectFactory.getClassNameCache().containsKey(TravelAgency.class.getName()));
    } finally {
        getMorphia().getMapper().getOptions().setCacheClassLookups(false);
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:13,代码来源:TestMapping.java


示例5: buildCrudService

import org.mongodb.morphia.mapping.DefaultCreator; //导入依赖的package包/类
private void buildCrudService(Dictionary<String, ?> properties, String id) {
    try {
        if (!PropertiesUtil.toString(properties.get(UNITNAME_PROP), "").equals("")) {
            //Aboard in case of nothing provided in dbname.
            //Avoiding db connection creation with blank db name.
            if (PropertiesUtil.toString(properties.get("dbName"), "").equals("")) {
                throw new InvalidMongoDatabaseException("Invalid mongo database name. Provide a valid database name.");
            }
            MongoCredential credential = null;
            if (!PropertiesUtil.toString(properties.get("username"), "").equals("")) {
                credential = MongoCredential.createCredential(
                        PropertiesUtil.toString(properties.get("username"), ""),
                        PropertiesUtil.toString(properties.get("dbName"), ""),
                        PropertiesUtil.toString(properties.get("password"), "").toCharArray()
                );
            }

            Morphia morphia = new Morphia();
            if (!PropertiesUtil.toString(properties.get("mappablePackage"), "").equals("")) {
                morphia.mapPackage(properties.get("mappablePackage").toString());
            }

            //Adding bundle class loader to load entity classes from fragment bundle.
            morphia.getMapper().getOptions().setObjectFactory(new DefaultCreator() {
                @Override
                protected ClassLoader getClassLoaderForClass() {
                    return MongoConnectionProvider.class.getClassLoader();
                }
            });

            ServerAddress serverAddress = new ServerAddress(
                    PropertiesUtil.toString(properties.get("hostName"), ""),
                    PropertiesUtil.toInteger(properties.get("port"), 0)
            );

            MongoClient mongoClient = null;
            if (credential != null) {
                mongoClient = new MongoClient(
                        serverAddress,
                        Arrays.asList(credential),
                        this.buildMongoOptions(properties)
                );
            } else {
                mongoClient = new MongoClient(
                        serverAddress,
                        this.buildMongoOptions(properties)
                );
            }

            if (this.unitMapping.containsKey(id)) {
                this.destroy(id);
            }

            this.serviceContainer.put(
                    PropertiesUtil.toString(properties.get(UNITNAME_PROP), ""),
                    new MongoCrudRepositoryImpl(
                            morphia.createDatastore(
                                    mongoClient,
                                    PropertiesUtil.toString(properties.get("dbName"), "")
                            )
                    )
            );

            this.unitMapping.put(id,
                    PropertiesUtil.toString(properties.get(UNITNAME_PROP), ""));
        } else {
            throw new InvalidMongoUnitException("Invalid Unit name provided for mongo db configuration. Provide Valid and unique name for unit");
        }
    } catch (Exception ex) {
        LOGGER.error("Unable to create mongo crud service for config id {} full exception ", id, ex);
    }
}
 
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:73,代码来源:MongoConnectionProvider.java


示例6: testBasicMapping

import org.mongodb.morphia.mapping.DefaultCreator; //导入依赖的package包/类
@Test
public void testBasicMapping() throws Exception {
    performBasicMappingTest();
    final DefaultCreator objectFactory = (DefaultCreator) getMorphia().getMapper().getOptions().getObjectFactory();
    assertTrue(objectFactory.getClassNameCache().isEmpty());
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:7,代码来源:TestMapping.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java DialShape类代码示例发布时间:2022-05-22
下一篇:
Java ParticleIO类代码示例发布时间: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