Skip to content

Commit

Permalink
Duplicate annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Jul 20, 2021
1 parent 7f7b3b7 commit 41c5a65
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/mongodb-panache.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ Projection can be done for both PanacheQL and native queries.

[source,java]
----
import io.quarkus.mongodb.panache.ProjectionFor;
import io.quarkus.mongodb.panache.common.ProjectionFor;
import org.bson.codecs.pojo.annotations.BsonProperty;
// using public fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ public abstract class BasePanacheMongoResourceProcessor {
public static final DotName BSON_ID = createSimple(BsonId.class.getName());
public static final DotName BSON_IGNORE = createSimple(BsonIgnore.class.getName());
public static final DotName BSON_PROPERTY = createSimple(BsonProperty.class.getName());
public static final DotName MONGO_ENTITY = createSimple(MongoEntity.class.getName());
public static final DotName MONGO_ENTITY = createSimple(io.quarkus.mongodb.panache.common.MongoEntity.class.getName());
public static final DotName DEPRECATED_MONGO_ENTITY = createSimple(MongoEntity.class.getName());
public static final DotName OBJECT_ID = createSimple(ObjectId.class.getName());
public static final DotName PROJECTION_FOR = createSimple(ProjectionFor.class.getName());
public static final DotName PROJECTION_FOR = createSimple(io.quarkus.mongodb.panache.common.ProjectionFor.class.getName());
public static final DotName DEPRECATED_PROJECTION_FOR = createSimple(ProjectionFor.class.getName());

@BuildStep
public void buildImperative(CombinedIndexBuildItem index,
Expand Down Expand Up @@ -223,6 +225,27 @@ protected void handleProjectionFor(CombinedIndexBuildItem index,
transformers.produce(new BytecodeTransformerBuildItem(info.name().toString(), fieldEnhancer));
}

// Register for building the property mapping cache
propertyMappingClass
.produce(new PropertyMappingClassBuildStep(targetClass.name().toString(),
annotationInstance.target().asClass().name().toString()));
}
for (AnnotationInstance annotationInstance : index.getIndex().getAnnotations(DEPRECATED_PROJECTION_FOR)) {
Type targetClass = annotationInstance.value().asClass();
ClassInfo target = index.getIndex().getClassByName(targetClass.name());
Map<String, String> classPropertyMapping = new HashMap<>();
extractMappings(classPropertyMapping, target, index);
propertyMapping.put(targetClass.name(), classPropertyMapping);
}
for (AnnotationInstance annotationInstance : index.getIndex().getAnnotations(DEPRECATED_PROJECTION_FOR)) {
Type targetClass = annotationInstance.value().asClass();
Map<String, String> targetPropertyMapping = propertyMapping.get(targetClass.name());
if (targetPropertyMapping != null && !targetPropertyMapping.isEmpty()) {
ClassInfo info = annotationInstance.target().asClass();
ProjectionForEnhancer fieldEnhancer = new ProjectionForEnhancer(targetPropertyMapping);
transformers.produce(new BytecodeTransformerBuildItem(info.name().toString(), fieldEnhancer));
}

// Register for building the property mapping cache
propertyMappingClass
.produce(new PropertyMappingClassBuildStep(targetClass.name().toString(),
Expand All @@ -242,6 +265,13 @@ public void mongoClientNames(ApplicationArchivesBuildItem applicationArchivesBui
values.add(clientName.asString());
}
}
instances = indexView.getAnnotations(DEPRECATED_MONGO_ENTITY);
for (AnnotationInstance annotation : instances) {
AnnotationValue clientName = annotation.value("clientName");
if ((clientName != null) && !clientName.asString().isEmpty()) {
values.add(clientName.asString());
}
}
for (String value : values) {
// we don't want the qualifier @MongoClientName qualifier added
// as these clients will only be looked up programmatically via name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

/**
* This annotation can be used to specify some configuration of the mapping of an entity to MongoDB.
*
* @deprecated use {@link io.quarkus.mongodb.panache.common.MongoEntity} instead.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Deprecated(forRemoval = true, since = "2.1.0")
public @interface MongoEntity {
/**
* The name of the collection (if not set the name of the entity class will be used)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @deprecated use {@link io.quarkus.mongodb.panache.common.ProjectionFor} instead.
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Deprecated(forRemoval = true, since = "2.1.0")
public @interface ProjectionFor {
Class<?> value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.mongodb.panache.common;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* This annotation can be used to specify some configuration of the mapping of an entity to MongoDB.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface MongoEntity {
/**
* The name of the collection (if not set the name of the entity class will be used)
*/
String collection() default "";

/**
* The name of the database (if not set the default from the property
* <code>quarkus.mongodb.database</code> will be used).
*/
String database() default "";

/**
* The name of the MongoDB client (if not set the default client will be used).
*/
String clientName() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.mongodb.panache.common;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ProjectionFor {
Class<?> value();
}

0 comments on commit 41c5a65

Please sign in to comment.