org.mongodb.morphia.Morphia.map()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中org.mongodb.morphia.Morphia.map()方法的一些代码示例,展示了Morphia.map()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Morphia.map()方法的具体详情如下:
包路径:org.mongodb.morphia.Morphia
类名称:Morphia
方法名:map

Morphia.map介绍

[英]Maps a set of classes
[中]映射一组类

代码示例

代码示例来源: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: 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: 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: 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: stackoverflow.com

@Configuration
public class MorphiaAutoConfiguration {

  @Autowired
  private MongoClient mongoClient; // created from MongoAutoConfiguration

  @Bean
  public Datastore datastore() {
    Morphia morphia = new Morphia();

    // map entities, there is maybe a better way to find and map all entities
    ClassPathScanningCandidateComponentProvider entityScanner = new ClassPathScanningCandidateComponentProvider(true);
    entityScanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class));
    for (BeanDefinition candidate : scanner.findCandidateComponents("your.basepackage")) { // from properties?
      morphia.map(Class.forName(candidate.getBeanClassName()));
    }

    return morphia.createDatastore(mongoClient, "dataStoreInstanceId"); // "dataStoreInstanceId" may come from properties?
  }
}

代码示例来源:origin: BlackLabs/play-morphia

try {
  debug("mapping class: %1$s", clz.getName());
  morphia_.map(clz);
} catch (ConstraintViolationException e) {
  throw new RuntimeException(e);

代码示例来源:origin: org.mongodb.morphia/morphia

/**
 * Tries to map all classes in the package specified.
 *
 * @param packageName          the name of the package to process
 * @param ignoreInvalidClasses specifies whether to ignore classes in the package that cannot be mapped
 * @return the Morphia instance
 */
public synchronized Morphia mapPackage(final String packageName, final boolean ignoreInvalidClasses) {
  try {
    for (final Class clazz : ReflectionUtils.getClasses(packageName, mapper.getOptions().isMapSubPackages())) {
      try {
        final Embedded embeddedAnn = ReflectionUtils.getClassEmbeddedAnnotation(clazz);
        final Entity entityAnn = ReflectionUtils.getClassEntityAnnotation(clazz);
        final boolean isAbstract = Modifier.isAbstract(clazz.getModifiers());
        if ((entityAnn != null || embeddedAnn != null) && !isAbstract) {
          map(clazz);
        }
      } catch (final MappingException ex) {
        if (!ignoreInvalidClasses) {
          throw ex;
        }
      }
    }
    return this;
  } catch (IOException e) {
    throw new MappingException("Could not get map classes from package " + packageName, e);
  } catch (ClassNotFoundException e) {
    throw new MappingException("Could not get map classes from package " + packageName, e);
  }
}

代码示例来源:origin: stackoverflow.com

public class Temp {
  @Id String _id;

  @Embedded // CHANGE HERE
  List<MapProxy> strings; // CHANGE HERE

  public Temp(){
    strings=new LinkedList<MapProxy>(); // CHANGE HERE
  }

  public static void main(String...args) throws UnknownHostException, MongoException{
    Mongo mongo=null;
    Morphia morphia=null;
    Datastore ds=null;
    mongo = new Mongo();
    morphia = new Morphia();
    morphia.map(Temp.class);
    ds = morphia.createDatastore(mongo, "test2");
    Temp t = new Temp();
    t._id ="hi";      
    MapProxy mp = new MapProxy(); // CHANGE HERE    
    mp.m.put("Hi","1"); // CHANGE HERE
    mp.m.put("Hi2",2); // CHANGE HERE
    t.strings.add(mp); // CHANGE HERE
    ds.save(t);
    t=ds.get(t);
    ds.ensureIndexes();
  }
}

代码示例来源:origin: protegeproject/webprotege

converters.addConverter(new HashedApiKeyConverter());
converters.addConverter(new ApiKeyIdConverter());
morphia.map(EntityDiscussionThread.class);
morphia.map(UserActivityRecord.class);
morphia.map(RoleAssignment.class);

相关文章