Package com.github.jmkgreen.morphia

Examples of com.github.jmkgreen.morphia.Morphia


*
*/
public class EntityScannerTest extends TestCase {
  @Test
  public void testScanning() throws Exception {
    final Morphia m = new Morphia();
    assertFalse(m.isMapped(E.class));
    new EntityScanner(m, Predicates.equalTo(E.class.getName() + ".class"));
    assertTrue(m.isMapped(E.class));
    assertFalse(m.isMapped(F.class));
    new EntityScanner(m, new Predicate<String>() {
     
      public boolean apply(final String input) {
        return input.startsWith(EntityScannerTest.class.getPackage().getName());
      }
    });
    assertTrue(m.isMapped(F.class));
   
  }
View Full Code Here


    } catch (final Exception e) {
      throw new RuntimeException(e);
    }
   
    this.mongo.dropDatabase("morphia_test");
    morphia = new Morphia();
    this.db = this.mongo.getDB("morphia_test");
    this.ds = this.morphia.createDatastore(this.mongo, this.db.getName())
  }
View Full Code Here

    private final Datastore db;
    public static final String DB_NAME = "cal_dev";
    public MongoConnectionManager(String host, int port) {
      try {
        Mongo m = new MongoClient(host, port);
        db = new Morphia().map(BookingDetail.class).createDatastore(m, DB_NAME);
        db.ensureIndexes();
      } catch (Exception e) {
        throw new RuntimeException("Error initializing mongo db", e);
      }
    }
View Full Code Here

        if (ds != null) {
            return;
        }
        try {
            final MongoClient mongoClient = new MongoClient(ConfigurationHelper.prop.getProperty("mongo.host") );
            final Morphia morphia = new Morphia();
            morphia.map(Meteolog.class).map(News.class).map(Cache.class).map(MapReduceMinMax.class).map(MapReduceHistoryMinMax.class);
            ds = morphia.createDatastore(mongoClient, ConfigurationHelper.prop.getProperty("mongo.dbname"));
            ds.ensureCaps();
            ds.ensureIndexes();
        } catch (Exception e) {
            throw new RuntimeException("Error initializing mongo db", e);
        }
View Full Code Here

    expect(env.getProperty(APP_NAMESPACE, String[].class)).andReturn(
        new String[]{getClass().getPackage().getName() });

    replay(env);

    Morphia morphia = new MorphiaModule().morphia(env);
    assertNotNull(morphia);

    verify(env);
  }
View Full Code Here

    Mongo mongo = createMock(Mongo.class);

    Datastore datastore = createMock(Datastore.class);

    Morphia morphia = createMock(Morphia.class);
    expect(morphia.createDatastore(mongo, "mydb")).andReturn(datastore);

    replay(morphia, mongo, uri, datastore);

    Datastore result =
        new MorphiaModule().morphiaDatastore(morphia, mongo, uri);
View Full Code Here

   */
  @Bean
  public Morphia morphia(final Environment env) {
    notNull(env, "The env is required.");
    String[] namespace = env.getProperty(APP_NAMESPACE, String[].class);
    Morphia morphia = new Morphia();
    for (String ns : namespace) {
      logger.debug("Adding pacakge: {}", ns);
      morphia.mapPackage(ns);
    }

    if (validationFactory != null) {
      morphia.getMapper().addInterceptor(
          new Jsr303Interceptor(validationFactory));
    }
    return morphia;
  }
View Full Code Here

TOP

Related Classes of com.github.jmkgreen.morphia.Morphia

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.