Search in sources :

Example 1 with Embedded

use of org.mongodb.morphia.annotations.Embedded 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 Embedded

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

the class MappedField method getConcreteType.

/**
     * @return the concrete type of the MappedField
     */
public Class getConcreteType() {
    final Embedded e = getAnnotation(Embedded.class);
    if (e != null) {
        final Class concrete = e.concreteClass();
        if (concrete != Object.class) {
            return concrete;
        }
    }
    final Property p = getAnnotation(Property.class);
    if (p != null) {
        final Class concrete = p.concreteClass();
        if (concrete != Object.class) {
            return concrete;
        }
    }
    return getType();
}
Also used : Embedded(org.mongodb.morphia.annotations.Embedded) Property(org.mongodb.morphia.annotations.Property)

Example 3 with Embedded

use of org.mongodb.morphia.annotations.Embedded 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(processingEnv, roundEnv, 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

Embedded (org.mongodb.morphia.annotations.Embedded)3 Entity (org.mongodb.morphia.annotations.Entity)2 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 Property (org.mongodb.morphia.annotations.Property)1 Transient (org.mongodb.morphia.annotations.Transient)1 MappingException (org.mongodb.morphia.mapping.MappingException)1