本文整理汇总了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.");
}
示例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.");
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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());
}