Package com.github.jmkgreen.morphia.mapping

Examples of com.github.jmkgreen.morphia.mapping.MappedClass


    assertTrue(hasNamedIndex("a_1", db.getCollection(mc.getCollectionName()).getIndexInfo()));
  }

  @Test
  public void testIndexedEntity() throws Exception {
    MappedClass mc = morphia.getMapper().getMappedClass(IndexedClass.class);
    ds.ensureIndexes();
    assertTrue(hasIndexedField("l", db.getCollection(mc.getCollectionName()).getIndexInfo()));
    ds.save(new IndexedClass());
    ds.ensureIndexes();
    assertTrue(hasIndexedField("l", db.getCollection(mc.getCollectionName()).getIndexInfo()));
  }
View Full Code Here


    public void preSave(Object ent, DBObject dbObj, Mapper mapr) {}

    public void preLoad(Object ent, DBObject dbObj, Mapper mapr) {}

    public void prePersist(Object ent, DBObject dbObj, Mapper mapr) {
      MappedClass mc = mapr.getMappedClass(ent);
      List<MappedField> toLowercase = mc.getFieldsAnnotatedWith(Lowercase.class);
      for (MappedField mf : toLowercase) {
        try {
          Object fieldValue = mf.getFieldValue(ent);
          dbObj.put(mf.getNameToStore() + "_lowercase", fieldValue.toString().toLowerCase());
        } catch (Exception e) {
View Full Code Here

  }

    @Test
    public void testLongPrimitiveHasVersioning() {
        ALongPrimitive a = new ALongPrimitive();
        MappedClass mc = morphia.map(ALongPrimitive.class).getMapper().getMappedClass(ALongPrimitive.class);
        Assert.assertTrue(mc.hasVersioning());

    }
View Full Code Here

  public static @interface NonNull {
  }

  public static class NonNullValidation extends AbstractEntityInterceptor {
    public void prePersist(Object ent, DBObject dbObj, Mapper mapr) {
      MappedClass mc = mapr.getMappedClass(ent);
      List<MappedField> fieldsToTest = mc.getFieldsAnnotatedWith(NonNull.class);
      for (MappedField mf : fieldsToTest) {
        if (mf.getFieldValue(ent) == null)
          throw new NonNullValidationException(mf);
      }
    }
View Full Code Here

    assertTrue(hasIndexedField("l", db.getCollection(mc.getCollectionName()).getIndexInfo()));
  }

  @Test
  public void testUniqueIndexedEntity() throws Exception {
    MappedClass mc = morphia.getMapper().getMappedClass(UniqueIndexClass.class);
    ds.ensureIndexes();
    assertTrue(hasIndexedField("l", db.getCollection(mc.getCollectionName()).getIndexInfo()));
    ds.save(new UniqueIndexClass("a"));

    try {
      // this should throw...
      ds.save(new UniqueIndexClass("v"));
      assertTrue(false);
      // } catch (MappingException me) {}
    } catch (Throwable me) {
    } // currently is masked by java.lang.RuntimeException: json can't
      // serialize type : class com.mongodb.DBTimestamp

    ds.ensureIndexes();
    assertTrue(hasIndexedField("l", db.getCollection(mc.getCollectionName()).getIndexInfo()));
  }
View Full Code Here

    assertTrue(hasIndexedField("l", db.getCollection(mc.getCollectionName()).getIndexInfo()));
  }

  @Test
  public void testNamedIndexEntity() throws Exception {
    MappedClass mc = morphia.getMapper().getMappedClass(NamedIndexClass.class);
    ds.ensureIndexes();
    assertTrue(hasIndexedField("l", db.getCollection(mc.getCollectionName()).getIndexInfo()));
    ds.save(new IndexedClass());
    ds.ensureIndexes();
    assertTrue(hasIndexedField("l", db.getCollection(mc.getCollectionName()).getIndexInfo()));

    assertTrue(hasNamedIndex("l_ascending", db.getCollection(mc.getCollectionName()).getIndexInfo()));
  }
View Full Code Here

 

    @Test
    public void testClassIndexInherit() throws Exception {
      morphia.map(Circle.class).map(Shape.class);
      MappedClass mc = morphia.getMapper().getMappedClass(Circle.class);
      assertNotNull(mc);
     
      assertEquals(2, mc.getAnnotations(Indexes.class).size());
     
      ds.ensureIndexes();
      DBCollection coll = ds.getCollection(Circle.class);
     
      assertEquals(4, coll.getIndexInfo().size());
View Full Code Here

  }

    @Test
    public void testInheritedFieldIndex() throws Exception {
      morphia.map(Circle.class).map(Shape.class);
      MappedClass mc = morphia.getMapper().getMappedClass(Circle.class);
     
      ds.ensureIndexes();
      DBCollection coll = ds.getCollection(Circle.class);
     
      assertEquals(4, coll.getIndexInfo().size());
View Full Code Here

    String car;
  }

    @Test
    public void testParamEntity() throws Exception {
      MappedClass mc = morphia.getMapper().getMappedClass(A.class);
      assertNotNull(mc);
     
      assertEquals(1, mc.getAnnotations(Indexes.class).size());
     
      ds.ensureIndexes(A.class);
      DBCollection coll = ds.getCollection(A.class);
     
      assertEquals("indexes found: coll.getIndexInfo()" + coll.getIndexInfo() , 3, coll.getIndexInfo().size());
View Full Code Here

     * @param clazz
     * @param background
     * @param <T>
     */
    public <T> void ensureIndexes(Class<T> clazz, boolean background) {
        MappedClass mc = mapr.getMappedClass(clazz);
        ensureIndexes(mc, background);
    }
View Full Code Here

TOP

Related Classes of com.github.jmkgreen.morphia.mapping.MappedClass

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.