diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 00e3561160a8a..d137beab2569a 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -261,6 +261,7 @@ stages:
- infinispan-cache-jpa
- infinispan-client
- mongodb-client
+ - mongodb-panache
- neo4j
name: data
diff --git a/bom/deployment/pom.xml b/bom/deployment/pom.xml
index c6711fbdd1f4c..c0358eb90323e 100644
--- a/bom/deployment/pom.xml
+++ b/bom/deployment/pom.xml
@@ -216,6 +216,11 @@
quarkus-resteasy-server-common-spi${project.version}
+
+ io.quarkus
+ quarkus-resteasy-common-spi
+ ${project.version}
+ io.quarkusquarkus-resteasy-server-common-deployment
diff --git a/bom/runtime/pom.xml b/bom/runtime/pom.xml
index aad9a845ff911..0d6438f47c19b 100644
--- a/bom/runtime/pom.xml
+++ b/bom/runtime/pom.xml
@@ -163,6 +163,8 @@
2.1.9.RELEASE2.4.4.Final3.0.0
+ 5.3.1
+ 4.7.2
@@ -317,11 +319,21 @@
quarkus-panache-common${project.version}
+
+ io.quarkus
+ quarkus-panacheql
+ ${project.version}
+ io.quarkusquarkus-hibernate-orm-panache${project.version}
+
+ io.quarkus
+ quarkus-mongodb-panache
+ ${project.version}
+ io.quarkusquarkus-hibernate-search-elasticsearch
@@ -693,7 +705,6 @@
-
commons-loggingcommons-logging
@@ -876,6 +887,11 @@
${debezium.version}test-jar
+
+ org.antlr
+ antlr4-runtime
+ ${antlr.version}
+ org.scala-langscala-reflect
@@ -1243,11 +1259,22 @@
json-smart${json-smart.version}
+
+
+ net.java.dev.jna
+ jna
+ ${jna.version}
+ org.testcontainerstestcontainers${test-containers.version}
+
+ org.testcontainers
+ junit-jupiter
+ ${test-containers.version}
+ org.codehaus.plexus
diff --git a/build-parent/pom.xml b/build-parent/pom.xml
index bee4d6e4bab8b..05d659fc2a83f 100644
--- a/build-parent/pom.xml
+++ b/build-parent/pom.xml
@@ -58,6 +58,9 @@
1.01.2.11.1.2
+
+
+ 4.7.2
@@ -245,6 +248,11 @@
${elasticsearch-server.version}
+
+ org.antlr
+ antlr4-maven-plugin
+ ${antlr.version}
+
diff --git a/core/deployment/src/main/java/io/quarkus/deployment/builditem/FeatureBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/builditem/FeatureBuildItem.java
index 8b1f80a28f564..82e44bd0f6ccc 100644
--- a/core/deployment/src/main/java/io/quarkus/deployment/builditem/FeatureBuildItem.java
+++ b/core/deployment/src/main/java/io/quarkus/deployment/builditem/FeatureBuildItem.java
@@ -34,6 +34,7 @@ public final class FeatureBuildItem extends MultiBuildItem {
public static final String KUBERNETES_CLIENT = "kubernetes-client";
public static final String MAILER = "mailer";
public static final String MONGODB_CLIENT = "mongodb-client";
+ public static final String MONGODB_PANACHE = "mongodb-panache";
public static final String NARAYANA_JTA = "narayana-jta";
public static final String REACTIVE_PG_CLIENT = "reactive-pg-client";
public static final String REACTIVE_MYSQL_CLIENT = "reactive-mysql-client";
diff --git a/devtools/common/src/main/filtered/extensions.json b/devtools/common/src/main/filtered/extensions.json
index c3597e9dca8f8..332f6c288145c 100644
--- a/devtools/common/src/main/filtered/extensions.json
+++ b/devtools/common/src/main/filtered/extensions.json
@@ -305,6 +305,18 @@
"groupId": "io.quarkus",
"artifactId": "quarkus-mongodb-client"
},
+ {
+ "name": "MongoDB with Panache",
+ "labels": [
+ "mongo",
+ "mongodb",
+ "nosql",
+ "datastore",
+ "panache"
+ ],
+ "groupId": "io.quarkus",
+ "artifactId": "quarkus-mongodb-panache"
+ },
{
"name": "Narayana JTA - Transaction manager",
"labels": [
diff --git a/docs/src/main/asciidoc/index.adoc b/docs/src/main/asciidoc/index.adoc
index ec869f52f1971..df55b45b7e656 100644
--- a/docs/src/main/asciidoc/index.adoc
+++ b/docs/src/main/asciidoc/index.adoc
@@ -47,6 +47,8 @@ include::quarkus-intro.adoc[tag=intro]
* link:kogito-guide.html[Using Kogito (business automation with processes and rules)]
* link:oauth2-guide.html[Using OAuth2 RBAC]
* link:tika-guide.html[Using Apache Tika]
+* link:mongo-guide.html[Using MongoDB]
+* link:mongodb-panache-guide.html[Simplified MongoDB with Panache]
* link:faq.html[FAQs]
diff --git a/docs/src/main/asciidoc/mongo-guide.adoc b/docs/src/main/asciidoc/mongo-guide.adoc
index a10186fd7d258..141ee6a3b44fe 100644
--- a/docs/src/main/asciidoc/mongo-guide.adoc
+++ b/docs/src/main/asciidoc/mongo-guide.adoc
@@ -462,6 +462,9 @@ public class CodecFruitService {
}
----
+== Simplifying MongoDB with Panache
+
+The link:mongodb-panache-guide.html[MongoDB with Panache] extension facilitates the usage of MongoDB by providing active record style entities (and repositories) like you have in link:hibernate-orm-panache-guide.html[Hibernate ORM with Panache] and focuses on making your entities trivial and fun to write in Quarkus.
== Building a native executable
diff --git a/docs/src/main/asciidoc/mongodb-panache-guide.adoc b/docs/src/main/asciidoc/mongodb-panache-guide.adoc
new file mode 100644
index 0000000000000..cc233fafc968a
--- /dev/null
+++ b/docs/src/main/asciidoc/mongodb-panache-guide.adoc
@@ -0,0 +1,512 @@
+////
+This guide is maintained in the main Quarkus repository
+and pull requests should be submitted there:
+https://github.com/quarkusio/quarkus/tree/master/docs/src/main/asciidoc
+////
+= Quarkus - Simplified MongoDB with Panache
+
+include::./attributes.adoc[]
+:config-file: application.properties
+
+MongoDB is a well known NoSQL Database that is widely used, but using its raw API can be cumbersome as you need to express your entities and your queries as a MongoDB link:https://mongodb.github.io/mongo-java-driver/3.11/bson/documents/#document[`Document`].
+
+MongoDB with Panache provides active record style entities (and repositories) like you have in link:hibernate-orm-panache-guide.html[Hibernate ORM with Panache] and focuses on making your entities trivial and fun to write in Quarkus.
+
+It is built on top of the link:mongo-guide.html[MongoDB Client] extension.
+
+WARNING: This extension is still experimental, feedback is welcome on the https://groups.google.com/d/forum/quarkus-dev[mailing list] or as issues in our https://github.com/quarkusio/quarkus/issues[GitHub issue tracker].
+
+== First: an example
+
+Panache allows you to write your MongoDB entities like this:
+
+[source,java]
+----
+public class Person extends PanacheMongoEntity {
+ public String name;
+ public LocalDate birth;
+ public Status status;
+
+ public static Person findByName(String name){
+ return find("name", name).firstResult();
+ }
+
+ public static List findAlive(){
+ return list("status", Status.Alive);
+ }
+
+ public static void deleteLoics(){
+ delete("name", "Loïc");
+ }
+}
+----
+
+You have noticed how much more compact and readable the code is compared to using the MongoDB API?
+Does this look interesting? Read on!
+
+NOTE: the `list()` method might be surprising at first. It takes fragments of PanacheQL queries (subset of JPQL) and contextualizes the rest.
+That makes for very concise but yet readable code.
+MongoDB native queries are also supported.
+
+== Solution
+
+We recommend that you follow the instructions in the next sections and create the application step by step.
+However, you can go right to the completed example.
+
+Clone the Git repository: `git clone {quickstarts-clone-url}`, or download an {quickstarts-archive-url}[archive].
+
+The solution is located in the `using-mongodb-panache` {quickstarts-tree-url}/using-mongodb-panache[directory].
+
+== Creating the Maven project
+
+First, we need a new project. Create a new project with the following command:
+
+[source,shell,subs=attributes+]
+----
+mvn io.quarkus:quarkus-maven-plugin:{quarkus-version}:create \
+ -DprojectGroupId=org.acme \
+ -DprojectArtifactId=using-mongodb-panache \
+ -DclassName="org.acme.mongodb.panache.FruitResource" \
+ -Dpath="/fruits" \
+ -Dextensions="resteasy-jsonb,mongodb-panache"
+----
+
+This command generates a Maven structure importing the RESTEasy/JAX-RS, JSON-B and MongoDB with Panache extensions.
+After this, the `quarkus-mongodb-panache` extension has been added to your `pom.xml`.
+
+If you don't want to generate a new project you can add the dependency in your `pom.xml`:
+
+[source,xml]
+----
+
+
+ io.quarkus
+ quarkus-mongodb-panache
+
+
+----
+
+== Setting up and configuring MongoDB with Panache
+
+To get started:
+
+* add your settings in `{config-file}`
+* Make your entities extend `PanacheMongoEntity`, you can use the `@MongoEntity` annotation to specify the name of the database and the name of the collection (it will default to the name of your entity).
+* place your entity logic in static methods in your entities
+
+Then add the relevant configuration properties in `{config-file}`.
+
+[source,properties]
+----
+# configure the MongoDB client for a replica set of two nodes
+quarkus.mongodb.connection-string = mongodb://mongo1:27017,mongo2:27017
+# mandatory if you don't specify the name of the database using @MongoEntity
+quarkus.mongodb.database = person
+----
+
+The `quarkus.mongodb.database` property will be used by MongoDB with Panache to determine the name of the database where your entities will be persisted.
+
+For advanced configuration of the MongoDB client, you can follow the link:mongo-guide.html#configuring-the-mongodb-database[Configuring the MongoDB database guide].
+
+== Defining your entity
+
+To define a Panache entity, simply extend `PanacheMongoEntity` and add your columns as public fields.
+You can add the `@MongoEntity` annotation to your entity if you need to customize the name of the collection and/or the database.
+
+[source,java]
+----
+@MongoEntity(collection="ThePerson")
+public class Person extends PanacheMongoEntity {
+ public String name;
+
+ // will be persisted as a 'birth' field in MongoDB
+ @BsonProperty("birth")
+ public LocalDate birthDate;
+
+ public Status status;
+}
+----
+
+NOTE: annotating with `@MongoEntity` is optional, it allows you to configure the name of the collection and the name of the database. Here the entity will be stored in the `ThePerson` collection instead of the default `Person` collection.
+
+MongoDB with Panache uses the link:https://mongodb.github.io/mongo-java-driver/3.10/bson/pojos/[PojoCodecProvider] to map your entities to a MongoDB `Document`.
+
+You will be allowed to use the following annotations to customize this mapping:
+
+- `@BsonId`: allows you to customize the ID field, see <>.
+- `@BsonProperty`: customize the serialized name of the field.
+- `@BsonIgnore`: ignore a field during the serialization.
+
+If you need to write accessors, you can:
+
+[source,java]
+----
+public class Person extends PanacheMongoEntity {
+ public String name;
+ public LocalDate birth;
+ public Status status;
+
+ // return name as uppercase in the model
+ public String getName(){
+ return name.toUpperCase();
+ }
+
+ // store all names in lowercase in the DB
+ public void setName(String name){
+ this.name = name.toLowerCase();
+ }
+}
+----
+
+And thanks to our field access rewrite, when your users read `person.name` they will actually call your `getName()` accessor, and similarly for field writes and the setter.
+This allows for proper encapsulation at runtime as all fields calls will be replaced by the corresponding getter/setter calls.
+
+== Most useful operations
+
+Once you have written your entity, here are the most common operations you will be able to do:
+
+[source,java]
+----
+// creating a person
+Person person = new Person();
+person.name = "Loïc";
+person.birth = LocalDate.of(1910, Month.FEBRUARY, 1);
+person.status = Status.Alive;
+
+// persist it
+person.persist();
+
+person.status = Status.Dead;
+
+// Your must call update() in order to send your entity modifications to MongoDB
+person.update();
+
+// delete it
+person.delete();
+
+// getting a list of all Person entities
+List allPersons = Person.listAll();
+
+// finding a specific person by ID
+person = Person.findById(personId);
+
+// finding all living persons
+List livingPersons = Person.list("status", Status.Alive);
+
+// counting all persons
+long countAll = Person.count();
+
+// counting all living persons
+long countAlive = Person.count("status", Status.Alive);
+
+// delete all living persons
+Person.delete("status", Status.Alive);
+
+// delete all persons
+Person.deleteAll();
+----
+
+All `list` methods have equivalent `stream` versions.
+
+[source,java]
+----
+Stream persons = Person.streamAll();
+List namesButEmmanuels = persons
+ .map(p -> p.name.toLowerCase() )
+ .filter( n -> ! "emmanuel".equals(n) )
+ .collect(Collectors.toList());
+----
+
+NOTE: A `persistOrUpdate()` method exist that persist or update an entity in the database, it uses the __upsert__ capability of MongoDB to do it in a single query.
+
+== Paging
+
+You should only use `list` and `stream` methods if your collection contains small enough data sets. For larger data
+sets you can use the `find` method equivalents, which return a `PanacheQuery` on which you can do paging:
+
+[source,java]
+----
+// create a query for all living persons
+PanacheQuery livingPersons = Person.find("status", Status.Alive);
+
+// make it use pages of 25 entries at a time
+livingPersons.page(Page.ofSize(25));
+
+// get the first page
+List firstPage = livingPersons.list();
+
+// get the second page
+List secondPage = livingPersons.nextPage().list();
+
+// get page 7
+List page7 = livingPersons.page(Page.of(7, 25)).list();
+
+// get the number of pages
+int numberOfPages = livingPersons.pageCount();
+
+// get the total number of entities returned by this query without paging
+int count = livingPersons.count();
+
+// and you can chain methods of course
+return Person.find("status", Status.Alive)
+ .page(Page.ofSize(25))
+ .nextPage()
+ .stream()
+----
+
+The `PanacheQuery` type has many other methods to deal with paging and returning streams.
+
+== Sorting
+
+All methods accepting a query string also accept an optional `Sort` parameter, which allows you to abstract your sorting:
+
+[source,java]
+----
+List persons = Person.list(Sort.by("name").and("birth"));
+
+// and with more restrictions
+List persons = Person.list("status", Sort.by("name").and("birth"), Status.Alive);
+----
+
+The `Sort` class has plenty of methods for adding columns and specifying sort direction.
+
+== Adding entity methods
+
+In general, we recommend not adding custom queries for your entities outside of the entities themselves,
+to keep all model queries close to the models they operate on. So we recommend adding them as static methods
+in your entity class:
+
+[source,java]
+----
+public class Person extends PanacheMongoEntity {
+ public String name;
+ public LocalDate birth;
+ public Status status;
+
+ public static Person findByName(String name){
+ return find("name", name).firstResult();
+ }
+
+ public static List findAlive(){
+ return list("status", Status.Alive);
+ }
+
+ public static void deleteLoics(){
+ delete("name", "Loïc");
+ }
+}
+----
+
+== Simplified queries
+
+Normally, MongoDB queries are of this form: `{'firstname': 'John', 'lastname':'Doe'}`, this is what we call MongoDB native queries.
+
+You can use them if you want, but we also support what we call **PanacheQL** that can be seen as a subset of link:https://docs.oracle.com/javaee/7/tutorial/persistence-querylanguage.htm#BNBTG[JPQL] (or link:https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#hql[HQL]) and allows you to easily express a query.
+MongoDB with Panache will then map it to a MongoDB native query.
+
+If your query does not start with `{`, we will consider it a PanacheQL query:
+
+- `` (and single parameter) which will expand to `{'singleColumnName': '?'}`
+- `` will expand to `{}` where we will map the PanacheQL query to MongoDB native query form. We support the following operators that will be mapped to the corresponding MongoDB operators: 'and', 'or' ( mixing 'and' and 'or' is not currently supported), '=', '>', '>=', '<', '<=', '!=', 'is null', 'is not null', and 'like' that is mapped to the MongoDB `$regex` operator.
+
+Here are some query examples:
+
+- `firstname = ?1 and status = ?2` will be mapped to `{'firstname': ?1, 'status': ?2}`
+- `amount > ?1 and firstname != ?2` will be mapped to `{'amount': {'$gt': ?1}, 'firstname': {'$ne': ?2}}`
+- `lastname like ?1` will be mapped to `{'lastname': {'$regex': ?1}}`. Be careful that this will be link:https://docs.mongodb.com/manual/reference/operator/query/regex/#op._S_regex[MongoDB regex] support and not SQL like pattern.
+- `lastname is not null` will be mapped to `{'lastname':{'$exists': true}}`
+
+We also handle some basic date type transformations: all fields of type `Date`, `LocalDate` or `LocalDateTime` will be mapped to the link:https://docs.mongodb.com/manual/reference/bson-types/#document-bson-type-date[BSON Date] using the `ISODate` type (UTC datetime).
+
+MongoDB with Panache also supports extended MongoDB queries by providing a `Document` query, this is supported by the find/list/stream/count/delete methods.
+
+== Query parameters
+
+You can pass query parameters, for both native and PanacheQL queries, by index (1-based) as shown below:
+
+[source,java]
+----
+Person.find("name = ?1 and status = ?2", "Loïc", Status.Alive);
+Person.find("{'name': ?1, 'status': ?2}", "Loïc", Status.Alive);
+----
+
+Or by name using a `Map`:
+
+[source,java]
+----
+Map params = new HashMap<>();
+params.put("name", "Loïc");
+params.put("status", Status.Alive);
+Person.find("name = :name and status = :status", params);
+Person.find("{'name': :name, 'status', :status}", params);
+----
+
+Or using the convenience class `Parameters` to either build a `Map` or just use as-is:
+
+[source,java]
+----
+// generate a Map
+Person.find("name = :name and status = :status",
+ Parameters.with("name", "Loïc").and("status", Status.Alive).map());
+
+// use it as-is
+Person.find("{'name': :name, 'status': :status}",
+ Parameters.with("name", "Loïc").and("status", Status.Alive));
+----
+
+Every query operation accepts passing parameters by index (`Object...`), or by name (`Map` or `Parameters`).
+
+When you use query parameters, be careful that PanacheQL queries will refer to the Object parameters name but native queries will refer to MongoDB field names.
+
+Imagine the following entity:
+
+[source,java]
+----
+public class Person extends PanacheMongoEntity {
+ @BsonProperty("lastname")
+ public String name;
+ public LocalDate birth;
+ public Status status;
+
+ public static Person findByNameWithPanacheQLQuery(String name){
+ return find("name", name).firstResult();
+ }
+
+ public static Person findByNameWithNativeQuery(String name){
+ return find("{'lastname': ?1}", name).firstResult();
+ }
+}
+----
+
+Both `findByNameWithPanacheQLQuery()` and `findByNameWithNativeQuery()` methods will return the same result but query written in PanacheQL
+will use the entity field name: `name`, and native query will use the MongoDB field name: `lastname`.
+
+== The DAO/Repository option
+
+Look, we get it: you have a love/hate relationship with DAOs/Repositories but you can't live without them. We don't judge, we know life is tough and we've got you covered.
+
+If you want to have Repositories, you can get the exact same convenient methods injected in your Repository by making it
+implement `PanacheMongoRepository`:
+
+[source,java]
+----
+@ApplicationScoped
+public class PersonRepository implements PanacheMongoRepository {
+
+ // put your custom logic here as instance methods
+
+ public Person findByName(String name){
+ return find("name", name).firstResult();
+ }
+
+ public List findAlive(){
+ return list("status", Status.Alive);
+ }
+
+ public void deleteLoics(){
+ delete("name", "Loïc");
+ }
+}
+----
+
+Absolutely all the operations that are defined on `PanacheMongoEntityBase` are available on your DAO, so using it
+is exactly the same except you need to inject it:
+
+[source,java]
+----
+@Inject
+PersonRepository personRepository;
+
+@GET
+public long count(){
+ return personRepository.count();
+}
+----
+
+So if Repositories are your thing, you can keep doing them. Even with repositories, you can keep your entities as
+subclasses of `PanacheMongoEntity` in order to get the ID and public fields working, but you can even skip that and
+go back to specifying your ID and using getters and setters if that's your thing. We're not judging.
+
+== Transactions
+
+WARNING: MongoDB offers ACID transactions since version 4.0. MongoDB with Panache doesn't provide support for them.
+
+== Custom IDs
+
+IDs are often a touchy subject. In MongoDB, they are usually auto-generated by the database with an `ObjectId` type.
+In MongoDB with Panache the ID are defined by a field named `id` of the `org.bson.types.ObjectId` type,
+but if you want ot customize them, once again we have you covered.
+
+You can specify your own ID strategy by extending `PanacheMongoEntityBase` instead of `PanacheMongoEntity`. Then
+you just declare whatever ID you want as a public field by annotating it by @BsonId:
+
+[source,java]
+----
+@MongoEntity
+public class Person extends PanacheMongoEntityBase {
+
+ @BsonId
+ public Integer myId;
+
+ //...
+}
+----
+
+If you're using repositories, then you will want to extend `PanacheMongoRepositoryBase` instead of `PanacheMongoRepository`
+and specify your ID type as an extra type parameter:
+
+[source,java]
+----
+@ApplicationScoped
+public class PersonRepository implements PanacheMongoRepositoryBase {
+ //...
+}
+----
+
+[NOTE]
+====
+When using `ObjectId`, MongoDB will automatically provide a value for you, but if you use a custom field type,
+you need to provide the value by yourself.
+====
+
+`ObjectId` can be difficult to use if you want to expose its value in your REST service.
+So we created JSON-B and Jackson providers to serialize/deserialize them as a `String` which are are automatically registered if your project depends on one of the RESTEasy with JSON-B or RESTEasy with Jackson extensions.
+
+== How and why we simplify MongoDB API
+
+When it comes to writing MongoDB entities, there are a number of annoying things that users have grown used to
+reluctantly deal with, such as:
+
+- Duplicating ID logic: most entities need an ID, most people don't care how it's set, because it's not really
+relevant to your model.
+- Dumb getters and setters: since Java lacks support for properties in the language, we have to create fields,
+then generate getters and setters for those fields, even if they don't actually do anything more than read/write
+the fields.
+- Traditional EE patterns advise to split entity definition (the model) from the operations you can do on them
+(DAOs, Repositories), but really that requires an unnatural split between the state and its operations even though
+we would never do something like that for regular objects in the Object Oriented architecture, where state and methods are in the same class. Moreover, this requires two classes per entity, and requires injection of the DAO or Repository where you need to do entity operations, which breaks your edit flow and requires you to get out of the code you're writing to set up an injection point before coming back to use it.
+- MongoDB queries are super powerful, but overly verbose for common operations, requiring you to write queries even
+when you don't need all the parts.
+- MongoDB queries are JSON based, so you will need some String manipulation or using the `Document` type and it will need a lot of boilerplate code.
+
+With Panache, we took an opinionated approach to tackle all these problems:
+
+- Make your entities extend `PanacheMongoEntity`: it has an ID field that is auto-generated. If you require
+a custom ID strategy, you can extend `PanacheMongoEntityBase` instead and handle the ID yourself.
+- Use public fields. Get rid of dumb getter and setters. Under the hood, we will generate all getters and setters
+that are missing, and rewrite every access to these fields to use the accessor methods. This way you can still
+write _useful_ accessors when you need them, which will be used even though your entity users still use field accesses.
+- Don't use DAOs or Repositories: put all your entity logic in static methods in your entity class. Your entity superclass comes with lots of super useful static methods and you can add your own in your entity class. Users can just start using your entity `Person` by typing `Person.` and getting completion for all the operations in a single place.
+- Don't write parts of the query that you don't need: write `Person.find("order by name")` or
+`Person.find("name = ?1 and status = ?2", "Loïc", Status.Alive)` or even better `Person.find("name", "Loïc")`.
+
+That's all there is to it: with Panache, MongoDB has never looked so trim and neat.
+
+== Defining entities in external projects or jars
+
+MongoDB with Panache relies on compile-time bytecode enhancements to your entities.
+If you define your entities in the same project where you build your Quarkus application, everything will work fine.
+If the entities come from external projects or jars, you can make sure that your jar is treated like a Quarkus application library
+by indexing it via Jandex, see link:cdi-reference.html#how-to-generate-a-jandex-index[How to Generate a Jandex Index] in the CDI guide.
+This will allow Quarkus to index and enhance your entities as if they were inside the current project.
+
diff --git a/extensions/panache/mongodb-panache/deployment/pom.xml b/extensions/panache/mongodb-panache/deployment/pom.xml
new file mode 100644
index 0000000000000..e3b43b025fd7b
--- /dev/null
+++ b/extensions/panache/mongodb-panache/deployment/pom.xml
@@ -0,0 +1,57 @@
+
+
+
+ quarkus-mongodb-panache-parent
+ io.quarkus
+ 999-SNAPSHOT
+ ../
+
+ 4.0.0
+
+ quarkus-mongodb-panache-deployment
+ Quarkus - MongoDB with Panache - Deployment
+
+
+
+ io.quarkus
+ quarkus-core-deployment
+
+
+ io.quarkus
+ quarkus-panache-common-deployment
+
+
+ io.quarkus
+ quarkus-resteasy-common-spi
+
+
+ io.quarkus
+ quarkus-mongodb-client-deployment
+
+
+ io.quarkus
+ quarkus-mongodb-panache
+
+
+
+
+
+
+ maven-compiler-plugin
+
+
+
+ io.quarkus
+ quarkus-extension-processor
+ ${project.version}
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/extensions/panache/mongodb-panache/deployment/src/main/java/io/quarkus/mongodb/panache/deployment/PanacheMongoEntityEnhancer.java b/extensions/panache/mongodb-panache/deployment/src/main/java/io/quarkus/mongodb/panache/deployment/PanacheMongoEntityEnhancer.java
new file mode 100644
index 0000000000000..27d5b0c216769
--- /dev/null
+++ b/extensions/panache/mongodb-panache/deployment/src/main/java/io/quarkus/mongodb/panache/deployment/PanacheMongoEntityEnhancer.java
@@ -0,0 +1,89 @@
+package io.quarkus.mongodb.panache.deployment;
+
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.bson.codecs.pojo.annotations.BsonIgnore;
+import org.jboss.jandex.ClassInfo;
+import org.jboss.jandex.DotName;
+import org.jboss.jandex.FieldInfo;
+import org.jboss.jandex.IndexView;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+import io.quarkus.gizmo.DescriptorUtils;
+import io.quarkus.mongodb.panache.runtime.MongoOperations;
+import io.quarkus.panache.common.deployment.EntityField;
+import io.quarkus.panache.common.deployment.EntityModel;
+import io.quarkus.panache.common.deployment.MetamodelInfo;
+import io.quarkus.panache.common.deployment.PanacheEntityEnhancer;
+
+public class PanacheMongoEntityEnhancer extends PanacheEntityEnhancer>> {
+ public final static String MONGO_OPERATIONS_NAME = MongoOperations.class.getName();
+ public final static String MONGO_OPERATIONS_BINARY_NAME = MONGO_OPERATIONS_NAME.replace('.', '/');
+
+ private static final DotName DOTNAME_BSON_IGNORE = DotName.createSimple(BsonIgnore.class.getName());
+
+ final Map entities = new HashMap<>();
+
+ public PanacheMongoEntityEnhancer(IndexView index) {
+ super(index, PanacheResourceProcessor.DOTNAME_PANACHE_ENTITY_BASE);
+ modelInfo = new MetamodelInfo<>();
+ }
+
+ @Override
+ public ClassVisitor apply(String className, ClassVisitor outputClassVisitor) {
+ return new PanacheMongoEntityClassVisitor(className, outputClassVisitor, modelInfo, panacheEntityBaseClassInfo);
+ }
+
+ static class PanacheMongoEntityClassVisitor extends PanacheEntityClassVisitor {
+
+ public PanacheMongoEntityClassVisitor(String className, ClassVisitor outputClassVisitor,
+ MetamodelInfo> modelInfo, ClassInfo panacheEntityBaseClassInfo) {
+ super(className, outputClassVisitor, modelInfo, panacheEntityBaseClassInfo);
+ }
+
+ @Override
+ protected void injectModel(MethodVisitor mv) {
+ mv.visitLdcInsn(thisClass);
+ }
+
+ @Override
+ protected String getModelDescriptor() {
+ return "Ljava/lang/Class;";
+ }
+
+ @Override
+ protected String getPanacheOperationsBinaryName() {
+ return MONGO_OPERATIONS_BINARY_NAME;
+ }
+
+ @Override
+ protected void generateAccessorSetField(MethodVisitor mv, EntityField field) {
+ mv.visitFieldInsn(Opcodes.PUTFIELD, thisClass.getInternalName(), field.name, field.descriptor);
+ }
+
+ @Override
+ protected void generateAccessorGetField(MethodVisitor mv, EntityField field) {
+ mv.visitFieldInsn(Opcodes.GETFIELD, thisClass.getInternalName(), field.name, field.descriptor);
+ }
+
+ @Override
+ public void visitEnd() {
+ super.visitEnd();
+ }
+ }
+
+ public void collectFields(ClassInfo classInfo) {
+ EntityModel entityModel = new EntityModel<>(classInfo);
+ for (FieldInfo fieldInfo : classInfo.fields()) {
+ String name = fieldInfo.name();
+ if (Modifier.isPublic(fieldInfo.flags()) && !fieldInfo.hasAnnotation(DOTNAME_BSON_IGNORE)) {
+ entityModel.addField(new EntityField(name, DescriptorUtils.typeToString(fieldInfo.type())));
+ }
+ }
+ modelInfo.addEntityModel(entityModel);
+ }
+}
diff --git a/extensions/panache/mongodb-panache/deployment/src/main/java/io/quarkus/mongodb/panache/deployment/PanacheMongoRepositoryEnhancer.java b/extensions/panache/mongodb-panache/deployment/src/main/java/io/quarkus/mongodb/panache/deployment/PanacheMongoRepositoryEnhancer.java
new file mode 100644
index 0000000000000..988a942d7420b
--- /dev/null
+++ b/extensions/panache/mongodb-panache/deployment/src/main/java/io/quarkus/mongodb/panache/deployment/PanacheMongoRepositoryEnhancer.java
@@ -0,0 +1,85 @@
+package io.quarkus.mongodb.panache.deployment;
+
+import org.jboss.jandex.ClassInfo;
+import org.jboss.jandex.DotName;
+import org.jboss.jandex.IndexView;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+import io.quarkus.mongodb.panache.PanacheMongoRepository;
+import io.quarkus.mongodb.panache.PanacheMongoRepositoryBase;
+import io.quarkus.panache.common.deployment.PanacheRepositoryEnhancer;
+
+public class PanacheMongoRepositoryEnhancer extends PanacheRepositoryEnhancer {
+ public final static DotName PANACHE_REPOSITORY_BASE_NAME = DotName.createSimple(PanacheMongoRepositoryBase.class.getName());
+
+ public final static DotName PANACHE_REPOSITORY_NAME = DotName.createSimple(PanacheMongoRepository.class.getName());
+
+ public PanacheMongoRepositoryEnhancer(IndexView index) {
+ super(index, PanacheResourceProcessor.DOTNAME_PANACHE_REPOSITORY_BASE);
+ }
+
+ @Override
+ public ClassVisitor apply(String className, ClassVisitor outputClassVisitor) {
+ return new PanacheMongoRepositoryClassVisitor(className, outputClassVisitor, panacheRepositoryBaseClassInfo,
+ this.indexView);
+ }
+
+ static class PanacheMongoRepositoryClassVisitor extends PanacheRepositoryClassVisitor {
+
+ public PanacheMongoRepositoryClassVisitor(String className, ClassVisitor outputClassVisitor,
+ ClassInfo panacheRepositoryBaseClassInfo, IndexView indexView) {
+ super(className, outputClassVisitor, panacheRepositoryBaseClassInfo, indexView);
+ }
+
+ @Override
+ protected DotName getPanacheRepositoryDotName() {
+ return PANACHE_REPOSITORY_NAME;
+ }
+
+ @Override
+ protected DotName getPanacheRepositoryBaseDotName() {
+ return PANACHE_REPOSITORY_BASE_NAME;
+ }
+
+ @Override
+ protected String getPanacheOperationsBinaryName() {
+ return PanacheMongoEntityEnhancer.MONGO_OPERATIONS_BINARY_NAME;
+ }
+
+ @Override
+ public void visitEnd() {
+ // Bridge for findById
+ MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_BRIDGE,
+ "findById",
+ "(Ljava/lang/Object;)Ljava/lang/Object;",
+ null,
+ null);
+ mv.visitParameter("id", 0);
+ mv.visitCode();
+ mv.visitIntInsn(Opcodes.ALOAD, 0);
+ mv.visitIntInsn(Opcodes.ALOAD, 1);
+ mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
+ daoBinaryName,
+ "findById",
+ "(Ljava/lang/Object;)" + entitySignature, false);
+ mv.visitInsn(Opcodes.ARETURN);
+ mv.visitMaxs(0, 0);
+ mv.visitEnd();
+
+ super.visitEnd();
+ }
+
+ @Override
+ protected void injectModel(MethodVisitor mv) {
+ // inject Class
+ mv.visitLdcInsn(entityType);
+ }
+
+ @Override
+ protected String getModelDescriptor() {
+ return "Ljava/lang/Class;";
+ }
+ }
+}
diff --git a/extensions/panache/mongodb-panache/deployment/src/main/java/io/quarkus/mongodb/panache/deployment/PanacheResourceProcessor.java b/extensions/panache/mongodb-panache/deployment/src/main/java/io/quarkus/mongodb/panache/deployment/PanacheResourceProcessor.java
new file mode 100644
index 0000000000000..2dbb00bec2809
--- /dev/null
+++ b/extensions/panache/mongodb-panache/deployment/src/main/java/io/quarkus/mongodb/panache/deployment/PanacheResourceProcessor.java
@@ -0,0 +1,121 @@
+package io.quarkus.mongodb.panache.deployment;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.bson.types.ObjectId;
+import org.jboss.jandex.ClassInfo;
+import org.jboss.jandex.CompositeIndex;
+import org.jboss.jandex.DotName;
+import org.jboss.jandex.Indexer;
+import org.jboss.jandex.Type;
+
+import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
+import io.quarkus.deployment.Capabilities;
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.ApplicationIndexBuildItem;
+import io.quarkus.deployment.builditem.BytecodeTransformerBuildItem;
+import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.substrate.ReflectiveHierarchyBuildItem;
+import io.quarkus.deployment.index.IndexingUtil;
+import io.quarkus.mongodb.panache.PanacheMongoEntity;
+import io.quarkus.mongodb.panache.PanacheMongoEntityBase;
+import io.quarkus.mongodb.panache.PanacheMongoRepository;
+import io.quarkus.mongodb.panache.PanacheMongoRepositoryBase;
+import io.quarkus.mongodb.panache.jackson.ObjectMapperProducer;
+import io.quarkus.mongodb.panache.jsonb.PanacheMongoJsonbContextResolver;
+import io.quarkus.panache.common.deployment.PanacheFieldAccessEnhancer;
+import io.quarkus.resteasy.common.spi.ResteasyJaxrsProviderBuildItem;
+
+public class PanacheResourceProcessor {
+ static final DotName DOTNAME_PANACHE_REPOSITORY_BASE = DotName.createSimple(PanacheMongoRepositoryBase.class.getName());
+ private static final DotName DOTNAME_PANACHE_REPOSITORY = DotName.createSimple(PanacheMongoRepository.class.getName());
+ static final DotName DOTNAME_PANACHE_ENTITY_BASE = DotName.createSimple(PanacheMongoEntityBase.class.getName());
+ private static final DotName DOTNAME_PANACHE_ENTITY = DotName.createSimple(PanacheMongoEntity.class.getName());
+
+ private static final DotName DOTNAME_OBJECT_ID = DotName.createSimple(ObjectId.class.getName());
+
+ @BuildStep(providesCapabilities = "io.quarkus.mongodb.panache")
+ FeatureBuildItem featureBuildItem() {
+ return new FeatureBuildItem(FeatureBuildItem.MONGODB_PANACHE);
+ }
+
+ @BuildStep
+ AdditionalBeanBuildItem registerJacksonSerDer(Capabilities capabilities) {
+ if (capabilities.isCapabilityPresent("io.quarkus.resteasy.jackson")) {
+ return AdditionalBeanBuildItem.unremovableOf(ObjectMapperProducer.class);
+ }
+ return null;
+ }
+
+ @BuildStep
+ ResteasyJaxrsProviderBuildItem registerJsonbSerDer(Capabilities capabilities) {
+ if (capabilities.isCapabilityPresent("io.quarkus.resteasy.jsonb")) {
+ return new ResteasyJaxrsProviderBuildItem(PanacheMongoJsonbContextResolver.class.getName());
+ }
+ return null;
+ }
+
+ @BuildStep
+ ReflectiveHierarchyBuildItem registerForReflection(CombinedIndexBuildItem index) {
+ Indexer indexer = new Indexer();
+ Set additionalIndex = new HashSet<>();
+ IndexingUtil.indexClass(ObjectId.class.getName(), indexer, index.getIndex(), additionalIndex,
+ PanacheResourceProcessor.class.getClassLoader());
+ CompositeIndex compositeIndex = CompositeIndex.create(index.getIndex(), indexer.complete());
+ Type type = Type.create(DOTNAME_OBJECT_ID, Type.Kind.CLASS);
+ return new ReflectiveHierarchyBuildItem(type, compositeIndex);
+ }
+
+ @BuildStep
+ void build(CombinedIndexBuildItem index,
+ ApplicationIndexBuildItem applicationIndex,
+ BuildProducer transformers) throws Exception {
+
+ PanacheMongoRepositoryEnhancer daoEnhancer = new PanacheMongoRepositoryEnhancer(index.getIndex());
+ Set daoClasses = new HashSet<>();
+ for (ClassInfo classInfo : index.getIndex().getAllKnownImplementors(DOTNAME_PANACHE_REPOSITORY_BASE)) {
+ // Skip PanacheRepository
+ if (classInfo.name().equals(DOTNAME_PANACHE_REPOSITORY))
+ continue;
+ daoClasses.add(classInfo.name().toString());
+ }
+ for (ClassInfo classInfo : index.getIndex().getAllKnownImplementors(DOTNAME_PANACHE_REPOSITORY)) {
+ daoClasses.add(classInfo.name().toString());
+ }
+ for (String daoClass : daoClasses) {
+ transformers.produce(new BytecodeTransformerBuildItem(daoClass, daoEnhancer));
+ }
+
+ PanacheMongoEntityEnhancer modelEnhancer = new PanacheMongoEntityEnhancer(index.getIndex());
+ Set modelClasses = new HashSet<>();
+ // Note that we do this in two passes because for some reason Jandex does not give us subtypes
+ // of PanacheMongoEntity if we ask for subtypes of PanacheMongoEntityBase
+ for (ClassInfo classInfo : index.getIndex().getAllKnownSubclasses(DOTNAME_PANACHE_ENTITY_BASE)) {
+ if (classInfo.name().equals(DOTNAME_PANACHE_ENTITY))
+ continue;
+ if (modelClasses.add(classInfo.name().toString()))
+ modelEnhancer.collectFields(classInfo);
+ }
+ for (ClassInfo classInfo : index.getIndex().getAllKnownSubclasses(DOTNAME_PANACHE_ENTITY)) {
+ if (modelClasses.add(classInfo.name().toString()))
+ modelEnhancer.collectFields(classInfo);
+ }
+ for (String modelClass : modelClasses) {
+ transformers.produce(new BytecodeTransformerBuildItem(modelClass, modelEnhancer));
+ }
+
+ if (!modelEnhancer.entities.isEmpty()) {
+ PanacheFieldAccessEnhancer panacheFieldAccessEnhancer = new PanacheFieldAccessEnhancer(
+ modelEnhancer.getModelInfo());
+ for (ClassInfo classInfo : applicationIndex.getIndex().getKnownClasses()) {
+ String className = classInfo.name().toString();
+ if (!modelClasses.contains(className)) {
+ transformers.produce(new BytecodeTransformerBuildItem(className, panacheFieldAccessEnhancer));
+ }
+ }
+ }
+ }
+}
diff --git a/extensions/panache/mongodb-panache/pom.xml b/extensions/panache/mongodb-panache/pom.xml
new file mode 100644
index 0000000000000..c10a0f718e2fb
--- /dev/null
+++ b/extensions/panache/mongodb-panache/pom.xml
@@ -0,0 +1,22 @@
+
+
+
+ quarkus-build-parent
+ io.quarkus
+ 999-SNAPSHOT
+ ../../../build-parent/pom.xml
+
+ 4.0.0
+
+ quarkus-mongodb-panache-parent
+ Quarkus - MongoDB with Panache - Parent
+ pom
+
+ runtime
+ deployment
+
+
+
+
\ No newline at end of file
diff --git a/extensions/panache/mongodb-panache/runtime/pom.xml b/extensions/panache/mongodb-panache/runtime/pom.xml
new file mode 100644
index 0000000000000..7e618e4a907ed
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/pom.xml
@@ -0,0 +1,95 @@
+
+
+
+ quarkus-mongodb-panache-parent
+ io.quarkus
+ 999-SNAPSHOT
+ ../
+
+ 4.0.0
+
+ quarkus-mongodb-panache
+ Quarkus - MongoDB with Panache - Runtime
+
+
+
+ io.quarkus
+ quarkus-core
+
+
+ io.quarkus
+ quarkus-panache-common
+
+
+ io.quarkus
+ quarkus-panacheql
+
+
+ io.quarkus
+ quarkus-mongodb-client
+
+
+
+
+ io.quarkus
+ quarkus-resteasy-jsonb
+ true
+
+
+
+
+ io.quarkus
+ quarkus-resteasy-jackson
+ true
+
+
+ org.junit.jupiter
+ junit-jupiter
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ test
+
+
+
+
+
+
+ io.quarkus
+ quarkus-bootstrap-maven-plugin
+
+
+
+ org.jboss.jandex
+ jandex-maven-plugin
+
+
+ make-index
+
+ jandex
+
+
+
+
+
+
+ ${project.build.directory}/classes
+
+
+ **/PanacheMongoJsonbContextResolver.class
+
+ **/ObjectMapperProducer.class
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/MongoEntity.java b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/MongoEntity.java
new file mode 100755
index 0000000000000..5fef718d89ab0
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/MongoEntity.java
@@ -0,0 +1,21 @@
+package io.quarkus.mongodb.panache;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * This annotation can be used to specify some configuration of the mapping of an entity to MongoDB.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+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
+ * quarkus.mongodb.database will be used.
+ */
+ String database() default "";
+}
diff --git a/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheMongoEntity.java b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheMongoEntity.java
new file mode 100755
index 0000000000000..c3ffb4437c151
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheMongoEntity.java
@@ -0,0 +1,30 @@
+package io.quarkus.mongodb.panache;
+
+import org.bson.types.ObjectId;
+
+/**
+ * Represents an entity with a generated ID field {@link #id} of type {@link ObjectId}. If your
+ * Mongo entities extend this class they gain the ID field and auto-generated accessors
+ * to all their public fields, as well as all the useful methods from {@link PanacheMongoEntityBase}.
+ *
+ * If you want a custom ID type or strategy, you can directly extend {@link PanacheMongoEntityBase}
+ * instead, and write your own ID field. You will still get auto-generated accessors and
+ * all the useful methods.
+ *
+ * @see PanacheMongoEntityBase
+ */
+public abstract class PanacheMongoEntity extends PanacheMongoEntityBase {
+
+ /**
+ * The auto-generated ID field.
+ * This field is set by Mongo when this entity is persisted.
+ *
+ * @see #persist()
+ */
+ public ObjectId id;
+
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName() + "<" + id + ">";
+ }
+}
diff --git a/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheMongoEntityBase.java b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheMongoEntityBase.java
new file mode 100755
index 0000000000000..c4ed06d9573cf
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheMongoEntityBase.java
@@ -0,0 +1,870 @@
+package io.quarkus.mongodb.panache;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import org.bson.Document;
+
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
+
+import io.quarkus.mongodb.panache.runtime.MongoOperations;
+import io.quarkus.panache.common.Parameters;
+import io.quarkus.panache.common.Sort;
+import io.quarkus.panache.common.impl.GenerateBridge;
+
+/**
+ * Represents an entity. If your Mongo entities extend this class they gain auto-generated accessors
+ * to all their public fields, as well as a lot of useful
+ * methods. Unless you have a custom ID strategy, you should not extend this class directly but extend
+ * {@link PanacheMongoEntity} instead.
+ *
+ * @see PanacheMongoEntity
+ */
+public abstract class PanacheMongoEntityBase {
+
+ // Operations
+
+ /**
+ * Persist this entity in the database.
+ * This will set it's ID field if not already set.
+ *
+ * @see #persist(Iterable)
+ * @see #persist(Stream)
+ * @see #persist(Object, Object...)
+ */
+ public void persist() {
+ MongoOperations.persist(this);
+ }
+
+ /**
+ * Update this entity in the database.
+ *
+ * @see #update(Iterable)
+ * @see #update(Stream)
+ * @see #update(Object, Object...)
+ */
+ public void update() {
+ MongoOperations.update(this);
+ }
+
+ /**
+ * Persist this entity in the database or update it if it already exist.
+ *
+ * @see #persistOrUpdate(Iterable)
+ * @see #persistOrUpdate(Stream)
+ * @see #persistOrUpdate(Object, Object...)
+ */
+ public void persistOrUpdate() {
+ MongoOperations.persistOrUpdate(this);
+ }
+
+ /**
+ * Delete this entity from the database, if it is already persisted.
+ *
+ * @see #delete(String, Object...)
+ * @see #delete(String, Map)
+ * @see #delete(String, Parameters)
+ * @see #deleteAll()
+ */
+ public void delete() {
+ MongoOperations.delete(this);
+ }
+
+ // Queries
+
+ /**
+ * Find an entity of this type by ID.
+ *
+ * @param id the ID of the entity to find.
+ * @return the entity found, or null if not found.
+ */
+ @GenerateBridge(targetReturnTypeErased = true)
+ public static T findById(Object id) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a query, with optional indexed parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params optional sequence of indexed parameters
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Sort, Object...)
+ * @see #find(String, Map)
+ * @see #find(String, Parameters)
+ * @see #list(String, Object...)
+ * @see #stream(String, Object...)
+ */
+ @GenerateBridge
+ public static PanacheQuery find(String query, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a query and the given sort options, with optional indexed parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params optional sequence of indexed parameters
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Object...)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Object...)
+ * @see #stream(String, Sort, Object...)
+ */
+ @GenerateBridge
+ public static PanacheQuery find(String query, Sort sort, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a query, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Map} of named parameters
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Object...)
+ * @see #find(String, Parameters)
+ * @see #list(String, Map)
+ * @see #stream(String, Map)
+ */
+ @GenerateBridge
+ public static PanacheQuery find(String query, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a query and the given sort options, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params {@link Map} of indexed parameters
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Map)
+ * @see #find(String, Sort, Object...)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Map)
+ * @see #stream(String, Sort, Map)
+ */
+ @GenerateBridge
+ public static PanacheQuery find(String query, Sort sort, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a query, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Parameters} of named parameters
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Sort, Parameters)
+ * @see #find(String, Map)
+ * @see #find(String, Parameters)
+ * @see #list(String, Parameters)
+ * @see #stream(String, Parameters)
+ */
+ @GenerateBridge
+ public static PanacheQuery find(String query, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a query and the given sort options, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params {@link Parameters} of indexed parameters
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public static PanacheQuery find(String query, Sort sort, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a BSON query.
+ *
+ * @param query a {@link org.bson.Document} query
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public static PanacheQuery find(Document query) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a a BSON query and a BSON sort.
+ *
+ * @param query a {@link org.bson.Document} query
+ * @param sort the {@link org.bson.Document} sort
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public static PanacheQuery find(Document query, Document sort) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find all entities of this type.
+ *
+ * @return a new {@link PanacheQuery} instance to find all entities of this type.
+ * @see #findAll(Sort)
+ * @see #listAll()
+ * @see #streamAll()
+ */
+ @GenerateBridge
+ public static PanacheQuery findAll() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find all entities of this type, in the given order.
+ *
+ * @param sort the sort order to use
+ * @return a new {@link PanacheQuery} instance to find all entities of this type.
+ * @see #findAll()
+ * @see #listAll(Sort)
+ * @see #streamAll(Sort)
+ */
+ @GenerateBridge
+ public static PanacheQuery findAll(Sort sort) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query, with optional indexed parameters.
+ * This method is a shortcut for find(query, params).list().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params optional sequence of indexed parameters
+ * @return a {@link List} containing all results, without paging
+ * @see #list(String, Sort, Object...)
+ * @see #list(String, Map)
+ * @see #list(String, Parameters)
+ * @see #find(String, Object...)
+ * @see #stream(String, Object...)
+ */
+ @GenerateBridge
+ public static List list(String query, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query and the given sort options, with optional indexed parameters.
+ * This method is a shortcut for find(query, sort, params).list().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params optional sequence of indexed parameters
+ * @return a {@link List} containing all results, without paging
+ * @see #list(String, Object...)
+ * @see #list(String, Sort, Map)
+ * @see #list(String, Sort, Parameters)
+ * @see #find(String, Sort, Object...)
+ * @see #stream(String, Sort, Object...)
+ */
+ @GenerateBridge
+ public static List list(String query, Sort sort, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query, with named parameters.
+ * This method is a shortcut for find(query, params).list().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Map} of named parameters
+ * @return a {@link List} containing all results, without paging
+ * @see #list(String, Sort, Map)
+ * @see #list(String, Object...)
+ * @see #list(String, Parameters)
+ * @see #find(String, Map)
+ * @see #stream(String, Map)
+ */
+ @GenerateBridge
+ public static List list(String query, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query and the given sort options, with named parameters.
+ * This method is a shortcut for find(query, sort, params).list().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params {@link Map} of indexed parameters
+ * @return a {@link List} containing all results, without paging
+ * @see #list(String, Map)
+ * @see #list(String, Sort, Object...)
+ * @see #list(String, Sort, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #stream(String, Sort, Map)
+ */
+ @GenerateBridge
+ public static List list(String query, Sort sort, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query, with named parameters.
+ * This method is a shortcut for find(query, params).list().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Parameters} of named parameters
+ * @return a {@link List} containing all results, without paging
+ * @see #list(String, Sort, Parameters)
+ * @see #list(String, Object...)
+ * @see #list(String, Map)
+ * @see #find(String, Parameters)
+ * @see #stream(String, Parameters)
+ */
+ @GenerateBridge
+ public static List list(String query, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query and the given sort options, with named parameters.
+ * This method is a shortcut for find(query, sort, params).list().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params {@link Parameters} of indexed parameters
+ * @return a {@link List} containing all results, without paging
+ * @see #list(String, Parameters)
+ * @see #list(String, Sort, Object...)
+ * @see #list(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public static List list(String query, Sort sort, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a BSON query.
+ * This method is a shortcut for find(query).list().
+ *
+ * @param query a {@link org.bson.Document} query
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public static List list(Document query) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a a BSON query and a BSON sort.
+ * This method is a shortcut for find(query, sort).list().
+ *
+ * @param query a {@link org.bson.Document} query
+ * @param sort the {@link org.bson.Document} sort
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public static List list(Document query, Document sort) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find all entities of this type.
+ * This method is a shortcut for findAll().list().
+ *
+ * @return a {@link List} containing all results, without paging
+ * @see #listAll(Sort)
+ * @see #findAll()
+ * @see #streamAll()
+ */
+ @GenerateBridge
+ public static List listAll() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find all entities of this type, in the given order.
+ * This method is a shortcut for findAll(sort).list().
+ *
+ * @param sort the sort order to use
+ * @return a {@link List} containing all results, without paging
+ * @see #listAll()
+ * @see #findAll(Sort)
+ * @see #streamAll(Sort)
+ */
+ @GenerateBridge
+ public static List listAll(Sort sort) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query, with optional indexed parameters.
+ * This method is a shortcut for find(query, params).stream().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params optional sequence of indexed parameters
+ * @return a {@link Stream} containing all results, without paging
+ * @see #stream(String, Sort, Object...)
+ * @see #stream(String, Map)
+ * @see #stream(String, Parameters)
+ * @see #find(String, Object...)
+ * @see #list(String, Object...)
+ */
+ @GenerateBridge
+ public static Stream stream(String query, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query and the given sort options, with optional indexed parameters.
+ * This method is a shortcut for find(query, sort, params).stream().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params optional sequence of indexed parameters
+ * @return a {@link Stream} containing all results, without paging
+ * @see #stream(String, Object...)
+ * @see #stream(String, Sort, Map)
+ * @see #stream(String, Sort, Parameters)
+ * @see #find(String, Sort, Object...)
+ * @see #list(String, Sort, Object...)
+ */
+ @GenerateBridge
+ public static Stream stream(String query, Sort sort, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query, with named parameters.
+ * This method is a shortcut for find(query, params).stream().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Map} of named parameters
+ * @return a {@link Stream} containing all results, without paging
+ * @see #stream(String, Sort, Map)
+ * @see #stream(String, Object...)
+ * @see #stream(String, Parameters)
+ * @see #find(String, Map)
+ * @see #list(String, Map)
+ */
+ @GenerateBridge
+ public static Stream stream(String query, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query and the given sort options, with named parameters.
+ * This method is a shortcut for find(query, sort, params).stream().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params {@link Map} of indexed parameters
+ * @return a {@link Stream} containing all results, without paging
+ * @see #stream(String, Map)
+ * @see #stream(String, Sort, Object...)
+ * @see #stream(String, Sort, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #list(String, Sort, Map)
+ */
+ @GenerateBridge
+ public static Stream stream(String query, Sort sort, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query, with named parameters.
+ * This method is a shortcut for find(query, params).stream().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Parameters} of named parameters
+ * @return a {@link Stream} containing all results, without paging
+ * @see #stream(String, Sort, Parameters)
+ * @see #stream(String, Object...)
+ * @see #stream(String, Map)
+ * @see #find(String, Parameters)
+ * @see #list(String, Parameters)
+ */
+ @GenerateBridge
+ public static Stream stream(String query, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query and the given sort options, with named parameters.
+ * This method is a shortcut for find(query, sort, params).stream().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params {@link Parameters} of indexed parameters
+ * @return a {@link Stream} containing all results, without paging
+ * @see #stream(String, Parameters)
+ * @see #stream(String, Sort, Object...)
+ * @see #stream(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public static Stream stream(String query, Sort sort, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a BSON query.
+ * This method is a shortcut for find(query).stream().
+ *
+ * @param query a {@link org.bson.Document} query
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public static Stream stream(Document query) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a a BSON query and a BSON sort.
+ * This method is a shortcut for find(query, sort).stream().
+ *
+ * @param query a {@link org.bson.Document} query
+ * @param sort the {@link org.bson.Document} sort
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public static Stream stream(Document query, Document sort) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find all entities of this type.
+ * This method is a shortcut for findAll().stream().
+ *
+ * @return a {@link Stream} containing all results, without paging
+ * @see #streamAll(Sort)
+ * @see #findAll()
+ * @see #listAll()
+ */
+ @GenerateBridge
+ public static Stream streamAll() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find all entities of this type, in the given order.
+ * This method is a shortcut for findAll(sort).stream().
+ *
+ * @param sort the sort order to use
+ * @return a {@link Stream} containing all results, without paging
+ * @see #streamAll()
+ * @see #findAll(Sort)
+ * @see #listAll(Sort)
+ */
+ @GenerateBridge
+ public static Stream streamAll(Sort sort) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Counts the number of this type of entity in the database.
+ *
+ * @return the number of this type of entity in the database.
+ * @see #count(String, Object...)
+ * @see #count(String, Map)
+ * @see #count(String, Parameters)
+ */
+ @GenerateBridge
+ public static long count() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Counts the number of this type of entity matching the given query, with optional indexed parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params optional sequence of indexed parameters
+ * @return the number of entities counted.
+ * @see #count()
+ * @see #count(String, Map)
+ * @see #count(String, Parameters)
+ */
+ @GenerateBridge
+ public static long count(String query, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Counts the number of this type of entity matching the given query, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Map} of named parameters
+ * @return the number of entities counted.
+ * @see #count()
+ * @see #count(String, Object...)
+ * @see #count(String, Parameters)
+ */
+ @GenerateBridge
+ public static long count(String query, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Counts the number of this type of entity matching the given query, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Parameters} of named parameters
+ * @return the number of entities counted.
+ * @see #count()
+ * @see #count(String, Object...)
+ * @see #count(String, Map)
+ */
+ @GenerateBridge
+ public static long count(String query, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Counts the number of this type of entity matching the given query
+ *
+ * @param query a {@link org.bson.Document} query
+ * @return he number of entities counted.
+ * @see #count()
+ * @see #count(String, Object...)
+ * @see #count(String, Map)
+ */
+ @GenerateBridge
+ public static long count(Document query) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Delete all entities of this type from the database.
+ *
+ * @return the number of entities deleted.
+ * @see #delete(String, Object...)
+ * @see #delete(String, Map)
+ * @see #delete(String, Parameters)
+ */
+ @GenerateBridge
+ public static long deleteAll() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Delete all entities of this type matching the given query, with optional indexed parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params optional sequence of indexed parameters
+ * @return the number of entities deleted.
+ * @see #deleteAll()
+ * @see #delete(String, Map)
+ * @see #delete(String, Parameters)
+ */
+ @GenerateBridge
+ public static long delete(String query, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Delete all entities of this type matching the given query, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Map} of named parameters
+ * @return the number of entities deleted.
+ * @see #deleteAll()
+ * @see #delete(String, Object...)
+ * @see #delete(String, Parameters)
+ */
+ @GenerateBridge
+ public static long delete(String query, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Delete all entities of this type matching the given query, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Parameters} of named parameters
+ * @return the number of entities deleted.
+ * @see #deleteAll()
+ * @see #delete(String, Object...)
+ * @see #delete(String, Map)
+ */
+ @GenerateBridge
+ public static long delete(String query, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Delete all entities of this type matching the given query
+ *
+ * @param query a {@link org.bson.Document} query
+ * @return he number of entities counted.
+ * @see #count()
+ * @see #count(String, Object...)
+ * @see #count(String, Map)
+ */
+ @GenerateBridge
+ public static long delete(Document query) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Insert all given entities.
+ *
+ * @param entities the entities to insert
+ * @see #persist()
+ * @see #persist(Stream)
+ * @see #persist(Object,Object...)
+ */
+ public static void persist(Iterable> entities) {
+ MongoOperations.persist(entities);
+ }
+
+ /**
+ * Insert all given entities.
+ *
+ * @param entities the entities to insert
+ * @see #persist()
+ * @see #persist(Iterable)
+ * @see #persist(Object,Object...)
+ */
+ public static void persist(Stream> entities) {
+ MongoOperations.persist(entities);
+ }
+
+ /**
+ * Insert all given entities.
+ *
+ * @param entities the entities to update
+ * @see #persist()
+ * @see #persist(Stream)
+ * @see #persist(Iterable)
+ */
+ public static void persist(Object firstEntity, Object... entities) {
+ MongoOperations.persist(firstEntity, entities);
+ }
+
+ /**
+ * Update all given entities.
+ *
+ * @param entities the entities to update
+ * @see #update()
+ * @see #update(Stream)
+ * @see #update(Object,Object...)
+ */
+ public static void update(Iterable> entities) {
+ MongoOperations.update(entities);
+ }
+
+ /**
+ * Update all given entities.
+ *
+ * @param entities the entities to insert
+ * @see #update()
+ * @see #update(Iterable)
+ * @see #update(Object,Object...)
+ */
+ public static void update(Stream> entities) {
+ MongoOperations.update(entities);
+ }
+
+ /**
+ * Update all given entities.
+ *
+ * @param entities the entities to update
+ * @see #update()
+ * @see #update(Stream)
+ * @see #update(Iterable)
+ */
+ public static void update(Object firstEntity, Object... entities) {
+ MongoOperations.update(firstEntity, entities);
+ }
+
+ /**
+ * Persist all given entities or update them if they already exist.
+ *
+ * @param entities the entities to update
+ * @see #persistOrUpdate()
+ * @see #persistOrUpdate(Stream)
+ * @see #persistOrUpdate(Object,Object...)
+ */
+ public static void persistOrUpdate(Iterable> entities) {
+ MongoOperations.persistOrUpdate(entities);
+ }
+
+ /**
+ * Persist all given entities.
+ *
+ * @param entities the entities to insert
+ * @see #persistOrUpdate()
+ * @see #persistOrUpdate(Iterable)
+ * @see #persistOrUpdate(Object,Object...)
+ */
+ public static void persistOrUpdate(Stream> entities) {
+ MongoOperations.persistOrUpdate(entities);
+ }
+
+ /**
+ * Persist all given entities.
+ *
+ * @param entities the entities to update
+ * @see #persistOrUpdate()
+ * @see #persistOrUpdate(Stream)
+ * @see #persistOrUpdate(Iterable)
+ */
+ public static void persistOrUpdate(Object firstEntity, Object... entities) {
+ MongoOperations.persistOrUpdate(firstEntity, entities);
+ }
+
+ /**
+ * Allow to access the underlying Mongo Collection.
+ */
+ @GenerateBridge
+ public static MongoCollection mongoCollection() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Allow to access the underlying Mongo Database.
+ */
+ @GenerateBridge
+ public static MongoDatabase mongoDatabase() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+}
diff --git a/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheMongoRepository.java b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheMongoRepository.java
new file mode 100755
index 0000000000000..8c259489ffd2f
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheMongoRepository.java
@@ -0,0 +1,15 @@
+package io.quarkus.mongodb.panache;
+
+import org.bson.types.ObjectId;
+
+/**
+ * Represents a Repository for a specific type of entity {@code Entity}, with an ID type
+ * of {@code ObjectId}. Implementing this repository will gain you the exact same useful methods
+ * that are on {@link PanacheMongoEntityBase}. If you have a custom ID strategy, you should
+ * implement {@link PanacheMongoRepositoryBase} instead.
+ *
+ * @param The type of entity to operate on
+ */
+public interface PanacheMongoRepository extends PanacheMongoRepositoryBase {
+
+}
diff --git a/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheMongoRepositoryBase.java b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheMongoRepositoryBase.java
new file mode 100755
index 0000000000000..c99958fd3df43
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheMongoRepositoryBase.java
@@ -0,0 +1,875 @@
+package io.quarkus.mongodb.panache;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import org.bson.Document;
+
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
+
+import io.quarkus.mongodb.panache.runtime.MongoOperations;
+import io.quarkus.panache.common.Parameters;
+import io.quarkus.panache.common.Sort;
+import io.quarkus.panache.common.impl.GenerateBridge;
+
+/**
+ * Represents a Repository for a specific type of entity {@code Entity}, with an ID type
+ * of {@code Id}. Implementing this repository will gain you the exact same useful methods
+ * that are on {@link PanacheMongoEntityBase}. Unless you have a custom ID strategy, you should not
+ * implement this interface directly but implement {@link PanacheMongoRepository} instead.
+ *
+ * @param The type of entity to operate on
+ * @param The ID type of the entity
+ * @see PanacheMongoRepository
+ */
+public interface PanacheMongoRepositoryBase {
+
+ // Operations
+
+ /**
+ * Persist the given entity in the database.
+ * This will set it's ID field if not already set.
+ *
+ * @param entity the entity to insert.
+ * @see #persist(Iterable)
+ * @see #persist(Stream)
+ * @see #persist(Object, Object...)
+ */
+ public default void persist(Entity entity) {
+ MongoOperations.persist(entity);
+ }
+
+ /**
+ * Update the given entity in the database.
+ *
+ * @param entity the entity to update.
+ * @see #update(Iterable)
+ * @see #update(Stream)
+ * @see #update(Object, Object...)
+ */
+ public default void update(Entity entity) {
+ MongoOperations.update(entity);
+ }
+
+ /**
+ * Persist the given entity in the database or update it if it already exist.
+ *
+ * @param entity the entity to update.
+ * @see #persistOrUpdate(Iterable)
+ * @see #persistOrUpdate(Stream)
+ * @see #persistOrUpdate(Object, Object...)
+ */
+ public default void persistOrUpdate(Entity entity) {
+ MongoOperations.persistOrUpdate(entity);
+ }
+
+ /**
+ * Delete the given entity from the database, if it is already persisted.
+ *
+ * @param entity the entity to delete.
+ * @see #delete(String, Object...)
+ * @see #delete(String, Map)
+ * @see #delete(String, Parameters)
+ * @see #deleteAll()
+ */
+ public default void delete(Entity entity) {
+ MongoOperations.delete(entity);
+ }
+
+ // Queries
+
+ /**
+ * Find an entity of this type by ID.
+ *
+ * @param id the ID of the entity to find.
+ * @return the entity found, or null if not found.
+ */
+ @GenerateBridge(targetReturnTypeErased = true)
+ public default Entity findById(Id id) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a query, with optional indexed parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params optional sequence of indexed parameters
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Sort, Object...)
+ * @see #find(String, Map)
+ * @see #find(String, Parameters)
+ * @see #list(String, Object...)
+ * @see #stream(String, Object...)
+ */
+ @GenerateBridge
+ public default PanacheQuery find(String query, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a query and the given sort options, with optional indexed parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params optional sequence of indexed parameters
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Object...)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Object...)
+ * @see #stream(String, Sort, Object...)
+ */
+ @GenerateBridge
+ public default PanacheQuery find(String query, Sort sort, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a query, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Map} of named parameters
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Object...)
+ * @see #find(String, Parameters)
+ * @see #list(String, Map)
+ * @see #stream(String, Map)
+ */
+ @GenerateBridge
+ public default PanacheQuery find(String query, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a query and the given sort options, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params {@link Map} of indexed parameters
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Map)
+ * @see #find(String, Sort, Object...)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Map)
+ * @see #stream(String, Sort, Map)
+ */
+ @GenerateBridge
+ public default PanacheQuery find(String query, Sort sort, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a query, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Parameters} of named parameters
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Sort, Parameters)
+ * @see #find(String, Map)
+ * @see #find(String, Parameters)
+ * @see #list(String, Parameters)
+ * @see #stream(String, Parameters)
+ */
+ @GenerateBridge
+ public default PanacheQuery find(String query, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a query and the given sort options, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params {@link Parameters} of indexed parameters
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public default PanacheQuery find(String query, Sort sort, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a BSON query.
+ *
+ * @param query a {@link org.bson.Document} query
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public default PanacheQuery find(Document query) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a a BSON query and a BSON sort.
+ *
+ * @param query a {@link org.bson.Document} query
+ * @param sort the {@link org.bson.Document} sort
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public default PanacheQuery find(Document query, Document sort) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find all entities of this type.
+ *
+ * @return a new {@link PanacheQuery} instance to find all entities of this type.
+ * @see #findAll(Sort)
+ * @see #listAll()
+ * @see #streamAll()
+ */
+ @GenerateBridge
+ public default PanacheQuery findAll() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find all entities of this type, in the given order.
+ *
+ * @param sort the sort order to use
+ * @return a new {@link PanacheQuery} instance to find all entities of this type.
+ * @see #findAll()
+ * @see #listAll(Sort)
+ * @see #streamAll(Sort)
+ */
+ @GenerateBridge
+ public default PanacheQuery findAll(Sort sort) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query, with optional indexed parameters.
+ * This method is a shortcut for find(query, params).list().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params optional sequence of indexed parameters
+ * @return a {@link List} containing all results, without paging
+ * @see #list(String, Sort, Object...)
+ * @see #list(String, Map)
+ * @see #list(String, Parameters)
+ * @see #find(String, Object...)
+ * @see #stream(String, Object...)
+ */
+ @GenerateBridge
+ public default List list(String query, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query and the given sort options, with optional indexed parameters.
+ * This method is a shortcut for find(query, sort, params).list().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params optional sequence of indexed parameters
+ * @return a {@link List} containing all results, without paging
+ * @see #list(String, Object...)
+ * @see #list(String, Sort, Map)
+ * @see #list(String, Sort, Parameters)
+ * @see #find(String, Sort, Object...)
+ * @see #stream(String, Sort, Object...)
+ */
+ @GenerateBridge
+ public default List list(String query, Sort sort, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query, with named parameters.
+ * This method is a shortcut for find(query, params).list().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Map} of named parameters
+ * @return a {@link List} containing all results, without paging
+ * @see #list(String, Sort, Map)
+ * @see #list(String, Object...)
+ * @see #list(String, Parameters)
+ * @see #find(String, Map)
+ * @see #stream(String, Map)
+ */
+ @GenerateBridge
+ public default List list(String query, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query and the given sort options, with named parameters.
+ * This method is a shortcut for find(query, sort, params).list().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params {@link Map} of indexed parameters
+ * @return a {@link List} containing all results, without paging
+ * @see #list(String, Map)
+ * @see #list(String, Sort, Object...)
+ * @see #list(String, Sort, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #stream(String, Sort, Map)
+ */
+ @GenerateBridge
+ public default List list(String query, Sort sort, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query, with named parameters.
+ * This method is a shortcut for find(query, params).list().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Parameters} of named parameters
+ * @return a {@link List} containing all results, without paging
+ * @see #list(String, Sort, Parameters)
+ * @see #list(String, Object...)
+ * @see #list(String, Map)
+ * @see #find(String, Parameters)
+ * @see #stream(String, Parameters)
+ */
+ @GenerateBridge
+ public default List list(String query, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query and the given sort options, with named parameters.
+ * This method is a shortcut for find(query, sort, params).list().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params {@link Parameters} of indexed parameters
+ * @return a {@link List} containing all results, without paging
+ * @see #list(String, Parameters)
+ * @see #list(String, Sort, Object...)
+ * @see #list(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public default List list(String query, Sort sort, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a BSON query.
+ * This method is a shortcut for find(query).list().
+ *
+ * @param query a {@link org.bson.Document} query
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public default PanacheQuery list(Document query) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a a BSON query and a BSON sort.
+ * This method is a shortcut for find(query, sort).list().
+ *
+ * @param query a {@link org.bson.Document} query
+ * @param sort the {@link org.bson.Document} sort
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public default PanacheQuery list(Document query, Document sort) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find all entities of this type.
+ * This method is a shortcut for findAll().list().
+ *
+ * @return a {@link List} containing all results, without paging
+ * @see #listAll(Sort)
+ * @see #findAll()
+ * @see #streamAll()
+ */
+ @GenerateBridge
+ public default List listAll() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find all entities of this type, in the given order.
+ * This method is a shortcut for findAll(sort).list().
+ *
+ * @param sort the sort order to use
+ * @return a {@link List} containing all results, without paging
+ * @see #listAll()
+ * @see #findAll(Sort)
+ * @see #streamAll(Sort)
+ */
+ @GenerateBridge
+ public default List listAll(Sort sort) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query, with optional indexed parameters.
+ * This method is a shortcut for find(query, params).stream().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params optional sequence of indexed parameters
+ * @return a {@link Stream} containing all results, without paging
+ * @see #stream(String, Sort, Object...)
+ * @see #stream(String, Map)
+ * @see #stream(String, Parameters)
+ * @see #find(String, Object...)
+ * @see #list(String, Object...)
+ */
+ @GenerateBridge
+ public default Stream stream(String query, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query and the given sort options, with optional indexed parameters.
+ * This method is a shortcut for find(query, sort, params).stream().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params optional sequence of indexed parameters
+ * @return a {@link Stream} containing all results, without paging
+ * @see #stream(String, Object...)
+ * @see #stream(String, Sort, Map)
+ * @see #stream(String, Sort, Parameters)
+ * @see #find(String, Sort, Object...)
+ * @see #list(String, Sort, Object...)
+ */
+ @GenerateBridge
+ public default Stream stream(String query, Sort sort, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query, with named parameters.
+ * This method is a shortcut for find(query, params).stream().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Map} of named parameters
+ * @return a {@link Stream} containing all results, without paging
+ * @see #stream(String, Sort, Map)
+ * @see #stream(String, Object...)
+ * @see #stream(String, Parameters)
+ * @see #find(String, Map)
+ * @see #list(String, Map)
+ */
+ @GenerateBridge
+ public default Stream stream(String query, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query and the given sort options, with named parameters.
+ * This method is a shortcut for find(query, sort, params).stream().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params {@link Map} of indexed parameters
+ * @return a {@link Stream} containing all results, without paging
+ * @see #stream(String, Map)
+ * @see #stream(String, Sort, Object...)
+ * @see #stream(String, Sort, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #list(String, Sort, Map)
+ */
+ @GenerateBridge
+ public default Stream stream(String query, Sort sort, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query, with named parameters.
+ * This method is a shortcut for find(query, params).stream().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Parameters} of named parameters
+ * @return a {@link Stream} containing all results, without paging
+ * @see #stream(String, Sort, Parameters)
+ * @see #stream(String, Object...)
+ * @see #stream(String, Map)
+ * @see #find(String, Parameters)
+ * @see #list(String, Parameters)
+ */
+ @GenerateBridge
+ public default Stream stream(String query, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities matching a query and the given sort options, with named parameters.
+ * This method is a shortcut for find(query, sort, params).stream().
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param sort the sort strategy to use
+ * @param params {@link Parameters} of indexed parameters
+ * @return a {@link Stream} containing all results, without paging
+ * @see #stream(String, Parameters)
+ * @see #stream(String, Sort, Object...)
+ * @see #stream(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public default Stream stream(String query, Sort sort, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a BSON query.
+ * This method is a shortcut for find(query).stream().
+ *
+ * @param query a {@link org.bson.Document} query
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public default PanacheQuery stream(Document query) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find entities using a a BSON query and a BSON sort.
+ * This method is a shortcut for find(query, sort).stream().
+ *
+ * @param query a {@link org.bson.Document} query
+ * @param sort the {@link org.bson.Document} sort
+ * @return a new {@link PanacheQuery} instance for the given query
+ * @see #find(String, Parameters)
+ * @see #find(String, Sort, Map)
+ * @see #find(String, Sort, Parameters)
+ * @see #list(String, Sort, Parameters)
+ * @see #stream(String, Sort, Parameters)
+ */
+ @GenerateBridge
+ public default PanacheQuery stream(Document query, Document sort) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find all entities of this type.
+ * This method is a shortcut for findAll().stream().
+ *
+ * @return a {@link Stream} containing all results, without paging
+ * @see #streamAll(Sort)
+ * @see #findAll()
+ * @see #listAll()
+ */
+ @GenerateBridge
+ public default Stream streamAll(Sort sort) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Find all entities of this type, in the given order.
+ * This method is a shortcut for findAll(sort).stream().
+ *
+ * @return a {@link Stream} containing all results, without paging
+ * @see #streamAll()
+ * @see #findAll(Sort)
+ * @see #listAll(Sort)
+ */
+ @GenerateBridge
+ public default Stream streamAll() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Counts the number of this type of entity in the database.
+ *
+ * @return the number of this type of entity in the database.
+ * @see #count(String, Object...)
+ * @see #count(String, Map)
+ * @see #count(String, Parameters)
+ */
+ @GenerateBridge
+ public default long count() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Counts the number of this type of entity matching the given query, with optional indexed parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params optional sequence of indexed parameters
+ * @return the number of entities counted.
+ * @see #count()
+ * @see #count(String, Map)
+ * @see #count(String, Parameters)
+ */
+ @GenerateBridge
+ public default long count(String query, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Counts the number of this type of entity matching the given query, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Map} of named parameters
+ * @return the number of entities counted.
+ * @see #count()
+ * @see #count(String, Object...)
+ * @see #count(String, Parameters)
+ */
+ @GenerateBridge
+ public default long count(String query, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Counts the number of this type of entity matching the given query, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Parameters} of named parameters
+ * @return the number of entities counted.
+ * @see #count()
+ * @see #count(String, Object...)
+ * @see #count(String, Map)
+ */
+ @GenerateBridge
+ public default long count(String query, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Counts the number of this type of entity matching the given query
+ *
+ * @param query a {@link org.bson.Document} query
+ * @return he number of entities counted.
+ * @see #count()
+ * @see #count(String, Object...)
+ * @see #count(String, Map)
+ */
+ @GenerateBridge
+ public default long count(Document query) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Delete all entities of this type from the database.
+ *
+ * @return the number of entities deleted.
+ * @see #delete(String, Object...)
+ * @see #delete(String, Map)
+ * @see #delete(String, Parameters)
+ */
+ @GenerateBridge
+ public default long deleteAll() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Delete all entities of this type matching the given query, with optional indexed parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params optional sequence of indexed parameters
+ * @return the number of entities deleted.
+ * @see #deleteAll()
+ * @see #delete(String, Map)
+ * @see #delete(String, Parameters)
+ */
+ @GenerateBridge
+ public default long delete(String query, Object... params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Delete all entities of this type matching the given query, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Map} of named parameters
+ * @return the number of entities deleted.
+ * @see #deleteAll()
+ * @see #delete(String, Object...)
+ * @see #delete(String, Parameters)
+ */
+ @GenerateBridge
+ public default long delete(String query, Map params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Delete all entities of this type matching the given query, with named parameters.
+ *
+ * @param query a {@link io.quarkus.mongodb.panache query string}
+ * @param params {@link Parameters} of named parameters
+ * @return the number of entities deleted.
+ * @see #deleteAll()
+ * @see #delete(String, Object...)
+ * @see #delete(String, Map)
+ */
+ @GenerateBridge
+ public default long delete(String query, Parameters params) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Delete all entities of this type matching the given query
+ *
+ * @param query a {@link org.bson.Document} query
+ * @return he number of entities counted.
+ * @see #count()
+ * @see #count(String, Object...)
+ * @see #count(String, Map)
+ */
+ @GenerateBridge
+ public default long delete(Document query) {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Persist all given entities.
+ *
+ * @param entities the entities to insert
+ * @see #persist(Object)
+ * @see #persist(Stream)
+ * @see #persist(Object,Object...)
+ */
+ public default void persist(Iterable entities) {
+ MongoOperations.persist(entities);
+ }
+
+ /**
+ * Persist all given entities.
+ *
+ * @param entities the entities to insert
+ * @see #persist(Object)
+ * @see #persist(Iterable)
+ * @see #persist(Object,Object...)
+ */
+ public default void persist(Stream entities) {
+ MongoOperations.persist(entities);
+ }
+
+ /**
+ * Persist all given entities.
+ *
+ * @param entities the entities to insert
+ * @see #persist(Object)
+ * @see #persist(Stream)
+ * @see #persist(Iterable)
+ */
+ public default void persist(Entity firstEntity, @SuppressWarnings("unchecked") Entity... entities) {
+ MongoOperations.persist(firstEntity, entities);
+ }
+
+ /**
+ * Update all given entities.
+ *
+ * @param entities the entities to update
+ * @see #update(Object)
+ * @see #update(Stream)
+ * @see #update(Object,Object...)
+ */
+ public default void update(Iterable entities) {
+ MongoOperations.update(entities);
+ }
+
+ /**
+ * Update all given entities.
+ *
+ * @param entities the entities to update
+ * @see #update(Object)
+ * @see #update(Iterable)
+ * @see #update(Object,Object...)
+ */
+ public default void update(Stream entities) {
+ MongoOperations.update(entities);
+ }
+
+ /**
+ * Update all given entities.
+ *
+ * @param entities the entities to update
+ * @see #update(Object)
+ * @see #update(Stream)
+ * @see #update(Iterable)
+ */
+ public default void update(Entity firstEntity, @SuppressWarnings("unchecked") Entity... entities) {
+ MongoOperations.update(firstEntity, entities);
+ }
+
+ /**
+ * Persist all given entities or update them if they already exist.
+ *
+ * @param entities the entities to update
+ * @see #persistOrUpdate(Object)
+ * @see #persistOrUpdate(Stream)
+ * @see #persistOrUpdate(Object,Object...)
+ */
+ public default void persistOrUpdate(Iterable entities) {
+ MongoOperations.persistOrUpdate(entities);
+ }
+
+ /**
+ * Persist all given entities or update them if they already exist.
+ *
+ * @param entities the entities to update
+ * @see #persistOrUpdate(Object)
+ * @see #persistOrUpdate(Iterable)
+ * @see #persistOrUpdate(Object,Object...)
+ */
+ public default void persistOrUpdate(Stream entities) {
+ MongoOperations.persistOrUpdate(entities);
+ }
+
+ /**
+ * Persist all given entities or update them if they already exist.
+ *
+ * @param entities the entities to update
+ * @see #update(Object)
+ * @see #update(Stream)
+ * @see #update(Iterable)
+ */
+ public default void persistOrUpdate(Entity firstEntity, @SuppressWarnings("unchecked") Entity... entities) {
+ MongoOperations.persistOrUpdate(firstEntity, entities);
+ }
+
+ /**
+ * Allow to access the underlying Mongo Collection
+ */
+ @GenerateBridge
+ public default MongoCollection mongoCollection() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+
+ /**
+ * Allow to access the underlying Mongo Database.
+ */
+ @GenerateBridge
+ public default MongoDatabase mongoDatabase() {
+ throw MongoOperations.implementationInjectionMissing();
+ }
+}
diff --git a/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheQuery.java b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheQuery.java
new file mode 100755
index 0000000000000..3ba5f0dd381cd
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/PanacheQuery.java
@@ -0,0 +1,157 @@
+package io.quarkus.mongodb.panache;
+
+import java.util.List;
+import java.util.stream.Stream;
+
+import io.quarkus.panache.common.Page;
+
+/**
+ * Interface representing an entity query, which abstracts the use of paging, getting the number of results, and
+ * operating on {@link List} or {@link Stream}.
+ *
+ * Instances of this interface cannot mutate the query itself or its parameters: only paging information can be
+ * modified, and instances of this interface can be reused to obtain multiple pages of results.
+ *
+ * @param The entity type being queried
+ */
+public interface PanacheQuery {
+
+ // Builder
+
+ /**
+ * Sets the current page.
+ *
+ * @param page the new page
+ * @return this query, modified
+ * @see #page(int, int)
+ * @see #page()
+ */
+ public PanacheQuery page(Page page);
+
+ /**
+ * Sets the current page.
+ *
+ * @param pageIndex the page index
+ * @param pageSize the page size
+ * @return this query, modified
+ * @see #page(Page)
+ * @see #page()
+ */
+ public PanacheQuery page(int pageIndex, int pageSize);
+
+ /**
+ * Sets the current page to the next page
+ *
+ * @return this query, modified
+ * @see #previousPage()
+ */
+ public PanacheQuery nextPage();
+
+ /**
+ * Sets the current page to the previous page (or the first page if there is no previous page)
+ *
+ * @return this query, modified
+ * @see #nextPage()
+ */
+ public PanacheQuery previousPage();
+
+ /**
+ * Sets the current page to the first page
+ *
+ * @return this query, modified
+ * @see #lastPage()
+ */
+ public PanacheQuery firstPage();
+
+ /**
+ * Sets the current page to the last page. This will cause reading of the entity count.
+ *
+ * @return this query, modified
+ * @see #firstPage()
+ * @see #count()
+ */
+ public PanacheQuery lastPage();
+
+ /**
+ * Returns true if there is another page to read after the current one.
+ * This will cause reading of the entity count.
+ *
+ * @return true if there is another page to read
+ * @see #hasPreviousPage()
+ * @see #count()
+ */
+ public boolean hasNextPage();
+
+ /**
+ * Returns true if there is a page to read before the current one.
+ *
+ * @return true if there is a previous page to read
+ * @see #hasNextPage()
+ */
+ public boolean hasPreviousPage();
+
+ /**
+ * Returns the total number of pages to be read using the current page size.
+ * This will cause reading of the entity count.
+ *
+ * @return the total number of pages to be read using the current page size.
+ */
+ public int pageCount();
+
+ /**
+ * Returns the current page.
+ *
+ * @return the current page
+ * @see #page(Page)
+ * @see #page(int,int)
+ */
+ public Page page();
+
+ // Results
+
+ /**
+ * Reads and caches the total number of entities this query operates on. This causes a database
+ * query with SELECT COUNT(*) and a query equivalent to the current query, minus
+ * ordering.
+ *
+ * @return the total number of entities this query operates on, cached.
+ */
+ public long count();
+
+ /**
+ * Returns the current page of results as a {@link List}.
+ *
+ * @return the current page of results as a {@link List}.
+ * @see #stream()
+ * @see #page(Page)
+ * @see #page()
+ */
+ public List list();
+
+ /**
+ * Returns the current page of results as a {@link Stream}.
+ *
+ * @return the current page of results as a {@link Stream}.
+ * @see #list()
+ * @see #page(Page)
+ * @see #page()
+ */
+ public Stream stream();
+
+ /**
+ * Returns the first result of the current page index. This ignores the current page size to fetch
+ * a single result.
+ *
+ * @return the first result of the current page index, or null if there are no results.
+ * @see #singleResult()
+ */
+ public T firstResult();
+
+ /**
+ * Executes this query for the current page and return a single result.
+ *
+ * @return the single result (throws if there is not exactly one)
+ * @see #firstResult()
+ */
+ public T singleResult();
+}
diff --git a/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jackson/ObjectIdDeserializer.java b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jackson/ObjectIdDeserializer.java
new file mode 100644
index 0000000000000..153959cea58a7
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jackson/ObjectIdDeserializer.java
@@ -0,0 +1,23 @@
+package io.quarkus.mongodb.panache.jackson;
+
+import java.io.IOException;
+
+import org.bson.types.ObjectId;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+
+public class ObjectIdDeserializer extends JsonDeserializer {
+
+ @Override
+ public ObjectId deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
+ throws IOException, JsonProcessingException {
+ String value = jsonParser.getValueAsString();
+ if (value != null) {
+ return new ObjectId(value);
+ }
+ return null;
+ }
+}
diff --git a/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jackson/ObjectIdSerializer.java b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jackson/ObjectIdSerializer.java
new file mode 100644
index 0000000000000..b474976094f9a
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jackson/ObjectIdSerializer.java
@@ -0,0 +1,20 @@
+package io.quarkus.mongodb.panache.jackson;
+
+import java.io.IOException;
+
+import org.bson.types.ObjectId;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+public class ObjectIdSerializer extends JsonSerializer {
+
+ @Override
+ public void serialize(ObjectId objectId, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
+ throws IOException {
+ if (objectId != null) {
+ jsonGenerator.writeString(objectId.toString());
+ }
+ }
+}
diff --git a/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jackson/ObjectMapperProducer.java b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jackson/ObjectMapperProducer.java
new file mode 100755
index 0000000000000..ccf41d8367add
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jackson/ObjectMapperProducer.java
@@ -0,0 +1,32 @@
+package io.quarkus.mongodb.panache.jackson;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Singleton;
+
+import org.bson.types.ObjectId;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+
+/**
+ * This ObjectMapperProducer will produce an ObjectMapper that will override the default one from resteasy-jackson.
+ *
+ * Note: to avoid automatically installing it, it is removed from the index via an exclusion on the Jandex Maven plugin.
+ * The PanacheResourceProcessor will include it as a CDI bean if the 'quarkus-resteasy-jackson' extension is used
+ * and it will replace the default ObjectMapperProducer.
+ */
+@ApplicationScoped
+public class ObjectMapperProducer {
+
+ @Singleton
+ @Produces
+ public ObjectMapper objectMapper() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ SimpleModule module = new SimpleModule("ObjectIdModule");
+ module.addSerializer(ObjectId.class, new ObjectIdSerializer());
+ module.addDeserializer(ObjectId.class, new ObjectIdDeserializer());
+ objectMapper.registerModule(module);
+ return objectMapper;
+ }
+}
diff --git a/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jsonb/ObjectIdDeserializer.java b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jsonb/ObjectIdDeserializer.java
new file mode 100644
index 0000000000000..9a2868983ea43
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jsonb/ObjectIdDeserializer.java
@@ -0,0 +1,20 @@
+package io.quarkus.mongodb.panache.jsonb;
+
+import java.lang.reflect.Type;
+
+import javax.json.bind.serializer.DeserializationContext;
+import javax.json.bind.serializer.JsonbDeserializer;
+import javax.json.stream.JsonParser;
+
+import org.bson.types.ObjectId;
+
+public class ObjectIdDeserializer implements JsonbDeserializer {
+ @Override
+ public ObjectId deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
+ String id = parser.getString();
+ if (id != null) {
+ return new ObjectId(id);
+ }
+ return null;
+ }
+}
diff --git a/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jsonb/ObjectIdSerializer.java b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jsonb/ObjectIdSerializer.java
new file mode 100644
index 0000000000000..74928d3299ba1
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jsonb/ObjectIdSerializer.java
@@ -0,0 +1,17 @@
+package io.quarkus.mongodb.panache.jsonb;
+
+import javax.json.bind.serializer.JsonbSerializer;
+import javax.json.bind.serializer.SerializationContext;
+import javax.json.stream.JsonGenerator;
+
+import org.bson.types.ObjectId;
+
+public class ObjectIdSerializer implements JsonbSerializer {
+
+ @Override
+ public void serialize(ObjectId obj, JsonGenerator generator, SerializationContext ctx) {
+ if (obj != null) {
+ generator.write(obj.toString());
+ }
+ }
+}
diff --git a/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jsonb/PanacheMongoJsonbContextResolver.java b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jsonb/PanacheMongoJsonbContextResolver.java
new file mode 100755
index 0000000000000..460015239f9b6
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jsonb/PanacheMongoJsonbContextResolver.java
@@ -0,0 +1,25 @@
+package io.quarkus.mongodb.panache.jsonb;
+
+import javax.json.bind.Jsonb;
+import javax.json.bind.JsonbBuilder;
+import javax.json.bind.JsonbConfig;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * This will provide serialization/deserialization of a MongoDB ObjectId as a String.
+ *
+ * Note: to avoid automatically installing it, it is removed from the index via an exclusion on the Jandex Maven plugin.
+ * The PanacheResourceProcessor will include it as a CDI bean if the 'quarus-resteasy-jsonb' extension is used
+ * and it will replace the default Jsonb ContextResolver.
+ */
+@Provider
+public class PanacheMongoJsonbContextResolver implements ContextResolver {
+
+ public Jsonb getContext(Class clazz) {
+ JsonbConfig config = new JsonbConfig();
+ config.withSerializers(new ObjectIdSerializer()).withDeserializers(new ObjectIdDeserializer());
+ return JsonbBuilder.create(config);
+ }
+
+}
diff --git a/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/package-info.java b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/package-info.java
new file mode 100644
index 0000000000000..a8008fb532476
--- /dev/null
+++ b/extensions/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/package-info.java
@@ -0,0 +1,70 @@
+/**
+ *
API usage
+ *
+ * Make your entities extend {@link io.quarkus.mongodb.panache.PanacheMongoEntity}, use public fields or getter/setter
+ * for your columns, use the existing operations defined as static methods on your entity class,
+ * and define custom ones as static methods on your entity class:
+ *
+ *
+ * public class Person extends PanacheMongoEntity {
+ * public String name;
+ * public LocalDate birth;
+ * public PersonStatus status;
+ *
+ * public static Person findByName(String name){
+ * return find("name", name).firstResult();
+ * }
+ *
+ * public static List<Person> findAlive(){
+ * return list("status", Status.Alive);
+ * }
+ *
+ * public static void deleteStefs(){
+ * delete("name", "Stef");
+ * }
+ * }
+ *
+ *
+ * You can also use {@link io.quarkus.mongodb.panache.PanacheMongoRepository} if you prefer the repository approach.
+ *
+ *
+ * You can use the @MongoEntity annotation to define the name of the MongoDB collection,
+ * otherwise it will be the name of your entity.
+ *
+ *
+ * The Mongo PojoCodec is used to serialize your entity to Bson Document, you can find more information on it's
+ * documentation page: https://mongodb.github.io/mongo-java-driver/3.10/bson/pojos/
+ * You can use the MongoDB annotations to control the mapping to the database : @BsonId,
+ * @BsonProperty("fieldName"), @BsonIgnore.
+ *
+ *
+ *
Simplified queries
+ *
+ *
+ * Normally, MongoDB queries are of this form: {"field1": "value1", "field2": "value2"}
+ *
+ *
+ * We support multiple convenience query implementations, this is what we called PanacheQL queries:
+ *
+ *
You can use one of the three flavours or parameterized query:
+ *
+ * They will all generates the same query : {"field": "value"}.
+ *
+ *
We support the following query operators: 'and', 'or' ( mixing 'and' and 'or' is not currently supported), '=',
+ * '>', '>=', '<', '<=', '!=', 'is null', 'is not null', and 'like' that is mapped to the MongoDB `$regex` operator.
+ *
field replacement is supported based on the value of the @BsonProperty annotations
+ *
+ *
+ *
+ * You can also write native MongoDB queries, in this case the field names are not replaced even if you use
+ * @BsonProperty, but you can still use parameterized queries by index or name.
+ * find("{'field':?1}", value) or find("{'field'::key}", value)
+ *