Search in sources :

Example 1 with Entity

use of org.mongodb.morphia.annotations.Entity in project morphia by mongodb.

the class Morphia method mapPackage.

/**
     * 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);
    }
}
Also used : Entity(org.mongodb.morphia.annotations.Entity) Embedded(org.mongodb.morphia.annotations.Embedded) IOException(java.io.IOException) MappingException(org.mongodb.morphia.mapping.MappingException)

Example 2 with Entity

use of org.mongodb.morphia.annotations.Entity in project morphia by mongodb.

the class QueryImpl method getFieldsObject.

@Override
@Deprecated
public DBObject getFieldsObject() {
    DBObject projection = getOptions().getProjection();
    if (projection == null || projection.keySet().size() == 0) {
        return null;
    }
    final MappedClass mc = ds.getMapper().getMappedClass(clazz);
    Entity entityAnnotation = mc.getEntityAnnotation();
    final BasicDBObject fieldsFilter = copy(projection);
    if (includeFields && entityAnnotation != null && !entityAnnotation.noClassnameStored()) {
        fieldsFilter.put(Mapper.CLASS_NAME_FIELDNAME, 1);
    }
    return fieldsFilter;
}
Also used : Entity(org.mongodb.morphia.annotations.Entity) BasicDBObject(com.mongodb.BasicDBObject) MappedClass(org.mongodb.morphia.mapping.MappedClass) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 3 with Entity

use of org.mongodb.morphia.annotations.Entity in project querydsl by querydsl.

the class MorphiaAnnotationProcessor method createConfiguration.

@Override
protected Configuration createConfiguration(RoundEnvironment roundEnv) {
    Class<? extends Annotation> entities = QueryEntities.class;
    Class<? extends Annotation> entity = Entity.class;
    Class<? extends Annotation> superType = QuerySupertype.class;
    Class<? extends Annotation> embedded = Embedded.class;
    Class<? extends Annotation> skip = Transient.class;
    DefaultConfiguration conf = new DefaultConfiguration(roundEnv, processingEnv.getOptions(), Collections.<String>emptySet(), entities, entity, superType, null, embedded, skip);
    try {
        // Point is an Expression<Double[]>
        @SuppressWarnings("unchecked") Class<? extends Expression<Double[]>> cl = (Class<? extends Expression<Double[]>>) Class.forName("com.querydsl.mongodb.Point");
        conf.addCustomType(Double[].class, cl);
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(e);
    }
    return conf;
}
Also used : Entity(org.mongodb.morphia.annotations.Entity) DefaultConfiguration(com.querydsl.apt.DefaultConfiguration) QuerySupertype(com.querydsl.core.annotations.QuerySupertype) QueryEntities(com.querydsl.core.annotations.QueryEntities) Expression(com.querydsl.core.types.Expression) Embedded(org.mongodb.morphia.annotations.Embedded) Transient(org.mongodb.morphia.annotations.Transient)

Aggregations

Entity (org.mongodb.morphia.annotations.Entity)3 Embedded (org.mongodb.morphia.annotations.Embedded)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 DefaultConfiguration (com.querydsl.apt.DefaultConfiguration)1 QueryEntities (com.querydsl.core.annotations.QueryEntities)1 QuerySupertype (com.querydsl.core.annotations.QuerySupertype)1 Expression (com.querydsl.core.types.Expression)1 IOException (java.io.IOException)1 Transient (org.mongodb.morphia.annotations.Transient)1 MappedClass (org.mongodb.morphia.mapping.MappedClass)1 MappingException (org.mongodb.morphia.mapping.MappingException)1