Package com.github.jmkgreen.morphia.mapping

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


        this.clazz = clazz;
        this.ds = ds;
        this.dbColl = coll;
        this.cache = this.ds.getMapper().createEntityCache();

        MappedClass mc = this.ds.getMapper().getMappedClass(clazz);
        if (mc != null)
            this.readPref = mc.getReadPreference();
    }
View Full Code Here


        this.fields = fields;
        return this;
    }

    public Query<T> retrieveKnownFields() {
        MappedClass mc = this.ds.getMapper().getMappedClass(clazz);
        ArrayList<String> fields = new ArrayList<String>(mc.getMappedFields().size() + 1);
        for (MappedField mf : mc.getMappedFields()) {
            fields.add(mf.getNameToStore());
        }
        retrievedFields(true, fields.toArray(new String[fields.size()]));
        return this;
    }
View Full Code Here

        MappedField mf = DefaultMapper.validate(query.getEntityClass(), query.getDatastore().getMapper(), sb, op, value, validateNames, validateTypes);
        field = sb.toString();

        Mapper mapr = query.getDatastore().getMapper();

        MappedClass mc = null;
        try {
            if (value != null && !ReflectionUtils.isPropertyType(value.getClass()) && !ReflectionUtils.implementsInterface(value.getClass(), Iterable.class))
                if (mf != null && !mf.isTypeMongoCompatible())
                    mc = mapr.getMappedClass((mf.isSingleValue()) ? mf.getType() : mf.getSubClass());
                else
View Full Code Here

  @Test
  public void testExternalMapping() throws Exception {
    Mapper mapr = morphia.getMapper();
    ExternalMapperExtTest.CloneMapper helper = new CloneMapper(mapr);
    helper.map(Skeleton.class, EntityWithNoAnnotations.class);
    MappedClass mc = mapr.getMappedClass(EntityWithNoAnnotations.class);
    mc.update();
    assertNotNull(mc.getIdField());
    assertNotNull(mc.getEntityAnnotation());
    Assert.assertEquals("special", mc.getEntityAnnotation().value());

    EntityWithNoAnnotations ent = new EntityWithNoAnnotations();
    ent.id = "test";
    Key<EntityWithNoAnnotations> k = ds.save(ent);
    assertNotNull(k);
View Full Code Here

    public CloneMapper(Mapper mapr) {
      this.mapr = mapr;
    }

    void map(Class sourceClass, Class destClass){
      MappedClass destMC = mapr.getMappedClass(destClass);
      MappedClass sourceMC = mapr.getMappedClass(sourceClass);
      //copy the class level annotations
      for(Entry<Class<? extends Annotation>, ArrayList<Annotation>> e: sourceMC.getRelevantAnnotations().entrySet()) {
        if ( e.getValue() != null && e.getValue().size() > 0)
          for(Annotation ann : e.getValue())
            destMC.addAnnotation(e.getKey(), ann);
      }
      //copy the fields.
      for(MappedField mf : sourceMC.getMappedFields()){
        Map<Class<? extends Annotation>, Annotation> annMap = mf.getAnnotations();
        MappedField destMF = destMC.getMappedFieldByJavaField(mf.getJavaFieldName());
        if (destMF != null && annMap != null && annMap.size() > 0) {
          for(Entry e : annMap.entrySet())
            destMF.addAnnotation((Class)e.getKey(), (Annotation)e.getValue());
View Full Code Here

    MappedClass addAnnotation(Class clazz, String field, Annotation... annotations) {
      if (annotations == null || annotations.length == 0)
        throw new IllegalArgumentException("Must specify annotations");

      MappedClass mc = mapr.getMappedClass(clazz);
      MappedField mf = mc.getMappedFieldByJavaField(field);
      if(mf == null)
        throw new IllegalArgumentException("Field \""+ field + "\" does not exist on: " + mc);

      for(Annotation an : annotations)
        mf.putAnnotation(an);
View Full Code Here

    assertEquals(ds.getCount(CurrentStatus.class), 1);
  }

  @Test
  public void testIndexes() {
    MappedClass mc = this.morphia.getMapper().addMappedClass(Ad2.class);

    assertFalse(hasNamedIndex("active_1_lastMod_-1", db.getCollection(mc.getCollectionName()).getIndexInfo()));
    ds.ensureIndexes(Ad2.class);
    assertTrue(hasNamedIndex("active_1_lastMod_-1", db.getCollection(mc.getCollectionName()).getIndexInfo()));
  }
View Full Code Here

    assertTrue(hasNamedIndex("active_1_lastMod_-1", db.getCollection(mc.getCollectionName()).getIndexInfo()));
  }

  @Test
  public void testEmbeddedIndex() {
    MappedClass mc = this.morphia.getMapper().addMappedClass(ContainsIndexedEmbed.class);

    assertFalse(hasNamedIndex("e.name_-1", db.getCollection(mc.getCollectionName()).getIndexInfo()));
    ds.ensureIndexes(ContainsIndexedEmbed.class);
    assertTrue(hasNamedIndex("e.name_-1", db.getCollection(mc.getCollectionName()).getIndexInfo()));
  }
View Full Code Here

    assertTrue(hasNamedIndex("e.name_-1", db.getCollection(mc.getCollectionName()).getIndexInfo()));
  }

  @Test
  public void testMultipleIndexedFields() {
    MappedClass mc = morphia.getMapper().getMappedClass(Ad.class);
    this.morphia.map(Ad.class);

    assertFalse(hasNamedIndex("lastMod_1_active_-1", db.getCollection(mc.getCollectionName()).getIndexInfo()));
    ds.ensureIndex(Ad.class, "lastMod, -active");
        assertTrue(hasNamedIndex("lastMod_1_active_-1", db.getCollection(mc.getCollectionName()).getIndexInfo()));
  }
View Full Code Here

        assertTrue(hasNamedIndex("lastMod_1_active_-1", db.getCollection(mc.getCollectionName()).getIndexInfo()));
  }

  @Test
  public void testIndexedRecursiveEntity() throws Exception {
    MappedClass mc = morphia.getMapper().getMappedClass(CircularEmbeddedEntity.class);
    ds.ensureIndexes();
    assertTrue(hasNamedIndex("a_1", db.getCollection(mc.getCollectionName()).getIndexInfo()));
  }
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.