コード例 #1
0
 private void mapClasses() throws ClassNotFoundException {
   // Register all models.Class
   Set<String> classes = new HashSet<String>();
   classes.addAll(Classpath.getTypesAnnotatedWith(application, "models", Entity.class));
   classes.addAll(Classpath.getTypesAnnotatedWith(application, "models", Embedded.class));
   for (String clazz : classes) {
     MorphiaLogger.debug("mapping class: %1$s", clazz);
     morphia.map(Class.forName(clazz, true, application.classloader()));
   }
   // @see http://code.google.com/p/morphia/wiki/Datastore#Ensure_Indexes_and_Caps
   ds.ensureCaps(); // creates capped collections from @Entity
   ds.ensureIndexes(); // creates indexes from @Index annotations in your entities
 }