Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix split MongoDB Panache packages #18803

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -39,7 +39,9 @@ public boolean test(String packageName) {
// Remove the elements from this list when the original issue is fixed
// so that we can detect further issues.
return packageName.startsWith("io.fabric8.kubernetes")
|| packageName.equals("io.quarkus.hibernate.orm.panache");
|| packageName.equals("io.quarkus.hibernate.orm.panache")
|| packageName.equals("io.quarkus.mongodb.panache.reactive")
|| packageName.equals("io.quarkus.mongodb.panache");
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
import io.quarkus.mongodb.deployment.MongoClientNameBuildItem;
import io.quarkus.mongodb.deployment.MongoUnremovableClientsBuildItem;
import io.quarkus.mongodb.panache.MongoEntity;
import io.quarkus.mongodb.panache.PanacheMongoRecorder;
import io.quarkus.mongodb.panache.ProjectionFor;
import io.quarkus.mongodb.panache.common.PanacheMongoRecorder;
import io.quarkus.mongodb.panache.jackson.ObjectIdDeserializer;
import io.quarkus.mongodb.panache.jackson.ObjectIdSerializer;
import io.quarkus.panache.common.deployment.EntityField;
Expand All @@ -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 @@ -8,7 +8,10 @@
* Interface representing an update query.
*
* Use one of its methods to perform the update query.
*
* @deprecated use {@link io.quarkus.mongodb.panache.common.PanacheUpdate} instead.
*/
@Deprecated(forRemoval = true, since = "2.1.0")
public interface PanacheUpdate {

/**
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
Expand Up @@ -6,7 +6,7 @@
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;

import io.quarkus.mongodb.panache.runtime.MongoPropertyUtil;
import io.quarkus.mongodb.panache.common.runtime.MongoPropertyUtil;
import io.quarkus.panacheql.internal.HqlLexer;
import io.quarkus.panacheql.internal.HqlParser;
import io.quarkus.panacheql.internal.HqlParserBaseVisitor;
Expand Down
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
@@ -1,8 +1,8 @@
package io.quarkus.mongodb.panache;
package io.quarkus.mongodb.panache.common;

import java.util.Map;

import io.quarkus.mongodb.panache.runtime.MongoPropertyUtil;
import io.quarkus.mongodb.panache.common.runtime.MongoPropertyUtil;
import io.quarkus.runtime.annotations.Recorder;

@Recorder
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.quarkus.mongodb.panache.common;

import java.util.Map;

import io.quarkus.panache.common.Parameters;

/**
* Interface representing an update query.
*
* Use one of its methods to perform the update query.
*/
public interface PanacheUpdate extends io.quarkus.mongodb.panache.PanacheUpdate {

/**
* Execute the update query with the update document.
*
* @param query a {@link io.quarkus.mongodb.panache query string}
* @param params params optional sequence of indexed parameters
* @return the number of entities updated.
*/
public long where(String query, Object... params);

/**
* Execute the update query with the update document.
*
* @param query a {@link io.quarkus.mongodb.panache query string}
* @param params {@link Map} of named parameters
* @return the number of entities updated.
*/
public long where(String query, Map<String, Object> params);

/**
* Execute the update query with the update document.
*
* @param query a {@link io.quarkus.mongodb.panache query string}
* @param params {@link Parameters} of named parameters
* @return the number of entities updated.
*/
public long where(String query, Parameters params);

/**
* Execute an update on all documents with the update document.
*
* @return the number of entities updated.
*/
public long all();
}
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();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.quarkus.mongodb.panache.common.reactive;

import java.util.Map;

import io.quarkus.panache.common.Parameters;
import io.smallrye.mutiny.Uni;

/**
* Interface representing an update query.
*
* Use one of its methods to perform the update query.
*/
public interface ReactivePanacheUpdate extends io.quarkus.mongodb.panache.reactive.ReactivePanacheUpdate {
/**
* Execute the update query with the update document.
*
* @param query a {@link io.quarkus.mongodb.panache query string}
* @param params params optional sequence of indexed parameters
* @return the number of entities updated.
*/
public Uni<Long> where(String query, Object... params);

/**
* Execute the update query with the update document.
*
* @param query a {@link io.quarkus.mongodb.panache query string}
* @param params {@link Map} of named parameters
* @return the number of entities updated.
*/
public Uni<Long> where(String query, Map<String, Object> params);

/**
* Execute the update query with the update document.
*
* @param query a {@link io.quarkus.mongodb.panache query string}
* @param params {@link Parameters} of named parameters
* @return the number of entities updated.
*/
public Uni<Long> where(String query, Parameters params);

/**
* Execute an update on all documents with the update document.
*
* @return the number of entities updated.
*/
public Uni<Long> all();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.mongodb.panache.reactive.runtime;
package io.quarkus.mongodb.panache.common.reactive.runtime;

import java.util.List;
import java.util.Optional;
Expand All @@ -11,7 +11,7 @@
import com.mongodb.client.model.Collation;

import io.quarkus.mongodb.FindOptions;
import io.quarkus.mongodb.panache.runtime.MongoPropertyUtil;
import io.quarkus.mongodb.panache.common.runtime.MongoPropertyUtil;
import io.quarkus.mongodb.reactive.ReactiveMongoCollection;
import io.quarkus.panache.common.Page;
import io.quarkus.panache.common.Range;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.quarkus.mongodb.panache.reactive.runtime;
package io.quarkus.mongodb.panache.common.reactive.runtime;

import static io.quarkus.mongodb.panache.runtime.BeanUtils.beanName;
import static io.quarkus.mongodb.panache.runtime.BeanUtils.clientFromArc;
import static io.quarkus.mongodb.panache.runtime.BeanUtils.getDatabaseName;
import static io.quarkus.mongodb.panache.common.runtime.BeanUtils.beanName;
import static io.quarkus.mongodb.panache.common.runtime.BeanUtils.clientFromArc;
import static io.quarkus.mongodb.panache.common.runtime.BeanUtils.getDatabaseName;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -214,17 +214,24 @@ public Uni<Void> delete(Object entity) {
}

public ReactiveMongoCollection mongoCollection(Class<?> entityClass) {
MongoEntity mongoEntity = entityClass.getAnnotation(MongoEntity.class);
ReactiveMongoDatabase database = mongoDatabase(mongoEntity);
MongoEntity legacyEntity = entityClass.getAnnotation(MongoEntity.class);
io.quarkus.mongodb.panache.common.MongoEntity mongoEntity = entityClass
.getAnnotation(io.quarkus.mongodb.panache.common.MongoEntity.class);
ReactiveMongoDatabase database = mongoDatabase(legacyEntity, mongoEntity);
if (legacyEntity != null && !legacyEntity.collection().isEmpty()) {
return database.getCollection(legacyEntity.collection(), entityClass);
}
if (mongoEntity != null && !mongoEntity.collection().isEmpty()) {
return database.getCollection(mongoEntity.collection(), entityClass);
}
return database.getCollection(entityClass.getSimpleName(), entityClass);
}

public ReactiveMongoDatabase mongoDatabase(Class<?> entityClass) {
MongoEntity mongoEntity = entityClass.getAnnotation(MongoEntity.class);
return mongoDatabase(mongoEntity);
MongoEntity legacyEntity = entityClass.getAnnotation(MongoEntity.class);
io.quarkus.mongodb.panache.common.MongoEntity mongoEntity = entityClass
.getAnnotation(io.quarkus.mongodb.panache.common.MongoEntity.class);
return mongoDatabase(legacyEntity, mongoEntity);
}

//
Expand Down Expand Up @@ -309,20 +316,21 @@ private ReactiveMongoCollection mongoCollection(Object entity) {
return mongoCollection(entityClass);
}

private ReactiveMongoDatabase mongoDatabase(MongoEntity entity) {
ReactiveMongoClient mongoClient = clientFromArc(entity, ReactiveMongoClient.class, true);
if (entity != null && !entity.database().isEmpty()) {
return mongoClient.getDatabase(entity.database());
private ReactiveMongoDatabase mongoDatabase(MongoEntity legacyEntity,
io.quarkus.mongodb.panache.common.MongoEntity mongoEntity) {
ReactiveMongoClient mongoClient = clientFromArc(legacyEntity, mongoEntity, ReactiveMongoClient.class, true);
if (legacyEntity != null && !legacyEntity.database().isEmpty()) {
return mongoClient.getDatabase(legacyEntity.database());
}
String databaseName = getDefaultDatabaseName(entity);
String databaseName = getDefaultDatabaseName(legacyEntity, mongoEntity);
return mongoClient.getDatabase(databaseName);
}

private String getDefaultDatabaseName(MongoEntity entity) {
return defaultDatabaseName.computeIfAbsent(beanName(entity), new Function<String, String>() {
private String getDefaultDatabaseName(MongoEntity legacyEntity, io.quarkus.mongodb.panache.common.MongoEntity mongoEntity) {
return defaultDatabaseName.computeIfAbsent(beanName(legacyEntity, mongoEntity), new Function<String, String>() {
@Override
public String apply(String beanName) {
return getDatabaseName(entity, beanName);
return getDatabaseName(legacyEntity, mongoEntity, beanName);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.quarkus.mongodb.panache.reactive.runtime;
package io.quarkus.mongodb.panache.common.reactive.runtime;

import java.util.Map;

import org.bson.BsonDocument;
import org.bson.conversions.Bson;

import io.quarkus.mongodb.panache.reactive.ReactivePanacheUpdate;
import io.quarkus.mongodb.panache.common.reactive.ReactivePanacheUpdate;
import io.quarkus.mongodb.reactive.ReactiveMongoCollection;
import io.quarkus.panache.common.Parameters;
import io.smallrye.mutiny.Uni;
Expand Down
Loading